【发布时间】:2020-02-15 23:53:25
【问题描述】:
我正在尝试设置通知。
private fun sendNotification(id: Int, name: String) {
val channelId = getString(R.string.default_notification_channel_id)
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notification = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.msg_new_ticket))
.setContentText(name)
.setGroup(GROUP_KEY)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.build()
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(id, notification)
}
通知可以很好地发送和接收,但不会自动分组。每次都使用唯一的id 调用该函数。在 Android 8 (API 26) 上进行测试。
任何想法请为什么分组不起作用?
更新
如果同一个应用发送四个或更多通知并且未指定 分组,系统会自动将它们分组在一起。
我已尝试发送 5 个通知,但即使定义了组,它们仍然没有分组。
【问题讨论】:
标签: android kotlin android-notifications