From dec5c4470c1735b524b8e253d314b3990656d8f5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 22 Sep 2022 17:39:27 -0300 Subject: [PATCH] Regression: Push notifications not working after update to Android 12 (#4532) * Remove unnecessary method from custom push notification * Use immutable * Maybe --- .../rocket/reactnative/CustomPushNotification.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java index 9311f7ebd..e8090c3ae 100644 --- a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java +++ b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java @@ -1,5 +1,7 @@ package chat.rocket.reactnative; +import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME; + import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -35,8 +37,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME; - public class CustomPushNotification extends PushNotification { public static ReactApplicationContext reactApplicationContext; final NotificationManager notificationManager; @@ -322,7 +322,12 @@ public class CustomPushNotification extends PushNotification { replyIntent.setAction(KEY_REPLY); replyIntent.putExtra("pushNotification", bundle); - PendingIntent replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent replyPendingIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + } else { + replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); + } RemoteInput remoteInput = new RemoteInput.Builder(KEY_REPLY) .setLabel(label) @@ -343,7 +348,7 @@ public class CustomPushNotification extends PushNotification { Intent intent = new Intent(mContext, DismissNotification.class); intent.putExtra(NOTIFICATION_ID, notificationId); - PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, intent, 0); + PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); notification.setDeleteIntent(dismissPendingIntent); }