Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 持续通知_Android - Fatal编程技术网

Android 持续通知

Android 持续通知,android,Android,我正在尝试创建一个通知,该通知将出现在通知栏的“正在进行”区域(如WeatherBug) 以下是我正在使用的代码: PendingIntent intent = PendingIntent.getActivity(lastContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR) 据我所知,FLAG_NO_C

我正在尝试创建一个通知,该通知将出现在通知栏的“正在进行”区域(如WeatherBug)

以下是我正在使用的代码:

PendingIntent intent = PendingIntent.getActivity(lastContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR)
据我所知,FLAG_NO_CLEAR也应通过按下CLEAR(清除)按钮防止通知被清除,这也不起作用


有什么提示吗?

这是因为您在错误的位置使用了标志

你应该做:

notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

在创建
通知
对象之后和调用
通知管理器#通知

之前,这是因为您在错误的位置使用了标志

你应该做:

notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
创建
通知
对象后,调用
通知管理器#通知