Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

clearAll notifications on Android if count zero when in background #2521

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/PAYLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ The following flowchart attempts to give you a picture of what happens when a pu
- If the app is running in the background the push plugin then checks to see if `content-available` exists in the push data.
- If `content-available` is set to `1`, then the plugin calls all of your `notification` event handlers.

> Note: if `count` is given as `0` then all notifications are first cleared: always on Android, and if the `count` has gone down on iOS

## User clicks on notification in notification center

- The app starts.
Expand Down
4 changes: 4 additions & 0 deletions src/android/com/adobe/phonegap/push/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ private void showNotificationIfPossible(Context context, Bundle extras) {
Log.d(LOG_TAG, "count =[" + badgeCount + "]");
PushPlugin.setApplicationIconBadgeNumber(context, badgeCount);
}
if (badgeCount == 0) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriscant okay, I haven't had a chance to test yet but what I see looks good. Let me confirm my thinking.

if count >= 0 then set the badge number, which is the current behaviour
if count == 0 then clear all the notifications which is new behaviour
if count is not provided in the push payload then extractBadgeCount returns -1 and neither of the above two statements are true so we get the existing behaviour.

So the only time the behaviour of the plugin changes is if someone explicitly sets the count/badge to 0 in the push payload? Note, that seems to be the best way forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my understanding, yes.

Note that if a title or message is also supplied then a new notification is created, as per current behaviour.

And the event handler is still called, as per current behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet that's what I was hoping for 🤞 I'll be able to test soon.


Log.d(LOG_TAG, "message =[" + message + "]");
Log.d(LOG_TAG, "title =[" + title + "]");
Expand Down