点击notifcation后,Android的通知不会消失 [英] Android notification doesn't disappear after clicking the notifcation

查看:215
本文介绍了点击notifcation后,Android的通知不会消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一个通知,我想在通知栏显示的一些问题。虽然我设置通知标志 Notification.DEFAULT_LIGHTS和放大器; Notification.FLAG_AUTO_CANCEL 的通知不点击它后消失。任何想法,我做错了什么?

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

    INT图标= R.drawable.icon;
    CharSequence的tickerText =新浪体育讯北京时间文本;
    很长一段时间= System.currentTimeMillis的();

    通知通知=新的通知(图标,tickerText,时间);
    notification.flags = Notification.DEFAULT_LIGHTS和放大器; Notification.FLAG_AUTO_CANCEL;

    上下文的背景下= getApplicationContext();
    CharSequence的contentTitle =标题;
    CharSequence的contentText =文本;
    意图notificationIntent =新的意图(这一点,SilentFlipConfiguration.class);
    PendingIntent contentIntent = PendingIntent.getActivity(此,0,notificationIntent,0);
    notification.setLatestEventInfo(背景下,contentTitle,contentText,contentIntent);
    mNotificationManager.notify(1,通知);
 

解决方案

  notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL
 

从文档:

  

位被bitwise- 编入,应设置标志字段   如果通知应取消当由用户点击

If got some issues with a notification I want to show in the notification bar. Although I set the notification flag to Notification.DEFAULT_LIGHTS & Notification.FLAG_AUTO_CANCEL the notification doesn't disappear after clicking it. Any ideas what I'm doing wrong?

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);

解决方案

notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL

From the documentation:

Bit to be bitwise-ored into the flags field that should be set if the notification should be canceled when it is clicked by the user

这篇关于点击notifcation后,Android的通知不会消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆