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.