如何在android中显示特定数量的通知

时间:2014-03-07 16:21:55

标签: android notifications push-notification

我在android中实现推送通知,我需要做的是显示具体的通知数量是通知栏。假设我必须显示最近的5个通知。我收到了5个通知并显示出来。在收到第6次通知后,我必须丢弃最早的通知,依此类推。 此外,我不想折叠通知,而是将每个通知显示为单独的通知。

修改

NotificationManager中有一个功能。

void cancel(int id)
Cancel a previously shown notification.

并检查应用的通知栏中仍有多少通知可见。 nNotificationListenerService的方法可以使用名为getActiveNotifications()的方法。但是,在Android API 18及更多版本中仍然存在getActiveNotifications()存在的问题。 API级别的任何解决方案< 18?

1 个答案:

答案 0 :(得分:2)

您可以通过提供通知的ID轻松取消通知: http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)

但是,您还可以通过重新使用ID来更新通知,您不必取消它。

我的攻击计划是迭代5个预定义ID以创建通知,然后重复使用第六个通知中的“最旧”ID。这将用最新的通知替换最旧的通知。