ubu*_*oid 12 notifications android
我有一个通知,每隔三秒刷新一次(即发送).我已经设置了FLAG_ONGOING_EVENT标志和FLAG_NO_CLEAR标志,以便始终显示.问题是,如果例如下载处于活动状态(在通知区域中显示进度条),则两个通知都会不断切换位置,因为它们每隔几秒刷新一次.
如何将我的通知固定到列表顶部(或某个静态位置),以便每次通过调用更新它时它都会停止跳转NotificationManager.notify()?
编辑:这是更新通知的代码.它每三秒钟运行一次.
Notification notification = new Notification();
notification.contentView = appBarNotification; // this sets the changed notification content
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.icon = R.drawable.icon;
nm.notify(APP_BAR_NOTIFICATION, notification);
Run Code Online (Sandbox Code Playgroud)
Vai*_*den 19
有一个解决方案可以完全满足您的需求.
在Notification类中,有一个名为when的公共字段.根据API:
通知的时间戳.图标和展开的视图按此键排序.
默认行为(代码和编码器一样:)是在通知的时间戳给出时:
notification.when = System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud)
所以 - 为了保持正确的通知顺序,你需要做的就是给它一个预设的时间戳:
notification.when = previousTimestamp;
Run Code Online (Sandbox Code Playgroud)
当您对所有通知执行此操作时,他们会维护其订单.我和你有同样的问题并以这种方式解决了.
| 归档时间: |
|
| 查看次数: |
11051 次 |
| 最近记录: |