tags:

views:

292

answers:

1

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?

+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
Sweet. You have to 'return true;' after doing your thing to suppress the phone's default volume behavior.
Jim Blackler
Also to completely suppress the default behavior you should also catch the events and return true in an onKeyUp() override.
Jim Blackler
Or you could override dispatchKeyEvent(KeyEvent event) method.
Immortal