I would like to access the number of currently available push notifications The following :, here on a Android TV emulator image..
So how can I read that number?
EDIT: I do not want to set anything.
I would like to access the number of currently available push notifications The following :, here on a Android TV emulator image..
So how can I read that number?
EDIT: I do not want to set anything.
You can use NotificationListenerService
to manage everything related to notifications. You can also extend it and override methods like onNotificationPosted
to maintain your own counter. Or better yet, directly use getActiveNotifications()
.
Check the docs here https://developer.android.com/reference/android/service/notification/NotificationListenerService#getActiveNotifications()
You need to give your app permission to access notifications for this to work.
You can set a Custom notification count.
By default, each notification increments a number displayed on the long-press menu (visible in figure 1), but you can override this number for your app.
For example, this might be useful if you're using just one notification to represent multiple new messages but you want the count here to represent the number of total new messages.
To set a custom number, call setNumber()
on the notification - in here below
public NotificationCompat.Builder setNumber(int number)
Sets the number of items this notification represents. On the latest platforms, this may be displayed as a badge count for Launchers that support badging. Prior to Build.VERSION_CODES.O
it could be shown in the header. And prior to Build.VERSION_CODES.N
this was shown in the notification on the right side.
Please Refer this article https://developer.android.com/training/notify-user/badges