admin管理员组

文章数量:1279008

I have created a notification channel in android with setShowBadge(true). In each notification I post there, I use setNumber() and set the number to the unread message count for that conversation. This affects the number shown on the Android launcher in the badge of my app icon.

However, there are cases where the unread number should be zero: e.g. the user using the "inline reply" or "mark as read" action of the notification. How can I set the counter to 0? There are apps such Telegram and Facebook messenger that have implemented this behavior.

Using setNumber(0), has the same behavior as not setting the number, which results to counting each notification as "1".

PS. I am using MessagingStyle and place multiple unread messages in a single notification.

I have created a notification channel in android with setShowBadge(true). In each notification I post there, I use setNumber() and set the number to the unread message count for that conversation. This affects the number shown on the Android launcher in the badge of my app icon.

However, there are cases where the unread number should be zero: e.g. the user using the "inline reply" or "mark as read" action of the notification. How can I set the counter to 0? There are apps such Telegram and Facebook messenger that have implemented this behavior.

Using setNumber(0), has the same behavior as not setting the number, which results to counting each notification as "1".

PS. I am using MessagingStyle and place multiple unread messages in a single notification.

Share Improve this question edited Feb 24 at 14:06 Petrakeas asked Feb 24 at 14:01 PetrakeasPetrakeas 1,69018 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It seems that Telegram uses undocumented broadcasts to set the badge number as shown in the NotificationBadge class.

The code sees heavily influenced by the library ShortcutBadger.

Facebook messenger is also doing something similar.

So, I guess that there is no formal way of achieving what I asked.

A workaround I thought of is to create a secondary "silent" notification channel with setShowBadge(false). When a notification is updated after using one of the aforementioned actions, the "silent" channel can be used instead.

本文标签: Set badge number to 0 in an Android notificationStack Overflow