出于测试目的,我将发送2条通知,并将其与摘要通知捆绑在一起。 它可以工作,但是会引起3种声音效果,这意味着有3个单独的通知到达。这是预期的行为吗?
public void sendOnChannel1(View v) {
String title1 = "Title 1";
String title2 = "Title 2";
String message1 = "Message 1";
String message2 = "Message 2";
Notification notification1 = new NotificationCompat.Builder(this, CHANNEL_1_ID)
.setSmallIcon(R.drawable.ic_one)
.setContentTitle(title1)
.setContentText(message1)
.setGroup("example_group")
.build();
Notification notification2 = new NotificationCompat.Builder(this, CHANNEL_1_ID)
.setSmallIcon(R.drawable.ic_one)
.setContentTitle(title2)
.setContentText(message2)
.setGroup("example_group")
.build();
Notification summaryNotification = new NotificationCompat.Builder(this, CHANNEL_1_ID)
.setSmallIcon(R.drawable.ic_one)
.setContentTitle("summary content title")
.setContentText("summary content text")
.setStyle(new NotificationCompat.InboxStyle()
.addLine(title2 + " " + message2)
.addLine(title1 + " " + message1)
.setBigContentTitle("2 new messages")
.setSummaryText("user@example.com"))
.setGroup("example_group")
.setGroupSummary(true)
.build();
notificationManager.notify(1, notification1);
notificationManager.notify(2, notification2);
notificationManager.notify(3, summaryNotification);
}
答案 0 :(得分:0)
我知道了。
为避免摘要引起混乱,我们必须在其上调用.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
。