From 5c8cb814f6f379a49361d3114e4cf9e65eba2590 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 27 Jul 2026 01:19:47 +0000 Subject: [PATCH] Avoid duplicated MessagingStyle notification text --- .../notificationlog/capture/NotificationSnapshot.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt index 8536639..51bebfc 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationSnapshot.kt @@ -21,14 +21,25 @@ data class NotificationSnapshot( object NotificationContents { fun extract(notification: Notification): String? { - val parts = linkedSetOf() val extras = notification.extras ?: Bundle.EMPTY + messagingContents(extras)?.let { return it } + + val parts = linkedSetOf() extras.getCharSequence(Notification.EXTRA_TITLE)?.addTo(parts) extras.getCharSequence(Notification.EXTRA_TEXT)?.addTo(parts) extras.getCharSequence(Notification.EXTRA_BIG_TEXT)?.addTo(parts) extras.getCharSequence(Notification.EXTRA_SUB_TEXT)?.addTo(parts) extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)?.addTo(parts) extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)?.forEach { it?.addTo(parts) } + return parts.takeIf { it.isNotEmpty() }?.joinToString(" — ") + } + + /** + * MessagingStyle also fills generic title and text fields. Those fields commonly duplicate + * the newest structured message, so structured messages are the canonical representation. + */ + private fun messagingContents(extras: Bundle): String? { + val parts = linkedSetOf() Notification.MessagingStyle.Message.getMessagesFromBundleArray( extras.getParcelableArray(Notification.EXTRA_MESSAGES, Bundle::class.java), ).forEach { message ->