# AudioDevice input not work

**URL:** <https://react-native-webrtc.discourse.group/t/audiodevice-input-not-work/1725>\
**Category:** Android\
**Created:** [March 21, 2023, 7:26am UTC](https://react-native-webrtc.discourse.group/t/audiodevice-input-not-work/1725 "2023-03-21T07:26:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MinhVu](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/minhvu/32/672_2.png) [@MinhVu](https://react-native-webrtc.discourse.group/u/MinhVu)\
**Post date:** [March 21, 2023, 7:26am UTC](https://react-native-webrtc.discourse.group/t/audiodevice-input-not-work/1725/1 "2023-03-21T07:26:59Z")

</div>

Here is native module to route audio input:

```auto

    // 1 bluetooth
    // 2 wired device
    // 0 phone speaker
    @ReactMethod
    public void setAudioInput(String route) {
        audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

        AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);

        MediaRecorder recorder = new MediaRecorder();
        if (route.contains("Bluetooth")) {
            for (AudioDeviceInfo device : devices){
                if (device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO || device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP) {

                    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
                    audioManager.setBluetoothScoOn(true);
                    audioManager.startBluetoothSco();
                    Log.d("setAudioRoute", "bluetooth");
                    break;
                }
            }

        } else if (route.contains("Wired")) {
            for (AudioDeviceInfo device : devices) {
                if (device.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
                    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
                    audioManager.setBluetoothScoOn(false);
                    audioManager.stopBluetoothSco();
                    audioManager.setMicrophoneMute(false);
                    Log.d("setAudioRoute", "wired");
                    break;
                }
            }

        } else {
            for (AudioDeviceInfo device : devices) {
                if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_MIC) {
                    audioManager.setMode(AudioManager.MODE_NORMAL);
                    audioManager.setMicrophoneMute(false);
                    audioManager.setBluetoothScoOn(false);
                    audioManager.stopBluetoothSco();

                    Log.d("setAudioRoute", "Built-in mic");
                    break;
                }
            }

        }
    }

```

I test in android 12, 13(Samsung, realme) is good. But not work in android 11(Sharp, Vsmart, Oppo).  
Here is logcat in android studio:

```auto
2023-03-21 14:13:12.465 30597-30780 org.webrtc.Logging com.walkietalkieapp I WebRtcAudioRecordExternal: Number of active recording sessions: 1
2023-03-21 14:13:12.465 30597-30780 org.webrtc.Logging com.walkietalkieapp I WebRtcAudioRecordExternal: AudioRecordingConfigurations: 
2023-03-21 14:13:12.467 30597-30780 org.webrtc.Logging com.walkietalkieapp I WebRtcAudioRecordExternal: client audio source=VOICE_COMMUNICATION, client session id=1329 (1329)
                                                                                                      Device AudioFormat: channel count=1, channel index mask=0, channel mask=IN_MONO, encoding=PCM_16BIT, sample rate=48000
                                                                                                      Client AudioFormat: channel count=1, channel index mask=0, channel mask=IN_MONO, encoding=PCM_16BIT, sample rate=48000
                                                                                                      AudioDevice: type=TYPE_WIRED_HEADSET, id=427
2023-03-21 14:13:12.467 30597-30780 org.webrtc.Logging com.walkietalkieapp I WebRtcAudioRecordExternal: verifyAudioConfig: PASS

```

Why AudioDevice: type=TYPE\_WIRED\_HEADSET but app still use built-in mic?  
Thank you.  
Vu.
