innom
innom

Reputation: 1125

XAMARIN.FORMS Android: FLAG_IMMUTABLE needs to be set when targeting Android S+

Ive seen this issue a few times now, but never for xamarin.forms:

When I am trying to deploy on android 12 I am getting:

com.interiorcircle.interiorcircledroid: 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.

Here in picture: enter image description here

Appearently, a flag needs to be set, but I cannot figure out where.

Anyone has some help here?

Upvotes: 11

Views: 9605

Answers (3)

Inaki Quintero
Inaki Quintero

Reputation: 69

It was resolved by updating the nuget (Xamarin.AndroidX.Work.Runtime ) with the most current version in the Android project.

https://www.nuget.org/packages/Xamarin.AndroidX.Work.Runtime/

Upvotes: 1

Namsiz
Namsiz

Reputation: 91

In my case following code has fixed the runtime error:

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingActivityIntent = PendingIntent.GetActivity(Application.Context, requestCode, activityIntent, pendingIntentFlags);
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, requestCode, intent, pendingIntentFlags);

Upvotes: 9

Ivan I
Ivan I

Reputation: 9990

If you cannot figure out where then you probably don't use PendingIntent in your code.

In that case it means that some of the packages that you use is using this code and they need to fix it. Possibly you need to report the problem to them if they are not already aware of it.

Upvotes: 2

Related Questions