tags:

views:

77

answers:

1

Hello All,

I have been trying to figure this out and know that overriding the volume keys is not the most ideal thing but its the one real buttons on every Android device which is needed for my application. Currently I am overriding the volume keys with dispatchKeyEvent because onKeyUp and onKeyDown were not working. Throughout the application there are little dialogs or context menus that pop up. The problem is when those take focus I lose control of the volume buttons and it adjusts the main volume instead of acting like my button. Is there any way to completely take over the volume buttons? Any help would be appreciated.

-mlove

+1  A: 

You have to implement a listener of type DialogInterface.OnKeyListener and set it on your dialogs with setOnKeyListener to capture the volume keys.

pivotnig
This is excellent and perfect timing! Thanks for you help - it works perfectly!
Mlove
glad to help, thanks for marking the answer.
pivotnig
This worked for a dialog but I have found that I can't get to the view that made the options menu. When the menu pops up the volume keys do what the system wants again. Any ideas on how to add a OnKeyListener to a menu?
Mlove
sorry, i dont know about menu keys, but did you have a look at Menu.isShortcutKey(int, android.view.KeyEvent), http://developer.android.com/reference/android/view/Menu.html#isShortcutKey%28int,%20android.view.KeyEvent%29 ?
pivotnig