Skip to content

Commit 748e219

Browse files
authored
android-get-initial-notification (#983)
1 parent 7925280 commit 748e219

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/android/app/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ private void callOnOpenedIfNeed(Activity activity) {
9595
Intent intent = activity.getIntent();
9696
if (NotificationIntentAdapter.canHandleIntent(intent)) {
9797
Context appContext = mApplication.getApplicationContext();
98-
Bundle notificationData = NotificationIntentAdapter.canHandleTrampolineActivity(appContext) ?
99-
intent.getExtras() : NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
98+
Bundle notificationData = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent);
10099
final IPushNotification pushNotification = PushNotification.get(appContext, notificationData);
101100
if (pushNotification != null) {
102101
pushNotification.onOpened();
102+
// Erase notification intent after using it, to avoid looping with the same notification
103+
// in case the app is moved to background and opened again
104+
activity.setIntent(new Intent());
103105
}
104106
}
105107
}

lib/android/app/src/main/java/com/wix/reactnativenotifications/core/NotificationIntentAdapter.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public static boolean canHandleTrampolineActivity(Context appContext) {
3232
}
3333

3434
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
35-
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
35+
Bundle notificationBundle = intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
36+
if (notificationBundle != null) {
37+
return notificationBundle;
38+
} else {
39+
return intent.getExtras();
40+
}
3641
}
3742

3843
public static boolean canHandleIntent(Intent intent) {

0 commit comments

Comments
 (0)