android mic切换_在android中连接蓝牙耳机后,如何在内置麦克风和耳机麦克风之间切换音频输入?...

时间:2025-01-31 08:57:12

您可以使用以下代码切换蓝牙耳机麦克风 .

AudioManager audiomanager= (AudioManager)(Context

.AUDIO_SERVICE);

IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);

(mBluetoothScoReceiver, intentFilter);

();

并听取广播接收器 .

private BroadcastReceiver mBluetoothScoReceiver = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

int state = (AudioManager.EXTRA_SCO_AUDIO_STATE, -1);

if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {

// Start recording audio

log("audio connected");

startRecording();

} else if(state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED){

log("audio disconnected");

}

}

};

并且要切换(断开蓝牙耳机麦克风),您可以使用此代码 .

();