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?
views:
292answers:
1
+5
A:
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
} else {
return super.onKeyDown(keyCode, event);
}
}
Segfault
2010-03-02 22:56:07
Sweet. You have to 'return true;' after doing your thing to suppress the phone's default volume behavior.
Jim Blackler
2010-03-02 23:11:55
Also to completely suppress the default behavior you should also catch the events and return true in an onKeyUp() override.
Jim Blackler
2010-03-03 11:08:29
Or you could override dispatchKeyEvent(KeyEvent event) method.
Immortal
2010-10-28 16:49:19