我有多个 Android 通知,但是当我从网络服务器发送消息时,Android 设备会在状态栏上创建一个新的通知图标。我想统计未读通知的数量,显示在statusbar
具有单个图标,并且当阅读通知时,该通知必须更改未读通知计数的数量。我该怎么做?它看起来像这张图片中的“3 Others”:通知图标
在这里查看答案:如果有多个通知,如何给出计数器
你只需要设置Notification.number:
Notification notification = new Notification(R.drawable.direction, "Cool Notification",
System.currentTimeMillis());
/********LIKE THIS*********/
notification.number = notificationCount++;
/********LIKE THIS*********/
notification.setLatestEventInfo(context, "Cool Notification Title",
"updated notificaiton message", null);
NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
nm.notify(R.id.my_motification, notification);
您必须通过以下方式发送通知NotificationManager.notify
方法,始终使用相同的 id。正如文档所述,id 是应用程序中该通知的唯一标识符。如果您重复使用相同的 ID,它只会更新该通知的文本和编号。
要检查用户何时单击通知,您需要提供一个 PendingIntent(请参阅tutorial)。要检查用户何时清除通知,您需要使用通知生成器仅在 Api 级别 11 中可用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)