我有由前台服务通知的正在进行的通知。我不想将此通知计入应用程序徽章计数,我找不到实现它的方法... 我创建了一个这样的通知通道,
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))
如何不将此通知计入我的应用程序徽章中?提前感谢您的交流。
上的
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)