Group summary notification not canceled when last containing notification is canceled

Viewed 2936

I have created a notification for group summary, which may contain many notifications.
Those notifications have some actions added by addAction().

I try to cancel the notification after a action has been made:

NotitifactionCompat.from(context).cancel(notificationId);

Unfortunately, when the canceled notification was the last one of the summary, only the notification itself will be canceled, but not the summary too.

What am i missing?

3 Answers

setAutoCancel(true) to the summary Notification solved my problem of summary notification being left in the tray.

Had the same problem. I cancel notification programmatically when I tap notification action. If you swipe it out it works well. I do this workaround:

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);
    }
}
Related