Detect Headset Buttons Double Click And Long Press(click) Android
Detect Headset buttons double click and Long press(click) Android I am trying the bellow code public class MediaButtonReceiver extends BroadcastReceiver { @Override
Solution 1:
For the double click you can detect it by overriding Activity onKeyDown
method and measuring time elapsed between each click:
@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HEADSETHOOK){
//check if it's the first or the second click and measure time between themreturntrue;
}
returnsuper.onKeyDown(keyCode, event);
}
There's also an Activity onKeyLongPress
method but it doesn't seem to work on my device with headset button as when I long press headset button it launches Google Now and I can't detect it inside my activity
Post a Comment for "Detect Headset Buttons Double Click And Long Press(click) Android"