In my activity, I override dispatchKeyEvent(final KeyEvent event) method to get KeyEvent.KEYCODE_VOLUME_UP and KeyEvent.KEYCODE_VOLUME_DOWN. What i want is to catch long presses and let short presses be handled by the system (actually change volume).
If you know how to implement such a behaviour stop reading here and answer the question, cause my wondering is irrelavant to you :)
What i found out is that there is a conjuction between what i want to do and how the system implemented the volume changing. the method isLongPress() can return true only on KeyEvent.ACTION_DOWN, and the volume is changed also only on KeyEvent.ACTION_DOWN. If we assume for a second that volume would change on KeyEvent.ACTION_UP instead, i could implement exactly what i want this way:
if (event.getAction() == KeyEvent.ACTION_UP) {
if (!event.isLongPress())
return super.dispatchKeyEvent(event);
else {
// handle long press here
return true;
}
} else {
return true;
}
But this wont work since volume doesnt change on ACTION_UP... So any ideas how can i implement such a behaviour?