Android:没有通知图标

发布于 2024-09-01 18:35:32 字数 193 浏览 7 评论 0原文

我想创建一个状态栏中没有图标的通知(未展开的状态)。我尝试了自定义扩展视图并仅为此视图设置图标。但这没有用。当我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木格 2024-09-08 18:35:33

这里有一些可以尝试的东西。放置通知两次,一次使用 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.

熟人话多 2024-09-08 18:35:32

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.

娇纵 2024-09-08 18:35:32

QuickSettings 做到了这一点,当我查看该代码时,我看到它使用通知的默认构造函数并将其图标推到通知栏的右侧。我认为它仍然使用空间但没有图标。

一些代码:

notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
long hiddenTime = Constants.SDK_VERSION >= 9 ? -Long.MAX_VALUE : Long.MAX_VALUE;
notification.when = visible ? System.currentTimeMillis() : hiddenTime; // align
// left (0) / right (max) in status bar

编辑:哦,抱歉,我错过了重要的一行代码,实际上他使用了占位符。但现在你有了一些代码;-)

notification.icon = visible ? (status == Constants.STATUS_BLACK_ICON ? 
                            R.drawable.ic_logo_black : R.drawable.ic_logo_white)
                            : R.drawable.ic_placeholder;

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:

notification = new Notification();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
long hiddenTime = Constants.SDK_VERSION >= 9 ? -Long.MAX_VALUE : Long.MAX_VALUE;
notification.when = visible ? System.currentTimeMillis() : hiddenTime; // align
// left (0) / right (max) in status bar

edit: oh sorry I missed an important line of code, in fact he uses a placeholder. But now you have some code ;-)

notification.icon = visible ? (status == Constants.STATUS_BLACK_ICON ? 
                            R.drawable.ic_logo_black : R.drawable.ic_logo_white)
                            : R.drawable.ic_placeholder;

http://code.google.com/p/quick-settings/source/browse/trunk/quick-settings/src/com/bwx/bequick/receivers/StatusBarIntegrationReceiver.java

紫南 2024-09-08 18:35:32

您可以使用透明图像作为通知图标。但正如 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文