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.
1 Answer
Reset to default 0It 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
版权声明:本文标题:Set badge number to 0 in an Android notification - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265688a2368418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论