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..a25d37a15 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); @@ -182,13 +185,9 @@ private void setUpIconColor(Notification.Builder notification) { protected int postNotification(Notification notification, Integer notificationId) { int id = notificationId != null ? notificationId : createNotificationId(notification); - postNotification(id, notification); - return id; - } - - protected void postNotification(int id, Notification notification) { final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); - notificationManager.notify(id, notification); + notificationManager.notify(notificationId, notification); + return id; } protected int createNotificationId(Notification notification) { 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() {