0

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?

Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
  • Take a look [here](http://stackoverflow.com/questions/12950215/onkeydown-and-onkeylongpress?lq=1) – Onik Oct 01 '14 at 15:34
  • @Onik this is almost what i want, the problem there is that they do distinguish between short and long press but they dont let short presses be handled by the system, and this is something that i want to do... – Ofek Ron Oct 06 '14 at 08:57

0 Answers0