我的问题很简单,但我花了很长时间都没有解决,所以现在来问一下。
如何隐藏状态栏中显示的正在进行通知的图标?我是用NotificationCompat.Builder
对象创建通知的。我尝试跳过(当未勾选显示图标选项时)builder.setSmallIcon()
函数调用,但结果是在通知屏幕上没有通知。
我的问题很简单,但我花了很长时间都没有解决,所以现在来问一下。
如何隐藏状态栏中显示的正在进行通知的图标?我是用NotificationCompat.Builder
对象创建通知的。我尝试跳过(当未勾选显示图标选项时)builder.setSmallIcon()
函数调用,但结果是在通知屏幕上没有通知。
自从Android 4.1(API 16)以来,可以指定通知的优先级
。如果将该标志设置为PRIORITY_MIN
,则通知图标不会显示在状态栏上。
builder.setPriority(NotificationCompat.PRIORITY_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());