点击通知后,Android通知不会消失,是怎么回事呢?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (447)

如果在通知栏中显示我想要显示的通知时遇到问题。虽然我将通知标志设置为通知Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL在点击后不会消失。这是为什么呢?

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    CharSequence tickerText = "Ticker Text";
    long time = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, time);
    notification.flags = Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL; 

    Context context = getApplicationContext();
    CharSequence contentTitle = "Title";
    CharSequence contentText = "Text";
    Intent notificationIntent = new Intent(this, SilentFlipConfiguration.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(1,notification);
提问于
用户回答回答于

同时建立NotificationNotificationBuilder就可以使用notificationBuilder.setAutoCancel(true);

用户回答回答于
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

从文档:

如果通知在被用户点击时应该被取消,则该位将被按位编辑到应该设置的标志字段中

扫码关注云+社区

领取腾讯云代金券