我不知道如何将两个或多个通知分组到一个并显示"你有两条新消息"这样的消息.
我有一个应用程序,用户可以收到他们需要做的事情的多个通知.用户可以选择使其中一些通知持久化(我通过调用NotificationCompat.Builder.setOngoing来实现).至少在我的Android版本Nougat上,当我的应用程序发布了三个以上的通知时,它们被捆绑在一起作为一个通知,这使得所有这些通知在一次刷卡中对用户是不允许的.这使先前持久的通知不再持久.有没有办法以编程方式指示Android不捆绑我的通知?
这是我用来构建通知并显示它的代码:
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());
Run Code Online (Sandbox Code Playgroud)
谢谢,Nir
因此,在Nougat中,来自同一应用程序的多个通知会自动捆绑到一个组中.我在我的通知上设置了一些额外的PendingIntent,如果点击了特定的通知,它会启动一个特定的活动(深层链接).
但是,如果我点击通知包(即没有扩展组),我的应用程序就像是来自启动器一样启动 - 即它的意图是空的,没有额外的(它不是通过提供的PendingIntent启动).
如何在用户点击通知包时指定使用意图?