0

I'm trying to make an app where if you hold down the volume down button, an action occurs. How would I go abouts doing this? I'm a noob for java, so an example would be excellent.

t3hcakeman
  • 2,289
  • 4
  • 25
  • 27

1 Answers1

3

Override onKeyLongPress in your Activity

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 
    {
        // to your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

how to capture long press volume down key in android?

Community
  • 1
  • 1
Maurice Lam
  • 354
  • 2
  • 12
  • In Eclipse, there is a shortcut key (Ctrl-Shift-O) to auto manage the imports. Otherwise you just need to import the classes you use (I can see KeyEvent here). – Maurice Lam Feb 04 '12 at 18:15