Android: reconnect the now-playing listener when the system drops it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 10:17:48 -04:00
co-authored by Claude Opus 5.5
parent e00f7da1d1
commit dd0f4bbe33
@@ -4,6 +4,7 @@ import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.provider.Settings import android.provider.Settings
import android.service.notification.NotificationListenerService
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import expo.modules.kotlin.exception.Exceptions import expo.modules.kotlin.exception.Exceptions
import expo.modules.kotlin.modules.Module import expo.modules.kotlin.modules.Module
@@ -60,7 +61,14 @@ class NowPlayingReaderModule : Module() {
prefs.deviceToken = deviceToken prefs.deviceToken = deviceToken
prefs.allowedPackages = allowedPackages.toSet() prefs.allowedPackages = allowedPackages.toSet()
if (tokenChanged) prefs.unauthorized = false 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). */ /** Re-send what's playing now (after resuming sharing). */