diff --git a/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java b/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java index dd38c7d9f600c4b9521a23ee9249a2a249746d3c..6588ce058b013f2ee0a87eec381377f3752a11f2 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java +++ b/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsModule.java @@ -65,7 +65,9 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements Bundle notificationData = intent.getExtras(); if (notificationData != null) { final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData); - notification.onOpened(); + if (notification != null) { + notification.onOpened(); + } } } diff --git a/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java b/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java index 26748a14bc46a1be4045fa5330cbe1b7003b41c9..d280fe7ebc6c2902fbc57e1f1308a583bfe67027 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java +++ b/android/src/main/java/com/wix/reactnativenotifications/RNNotificationsPackage.java @@ -63,11 +63,14 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade. final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(mApplication.getApplicationContext()); notificationsDrawer.onNewActivity(activity); - Bundle notificationData = activity.getIntent().getExtras(); - if (notificationData != null) { - final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData); - if (pushNotification != null) { - pushNotification.onOpened(); + Intent intent = activity.getIntent(); + if (intent != null) { + Bundle notificationData = intent.getExtras(); + if (notificationData != null) { + final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData); + if (pushNotification != null) { + pushNotification.onOpened(); + } } } } diff --git a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 356faed292d0cfed8b8d74d4d40231034744d261..ba5e1c3238f22000b3127ba53f9a54120a7b2b76 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/android/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -43,6 +43,10 @@ public class PushNotification implements IPushNotification { }; public static IPushNotification get(Context context, Bundle bundle) { + if (verifyNotificationBundle(bundle) == false) { + return null; + } + Context appContext = context.getApplicationContext(); if (appContext instanceof INotificationsApplication) { return ((INotificationsApplication) appContext).getPushNotification(context, bundle, AppLifecycleFacadeHolder.get(), new AppLaunchHelper()); @@ -58,6 +62,14 @@ public class PushNotification implements IPushNotification { mNotificationProps = createProps(bundle); } + private static boolean verifyNotificationBundle(Bundle bundle) { + if (bundle.getString("google.message_id") != null) { + return true; + } + + return false; + } + @Override public void onReceived() throws InvalidNotificationException { postNotification(null); diff --git a/android/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java b/android/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java index cb7763c7293e10567c6107bb0b250fe5ead68dec..2456913ea09c931e99aa29550c9a61ac0c07c237 100644 --- a/android/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java +++ b/android/src/main/java/com/wix/reactnativenotifications/gcm/FcmInstanceIdListenerService.java @@ -21,8 +21,7 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage message){ - Map data = message.getData(); - Bundle bundle = convertMapToBundle(data); + Bundle bundle = message.toIntent().getExtras(); Log.d(LOGTAG, "New message from GCM: " + bundle); try { @@ -33,14 +32,4 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService { Log.v(LOGTAG, "GCM message handling aborted", e); } } - - private Bundle convertMapToBundle(Map map) { - Bundle bundle = new Bundle(); - for (Map.Entry entry : map.entrySet()) { - bundle.putString(entry.getKey(), entry.getValue()); - } - - return bundle; - } - } diff --git a/package.json b/package.json index 6fb9d9014dae600c1b2473b27914621abbe1982e..26976c31fbb38bd29d6ea01664f61230d36adec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-notifications", - "version": "1.2.5", + "version": "1.2.51", "description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android", "author": "Lidan Hifi ", "license": "MIT",