【发布时间】:2018-01-06 12:05:07
【问题描述】:
我正在尝试堆叠来自应用的通知,以便它们显示为 gmail 等应用。以下代码每次在通知栏中生成一个新通知。
android 文档https://developer.android.com/guide/topics/ui/notifiers/notifications.html 讨论了与setGroup 一起使用的通知通道组。但 NotificationChannelGroup 仅适用于 API 26。该功能适用于我的手机(API 24)的其他应用程序,因此必须有办法制作通知堆栈。有谁知道我怎么能做到这一点?
更新:
我找到了它,事实证明,为了使用setGroup("MY SUPER DUPER GROUP") 将消息分组到一个堆栈中,您首先必须发送一个通知,该通知用作其他具有setGroupSummary(true) 的容器。并为该通知使用零 ID nmng.notify("CROWMAIL", 0, sum),这样如果先前的摘要已被删除,它将创建一个新摘要,但如果已存在则将无效。
更新的工作代码:
NotificationManagerCompat nmng = NotificationManagerCompat.from(context);
Message[] msgs = folder.getMessagesByUID(a.data.uidnext, uidnext-1);
Notification sum = new Notification.Builder(context)
.setSmallIcon(R.drawable.notif)
.setGroupSummary(true)
.setGroup("CROWMAIL")
.build();
nmng.notify("CROWMAIL", 0, sum);
for(int i = 0; i < msgs.length; i++) {
Notification n = new Notification.Builder(context)
.setContentTitle(msgs[i].getFrom()[0].toString())
.setContentText(msgs[i].getSubject())
.setSmallIcon(R.drawable.notif)
.setGroupSummary(false)
.setGroup("CROWMAIL")
.build();
nmng.notify("CROWMAIL", previous+i, n);
}
【问题讨论】:
标签: android mobile notifications android-notifications