I would like to trigger an event only by pressing the 2x volume button quickly.
I have the following code, but it fires when I press the button once. How do I trigger it only by pressing 2 times at a certain speed?
Follow the code:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
toDoUp();
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
toDoDown();
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}