Reputation: 11
I have source code for SmartMouse android app. I want to alter the function of volume keys with the onscreen buttons. I have basic knowledge for C programming but don't know java. What part should I search for in the code?
This might be a lame question but I badly need this.
Upvotes: 1
Views: 2524
Reputation: 1643
You have to capture the event as mentionned here : Android - Volume Buttons used in my application
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
//TODO
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
dispatchKeyEvent is not only called for volume keys, it will catch all the key event so you have to :
The key is dispatchKeyEvent is called before any other method by the system, so you can intercept the event
Upvotes: 4