Skip to content

Commit

Permalink
android: do not display data-only PN
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEliraz committed Feb 15, 2022
1 parent c628f5b commit f7c443e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 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 Expand Up @@ -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) {
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

0 comments on commit f7c443e

Please sign in to comment.