GooglePlayServicesComponents
GooglePlayServicesComponents copied to clipboard
Google Cast failed on Android 12 - Missing Flag_Immutable
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):
- Run the app on Android 12
- Click on the Cast button
- Select the device
- 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)
I have the exact same issue
@valentin-debris @jpd21122012 Thanks for the feedback.
@valentin-debris And thanks for the repro sample. Helps a lot.
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 :/
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
- add nuget
Xamarin.AndroidX.Work.Runtime
2.7.1 (2.7.1.2) - or add
Xamarin.AndroidX.Media
1.4.1+ https://www.nuget.org/packages/Xamarin.AndroidX.Media/1.4.1 - 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); }
@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.
Hi @moljac, any news on this issue ? Thanks a lot for your feedback.
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.
It looks like #582 updates the Cast Framework to version 21.0.1. @moljac anything we can do to speed this up?
works only with netstandard 2.0, i'm working with 2.1
Same issue, can't use Cast