Turn on the speaker
public void Openspeaker () {
try{
Audiomanager Audiomanager = (audiomanager) mcontext.getsystemservice (Context.audio_service);
Audiomanager.setmode (Audiomanager.route_speaker);
Currvolume =audiomanager.getstreamvolume (Audiomanager.stream_voice_call);
if (!audiomanager.isspeakerphoneon ()) {
Audiomanager.setspeakerphoneon (TRUE);
Audiomanager.setstreamvolume (Audiomanager.stream_voice_call,
Audiomanager.getstreammaxvolume (Audiomanager.stream_voice_call),
Audiomanager.stream_voice_call);
}
} catch (Exception e) {
E.printstacktrace ();
}
}
Turn off the speakers
public void Closespeaker () {
try {
Audiomanager Audiomanager = (audiomanager) mcontext.getsystemservice (Context.audio_service);
if (Audiomanager! = null) {
if (Audiomanager.isspeakerphoneon ()) {
Audiomanager.setspeakerphoneon (FALSE);
Audiomanager.setstreamvolume (Audiomanager.stream_voice_call,currvolume,
Audiomanager.stream_voice_call);
}
}
} catch (Exception e) {
E.printstacktrace ();
}
Toast.maketext (Context, "The speaker has been closed", Toast.length_short). Show ();
}
android--Open/close speakerphone