7

I know how to detect whether a headset is plugged in but some headsets (e.g Samsung EHS60ANNBE) come with the PAUSE/PLAY (a.k.a KeyEvent.KEYCODE_HEADSETHOOK) button only, without the PREV/NEXT...

I would like to be able to detect whether the headset currently plugged into the Android device has PREV/NEXT (a.k.a KeyEvent.KEYCODE_MEDIA_PREVIOUS/KeyEvent.KEYCODE_MEDIA_NEXT) or not.

Is this possible?

Community
  • 1
  • 1
an00b
  • 11,338
  • 13
  • 64
  • 101

1 Answers1

1

Are you using a BroadcastReceiver? I'm guessing you are.

from Android Dev:

public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
        //receive the key press event
        KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        //check the keypress
        if (KeyEvent.**** == event.getKeyCode()) {
            // Handle key press.
        }
    }
  }
}

** a link with various keypress codes

Jason John
  • 934
  • 2
  • 12
  • 23