How to access the Push Notification counter on Android (TV)?

915 Views Asked by At

I would like to access the number of currently available push notifications The following :example has '1' push notification, here on a Android TV emulator image..

So how can I read that number?

EDIT: I do not want to set anything.

2

There are 2 best solutions below

5
penguin2048 On

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.

0
Himesh Perera On

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