0

I'm trying to figure out how long the volume up and volume down buttons are pressed, but so far, all I've found is this answer here: Android - Getting volume button long clicks

I can't find anything less abstract than this so I have no idea how to go about implementing it; could someone point me to an example? Any help would be greatly appreciated.

1 Answers1

0
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
    int action = event.getAction();
    if(keyCode==KeyEvent.KEYCODE_VOLUME_UP){
            if (action == KeyEvent.ACTION_DOWN) {
                volUpPressed = System.currentTimeMillis();
            }
            else if (action == KeyEvent.ACTION_UP) {
                totalTimePressed = System.currentTimeMillis() - volUpPressed;
            }
    }
    return true;
    }
Wukash
  • 666
  • 5
  • 9
  • Nvm, there's also onKeyUp method so just remove `else if` part from above and move `totalTimePressed = ...` to onKeyUp – Wukash Aug 17 '16 at 21:48