I'm having a strange issue with notification groups on Android 12. (I haven't checked other OS versions.) I show two notifications, and a group summary notification, using the code below:
val notificationManager = NotificationManagerCompat.from(context)
fun showNotification(title: String, summary: Boolean) {
NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setSmallIcon(R.drawable.ikona_bez)
.setGroup(groupKey)
.setGroupSummary(summary)
.build()
.let { notificationManager.notify(Random.nextInt(), it) }
}
showNotification("asdf 1", false)
showNotification("asdf 2", false)
showNotification("group", true)
When this code runs on a locked phone, the lock screen initially shows three notifications: "asdf 1", "asdf 2", and "group", with no grouping behavior.
Notifications initially not grouped on lock screen
But, when I unlock the phone, and lock it again, the separate "group" notification disappears, and the "asdf 1" and "asdf 2" notifications are grouped correctly.
Notifications grouped on lock screen after un/re/locking phone
I don't know that I'm doing anything unusual in my code, so this seems to me like an Android bug. But, I haven't been about to find any trace of someone else on the Internet having this issue. Does this issue look familiar to anyone, or do you maybe know what I might be doing wrong?
In case anyone comes looking, here's the fix: