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
Ravikant SahuPosted Aug 10, 2023, 12:54 PM
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);
}
Tuhin PaulPosted Feb 19, 2023, 9:07 PM
This error message is related to the
PendingIntentflags when creating a PendingIntent object. According to the error message, when targeting Android S+ (version 31 and above), you need to specify one of the flagsFLAG_IMMUTABLEorFLAG_MUTABLEwhen creating a PendingIntent object.FLAG_IMMUTABLEindicates that the PendingIntent should be immutable, andFLAG_MUTABLEindicates that the PendingIntent should be mutable. MutablePendingIntentobjects can be used with inline replies or bubbles.So, if your app targets Android S+ and you are creating a
PendingIntentobject, you should use one of these flags when creating thePendingIntent. In your case, you usedPendingIntent.FLAG_IMMUTABLEbut still received the error. This might be because thePendingIntentis used in a way that requires it to be mutable.To resolve the issue, you can try using
PendingIntent.FLAG_MUTABLEinstead ofPendingIntent.FLAG_IMMUTABLE. However, if your app does not require the PendingIntent to be mutable, it is better to usePendingIntent.FLAG_IMMUTABLEfor better security.