Android examples for android.media:AudioManager
Close Speaker
import android.content.Context; import android.media.AudioManager; public class Main { private static int currVolume = 0; public static void CloseSpeaker(Context context) { try {//from w w w .j a v a 2 s.c o m AudioManager audioManager = (AudioManager) context.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(); } } }