Http://blog.csdn.net/hufeng882412/article/details/7310131
[Java]View
Plaincopy
- // Volume control, initialization Definition
- Audiomanager maudiomanager = (audiomanager) getsystemservice (context. audio_service );
- // Maximum volume
- Int maxvolume = maudiomanager. getstreammaxvolume (audiomanager. stream_music );
- // Current volume
- Int currentvolume = maudiomanager. getstreamvolume (audiomanager. stream_music );
Directly control the volume:
[Java]View
Plaincopy
- If (issilent ){
- Maudiomanager. setstreamvolume (audiomanager. stream_music, 0, 0 );
- } Else {
- Maudiomanager. setstreamvolume (audiomanager. stream_music, tempvolume, 0); // tempvolume: absolute volume value
- }
Use one step to increase or decrease the volume. The default volume control bar is displayed:
[Java]View
Plaincopy
- // Reduce the volume and bring up the system volume control
- If (flag = 0 ){
- Maudiomanager. adjuststreamvolume (audiomanager. stream_music, audiomanager. adjust_lower,
- Audiomanager. fx_focus_navigation_up );
- }
- // Increase the volume and bring up the system volume control
- Else if (flag = 1 ){
- Maudiomanager. adjuststreamvolume (audiomanager. stream_music, audiomanager. adjust_raise,
- Audiomanager. fx_focus_navigation_up );
- }