I’m attempting to receive media button presses using the new MediaSession class and so far I’ve been unsuccessful. Has anyone managed to receive them using the new class?
The default implementation of onMediaButtonEvent is what figures out the specific callback for a given media key event. Since you're overriding onMediaButtonEvent and not calling the super's implementation you will only get onPlay/Pause/etc. calls from other apps that are using a MediaController to make those calls directly.
If you add change your implementation to
public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
_log.d(TAG, "onMediaButtonEvent called: " + mediaButtonIntent);
return super.onMediaButtonEvent(mediaButtonIntent);
}
You should start seeing the keys translated to the other callback methods.
onMediaButtonEvent(..)
has a default implementation in MediaSession.Callback. In your code if you call super.onMediaButtonEvent(..), then depending on the keycodes the correct callback namely onPlay()
, onPause()
will be called.
You can take a look at the default implementation in MediaSession.java