Android Development's method of shutting down and opening speaker (loudspeakers) _android

Source: Internet
Author: User

The examples in this article describe the way Android developed to turn off and turn on speaker (speakers). Share to everyone for your reference, specific as follows:

private int currvolume = 0; /** * Open Speaker */private void Openspeaker () {try{Audiomanager Audiomanager = (audiomanager) getsystemservice (Con Text.
      Audio_service);
      Audiomanager.setmode (Audiomanager.route_speaker);
      Currvolume = Audiomanager.getstreamvolume (Audiomanager.stream_voice_call);
        if (!audiomanager.isspeakerphoneon ()) {//setspeakerphoneon () is work when audio mode set to Mode_in_call.
        Audiomanager.setmode (Audiomanager.mode_in_call);
        Audiomanager.setspeakerphoneon (TRUE); Audiomanager.setstreamvolume (Audiomanager.stream_voice_call, Audiomanager.getstreammaxvolume (AudioManager.STRE
      Am_voice_call), Audiomanager.stream_voice_call);
    } catch (Exception e) {e.printstacktrace (); }/** * Shut down speaker/public void Closespeaker () {try {Audiomanager Audiomanager = (audiomanager) Getsystemservic
      E (Context.audio_service); if (Audiomanager!= null) {if (audiomanager.isSpeakerphoneon ()) {Audiomanager.setspeakerphoneon (false);
        Audiomanager.setstreamvolume (Audiomanager.stream_voice_call,currvolume, Audiomanager.stream_voice_call);
    A catch (Exception e) {e.printstacktrace ());

 }
}

For more information on Android-related content readers can view the site topics: "Android Debugging techniques and common problems solution summary", "Android Development introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", " Android Basic Components Usage Summary, Android View tips Summary, Android layout layout tips and Android Control usage summary

I hope this article will help you with the Android program.

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.