Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using on android 12 #55

Open
GastonVottero opened this issue Feb 13, 2023 · 6 comments
Open

Problem using on android 12 #55

GastonVottero opened this issue Feb 13, 2023 · 6 comments

Comments

@GastonVottero
Copy link

Problem situation

The problem arises when increasing the SDK version of the application to be published on the play store. If the SDK version is increased, the application stops on android 12 devices when trying to send a video to play on chromecast.

After investigation, it was discovered that the play-services-cast-framework version should be migrated to 20.1.0 (https://developers.google.com/cast/docs/release-notes#november-16,-2021).

A copy of the project was downloaded, the dependencies were migrated and a test was carried out with partially positive results. It was possible to send a video to play on the chromecast and also to run the basic actions of: pause, play and stop.

A complete test was carried out and it was found that when trying to use the showController() function on any android device, the application fails with no chances of recovery.

Console error: Unable to instantiate activity ComponentInfo{.../com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity}: java.lang.InstantiationException: java.lang.Class<com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity> cannot be instantiated.

Which platform(s) does your issue occur on?

The problem occurs on any Android 12 devices or higher versions

How to reproduce the problem?

Run the demo project on an Android 12 device and send a video to play on Chromecast. The application fails with the next error message: requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
If changes of the play-services-cast-framework are performed, this error disappears but the one explained before appears (Console error: Unable to instantiate activity).

Steps that led me to the error message: "Unable to instantiate activity...":

  • I updated the include.gradle of the plugin:

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.mediarouter:mediarouter:1.2.5'
implementation 'com.google.android.gms:play-services-cast-framework:20.1.0'
}

  • app.gradle of the application:

compileSdkVersion 31
defaultConfig {
minSdkVersion 17
targetSdkVersion 31
generatedDensities = []
}

  • I Compiled and run the project on a device.
  • I connected to chromecast.
  • I sent a video to be played.
  • I pressed the Show controller button ((onTap)="handleShowControllerTap()")

Additional data.

Angular version 14.0.0
Nativescript version 8.3.3

@lochstar
Copy link
Owner

Hey @GastonVottero thanks for checking this out. It looks like you're on the right track bumping up those versions.

I'm guessing there's been some API changes which is why you're seeing the crash. My Android phone doesn't support version 12 and I'm not sure when I'll get around to trying it on an emulator. Does it work on Android 11 with the included updates?

@GastonVottero
Copy link
Author

GastonVottero commented Feb 15, 2023

Hi, thanks a lot for your quick reply, @lochstar. In higher versions, the application works on the different devices that I have tested on(Andorid 6, andorid 9, andorid 12). but the problem comes with the showController() function. It stops the device without recovery possibility (this happened in all the tested devices).

Without performing the version changes, the application works on the first android version up to android 11. my users informed me that the problem is in android 12 and 13, giving the error of FLAG_IMMUTABLE or FLAG_MUTABLE when debugging

I don't know if this information will help you.

After looking a little deeper into the plugin, I noticed that the problem seems to come from using startActivity(ExpandedControllerActivity.class). It seems that the class was not initialized at that point but I don't know why.

Although that's what I've managed to interpret with my basic knowledge of java so far.

@justinbeatz
Copy link

Hi, there are some API changes in the latest version of the SDK, now you need to subclass ExpandedControllerActivity since its an abstract class, that is why this error is popping out and will not work after updating the library in the include.gradle which is necessary to avoid the FLAG_INMUTABLE error. I hope this helps.

@maddy2get
Copy link

Hey @GastonVottero / @justinbeatz, would you please share how you fixed the Android showController function, I am having the same issue, any help is appreciated. Thanks

@justinbeatz
Copy link

Sure, I just created 2 files, one called ExpandedControlsActivity.java inside my project in App_Resources/Android/src/main/java/org/nativescript/cast then added this code which I got from https://developers.google.com/android/reference/com/google/android/gms/cast/framework/media/widget/ExpandedControllerActivity

package org.nativescript.cast;

import com.google.android.gms.cast.framework.CastButtonFactory;
import com.google.android.gms.cast.framework.media.widget.ExpandedControllerActivity;
import android.view.Menu;
import android.content.res.Resources;
import yourprojectpackage.R;

public class ExpandedControlsActivity extends ExpandedControllerActivity {
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        Resources r = ExpandedControlsActivity.this.getResources();
        int mediaRouteItem = r.getIdentifier("media_route_menu_item", "id", getPackageName());
        getMenuInflater().inflate(R.menu.expanded_controller, menu);
        CastButtonFactory.setUpMediaRouteButton(this, menu, mediaRouteItem);
        return true;
    }
}

And added this in the res/menu folder:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
            android:id="@+id/media_route_menu_item"
            android:title="@string/media_route_menu_title"
            app:actionProviderClass="androidx.mediarouter.app.MediaRouteActionProvider"
            android:orderInCategory="101"
            app:showAsAction="always"/>
</menu>

I hope this works for you.

@maddy2get
Copy link

Great, thanks, this helps a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants