It’s relatively easy to add headset button support to your application. For example you want to play/pause media playback in your super media player.

But here are a few moments that you should take into consideration:

    1. You should register your broadcast receiver inside your application (not in manifest file). Otherwise Google Music player will catch your broadcast and aboard it.;a=blob;f=src/com/android/music/
    2. Your IntentFilter priority should be higher that other media players priorities in your phone:) That’s kind of tricky thing.

      The code snippet will look like:

      MediaButtonIntentReceiver mMediaButtonReceiver = new MediaButtonIntentReceiver();
      IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
      registerReceiver(mMediaButtonReceiver, mediaFilter);


      public class MediaButtonIntentReceiver extends BroadcastReceiver {
          public MediaButtonIntentReceiver() {
          public void onReceive(Context context, Intent intent) {
              String intentAction = intent.getAction();
              if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
              KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
              if (event == null) {
              int action = event.getAction();
              if (action == KeyEvent.ACTION_DOWN) {
      	    // do something
      1. Don’t forget to unregister your broadcast receiver
      2. Add “android.permission.BLUETOOTH” permission if you want to support bluetooth headset

      // DL