The right method to use would be setStreamVolume on your AudioManager
. It could looks like this
AudioManager audioManager =
(AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
[int value],
[if desired a flag]);
An example use of the flag is to get the beep when setting the volume so the user can hear the outcome. The flag for that would be AudioManager.FLAG_PLAY_SOUND
.
You could use AudioManager.FLAG_SHOW_UI
if you don't want to play a sound but display a toast with the current value. The use has to get a feedback tho. Doesn't matter if it is audible or visual.
To get the maximal valid value for the given stream you just call getStreamMaxVolume()
on the AudioManager
and get an integer back which represents ... well the maximal valid value for the volume.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…