Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit 954cac2

Browse files
authored
Merge pull request #397 from rafaelmaeuer/dev/fix-android-12-pending-intent-mutability
Fix Android Apps crashing when targeting v12 / SDK31
2 parents 8edd66c + b14e006 commit 954cac2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

android/src/main/java/com/tanguyantoine/react/MusicControlNotification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ public synchronized Notification prepareNotification(NotificationCompat.Builder
108108
String packageName = context.getPackageName();
109109
Intent openApp = context.getPackageManager().getLaunchIntentForPackage(packageName);
110110
try {
111-
builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, 0));
111+
builder.setContentIntent(PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_IMMUTABLE));
112112
}catch(Exception e){
113113
System.out.println(e.getMessage());
114114
}
115115

116116
// Remove notification
117117
Intent remove = new Intent(REMOVE_NOTIFICATION);
118118
remove.putExtra(PACKAGE_NAME, context.getApplicationInfo().packageName);
119-
builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, remove, PendingIntent.FLAG_UPDATE_CURRENT));
119+
builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, remove, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
120120

121121
return builder.build();
122122
}
@@ -176,7 +176,7 @@ private NotificationCompat.Action createAction(String iconName, String title, lo
176176
Intent intent = new Intent(MEDIA_BUTTON);
177177
intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
178178
intent.putExtra(PACKAGE_NAME, packageName);
179-
PendingIntent i = PendingIntent.getBroadcast(context, keyCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
179+
PendingIntent i = PendingIntent.getBroadcast(context, keyCode, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
180180

181181
return new NotificationCompat.Action(icon, title, i);
182182
}

0 commit comments

Comments
 (0)