开发者

Ongoing notifications

开发者 https://www.devze.com 2023-01-11 20:00 出处:网络
I am trying to create a notification that will appear in the \"ongoing\" area of the notification bar (like WeatherBug).

I am trying to create a notification that will appear in the "ongoing" area of the notification bar (like WeatherBug).

Here is the code that I am usi开发者_如何学编程ng:

PendingIntent intent = PendingIntent.getActivity(lastContext, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR)

From what I understand, FLAG_NO_CLEAR, should also prevent the notification from being cleared by pressing the Clear button, this is also not working

Any tips SO?


This is because you are using the flags in the wrong place.

You should be doing:

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

After you create your Notification object and before you call NotificationManager#notify

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号