From 71cbea14da07ab214710d05638b3c489a3f372c5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 15 Sep 2022 14:36:31 -0300 Subject: [PATCH 1/3] Remove unnecessary method from custom push notification --- .../rocket/reactnative/CustomPushNotification.java | 10 ---------- 1 file changed, 10 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 9311f7ebd97..0657b40d907 100644 --- a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java +++ b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java @@ -133,7 +133,6 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) { notificationColor(notification); notificationChannel(notification); notificationIcons(notification, bundle); - notificationDismiss(notification, notificationId); // if notificationType is null (RC < 3.5) or notificationType is different of message-id-only or notification was loaded successfully if (ejson.notificationType == null || !ejson.notificationType.equals("message-id-only") || notificationLoaded) { @@ -339,15 +338,6 @@ private void notificationReply(Notification.Builder notification, int notificati .addAction(replyAction); } - private void notificationDismiss(Notification.Builder notification, int notificationId) { - Intent intent = new Intent(mContext, DismissNotification.class); - intent.putExtra(NOTIFICATION_ID, notificationId); - - PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, intent, 0); - - notification.setDeleteIntent(dismissPendingIntent); - } - private void notificationLoad(Ejson ejson, Callback callback) { LoadNotification.load(reactApplicationContext, ejson, callback); } From 653068d50c7b99cd08d6f8d5c91d3753c19f9685 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 15 Sep 2022 14:59:51 -0300 Subject: [PATCH 2/3] Use immutable --- .../chat/rocket/reactnative/CustomPushNotification.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 0657b40d907..8b64674d32b 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.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; @@ -321,7 +321,7 @@ private void notificationReply(Notification.Builder notification, int notificati replyIntent.setAction(KEY_REPLY); replyIntent.putExtra("pushNotification", bundle); - PendingIntent replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_IMMUTABLE); RemoteInput remoteInput = new RemoteInput.Builder(KEY_REPLY) .setLabel(label) From 9031f408a4016397fc964df0c22ac99f86f8a238 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 15 Sep 2022 15:53:02 -0300 Subject: [PATCH 3/3] Maybe --- .../reactnative/CustomPushNotification.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 8b64674d32b..e8090c3ae95 100644 --- a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java +++ b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java @@ -133,6 +133,7 @@ protected Notification.Builder getNotificationBuilder(PendingIntent intent) { notificationColor(notification); notificationChannel(notification); notificationIcons(notification, bundle); + notificationDismiss(notification, notificationId); // if notificationType is null (RC < 3.5) or notificationType is different of message-id-only or notification was loaded successfully if (ejson.notificationType == null || !ejson.notificationType.equals("message-id-only") || notificationLoaded) { @@ -321,7 +322,12 @@ private void notificationReply(Notification.Builder notification, int notificati replyIntent.setAction(KEY_REPLY); replyIntent.putExtra("pushNotification", bundle); - PendingIntent replyPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, replyIntent, PendingIntent.FLAG_IMMUTABLE); + 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) @@ -338,6 +344,15 @@ private void notificationReply(Notification.Builder notification, int notificati .addAction(replyAction); } + private void notificationDismiss(Notification.Builder notification, int notificationId) { + Intent intent = new Intent(mContext, DismissNotification.class); + intent.putExtra(NOTIFICATION_ID, notificationId); + + PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(mContext, notificationId, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); + + notification.setDeleteIntent(dismissPendingIntent); + } + private void notificationLoad(Ejson ejson, Callback callback) { LoadNotification.load(reactApplicationContext, ejson, callback); }