Android 通知 FLAG_AUTO_CANCEL 不工作且不显示新 Activity

标签 android android-notifications

我已经为这个问题搜索了将近一天,我在这里遵循了关于 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);

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

最佳答案

use this..

notification.flags = 通知.DEFAULT_LIGHTS |通知.FLAG_AUTO_CANCEL

Android notification doesn't disappear after clicking the notifcation

关于Android 通知 FLAG_AUTO_CANCEL 不工作且不显示新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18479253/

相关文章:

java - 从另一个类导入int变量会使应用程序崩溃

Android JellyBean BigTextStyle 通知不工作 - HTC One X AT&T

android - Android BigPictureStyle 推送通知中的图像/位图大小应该是多少?

java - Android 字符编码与 Java 字符编码

android - 应用程序 MediaRecorder 程序 ANR

android - 具有上下文的无内存泄漏单例

android - 应用程序崩溃-空指针异常[Android]

android - 附近的通知不显示

android - 如何将通知按钮设置为图标而不是文字

java - .setSmallIcon 未更改通知图标