Skip to content

Commit

Permalink
Fixes Android 12 missing FLAG_IMMUTABLE (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Aug 2, 2022
1 parent 9a08604 commit dc038e2
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public Notification getNotification(String title, String text, String largeIcon,
builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
}
if (largeIcon != null && !largeIcon.isEmpty()) {
builder.setLargeIcon(BitmapFactory.decodeResource(appContext.getResources(), mResolver.getDrawable(largeIcon)));
int largeIconId = mResolver.getDrawable(largeIcon);
if (largeIconId == 0) {
logger.warn("The resource " + largeIcon + " was not found in the drawable folder. Please include it when building the app.");
}
builder.setLargeIcon(BitmapFactory.decodeResource(appContext.getResources(), largeIconId));
}
if (color != null && !color.isEmpty()) {
builder.setColor(this.parseNotificationIconColor(color));
Expand All @@ -74,7 +78,10 @@ public Notification getNotification(String title, String text, String largeIcon,
if (launchIntent != null) {
// NOTICE: testing apps might not have registered launch intent
launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(appContext, 0, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT);
int flags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
? PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE
: PendingIntent.FLAG_CANCEL_CURRENT;
PendingIntent contentIntent = PendingIntent.getActivity(appContext, 0, launchIntent, flags);
builder.setContentIntent(contentIntent);
}

Expand Down

0 comments on commit dc038e2

Please sign in to comment.