Reputation: 51
App crashes at runtime with the following error :
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 tried all solutions available but the app still crashing on Android 12.
private Notification buildNotification() {
int playButtonResId = isPaused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp;
PendingIntent clickIntent = PendingIntent.getActivity(
this, 1,
new Intent(this, MainActivity.class),
PendingIntent.FLAG_IMMUTABLE);
Upvotes: 5
Views: 1036
Reputation: 1
PendingIntent clickIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
clickIntent = PendingIntent.getActivity(
getApplicationContext(),
1,
intent,
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT
);
} else {
clickIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0);
}
Upvotes: -2