我特灵创建通知组,这是我的代码:
// Build the notification, setting the group appropriately
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("New mail from " + 1)
.setContentText("cv")
.setSmallIcon(R.drawable.rh_logo)
.setStyle(new NotificationCompat.InboxStyle()
.addLine("Alex Faaborg Check this out")
.addLine("Jeff Chang Launch Party")
.setBigContentTitle("2 new messages")
.setSummaryText("johndoe@gmail.com"))
.setGroup(GROUP_KEY_EMAILS)
.setGroupSummary(true)
.build();
// Issue the notification
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(++NOTIFICATION_ID, notif);
当我运行应用程序,并发送通知消息,他们不显示在组中。有人能告诉我我需要改变什么吗?
3条答案
按热度按时间lnxxn5zx1#
创建自定义通知之前,必须先创建群组通知。就像这样:
不要忘记setGroupSummary为true。
然后创建您的子通知,其中group值与groupBuilder的值相同,这里是“GROUP_1”。
最后使用NoticationManagerCompat通知他们。
6ioyuze22#
更换
与
因为您正在使用NotificationCompat
nkhmeac63#
有一个奇怪的通知行为。如果添加自动取消通知组不起作用,如果添加setGroup或setGroupSummary。这行不通。删除所有这些为我解决了问题。基本上,你不需要提到任何组,它将自动组。测试上红米10 pr0,Poco x3 NFC,华为设备.