Rebind notification listener after device reboot#19
Open
dpeite wants to merge 1 commit into
Open
Conversation
On many devices (notably Android TV) the system fails to re-bind the NotificationListenerService after a reboot, so the app silently stops receiving media session updates until the notification access permission is manually toggled off and on again. Add a BOOT_COMPLETED receiver that forces the system to rebind the listener on boot by toggling the service component and calling NotificationListenerService.requestRebind(). The notification-access grant is not affected.
Owner
|
Thank you very much for investigating this. Indeed I received a few bug reports hinting about this bug. I was planning to add a delay before retrieving the MediaSessions but I suspect this would have no effect because the root cause is the Service not binding. Before merging I want to check a few things with you:
|
cbeyls
reviewed
Jul 17, 2026
| val component = ComponentName(context, MediaSessionListenerService::class.java) | ||
|
|
||
| // (1) Forceful rebind: toggle the component off and back on. | ||
| runCatching { |
Owner
There was a problem hiding this comment.
runCatching is a method to create a Result, I would rather explicitly catch the Exception if the result is ignored.
| // (2) Ask the system to rebind the listener (available since API 24). | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
| runCatching { | ||
| NotificationListenerService.requestRebind(component) |
Owner
There was a problem hiding this comment.
Is it needed to do both the disable/enable and the rebind, or one of them is enough?
Maybe the Service enable/disable can be used as a fallback on older Android versions, while newer Android versions can just rebind the service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On many devices — notably Android TV — the system fails to re-bind the
NotificationListenerServiceafter a reboot. When this happens the app silently stops publishing media session state to MQTT until the user manually toggles the notification access permission off and on again.This PR adds a
BOOT_COMPLETEDbroadcast receiver that forces the system to rebind the listener on boot:NotificationListenerService.requestRebind()(API 24+) as a final nudge.The notification-access grant is stored separately (by component name) and is not affected by the component toggle. Failures are caught defensively so the receiver never crashes on boot.
Tested on a Philips Android TV (Android 12): after a reboot the listener reconnects automatically and playback state keeps publishing without any manual intervention.
Reference: https://stackoverflow.com/a/64576489
Fixes #7 · May also address #12