leolin310148 / ShortcutBadger

An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.
Other
7.35k stars 1.34k forks source link

Notification badge count not clearing #388

Open stib opened 2 months ago

stib commented 2 months ago

Hello,

I am using shortcutBadger through the @capawesome/capacitor-badge plugin. I posted this issue in the @capawesome plugins project but was advised by the @capawesome/capacitor-badge author Robin to post the issue here. I am hoping someone is still looking at these questions here and can help address this issue.

Badge setting and clearing work fine on iOS but on Android the Badge clear does not clear the badge count coming from push notification. So if I have a App badge count of say 3 from push notifications that have come in, calling badge clear doesn't have any effect. If I set badge count to 5 through Badge.set then App badge will change to 5 and when that gets cleared through Badge.clear, the App badge count goes back to push notification count of 3. It seems like they are two different counts that the system maintains and the Badge.clear does not have any impact on the notification count for Android.

Here are more details -

  1. I am on Samsung Galaxy S22, Android version 13. Using @capawesome/capacitor-badge version 5.0.0
  2. Send push notification - App badge count goes to 1. Sending more will increment that count
  3. When App goes in background, catch that event and call Badge.clear
  4. The push notification count does not change.
  5. Open the App again and Set badge count to say 5 with Badge.set
  6. Badge count goes from 1 to 5
  7. When App goes in background again (as in 3) catch the event and call Badge.clear
  8. The badge count goes back to 1 or 2 or 3, the number for push notifications that have come in

The system seems to keep two different counts - one for the push notifications coming in and one that is set through Badge.set

Appreciate any thoughts/guidance on how to resolve this in clearing the count for push notifications as well.

Thanks, Sanjay.

boblepepeur commented 2 months ago

Same here

namnguyendjv commented 4 days ago

Through observation, ShortcutBadger.applyCount(0) will lead Android system to use number of push notifications as app badge (which is og behavior). If you want to completely remove app badge, then you should call NotificationManager.cancelAll() to clear all notification before, then ShortcutBadger.applyCount(0)