正在进行的通知

NPi*_*ike 1 android

我正在尝试创建一个通知,该通知将显示在通知栏的"正在进行"区域(如WeatherBug).

这是我正在使用的代码:

PendingIntent intent = PendingIntent.getActivity(lastContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR)
Run Code Online (Sandbox Code Playgroud)

根据我的理解,FLAG_NO_CLEAR也应该通过按下清除按钮来防止通知被清除,这也是行不通的

任何提示SO?

Ric*_*ler 5

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

你应该这样做:

notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
Run Code Online (Sandbox Code Playgroud)

在创建Notification对象之后和调用之前NotificationManager#notify