5

我已经为这个问题搜索了将近一天,我在这里遵循了有关 Android 通知的示例:http ://www.vogella.com/articles/AndroidNotifications/article.html 。它运行良好,我可以发送Notification. 问题是,当我点击通知时,即使我设置了它也不会消失:

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

更新:这是我的代码

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 " + "test@gmail.com")
    .setContentText("Subject");

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

问题来自哪里的任何想法?感谢您的帮助。

4

2 回答 2

6

用这个..

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

点击通知后Android通知不会消失

于 2013-08-29T07:29:38.230 回答
1

尝试删除:

noti.flags |= Notification.FLAG_AUTO_CANCEL;

它应该在没有 noti.flags 的情况下工作。

在 NotificationCompat 中使用标志的新方法是使用已定义的方法,例如 setAutoCancel(true)。

于 2015-08-28T15:30:38.533 回答