Reputation: 3716
I am getting the below error for my xamarin forms application on version 31 and above.
com.mycompanyname.myappname: 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. [ImeFocusController] onWindowFocus: DecorView@74e918a[MainActivity] softInputMode=STATE_UNSPECIFIED|ADJUST_RESIZE|IS_FORWARD_NAVIGATION [ImeFocusController] Restarting due to isRestartOnNextWindowFocus as true [ImeFocusController] onViewFocusChanged, view=DecorView@74e918a[MainActivity], mServedView=null [ImeFocusController] checkFocus: view=null next=DecorView@74e918a[MainActivity] force=true package= The thread 0xb has exited with code 0 (0x0). [AndroidRuntime] FATAL EXCEPTION: pool-2-thread-1 [AndroidRuntime] Process: com.mycompanyname.myappname, PID: 7466 [AndroidRuntime] java.lang.IllegalArgumentException: com.mycompanyname.myappname: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. [AndroidRuntime] 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. [AndroidRuntime] at android.app.PendingIntent.checkFlags(PendingIntent.java:375) [AndroidRuntime] at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) [AndroidRuntime] at android.app.PendingIntent.getBroadcast(PendingIntent.java:632) [AndroidRuntime] at com.google.firebase.iid.zzl.zzd(Unknown Source:18) [AndroidRuntime] at com.google.firebase.iid.zzl.zzb(Unknown Source:229) [AndroidRuntime] at com.google.firebase.iid.zzl.zza(Unknown Source:0) [AndroidRuntime] at com.google.firebase.iid.zzj.zzb(Unknown Source:41) [AndroidRuntime] at com.google.firebase.iid.zzj.getToken(Unknown Source:56) [AndroidRuntime] at com.google.firebase.iid.FirebaseInstanceId.getToken(Unknown Source:10) [AndroidRuntime] at com.google.firebase.iid.FirebaseInstanceId.zzcfy(Unknown Source:4) [AndroidRuntime] at com.google.firebase.iid.FirebaseInstanceIdService.zza(Unknown Source:148) [AndroidRuntime] at com.google.firebase.iid.FirebaseInstanceIdService.handleIntent(Unknown Source:122) [AndroidRuntime] at com.google.firebase.iid.zzc.run(Unknown Source:4) [AndroidRuntime] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) [AndroidRuntime] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) [AndroidRuntime] at java.lang.Thread.run(Thread.java:920) Thread started: #12 Java.Lang.IllegalArgumentException: 'com.mycompanyname.myappname: 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.'
I am using pendingIntent on my project for FCM.
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
I tried FLAG_IMMUTABLE
and FLAG_MUTABLE
instead of OneShot
, but app is breaking. I commented the entire code related to FCM, but after that also, the app is breaking with the same issue.
I tried updating the FCM related Packages, that also don't work. Any other olutions?
Upvotes: 3
Views: 1966
Reputation: 13899
You can recheck your problem by following steps as follows:
1.try to update all your firebase libraries and google libraries to the latest;
2.try to add PendingIntent.FLAG_IMMUTABLE
to your pending intents.
Here is an example :
var intent = new Intent(this,typeof(MainActivity));
var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
: PendingIntentFlags.UpdateCurrent;
var pendingActivityIntent = PendingIntent.GetActivity(Application.Context, requestCode, intent, pendingIntentFlags);
For more information, you can check this link: PendingIntent#FLAG_IMMUTABLE
3.check if you have installed the latest nuget Xamarin.AndroidX.work.runtime;
Upvotes: 3