我已经为群汇总创建了一个通知,其中可能包含许多通知。
这些通知中有一些由addAction()
添加的操作。
在执行操作后,我会尝试取消通知:
NotitifactionCompat.from(context).cancel(notificationId);
不幸的是,当取消的通知是摘要的最后一个通知时,只有通知本身将被取消,而摘要也不会被取消。
我遗漏了什么?
发布于 2018-10-29 18:19:19
摘要通知的setAutoCancel(true)
解决了摘要通知留在托盘中的问题。
发布于 2019-03-11 21:47:49
也有同样的问题。当我点击通知操作时,我以编程方式取消通知。如果你把它刷出来,它就能很好地工作。我执行以下解决方法:
public static void cancelNotification(Context context, int notifyId, int summeryId) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
boolean cancelSummary = false;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N && summeryId != 0) {
StatusBarNotification[] statusBarNotifications = notificationManager.getActiveNotifications();
String groupKey = null;
for (StatusBarNotification statusBarNotification : statusBarNotifications) {
if (notifyId == statusBarNotification.getId()) {
groupKey = statusBarNotification.getGroupKey();
break;
}
}
int counter = 0;
for (StatusBarNotification statusBarNotification : statusBarNotifications) {
if (statusBarNotification.getGroupKey().equals(groupKey)) {
counter++;
}
}
if (counter == 2) {
cancelSummary = true;
}
}
if (cancelSummary) {
notificationManager.cancel(summeryId);
} else {
notificationManager.cancel(notifyId);
}
}
发布于 2017-08-14 03:17:54
当以编程方式取消所有分组的通知时,不会自动取消摘要通知。来自
显然,你需要跟踪新的通知。但这也意味着你必须跟踪已经被驳回的通知。否则,摘要可能仍包含有关捆绑包中不再包含的通知的信息。
https://stackoverflow.com/questions/45590860
复制相似问题