Pre API 21 I was using a call like audioManager.registerMediaButtonEventReceiver(receiver);
to handle media button events when a user pressed a button on his headset. As of API 21, it seems that MediaSession
should be used. However, I'm not getting any response whatsoever.
final MediaSession session = new MediaSession(context, "TAG");
session.setCallback(new Callback() {
@Override
public boolean onMediaButtonEvent(final Intent mediaButtonIntent) {
Log.i("TAG", "GOT EVENT");
return super.onMediaButtonEvent(mediaButtonIntent);
}
});
session.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
session.setActive(true);
Above is what I think should work but doesn't. Does anyone know why this isn't working or how I should register?
session.setActive(true)
– Watchmansession.setActive(true);
– Eby