Notification Count Badge in Android App Icon
Solution 1
Android O introduces notification badges:
https://developer.android.com/preview/features/notification-badges.html
They show the number of notifications with a long-press on the icon. It will be awhile before O has widespread adoption, though.
Solution 2
If you have your own FirebaseMessagingService, you could set your badge count in onCreate.
public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onCreate() {
super.onCreate();
ShortcutBadger.applyCount(MyFirebaseMessagingService.this, 1);
}
}
onCreate will be fired when the notification arrives. I hope it helps you.
![Umang Bhola](https://lh3.googleusercontent.com/-HqsSCD7NW8o/AAAAAAAAAAI/AAAAAAAAABE/ZGbRt_GGA2k/photo.jpg?sz=256)
Umang Bhola
Updated on June 04, 2022Comments
-
Umang Bhola about 2 years
I am developing and android application, where I am sending notifications to the user using Firebase Cloud Messaging Service. In order to make user more aware of notifications, I want to show the count of the notifications on the launcher icon of the app. Is there any way how can I do it? I don't want to create a widget. I have tried the library ShortcutBadger Link for the Library
But the issue with this library is that it is not working when the app is in background or killed?
I have used the count update method in the BroadcastReceiver of my app
Can someone suggest how to use it or a better way of doing it?