Volume control on Android

I’m trying to get my phone’s hard volume keys to control the volume of sounds in my game, which uses SDL 2.0 and SDL_mixer.

Google suggests adding the following in my onCreate method:

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

So I did this:

Code:

public class GravityActivity extends SDLActivity {

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
} 

}

But the volume buttons still don’t do anything.

Has anyone got this working?

I’m testing on a Motorola Droid Razr running Ice Cream Sandwich.

Thanks,
Philip.

Thanks for your help. Since I don’t think I need to process the volume keys in my game (so long as Android changes the volume), I ended up doing this:

Code:

public boolean onKey(View  v, int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
        keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
    {
        return false;
    }
    ....

Seems to work well.

Thanks again!

Philip.