Today, we have a requirement in the project to use seekbar to control the volume.
I thought it was a very simple thing (it was indeed a very simple thing), but at the beginning it could not achieve what I wanted. After some modifications and searches, the solution was finally solved. In the process of solving this problem, I also found some shortcomings in my understanding of Android.
So, let's discuss it. Let's talk about the volume now.
In the Android system, there is a sound system volume, call volume, ringtone volume, Music volume, and prompt sound volume (I thought there was only one volume in Android: system volume (incomplete self-taught .....)).
Next we will introduce the methods for obtaining these volumes one by one.
To obtain these volumes, you need an audiomanager class that controls the volume together. (You can just click here on your own)
Audiomanager = (audiomanager) getsystemservice (context. audio_service );
Int Max; // The maximum volume.
Int current; // current volume
// System volume
Max = maudiomanager. getstreammaxvolume (audiomanager. stream_system );
Current = maudiomanager. getstreamvolume (audiomanager. stream_system );
// Call volume
Int max = aM. getstreammaxvolume (audiomanager. stream_voice_call );
Int current = aM. getstreamvolume (audiomanager. stream_voice_call );
// Ringtone volume
Max = maudiomanager. getstreammaxvolume (audiomanager. stream_ring );
Current = maudiomanager. getstreamvolume (audiomanager. stream_ring );
// Music volume
Max = maudiomanager. getstreammaxvolume (audiomanager. stream_music );
Current = maudiomanager. getstreamvolume (audiomanager. stream_music );
// Sound volume prompt
Max = aM. getstreammaxvolume (audiomanager. stream_alarm );
Current = Sm. getstreamvolume (audiomanager. stream_alarm );