I wrote some service which uses BroadcastReceiver to capture one of media buttons (\"play button\" from a headset), and it works perfectly on android 2.3.x (HTC Nexus One or
Make sure that you have an activity in your app, and that the user runs this activity before attempting to press that button. Until then, your will not receive any broadcasts.
UPDATE
On Android 4.0 and higher, it appears that you also need to call registerMediaButtonEventReceiver() on AudioManager in order to receive the events. That state will hold until something else calls registerMediaButtonEventReceiver() or until you call unregisterMediaButtonEventReceiver().
For example, an activity like this:
public class MediaButtonActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((AudioManager)getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(new ComponentName(
this,
MediaButtonReceiver.class));
}
}
will enable a manifest-registered MediaButtonReceiver to get ACTION_MEDIA_BUTTON events.