AudioManager对扬声器的控制的附带问题

来源:互联网 发布:网络贷款不还会判刑么 编辑:程序博客网 时间:2024/06/06 02:38

如果设置了扬声器状态没有还原,会影响到来电通话时的扬声器状态,所以在程序中控制扬声器时,需要在Onstart时记录


         /** 记录语音播放状态 */
        AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
        mIsAudioSpeakerOn = audioManager.isSpeakerphoneOn();
        mAudioMode = audioManager.getMode();
        mIsBluetoothScoOn = audioManager.isBluetoothScoOn(); 


在OnStop时还原:


OnStop的时候需要还原状态:
       /** 还原语音播放状态 by oujingwen */
       AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
       audioManager.setSpeakerphoneOn(mIsAudioSpeakerOn);
       audioManager.setMode(mAudioMode);
       audioManager.setBluetoothScoOn(mIsBluetoothScoOn);