我有一个应用程序,用户可以在其中收到有关他们需要做的事情的多个通知。用户可以选择使其中一些通知持久化(我通过调用 NotificationCompat.Builder.setOngoing 实现)。至少在我的 Android 版本 Nougat 上,当我的应用程序发布了三个以上的通知时,它们会被 bundle 到一个通知中,这使得用户可以一次滑动就可以关闭所有通知。这使得以前持久化的通知不再持久化。有没有办法以编程方式指示 Android 不要 bundle 我的通知?
这是我用来构建通知并显示它的代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(eventName + " " + notificationText)
.setDefaults(Notification.DEFAULT_ALL)
.setOnlyAlertOnce(true)
.setContentIntent(eventListPendingIntent);
if (goalInfo.goal.persistNotification) {
builder.setOngoing(true);
} else {
builder.setAutoCancel(true);
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(eventType.value(), builder.build());
谢谢,尼尔
最佳答案
根据 Google 文档,来自同一应用的通知将自动 bundle -
Note: If the same app sends four or more notifications and does not specify a grouping, the system automatically groups them together.
所以在你的情况下,你可以做的是,而不是系统应用默认分组,你可以将你的通知分成两组,使用一个单独的组 key 用于持久通知和一个用于非持久通知。
查看 Google 文档。 NotificationBuilderCompat
上的方法 Builder.setGroup()
采用作为键的字符串参数。
有一个相关方法 Builder.setGroupSummary
,您应该在 Builder
希望这是清楚的。
关于Android:有没有办法禁用通知 bundle ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42170889/