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
I can’t update the pending intent flag in android studio project coding
This is a place in AlarmPingSender.java where the error occurred
public void start()
{
String action = MqttServiceConstants.PING_SENDER
+ comms.getClient().getClientId();
Log.d(TAG, "Register alarmreceiver to MqttService"+ action);
service.registerReceiver(alarmReceiver, new IntentFilter(action));
pendingIntent = PendingIntent.getBroadcast(service, 0, new Intent(
action), PendingIntent.FLAG_UPDATE_CURRENT);
schedule(comms.getKeepAlive());
hasStarted = true;
}
Help me to fix the issue ERROR IN ANDROID STUDIO IMAGE
4
Answers
You need to do this:
Since you are using
AlarmManager
you should be able to use theIMMUTABLE
flag.Use this two public methods when you want to create any
PendingIntent
in your projectCreate activity pendingIntent
Create broadcast pendingIntent
Kotlin answer:
I had the same issue, and adding JUST the IMMUTABLE flag to my PendingIntents did not work for some reason.
Please make sure that in app/build.gradle, you have at least the 2.7.1 work manager version (If you’re also using WorkManager inside the app):
implementation ‘androidx.work:work-runtime:2.7.1’
I had 1.0.3. After upgrading to this (or latest version), the problem was solved.
If you are not using
PendingIntent
anywhere in your code but still get this error, chances are that one of your library dependencies does so just update your dependencies to their latest versions (its what worked for me)