如何在状态栏的特定位置添加通知/正在进行的事件图标?
我想将正在进行的事件图标放在状态栏的第二个位置,就像 Skype 在登录时所做的那样。
I want to put my ongoing event icon on status bar at 2nd position like Skype does on login.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于通知管理器管理通知,因此这是不可能的。到达第一个位置的唯一方法是拥有一个 Service 并调用 startForeground() - 但如果另一个服务已经做了同样的事情,您的通知将位于第二个位置。
除此之外,没有其他方法可以影响该位置。如果您首先创建通知,那么您就是第一位。如果另一个应用程序首先创建通知,那么您是第二个。
As the Notification Manager manages the notifications, this is not possible. The only way to get to the first position would be to have a Service and call startForeground() - but if another service already has done the same, your notification would be on the second position.
Apart from that there is no other way of influencing the position. If you create your notification first, you are on the first place. If another app creates the notification first, you are second.
所以我去谷歌搜索这个答案,并在令人惊叹的 StackOverflow 上发现了这个问题。虽然
Notification.priority = notification.PRIORITY_MIN
适用于 API 16 及更高版本,但Notification.when = 0
对于 API
Notification.when = 0
效果非常好。 16.So i went googling for this answer, and i found this question on the amazing StackOverflow. While
Notification.priority = Notification.PRIORITY_MIN
works for API 16 and higher, doingNotification.when = 0
works wonderously for API < 16.
http://grail .cba.csuohio.edu/~matos/notes/cis-493/lecture-notes/Android-Chapter23-Notifications.pdf
很棒 文档!
查看示例:
抱歉,只是发布链接。但是,我相信这也会有所帮助:
在android中显示来自服务的状态栏通知
http://grail.cba.csuohio.edu/~matos/notes/cis-493/lecture-notes/Android-Chapter23-Notifications.pdf
is a great document!
Check out the example:
Sorry to just post links. But, this will also be helpful, I believe:
Display status bar notification from service in android
设置通知时,只需将 .when 字段设置为 Integer.MIN 或 Integer.MAX 即可分别将通知显示在最左侧或最右侧。
在包括 ICS 在内的所有 Android 版本上,图标均按此字段排序。
在 JB (4.1) 上,您需要设置通知优先级以使其在左侧或右侧:
notification.priority = PRIORITY_MIN 为右侧
notification.priority = PRIORITY_MAX 左侧
编辑:在平板电脑上,如果您使用Notification.FLAG_FOREGROUND_SERVICE 或startForeground,图标将位于右侧,并且我尝试将其移动到左侧的所有内容都不起作用(在ICS 上测试) 。
When setting-up the notification, just set the .when field to Integer.MIN or Integer.MAX to respectively have the notification on the far left or far right.
Icons are sorted by this field on all versions of Android up-to ICS included.
On JB (4.1), you need to set the notification priority to get it on the left or right:
notification.priority = PRIORITY_MIN for the right side
notification.priority = PRIORITY_MAX for the left side
EDIT: On tablets, if you use Notification.FLAG_FOREGROUND_SERVICE or startForeground, the icon will be positioned to the right and everything I tried to move it to the left didn't work (Tested on ICS).