Question

Doese anyone know of a tutorial on how to make a Volume Controller like this one (with a Save button at the bottom). This is my problem, how to make that "Save" button. I can create all the volume SeekBars, but unfortunately when I make changes on SseekBar it automatically changes the volume from the phone settings (ringer, notification, media, in call).

Thanks in advance.

Was it helpful?

Solution

First off, use the SeekBar and retrieve the value it sets to. Don't set the volumes while the SeekBar is adjusted. And then, when the button Save is pushed, send those values to the AudioManager.

Use this link for more detailed explanation: Android Development: Change Media volume? as well as this one: SeekBar1.java

Here's a quick example of how it might look like:

AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

ImageButton save = (ImageButton) findViewById(R.id.save);

save.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, valueFromSeekBar, flagIfNeeded);
    }
}); //End setOnClickListener()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top