如何不将持续通知计为应用程序的徽章计数?

问题描述 投票:0回答:1

我有由前台服务通知的正在进行的通知。我不想将此通知计入应用程序徽章计数,我找不到实现它的方法... 我创建了一个这样的通知通道,

 fun createNotificationChannel(context: Context) {
        val channel = NotificationChannel(CHANNEL_ID, _NOTIFICATION_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT)
        val nm = context.getSystemService(NotificationManager::class.java) as NotificationManager
        nm.createNotificationChannel(channel)
    }

并创建通知,

fun createNotification(context: Context, remoteViews: RemoteViews) =
        NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID).setPriority(NotificationCompat.PRIORITY_LOW).setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("notification").setContentText("notification").setOngoing(true).setStyle(NotificationCompat.DecoratedCustomViewStyle()).setCustomContentView(remoteViews)
.setCustomBigContentView(remoteViews).setContentIntent(getClickPendingIntent(context))

如何不将此通知计入我的应用程序徽章中?提前感谢您的交流。

android notifications
1个回答
0
投票

这正是 setShowBadge(false)

 上的 
NotificationChannel
 方法的用途:

设置发布到此频道的通知是否可以在启动器中显示为应用程序图标徽章。只能在频道提交到

createNotificationChannel
之前修改。

所以您的频道创建应该使用该方法:

val channel = NotificationChannel(CHANNEL_ID, _NOTIFICATION_CHANNEL_ID,
    NotificationManager.IMPORTANCE_DEFAULT)

// Add this line
channel.setShowBadge(false)

val nm = context.getSystemService(NotificationManager::class.java) as NotificationManager
nm.createNotificationChannel(channel)
© www.soinside.com 2019 - 2024. All rights reserved.