Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Google Cast failed on Android 12 - Missing Flag_Immutable #576

Open
valentin-debris opened this issue Feb 17, 2022 · 10 comments
Open

Google Cast failed on Android 12 - Missing Flag_Immutable #576

valentin-debris opened this issue Feb 17, 2022 · 10 comments

Comments

@valentin-debris
Copy link

Xamarin.Android Version

Minimum 5.0, Target 12.0

Operating System & Version

Windows 10 - Tested on real device Pixel 6 (Android 12.0)

Google Play Services Version

  • Xamarin.GooglePlayServices.Cast.Framework (version 120.0.0.3)
  • Xamarin.AndroidX.AppCompat (version 1.3.1.3)
  • Xamarin.AndroidX.MediaRouter (version 1.2.5.2)

Describe your Issue

With Android 12, the Cast crashes the app as soon as I select the device to Cast. Everything works well lower Android 12. I noticed that if I comment this line, it doesn't fail, but I can't do anything without that line !

Minimal Repro Code Sample

You can test with this example https://github.com/valentin-debris/XamarinTestCast

Steps to Reproduce (with link to sample solution if possible):

  1. Run the app on Android 12
  2. Click on the Cast button
  3. Select the device
  4. Cry because it crash !

Include any relevant Exception Stack traces, build logs, adb logs:

FATAL EXCEPTION: main
Process: com.companyname.testcast, PID: 25895
java.lang.IllegalArgumentException: com.companyname.testcast: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
 at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
 at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
 at com.google.an02-17 11:51:01.761 E/AndroidRuntime(25895):   at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
 at com.google.android.gms.internal.cast.zzch.zzb(com.google.android.gms:play-services-cast@@20.0.0:1)
 at com.google.android.gms.cast.framework.media.internal.zzp.zzb(com.google.android.gms:play-services-cast-framework@@20.0.0:10)
 at com.google.android.gms.cast.framework.CastSession.zzi(com.google.android.gms:play-services-cast-framework@@20.0.0:11)
 at com.google.android.gms.cast.framework.zzk.onComplete(com.google.android.gms:play-services-cast-framework@@20.0.0:1)
 at android.os.Handler.handleCallback(Handler.java:938)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loopOnce(Looper.java:201)
 at android.os.Looper.loop(Looper.java:288)
 at android.app.ActivityThread.main(ActivityThread.java:7839)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
@jpd21122012
Copy link

I have the exact same issue

@moljac
Copy link
Member

moljac commented Feb 25, 2022

@valentin-debris @jpd21122012 Thanks for the feedback.

@valentin-debris And thanks for the repro sample. Helps a lot.

@valentin-debris
Copy link
Author

Hello @moljac , any news about this issue ?
Until a fix, we have to disable this functionnality in our app for OS12, which is not good for our customers that upgrade and miss it now :/

@moljac
Copy link
Member

moljac commented Mar 7, 2022

Hello @moljac , any news about this issue ?

Sorry, but no. Nothing yet. Trying to catch up with updates - a lot of new dependencies.

Until a fix, we have to disable this functionnality in our app for OS12, which is not good for our customers that upgrade and miss it now :/

OK from here (quick search):

https://stackoverflow.com/questions/68473542/mediasessioncompattargeting-s-version-31-and-above-requires-that-one-of-flag

Workarounds to try

  1. add nuget Xamarin.AndroidX.Work.Runtime 2.7.1 (2.7.1.2)
  2. or add Xamarin.AndroidX.Media 1.4.1+
    https://www.nuget.org/packages/Xamarin.AndroidX.Media/1.4.1
  3. or try adding this snippet, but ported to c#
    PendingIntent pendingIntent = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
        pendingIntent = PendingIntent.getActivity
               (this, 0, notificationIntent, PendingIntent.FLAG_MUTABLE);
    }
    else
    {
         pendingIntent = PendingIntent.getActivity
                (this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
    }

@valentin-debris
Copy link
Author

@moljac , with my repo for testing, I tryed the first 2 solutions and they failed, same error. And the third one, I can't use it since the place where PendingIntent.getActivity() is not in my code, but somewhere in GooglePlayServicesComponents I guess.

@florian-magina
Copy link

Hi @moljac, any news on this issue ? Thanks a lot for your feedback.

@janwiebe-jump
Copy link

janwiebe-jump commented Mar 28, 2022

I assume I have 'mitigated' this issue, by disabling the Cast notification when running on Android 12, by passing null into the CastMediaOptions.Bulder's SetNotificaiitonOptions() in my CastOptionsProvider.
Maybe this is of some help to anybody here.

However, I prefer an update of the bindings to the latest version to be able to use the notification as well.

Unfortunately the sample above doesn't work.

@janwiebe-jump
Copy link

It looks like #582 updates the Cast Framework to version 21.0.1.
@moljac anything we can do to speed this up?

@gjlozano
Copy link

gjlozano commented Aug 30, 2022

works only with netstandard 2.0, i'm working with 2.1

@ivs88
Copy link

ivs88 commented Apr 18, 2023

Same issue, can't use Cast

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

Successfully merging a pull request may close this issue.

7 participants