Fane
Fane

Reputation: 2076

How can I check if a notification is running?

I've seen the other answers but I'd like not to involve a broadcast receiver. Keep in mind I don't want to know when a notification is dismissed. What I want is, when issuing a new notification, to previously check if the notification of id 'x' is still there.

int ID_NOTIFICATION = 0 //check if notification with this id is running
mainNotification = new NotificationCompat.Builder(getApplicationContext())
                .setContentTitle("something")
                .setContentText(notificationText)
                .setTicker("Notification!")
                .setWhen(System.currentTimeMillis())
                .setDefaults(Notification.DEFAULT_SOUND)
                .setAutoCancel(true)
                .setSmallIcon(R.drawable.ic_launcher)
                .build();

C.notificationManager.notify(ID_NOTIFICATION, mainNotification);

How can I achieve this?

Upvotes: 0

Views: 1411

Answers (1)

cketti
cketti

Reputation: 1377

A quick look at the documentation of NotificationManager tells us that checking the existence of a notification is not part of the notification API.

If you really need to know whether or not a notification exists you need to keep track of it yourself. I assume you were already told how that works.

On Android 4.3 or newer you could implement a NotificationListenerService. But that's even more work and requires user interaction to enable the notification listener.

Upvotes: 1

Related Questions