1

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.

manlio
  • 18,345
  • 14
  • 76
  • 126

1 Answers1

4

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 :

  • Get the event code
  • Check if it's what you are seeking for
  • Do what you want according to the event :)

The key is dispatchKeyEvent is called before any other method by the system, so you can intercept the event

Community
  • 1
  • 1
Plumillon Forge
  • 1,659
  • 1
  • 16
  • 31