Receiving Media Key Events In Service
I know it has been explained a hundred times, and I've looked at them all and still can't figure it out. I have experience on BlackBerry 10 QT/C++ but am trying to ride the BlackBe
Solution 1:
There's a few things in the MediaButtonReceiver documentation you are missing firstly:
- You need to add the
<intent-filter>
forandroid.intent.action.MEDIA_BUTTON
to your.myService
- without this,MediaButtonReceiver
won't know which Service to forward media buttons to - You need to call handleIntent() in your onStartCommand()
After that, your Service will be set up correctly, but you still won't receive media buttons. As explained in the Media Playback the Right Way talk, you need to become the preferred media button receiver by calling mediaSessionCompat.setActive(true).
You'll also want to make sure you are calling
mediaSessionCompat.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSessionCompat.setCallback(mediaSessionCompatCallBack);
This ensures that you say you can handle media buttons and registers your Callback instance with the MediaSessionCompat.
Note that MediaSessionCompat
will automatically translate media buttons into the appropriate Callback methods (i.e., play will translate to onPlay()
being called, etc) so in many cases you don't need to directly override onMediaButtonEvent()
.
Post a Comment for "Receiving Media Key Events In Service"