un-snooze notification

1.3k views Asked by At

I am using a notification listener to snooze unwanted notifications, but how do I un-snooze these once my app is no longer running? Currently they only way I have found to do this is the user must reboot their phone.

This is how I am snoozing the notification, I found out I can use getSnoozedNotifications to get a list of snoozed apps, but what is the command to un-snooze it?

snoozeNotification(sbn.getKey(), Long.MAX_VALUE - System.currentTimeMillis());

And this is how I get the snoozed apps, I just can't find anywhere that tells me the command to un-snooze it, I have even tried to set the duration to 0.

private void clearSnoozedNotifications()
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        StatusBarNotification sbns[] = getSnoozedNotifications();
        for (StatusBarNotification sbn : sbns) {
            try {
                if (sbn == null) {
                    Log.e("Notification Listener", "sbn is null");
                    return;
                }

                Log.e("Notification Listener", "Starting: " + sbn.getKey());
                snoozeNotification(sbn.getKey(), 0);
            } catch (Exception e) {
                Log.e("Notification Listener", "error: " + e.getMessage());
            }
        }
    }
}
1

There are 1 answers

1
JamieH On

I have observed on Android 11 that you can restore the notification by calling snoozeNotification on the same key with a low duration number greater than zero.

For example I use the following:

snoozeNotification(key, 100L);

On earlier versions of Android the notifications will re-appear after a reboot when they have been snoozed, in Android 11 they won't.