Android手机听筒和扬声器切换


AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
private void setSpeakerphoneOn(boolean on) { if(on) {
                         audioManager.setSpeakerphoneOn(true);
                 } else {
                         audioManager.setSpeakerphoneOn(false);//关闭扬声器
                         audioManager.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
                         setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
                         //把声音设定成Earpiece(听筒)出来,设定为正在通话中
                         audioManager.setMode(AudioManager.MODE_IN_CALL);
                 }
}


你可能感兴趣的:(Android手机听筒和扬声器切换)