A media button receiver receives and helps translate hardware media playback buttons, such as
those found on wired and wireless headsets, into the appropriate callbacks in your app.
You can add this MediaButtonReceiver to your app by adding it directly to your
AndroidManifest.xml:
This class assumes you have a Service in your app that controls media playback via a
MediaSessionCompat. Once a key event is received by MediaButtonReceiver, this class tries
to find a Service that can handle ACTION_MEDIA_BUTTON, and a
MediaBrowserServiceCompat in turn. If an appropriate service is found, this class
forwards the key event to the service. If neither is available or more than one valid
service/media browser service is found, an IllegalStateException will be thrown. Thus,
your app should have one of the following services to get a key event properly.
Service Handling ACTION_MEDIA_BUTTON
A service can receive a key event by including an intent filter that handles
ACTION_MEDIA_BUTTON:
Creates a broadcast pending intent that will send a media button event. The action
will be translated to the appropriate KeyEvent, and sent to the provided media
button receiver via the pending intent. The action should be one of the following:
Creates a broadcast pending intent that will send a media button event. The action
will be translated to the appropriate KeyEvent, and it will be sent to the
registered media button receiver in the given context. The action should be one of
the following:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{
"lastModified": "Last updated 2024-04-11 UTC.",
"confidential": False
}