@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) {
//navigate up
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//navigate down
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
startActivity(new Intent(getApplicationContext(), fish.class));
return true;
}
return super.onKeyLongPress(keyCode, event);
}
I have few buttons in a class which i want to navigate using the volume up/down keys. and want to press the button when the key is long pressed. The navigation through the buttons works perfectly fine but the long press to click the button in the class doesn't works.