引脚通知到通知区域的顶部 [英] Pin Notification to top of notification area

查看:140
本文介绍了引脚通知到通知区域的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被刷新,每三秒钟的通知(即发送)。我给自己定了FLAG_ONGOING_EVENT标志和FLAG_NO_CLEAR标志,以便始终显示。的问题是,如果例如下载是活动的(它显示在通知区域中的进度条),这两个通知,不断变换位置,因为它们都是每隔几秒钟刷新。

我怎么能销我的通知列表的顶部(或一些静态的位置),使之停止我每次调用更新时间 NotificationManager.notify()

编辑:这里的code更新通知。它的运行每隔三秒钟。

 的通知的通知=新的通知();
notification.contentView = appBarNotification; //这个设置改变的通知内容
notification.flags | = Notification.FLAG_ONGOING_EVENT;
notification.flags | = Notification.FLAG_NO_CLEAR;

意图notificationIntent =新意图();
PendingIntent contentIntent = PendingIntent.getActivity(此,0,notificationIntent,0);
notification.contentIntent = contentIntent;
notification.icon = R.drawable.icon;

nm.notify(APP_BAR_NOTIFICATION,通知);
 

解决方案

有一个解决方案,它正是你想要的。

通知类,有一个公共领域的名为< A HREF =htt​​p://developer.android.com/reference/android/app/Notification.html#when相对=nofollow>当。根据API:

  

的时间戳通知。图标和扩展视图通过此键进行排序。

默认的行为(code和codeRS一样:)是给的的通知的时间戳记:

  notification.when = System.currentTimeMillis的();
 

所以 - 为了保持通知的正确顺序,所有你需要做的就是给它一个preset的时间戳来代替:

  notification.when = previousTimestamp;
 

当你这样做你所有的通知,他们认为他们的订单。我有同样的问题,因为你并解决了这种方式。

I have a Notification which is refreshed (i.e. sent) every three seconds. I've set the FLAG_ONGOING_EVENT flag and the FLAG_NO_CLEAR flag so that is always shown. The problem is, that if e.g. a download is active (which displays a progress bar in the notification area) both notifications constantly switch positions as they are both refreshed every few seconds.

How can I pin my notification to the top of the list (or to some static position), so that it stops jumping around every time I update it by calling NotificationManager.notify()?

Edit: Here's the code to update the notification. It's run every three seconds.

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);

解决方案

There is a solution that does exactly what you want.

In the Notification class, there is a public field called when. According to the API:

The timestamp for the notification. The icons and expanded views are sorted by this key.

The default behaviour (for code and coders alike :) is to give when the timestamp of the notification:

notification.when = System.currentTimeMillis();

So - in order to maintain the correct order of notifications, all you need to do is give it a preset timestamp instead:

notification.when = previousTimestamp;

When you do this with all of your notifications, they maintain their order. I had the same problem as you and solved it this way.

这篇关于引脚通知到通知区域的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆