Reputation: 15
I have developed my application using xamarin forms default template. The application is working fine on all the devices below the Android 12. But running the app on android 12 in release mode it shows nothing and app is crashed, in debug mode application crash with the exception.
Java.Lang.IllegalArgumentException: 'com.infinity.estrats: 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 Plugin.Firebasepushnotifcation package for notification, I doubts this package is making some error. I have tried the code in mainApplication but didn't work.
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
Intent intent =new Intent(this,typeof(MainActivity));
FirebasePushNotificationManager.NotificationActivityFlags = ActivityFlags.ClearTop | ActivityFlags.SingleTop;
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";
// FirebasePushNotificationManager.NotificationActivityFlags = (Android.Content.ActivityFlags?)PendingIntentFlags.Mutable;
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
pendingIntent = PendingIntent.GetActivity(this,1337,intent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable);
//pendingintent.Send();
}
Upvotes: 1
Views: 1548
Reputation: 1631
I found this link to a Microsoft forum and it solved the problem for me. https://learn.microsoft.com/en-us/answers/questions/1141585/xamarin-forms-targeting-s-version-31-and-above-req.html
It basically says.. "You could add this Nuget package into your project Xamarin.AndroidX.Work.Runtime."
To get that nuget package to work I also had to update Xamarin.Forms to the latest version.
Upvotes: 2