From dd0f4bbe33ed985fcbcde4d72835f5fc3f3f1be6 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 15 Oct 2026 10:17:48 -0400 Subject: [PATCH] Android: reconnect the now-playing listener when the system drops it Co-Authored-By: Claude Opus 5.5 --- .../musicshare/nowplaying/NowPlayingReaderModule.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/mobile/modules/now-playing-reader/android/src/main/java/tech/chrisedwards/musicshare/nowplaying/NowPlayingReaderModule.kt b/apps/mobile/modules/now-playing-reader/android/src/main/java/tech/chrisedwards/musicshare/nowplaying/NowPlayingReaderModule.kt index 0d74507..108d5f0 100644 --- a/apps/mobile/modules/now-playing-reader/android/src/main/java/tech/chrisedwards/musicshare/nowplaying/NowPlayingReaderModule.kt +++ b/apps/mobile/modules/now-playing-reader/android/src/main/java/tech/chrisedwards/musicshare/nowplaying/NowPlayingReaderModule.kt @@ -4,6 +4,7 @@ import android.content.ComponentName import android.content.Intent import android.os.Build import android.provider.Settings +import android.service.notification.NotificationListenerService import androidx.core.app.NotificationManagerCompat import expo.modules.kotlin.exception.Exceptions import expo.modules.kotlin.modules.Module @@ -60,7 +61,14 @@ class NowPlayingReaderModule : Module() { prefs.deviceToken = deviceToken prefs.allowedPackages = allowedPackages.toSet() if (tokenChanged) prefs.unauthorized = false - MediaListenerService.instance?.refresh() + val listener = MediaListenerService.instance + if (listener != null) { + listener.refresh() + } else { + // Android often doesn't reconnect the listener after an app update or after killing it + // in the background; access stays granted but nothing is reported. Ask for it back. + NotificationListenerService.requestRebind(ComponentName(context, MediaListenerService::class.java)) + } } /** Re-send what's playing now (after resuming sharing). */