Android 安卓4:can';不要通过刷卡取消通知
我有一些创建一些通知的代码,这是非常基本的Android 安卓4:can';不要通过刷卡取消通知,android,android-notifications,Android,Android Notifications,我有一些创建一些通知的代码,这是非常基本的 int icon = R.drawable.notification; CharSequence tickerText = "Text"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); Char
int icon = R.drawable.notification;
CharSequence tickerText = "Text";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Text";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, RequestActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.flags |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(notificationID, notification);
在2.1中一切都很好。
在4.0中,除了“刷消”操作不起作用外,其他操作都可以正常工作。通知会稍微向一侧移动,然后粘住并反弹回来。
有什么想法吗?
谢谢。您不能刷走您的通知,因为它处于“正在进行”状态 首先选择解决方案: 将设置标志替换为以下代码:
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
默认值用于默认值部分,标志用于标志部分
现在,这项工作进行的原因是什么?
正如您可能已经知道的,通知的标志(和默认值)是由设置的。表示每个标志都有一个2的幂的常量值。添加它们会导致一组标志的唯一编号,这使得计算实际设置的标志非常快速
及
具有相同的常量值2 发出通知时只需插入这一行即可
// Will show lights and make the notification disappear when the presses it
notification.flags == Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
您应该使用
设置这是否为“正在进行的”通知。持续通知
用户无法拒绝,因此您的应用程序或服务必须
注意取消它们。它们通常用于表示
用户积极参与的后台任务(例如,播放
音乐)或以某种方式挂起,因此占用了设备
(例如,文件下载、同步操作、活动网络连接)
你可以用
.setOngoing(false);
尝试删除标志\u AUTO\u CANCELmh。。。尝试将第一个标志指定给ntotation.flags,而不是按位或第一个标志。将notification.flags |=DEFAULT_SOUND更改为notification.flags=notification.DEFAULT_SOUND;也许这会有帮助这似乎是一个非常奇怪的问题。对不起,我想我帮不了你解决这个问题:(这正是我需要知道的。谢谢!开始使用setContinuous(false)和notification.flags |=notification.FLAG_AUTO_CANCEL。