【发布时间】:2014-10-21 13:24:44
【问题描述】:
我有一个找不到答案的问题。我已经尝试过 AndroidDeveloper 教程,我已经在 stackoverflow 和 google 上进行了搜索,但是我的搜索技能很棒,或者没有答案,我认为可以解决我的问题。
当有多个新消息时,我想将消息通知堆叠到一个通知中。我可以为每条消息显示一个通知,但我不能发出堆栈/摘要通知。
我得到的最好的是:http://developer.android.com/images/android-5.0/notifications/Summarise_Dont.png
我想要的是这个:http://developer.android.com/images/android-5.0/notifications/Summarise_Do.png
我使用的是 API 19,它不必向后兼容。在 AndroidStudio 中编写我的代码并在 Genymotion 中进行测试。
我曾尝试使用 NotificationCompatManager 并收到多个通知:NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
我也尝试过使用 NotificationManager 得到相同的结果,即多个通知:
NotificationManager notificationManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
我的通知如下所示:
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle( "New message from... ")
.setContentText("Message:...")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION))
.setGroup(mNoti)
.setGroupSummary(true)
.setAutoCancel(true)
.build();
然后我像这样触发通知:
notificationManager.notify(counter, notification);
每个通知的计数器都会递增,因此每个通知都有自己的 ID。
我也尝试过这种形式来构建和发送通知但没有成功:
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle("message from...")
.setContentText("message...")
.setContentIntent(pIntent)
.setAutoCancel(true)
.setGroup(mNoti)
.setGroupSummary(true)
.setSound(RingtoneManager.getDefaultUri(TYPE_NOTIFICATION));
notificationManager.notify(counter, notificationBuilder.build());
setGroup 显然没有注意到我。我不明白为什么它不起作用或我应该如何使它起作用。
我的小组是这样的:
final static String mNoti = "mNoti";
唯一与我想要的远程接近的事情是对所有通知使用相同的 ID,以便新通知覆盖旧通知,并在构建通知时使用 setNumber(int)。但是,这并不能真正给我想要的结果,因为我认为我无法获得用户未处理的通知数量。或者我可以吗?
谁能帮助我达到我想要的目标?
【问题讨论】:
标签: android notifications android-4.4-kitkat