Android volume control adjustment

Source: Internet
Author: User

Http://blog.csdn.net/hufeng882412/article/details/7310131

[Java]View
Plaincopy

  1. // Volume control, initialization Definition
  2. Audiomanager maudiomanager = (audiomanager) getsystemservice (context. audio_service );
  3. // Maximum volume
  4. Int maxvolume = maudiomanager. getstreammaxvolume (audiomanager. stream_music );
  5. // Current volume
  6. Int currentvolume = maudiomanager. getstreamvolume (audiomanager. stream_music );



Directly control the volume:
[Java]View
Plaincopy

  1. If (issilent ){
  2. Maudiomanager. setstreamvolume (audiomanager. stream_music, 0, 0 );
  3. } Else {
  4. Maudiomanager. setstreamvolume (audiomanager. stream_music, tempvolume, 0); // tempvolume: absolute volume value
  5. }




Use one step to increase or decrease the volume. The default volume control bar is displayed:
[Java]View
Plaincopy

  1. // Reduce the volume and bring up the system volume control
  2. If (flag = 0 ){
  3. Maudiomanager. adjuststreamvolume (audiomanager. stream_music, audiomanager. adjust_lower,
  4. Audiomanager. fx_focus_navigation_up );
  5. }
  6. // Increase the volume and bring up the system volume control
  7. Else if (flag = 1 ){
  8. Maudiomanager. adjuststreamvolume (audiomanager. stream_music, audiomanager. adjust_raise,
  9. Audiomanager. fx_focus_navigation_up );
  10. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.