简体   繁体   中英

Android group summary displayed as a separate notification on lock screen

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 Inte.net 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:

setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM