detecting bluetooth headset call button press in android -
i developing calling app. need pick/hangup call bluetooth device . can not key press event bluetooth headset. have tried broadcast , audio manager getting play/pause, pre , next button callbacks .
public class mediabuttonintentreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { if (intent.action_media_button.equals(intent.getaction())) { keyevent event = (keyevent) intent .getparcelableextra(intent.extra_key_event); if (event == null) { return; } if (event.getaction() == keyevent.action_down) { //context.sendbroadcast(new intent(intents.action_player_pause)); } } } }
menifest is
<receiver android:name=".net.mediabuttonintentreceiver"> <intent-filter> <action android:name="android.intent.action.media_button" /> </intent-filter> </receiver>
i need event when activity alive have use onkeydown , dispatchkeyevent methods of activity nothing seems work. giving me same result , previous. there must way cause system phone app getting event starting dialer. pls suggest me useful way .
i think need listen keyevent.keycode_call
, keyevent.keycode_endcall
a complete list of keyevents can found here: https://developer.android.com/reference/android/view/keyevent.html
keep in mind call handling headsets (wired or not) use play/pause button ending call.
edit:
try in dispatchkeyevent:
@override public boolean dispatchkeyevent(keyevent event) { if (event.getkeycode() == keyevent.keycode_call) { toast.maketext(this, "calling!", toast.length_long).show(); return true; } return super.dispatchkeyevent(event); }
keep in mind should use event.getkeycode();
instead of event.getaction();
when dealing static keycode_{somekey} integers.
Comments
Post a Comment