Reputation: 1686
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.
Upvotes: 5
Views: 14628
Reputation: 564
Use this:
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
Source: @synic's answer to Android notification doesn't disappear after clicking the notification
Upvotes: 5
Reputation: 1342
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).
Upvotes: 1