Notification counter icon in Android App

I am developing an android application where I send notifications to the user using Firebase Cloud Messaging Service. To make the user aware of notifications, I want to show the number of notifications on the app launcher icon. Is there a way how I can do this? I don't want to create a widget. I tried ShortcutBadger library Link for library

But the problem with this library is that it doesn't work when the app is in the background or killed?

I used the count update method in the BroadcastReceiver of my application

Can anyone suggest how to use it or a better way to do this?

+3


source to share


3 answers


Android O introduces notification icons:

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 some time before O becomes widespread, however.

+2


source


If you have your own FirebaseMessagingService, you can set your icon to 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 notified. Hope this helps you.

+1


source


So, in order to take any action in the application when a notification is received regardless of the state of the application, we need to send the data type to send. onMessageReceived()

the method FireabaseMessagingService

is always run, regardless of the state of the application, the user is assigned a data type for notifications, otherwise if the notification object also contains a notification field, then the system tray itself processes the collection of notifications in the device and the application has nothing to do with this.

0


source







All Articles