Using MediaSessionManager.OnActiveSessionsChangedListener on AndroidTV

1.4k Views Asked by At

I'm trying to listen for changes to the active media sessions on my Android TV (specifically to set my Hue lights into a sort of "movie mode"). On a normal Android device (4.3+) I'd set up a NotificationListenerService to allow me to call MediaSessionManager.addOnActiveSessionsChangedListener().

The problem is that Android TV doesn't seem to have a UI to enable my NotificationListenerService, and there is nothing to handle Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS. Does anyone know of another approach to listen for media changes or a way to enable a NotificationListenerService on Android TV? This is just for my own use, so this doesn't need to be a scalable solution (adb is fine).

1

There are 1 best solutions below

6
On BEST ANSWER

From an ADB shell:

  1. Get the current list of enabled notification listeners:

settings get secure enabled_notification_listeners

By default on my TV, this returns com.google.android.leanbacklauncher/.notifications.NotificationMonitorService.

  1. Add yours to the list, separated by a colon.

settings put secure enabled_notification_listeners com.google.android.leanbacklauncher/.notifications.NotificationMonitorService:com.example/com.example.MyNotificationListenerService