diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java index 3991c34ad..edd77da34 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java @@ -87,6 +87,9 @@ public PushNotificationProps asProps() { } protected int postNotification(Integer notificationId) { + if (mNotificationProps.isDataOnlyPushNotification()) { + return -1; + } final PendingIntent pendingIntent = NotificationIntentAdapter.createPendingNotificationIntent(mContext, mNotificationProps);; final Notification notification = buildNotification(pendingIntent); return postNotification(notification, notificationId); diff --git a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java index 82b9706f1..3bcc3149b 100644 --- a/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java +++ b/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotificationProps.java @@ -30,6 +30,10 @@ public boolean isFirebaseBackgroundPayload() { return mBundle.containsKey("google.message_id"); } + public boolean isDataOnlyPushNotification() { + return getTitle() == null && getBody() == null; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(1024); diff --git a/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java b/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java index 6f3718846..fb2d55e7d 100644 --- a/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java +++ b/lib/android/app/src/test/java/com/wix/reactnativenotifications/core/notification/PushNotificationTest.java @@ -301,7 +301,7 @@ public void onPostRequest_emptyData_postNotification() throws Exception { PushNotification uut = createUUT(new Bundle()); uut.onPostRequest(null); - verify(mNotificationManager).notify(anyInt(), any(Notification.class)); + verify(mNotificationManager, never()).notify(anyInt(), any(Notification.class)); } protected PushNotification createUUT() { diff --git a/website/docs/api/general-events.md b/website/docs/api/general-events.md index b2ae16753..91526ca1c 100755 --- a/website/docs/api/general-events.md +++ b/website/docs/api/general-events.md @@ -44,7 +44,7 @@ To receive background notifications on iOS follow [this guide](https://developer ## registerNotificationOpened() Fired when a remote notification is opened from dead or background state. The handler will be invoked with an instance of [Notification](notification-obj). Should call completion function on iOS, will be ignored on Android. -Being called before component is mounted, if you want to know the initial notification in the component please use [getInitialNotification](general-api#getInitialNotification) on mount. +Android: This event will be called before the component is mounted, if you want to know the initial notification in the component please use [getInitialNotification](general-api#getInitialNotification) on mount. ```js Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void) => {