-1

Hi im having a problem with notification getting cleared by clicking clear all in the status bar on the phone.I need to clear the notification only when the user clicks the specified notification and not by clearall option.The notification has to be displayed until he clears it by clicking it. Help me find a solution to this problem.

Meenu K
  • 11
  • 2
    possible duplicate of [Is there a way to keep notification active until user clicks clear?](http://stackoverflow.com/questions/20054621/is-there-a-way-to-keep-notification-active-until-user-clicks-clear) – karan Sep 22 '15 at 10:58

2 Answers2

1

Use the Notification.FLAG_NO_CLEAR AND Notification.FLAG_ONGOING_EVENT. This should give you the effect you want

Akash
  • 681
  • 3
  • 17
0

Set the Notification.FLAG_NO_CLEAR flag to the notification.

Notification notification = new NotificationCompat.Builder(getApplicationContext())
        .setContentTitle(notificationTitle)
        .setContentText(notificationMessage)
        .setSmallIcon(notificationIcon)
        .setContentIntent(pIntent)
        .build();

notification.flags |= Notification.FLAG_NO_CLEAR;

NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, notification);
Boban S.
  • 1,662
  • 13
  • 16