admin管理员组文章数量:1389834
I have this code. Basically, when I get a notification, I want my badge number to be badgeCount (lets say 10). But, what happens is when I get another notification, it is adding to the old badgeCount. So, after two notifications, it would be 20.
I notice on iOS, when I get an apns with a badge attribute, it just sets the bade number to that. It does not add to the pervious notification value. So, its 10 every time.
Is it possible to do this on Android? I would basically want to clear any previous badge count value before setting a new one. If I get a PN with a badgeCount of 10, I want to see 10 on the badge, regardless of what it looked like before.
Is that possible?
var randomRequestCode = (0..1000000).shuffled().last()
val pendingIntent = PendingIntent.getActivity(this, randomRequestCode, intent, PendingIntent.FLAG_IMMUTABLE)
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, "test")
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
badgeCount?.let {
notificationBuilder.setNumber(it)
}
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel("test", "testtest", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
val notification = notificationBuilder.build()
notificationManager.notify(randomRequestCode, notification)
本文标签: kotlinAndroid notification badge count setNumber is adding to itselfStack Overflow
版权声明:本文标题:kotlin - Android notification badge count .setNumber is adding to itself - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631034a2616538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论