From bc5775c3b0aa980d56696f90667a65b9c23a34de Mon Sep 17 00:00:00 2001 From: chriscant Date: Fri, 10 Aug 2018 13:58:12 +0100 Subject: [PATCH] clearAll notifications on Android if count zero when in background --- docs/PAYLOAD.md | 2 ++ src/android/com/adobe/phonegap/push/FCMService.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/PAYLOAD.md b/docs/PAYLOAD.md index 6acf4367e..c10d4c7f0 100644 --- a/docs/PAYLOAD.md +++ b/docs/PAYLOAD.md @@ -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. diff --git a/src/android/com/adobe/phonegap/push/FCMService.java b/src/android/com/adobe/phonegap/push/FCMService.java index af9ebb028..db1738a72 100644 --- a/src/android/com/adobe/phonegap/push/FCMService.java +++ b/src/android/com/adobe/phonegap/push/FCMService.java @@ -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(); + } Log.d(LOG_TAG, "message =[" + message + "]"); Log.d(LOG_TAG, "title =[" + title + "]");