Android:没有通知图标
我想创建一个状态栏中没有图标的通知(未展开的状态)。我尝试了自定义扩展视图并仅为此视图设置图标。但这没有用。当我将 0 作为图标提供给构造函数时,图标会消失,但通知也不会出现在展开视图中。
通知通知 = 新通知(0, "", 0);
我尝试了很多组合,但没有找到解决方案。顺便说一句,我知道它有效,因为我在某些应用程序中看到了此功能。谢谢。
I wanted to create a notification without the icon in the status bar (the state that is not expanded). I tried the custom expanded view and set the icon for this view only. But it did not work. When I give 0 as icon to the constructor, the icon disappears but notification also does not appear in the expanded view.
Notification notification = new Notification(0, "", 0);
I tried a lot of combinations but didn't come out with a solution. By the way, I know it is working because I saw this feature in some apps. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里有一些可以尝试的东西。放置通知两次,一次使用 icon=0,一次使用真实图标。按一种顺序尝试,然后按相反的顺序尝试。
当我执行类似的操作时,我得到了状态栏中没有通知和扩展列表中没有通知的效果,除了两者之一(图标=0的那个)是由 Service.startForeground() 放置的。我现在没有时间进行更多实验。
Here's something to experiment with. Put up a notification twice, once with icon=0 and once with a real icon. Try it in one order and then in the opposite order.
I got the effect of no notification in status bar and notification in expanded list when I did something like this, except that one of the two (the one with icon=0) was put up by Service.startForeground(). I don't have time to experiment more right now.
Android 4.1 现在可以实现这一点; Jelly Bean 状态栏的参考实现将隐藏 PRIORITY_MIN 通知,尽管其内容仍会显示在通知面板中。
This is now possible in Android 4.1; the reference implementation of the Jelly Bean status bar will suppress icons for PRIORITY_MIN notifications, although their content will still show in the notification panel.
QuickSettings 做到了这一点,当我查看该代码时,我看到它使用通知的默认构造函数并将其图标推到通知栏的右侧。我认为它仍然使用空间但没有图标。
一些代码:
编辑:哦,抱歉,我错过了重要的一行代码,实际上他使用了占位符。但现在你有了一些代码;-)
http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java
QuickSettings did this and as I looked at that code I saw it uses the default constructor of Notification and pushes its icon to the right of the notification bar. I think it still uses space but has no icon.
Some code:
edit: oh sorry I missed an important line of code, in fact he uses a placeholder. But now you have some code ;-)
http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java
您可以使用透明图像作为通知图标。但正如 molnarm 已经提到的,用户不会通知有新通知
You could use a transparent images as the notification icon. but as molnarm already mentioned, the user won't notify that there is a new notification