76

Some apps have notifications which can´t be dismissed by swiping them away.

How can I manage such behaviour?

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136

3 Answers3

154

In addition to Andro Selvas answer:

If you are using the NotificationCompat.Builder, just use

builder.setOngoing(true);
Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
42

Use the flag,FLAG_ONGOING_EVENT to make it persistent.

Notification notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_ONGOING_EVENT;

Also you can check, FLAG_NO_CLEAR

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
2

I used the below code to make my notification persistent:

startForeground(yourNotificationId,notificationObject);

To make it dismissable, just do the below:

stopForeground(true);