Java.Lang.IllegalArgumentException: 'com.isaweb.ojtqr: 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.'
Loading

Kiflay TeweldebrhanePosted Jul 13, 2023, 6:47 PM
Hey Nimish,
I still have the same issue. I am not even using the PendingIntent. below is the code on my create
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; string sqlLiteName = *; InstallDatabase(sqlLiteName); base.OnCreate(savedInstanceState); Rg.Plugins.Popup.Popup.Init(this); MobileAds.Initialize(Android.App.Application.Context); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); CreateNotificationFromIntent(Intent); MobileAds.Initialize(ApplicationContext); } protected override void OnNewIntent(Intent intent) { CreateNotificationFromIntent(intent); PendingIntent pendingIntent; if (Build.VERSION.SdkInt >= BuildVersionCodes.S) { pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Immutable); } else { pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); } } } Will this code work eventhough I am not calling the pendingIntent
Ravikant SahuPosted Jun 13, 2023, 4:32 AM
I got the same error in my project because of "Starting with
Build.VERSION_CODES.S (Android 12), it will be required to explicitly specify the mutability of Pending Intent" and solved with replacing the code by below-Before code-
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) (Math.random() * 10000), notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
Replace code-
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, (int) (Math.random() * 10000), notificationIntent, PendingIntent.FLAG_IMMUTABLE);
}else{
pendingIntent = PendingIntent.getActivity(this, (int) (Math.random() * 10000), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Nimish SaxenaPosted Apr 11, 2023, 4:58 AM
Does any one have a better solutoin?
Nimish SaxenaPosted Apr 10, 2023, 11:28 AM
I tried but still this error ocurred..
Tuhin PaulPosted Feb 17, 2023, 7:31 PM
Hi Nimish,
I think this exception is thrown by the Android operating system when you are trying to create a PendingIntent that targets Android API level 31 (Android 12) or higher, but you haven't specified one of the flags FLAG_IMMUTABLE or FLAG_MUTABLE.
Starting from Android API level 31, PendingIntent objects are required to be either immutable or mutable. This means that you must specify either FLAG_IMMUTABLE or FLAG_MUTABLE when creating a PendingIntent.
Here's an example of how to create a PendingIntent with the FLAG_IMMUTABLE flag:
In this example, the GetBroadcast method is used to create a broadcast PendingIntent with the FLAG_IMMUTABLE flag.
If you need to create a mutable PendingIntent, you can use the FLAG_MUTABLE flag:
Note that you should only use the FLAG_MUTABLE flag if your functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
By specifying one of these flags, you will avoid the Java.Lang.IllegalArgumentException when targeting Android API level 31 or higher. I this my assumption, please let me know if it works for you.