Skip to content

Commit

Permalink
android: do not display data-only PN (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEliraz authored Feb 15, 2022
1 parent c628f5b commit f60895c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/api/general-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit f60895c

Please sign in to comment.