Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't let user clear android notification?

There is a way that don't let user clear the notification without press button inside her? I already set setAutoCancel(false) and it's ok, but there is a button that clear all notifications and I don't want it clear my notification cause it's important to user and he has to read it and choose an action.

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.icon)
        .setContentTitle("Sync Failed")
        .setContentText("Lorem ipsum dolor sit amet")
        .setStyle(new NotificationCompat.BigTextStyle().bigText("Lorem ipsum dolor sit amet"))
        .addAction(R.drawable.change, "Change Pass", pChangePass)
        .addAction(R.drawable.remove, "Ignore", pIgnore)
        .setAutoCancel(false);


mNotificationManager.notify(accountUnique, builder.build());
like image 322
Poliane Brito Avatar asked Oct 17 '13 13:10

Poliane Brito


2 Answers

.setOngoing(true) 

need to be added also!

like image 117
Carnal Avatar answered Sep 18 '22 18:09

Carnal


For that change your last three lines code like this..

final Notification notification = builder.build();
notification.flags = Notification.FLAG_NO_CLEAR;
mNotificationManager.notify(accountUnique, notification);
like image 34
kalyan pvs Avatar answered Sep 18 '22 18:09

kalyan pvs