I have a service which connects to other devices wirelessly. When the service is enabled, I have an ongoing notification which states it is enabled.
After the service is enabled, the user then connects to another device. At this point, I would like to update my ongoing notification to state the name of the device which has been connected to. This is easy enough to do by calling startForeground(ONGOING_NOTIFICATION, notification)
again with the updated information; however this flashes the notification on the bar each time it is called. What I would really like is the notification to quietly update in the background without flashing on the notification bar so the user doesn't know the difference until he or she opens the notification area to look.
Is there someway to update the notification without calling startForeground()
?
This behavior only occurs in Honeycomb. Gingerbread devices (and I assume Froyo, etc.) behave the desired way.
4条答案
按热度按时间vhipe2zx1#
我也经历过这个问题,在以前的评论和一点挖掘的帮助下,我找到了解决办法。
如果您不希望更新时通知闪烁,或持续占据设备的状态栏,则必须:
如果你每次都使用一个新的构建器,那么我猜Android必须重新构建视图,导致它短暂消失。
下面是一些好代码的例子:
使用上面的代码,您可以只调用updateNotification(String,int),其中包含消息和进度(0-100),它将更新通知,而不会打扰用户。
bf1o4zei2#
您应根据文档更新现有通知:https://developer.android.com/training/notify-user/build-notification.html#Updating
42fyovps3#
这对我很有效,一个正在进行的活动(不是服务)通知被“无声地”更新。
raogr8fs4#
试试这个
在notify()方法中使用此ID。Android系统本身的时间会创建一个唯一ID