Skip to content Skip to sidebar Skip to footer

Detecting Bluetooth Headset Call Button Press In Android

I am developing a calling app. So i need to pick/hangup call from bluetooth device too . But i just can not get the key press event from bluetooth headset. I have tried with Broadc

Solution 1:

I think you need to listen for KeyEvent.KEYCODE_CALL and KeyEvent.KEYCODE_ENDCALL

A complete list of KeyEvents can be found here: https://developer.android.com/reference/android/view/KeyEvent.html

Keep in mind that call handling for most headsets (wired or not) use the play/pause button too for ending a call.

EDIT:

Try this in your dispatchKeyEvent:

@Overridepublic boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_CALL) {
        Toast.makeText(this, "CALLING!", Toast.LENGTH_LONG).show();
        returntrue;
    }
    returnsuper.dispatchKeyEvent(event);
}

Keep in mind that you should use event.getKeyCode(); instead of event.getAction(); when dealing with the static KEYCODE_{SOMEKEY} integers.

Solution 2:

Try to get event KeyEvent.KEYCODE_HEADSETHOOK

if (event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) {
  //do somethingenter code here
}

Post a Comment for "Detecting Bluetooth Headset Call Button Press In Android"