[英]Android how to hide NotificationCompat.Builder notification`s icon on status bar?
My question is quite simple, but I couldn't get around it for a long time so I'm asking here. 我的问题很简单,但我无法解决它很长一段时间,所以我在这里问。
How to hide the ongoing notification's icon, that is displayed in the status bar? 如何隐藏状态栏中显示的正在进行的通知图标? I am creating the notification with
NotificationCompat.Builder
object. 我正在使用
NotificationCompat.Builder
对象创建通知。 I tried to skip (when the option to show icon is unchecked) the builder.setSmallIcon()
function call, but that resulted in no notification on the notifications screen. 我试图跳过(当取消选中显示图标的选项时)
builder.setSmallIcon()
函数调用,但这导致通知屏幕上没有通知。
Since Android 4.1 (API 16) it's possible to specify a notification's priority
. 从Android 4.1(API 16)开始,可以指定通知的
priority
。 If you set that flag to PRIORITY_MIN
the notification icon won't show up on the statusbar. 如果将该标志设置为
PRIORITY_MIN
,通知图标将不会显示在状态栏上。
builder.setPriority(NotificationCompat.PRIORITY_MIN);
As of Android 8.0 Oreo (API level 26) you have to create a NotificationChannel
and set its importance
to IMPORTANCE_MIN
: 从Android 8.0 Oreo(API级别26)开始,您必须创建
NotificationChannel
并将其importance
设置为IMPORTANCE_MIN
:
NotificationChannel channel =
new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MIN);
notificationManager.createNotificationChannel(channel);
...
builder.setChannelId(channel.getId());
How to hide the ongoing notifications icon, that is displayed in status bar?
如何隐藏状态栏中显示的正在进行的通知图标?
You don't. 你没有。
I tried to skip (when the option to show icon is unchecked) the builder.setSmallIcon() function call, but that resulted in no notification in notifications screen.
我试图跳过(当取消选中显示图标的选项时)builder.setSmallIcon()函数调用,但这导致通知屏幕中没有通知。
Correct. 正确。 Since the primary point of raising a
Notification
is to put an icon in the status bar, there is no means to not put an icon in the status bar. 由于提出
Notification
的主要目的是在状态栏中放置一个图标,因此无法在状态栏中放置图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.