简体   繁体   English

Android如何隐藏状态栏上的NotificationCompat.Builder通知图标?

[英]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.

相关问题 Android:如何在通知范围内调整NotificationCompat.Builder的largeIcon - Android: How to adjust the largeIcon of a NotificationCompat.Builder in the bounds of the notification 如何使用 NotificationCompat.Builder 创建通知? - How to create a notification with NotificationCompat.Builder? 使用NotificationCompat.Builder构建GCM通知的图标问题 - Icon problems for GCM notification build with NotificationCompat.Builder NotificationCompat.Builder通知问题 - NotificationCompat.Builder notification issue 如何使其工作NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID); - How to make it work NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); Android NoClassDefFoundError NotificationCompat.Builder - Android NoClassDefFoundError NotificationCompat.Builder 带有NotificationCompat.Builder的Android状态栏通知。 正确的实施方式? - Android Status bar notification with NotificationCompat.Builder. Correct way to implement? 使用NotificationCompat.Builder删除应用程序图标 - Remove app icon with NotificationCompat.Builder 通知不使用显示:NotificationCompat.Builder - Notification is not displayed using : NotificationCompat.Builder NotificationCompat.Builder显示一个对话框而不是通知 - NotificationCompat.Builder shows a Dialog instead of notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM