尝试以下代码:

private void setMicMuted(boolean state){

AudioManager myAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);

// get the working mode and keep it

int workingAudioMode = myAudioManager.getMode();

myAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

// change mic state only if needed

if (myAudioManager.isMicrophoneMute() != state) {

myAudioManager.setMicrophoneMute(state);

}

// set back the original working mode

myAudioManager.setMode(workingAudioMode);

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐