an00b
an00b

Reputation: 11478

How to Detect Headset Capabilities

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?

Upvotes: 7

Views: 384

Answers (1)

Jason John
Jason John

Reputation: 936

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

Upvotes: 1

Related Questions