gpt4 book ai didi

android - startForeground()时如何隐藏徽章计数

转载 作者:行者123 更新时间:2023-12-03 10:01:21 26 4
gpt4 key购买 nike

startForeground() 需要创建 NotificationChannel 以便在 Oreo 设备的 Launcher 图标上显示徽章编号 1

如何以编程方式隐藏/禁用它?

因为 Galaxy S8(Oreo) 显示徽章编号 1。
Android 8.0 模拟器也显示点。

这就是我现在正在做的事情。但是 setShowBadge(false) 不起作用

编辑1:

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

NotificationChannel tmpC = new NotificationChannel(id, "basic", NotificationManager.IMPORTANCE_MIN);
tmpC.setShowBadge(false);

manager.createNotificationChannel(tmpC);

Notification notification = new NotificationCompat.Builder(this, id)
.setChannelId(id)
.setAutoCancel(true)
.build();

startForeground(getPackageName().hashCode(), notification);

最佳答案

您只需调用setShowBadge(false)在您的 NotificationChannel 上目的。

NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// Create notification channel.
NotificationChannel channel = new NotificationChannel({channel_id}, {name}, {importance});
mChannel.setShowBadge(false); // Disable badges for this notification channel.
mNotificationManager.createNotificationChannel(mChannel);

// Create notification and use channel
Notification notification = new NotificationCompat.Builder(context, {channel_id})
...
.build();

// notify
mNotificationManager.notify({notification_id}, notification)

查看 Modify a Notification Badge .

关于android - startForeground()时如何隐藏徽章计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54472497/

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