From 748e21976719d3aa5138d233c29cae66fa39925d Mon Sep 17 00:00:00 2001 From: DanielEliraz Date: Thu, 20 Jul 2023 11:56:10 +0300 Subject: [PATCH] android-get-initial-notification (#983) --- .../reactnativenotifications/RNNotificationsPackage.java | 6 ++++-- .../core/NotificationIntentAdapter.java | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java index a249c6ad3..5b7f15f30 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java @@ -95,11 +95,13 @@ private void callOnOpenedIfNeed(Activity activity) { Intent intent = activity.getIntent(); if (NotificationIntentAdapter.canHandleIntent(intent)) { Context appContext = mApplication.getApplicationContext(); - Bundle notificationData = NotificationIntentAdapter.canHandleTrampolineActivity(appContext) ? - intent.getExtras() : NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent); + Bundle notificationData = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent); final IPushNotification pushNotification = PushNotification.get(appContext, notificationData); if (pushNotification != null) { pushNotification.onOpened(); + // Erase notification intent after using it, to avoid looping with the same notification + // in case the app is moved to background and opened again + activity.setIntent(new Intent()); } } } diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java index 70f609a81..1e7e8719b 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java @@ -32,7 +32,12 @@ public static boolean canHandleTrampolineActivity(Context appContext) { } public static Bundle extractPendingNotificationDataFromIntent(Intent intent) { - return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME); + Bundle notificationBundle = intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME); + if (notificationBundle != null) { + return notificationBundle; + } else { + return intent.getExtras(); + } } public static boolean canHandleIntent(Intent intent) {