Android开发――打开/关闭免提

//打开扬声器
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();
    }
}


//关闭扬声器
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,"�P�器已��P�]",Toast.LENGTH_SHORT).show();
}

你可能感兴趣的:(android,免提)