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.
Asked
Active
Viewed 1,192 times
1 Answers
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);
}

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