tags:

views:

113

answers:

2

I want to take overinput over the Volume Up and Down. At the moment my code is:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    Log.v(TAG, event.toString());
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
        mLamp.moveBackward();

        return false;
    }
    else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
        mLamp.moveForward();

        return false;
    }

    return true;
}
public boolean onKeyUp(int keyCode, KeyEvent event) {

    Log.v(TAG, event.toString());
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
        return false;
    }
    else if(keyCode == KeyEvent.KEYCODE_VOLUME_UP){
        return false;
    }

    return true;
}

This triggers the mLamp.moveBackward() and mLamp.moveForward() function but it still changes the volume of the ringer. What do I have to do that the ringer loudness doesn't change?

+5  A: 

If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

zed_0xff
A: 

So what would the correct code look like? I'm dealing with this same problem on build target 1.5 and it works sometimes.....if that makes any sense.

TimothyMiller