Android:有没有办法禁用通知 bundle ?

标签 android android-notifications

我有一个应用程序,用户可以在其中收到有关他们需要做的事情的多个通知。用户可以选择使其中一些通知持久化(我通过调用 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/

相关文章:

android - 如何捕获图像并保存在文件夹中

android - NotificationListenerService 和 Doze 模式以及 App Standby

android - MessagingStyle 不显示文本

android - 如何以正确的方式android设置通知声音持续时间

java - 我们可以使用 Firebase 的 UID 而不是注册 token 在 android 中发送通知吗?

android - 应用程序关闭时如何获取android通知?

android - 房间插入 "one-to-many"关系

Android布局按钮在水平线性布局中低于其他按钮

android - 按下后退按钮 android 时共享首选项数据丢失了吗?

android - 使用 play-services-ads 添加 firebase 时出现重复类构建错误