Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification FLAG_AUTO_CANCEL not working and not showing new Activity

I've been searching for almost a day for this problem, I followed the example about Android Notification here: http://www.vogella.com/articles/AndroidNotifications/article.html. It worked well and I can send the Notification. The problem is, when I click on the notification, it does NOT disappear even though I have set:

setAutoCancel(true) AND notification.flags |= Notification.FLAG_AUTO_CANCEL

Update: Here is my code

Intent intent = new Intent(MyNotification.this, NotificationReceiver.class);

PendingIntent pIntent = PendingIntent.getActivity(
    MyNotification.this, 0, intent, 0);

NotificationCompat.Builder builder = 
     new NotificationCompat.Builder(MyNotification.this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setAutoCancel(true)
    .addAction(R.drawable.ic_launcher, "Call", pIntent)
    .addAction(R.drawable.ic_launcher, "More", pIntent)
    .addAction(R.drawable.ic_launcher, "And more", pIntent)
    .setContentTitle("New mail from " + "[email protected]")
    .setContentText("Subject");

Notification noti = builder.build();
noti.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = 
    (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);

Any ideas where the problem come from? Thanks for your helps.

like image 465
user2652394 Avatar asked Aug 28 '13 04:08

user2652394


2 Answers

use this..

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

Android notification doesn't disappear after clicking the notifcation

like image 197
Aarun Avatar answered Nov 14 '22 00:11

Aarun


Try removing:

noti.flags |= Notification.FLAG_AUTO_CANCEL;

It should work without noti.flags.

The new way of using flags in NotificationCompat is to use the defined methods, like setAutoCancel(true).

like image 45
clauziere Avatar answered Nov 13 '22 23:11

clauziere