gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:06 26 4
gpt4 key购买 nike

我的问题很简单,但我想了很久都绕不开它,所以我在这里问。

如何隐藏显示在状态栏中的正在进行的通知图标?我正在使用 NotificationCompat.Builder 对象创建通知。我试图跳过(未选中显示图标的选项时)builder.setSmallIcon() 函数调用,但这导致通知屏幕上没有通知。

最佳答案

从 Android 4.1 (API 16) 开始,可以指定一个通知的 priority .如果你set that flagPRIORITY_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());

关于Android 如何隐藏状态栏上的 NotificationCompat.Builder 通知图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15901312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com