My service extends the MediaBrowserService class and it responds to certain MediaController actions such as getMediaController().getTransportControls().onPlay()
. However, I didn't find a way to "control" my service from a Widget, because the MediaController class isn't available from it. How can I communicate with my service?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
The recommended approach is to use a MediaButtonReceiver, which will forward commands to your
MediaBrowserService
, where you can then handle them by adding a call to MediaButtonReceiver.handleIntent() in youronStartCommand
as per the documentation.You can use the buildMediaButtonPendingIntent() to construct a
PendingIntent
for various media buttons (such as play, pause, etc), which can then be set on your widget's buttons with setOnClickPendingIntent()