【发布时间】:2023-03-24 17:18:01
【问题描述】:
【问题讨论】:
标签: android-notifications android-tv android-notification-bar android-push-notification
【问题讨论】:
标签: android-notifications android-tv android-notification-bar android-push-notification
您可以使用NotificationListenerService 管理与通知相关的所有内容。您还可以扩展它并覆盖 onNotificationPosted 等方法来维护您自己的计数器。或者更好的是,直接使用getActiveNotifications()。
您需要授予您的应用访问通知的权限才能使其正常工作。
【讨论】:
您可以设置自定义通知计数。
默认情况下,每个通知都会增加一个显示在长按菜单上的数字(如图 1 所示),但您可以为您的应用覆盖此数字。
例如,如果您只使用一个通知来表示多条新消息,但您希望此处的计数表示新消息的总数,这可能会很有用。
要设置自定义号码,请在通知上致电setNumber() - 在下面
public NotificationCompat.Builder setNumber(int number)
设置此通知表示的项目数。在最新的平台上,这可能会显示为支持徽章的启动器的徽章计数。在Build.VERSION_CODES.O 之前,它可以显示在标题中。在Build.VERSION_CODES.N 之前,这显示在右侧的通知中。
请参考这篇文章 https://developer.android.com/training/notify-user/badges
【讨论】: