Reputation: 23179
I'd like to use the volume buttons for something else in my Android application. The Dolphin browser does this I am told. Anyone know how?
Upvotes: 28
Views: 20385
Reputation: 12444
in your activity,
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
return true;
default:
return super.dispatchKeyEvent(event);
}
}
Upvotes: 38
Reputation: 8290
I imagine it looks something like this:
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
// Do your thing
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
Upvotes: 38