Android:有没有办法禁用通知捆绑功能? [英] Android: Is there a way to disable notification bundling?

查看:91
本文介绍了Android:有没有办法禁用通知捆绑功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户可以在其中收到有关他们需要做的事情的多个通知.用户可以选择使某些通知持久化(我可以通过调用NotificationCompat.Builder.setOngoing来实现).至少在我的Android版本的Nougat上,当我的应用发布了三个以上的通知时,它们会捆绑在一起成为一个通知,这样一来,所有这些通知都将被用户忽略.这使得以前的持久通知不再持久.有没有办法以编程方式指示Android不要捆绑我的通知?

I have an app where the user can receive multiple notifications for things they need to do. The user has a choice of making some of these notifications persistent (which I achieve by calling NotificationCompat.Builder.setOngoing). At least on my version of Android which is Nougat, when more than three notifications are posted by my app they get bundled together into one notification, which makes all of them dismissible to the user in one swipe. This makes the previously persistent notifications no longer persistent. Is there a way to programmatically instruct Android not to bundle my notifications?

这是我用来构建通知并显示它的代码:

This is the code I use to build the notification and display it:

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文档,来自同一应用的通知将自动捆绑-

As per Google docs, notifications from the same app would be bundled automatically -

注意:如果同一个应用发送了四个或更多通知,但没有发送 指定分组,系统会自动将它们分组在一起.

Note: If the same app sends four or more notifications and does not specify a grouping, the system automatically groups them together.

因此,在您的情况下,您可以做的是,而不是系统应用默认分组,而是可以将通知分为两类,使用分别用于持久性通知的组密钥和用于非持久性通知的组密钥.

So in your case, what you can do is , instead of system applying the default grouping, you can separate your notifications into two groups using a separate group key for the persistent notifications and one for the non-persistent ones.

检查Google文档. NotificationBuilderCompat上的方法Builder.setGroup()采用字符串参数,它是键. 有一个相关的方法B uilder.setGroupSummary,您应该在Builder

Check the Google docs. The method Builder.setGroup() on NotificationBuilderCompat takes a string parameter which is the key. There is a related method Builder.setGroupSummary which you should call on your Builder

希望这很清楚.

这篇关于Android:有没有办法禁用通知捆绑功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆