Microphone not working in wired headset on android 12

I have an issue related to the headset mic in my android app. This headset is working absolutely fine with all other apps on this device, but I can’t get audio from it my app. Also this app works fine with headsets on other devices.

Can’t reproduce with other headsets and devices. Same time other wireless headset works fine with my app

Android 12 Device Samsung A12 SDK 31

I use code below

val playbackAttributes = AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
        .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
        .build()
val audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
        .setAudioAttributes(playbackAttributes)
        .setAcceptsDelayedFocusGain(true)
        .setOnAudioFocusChangeListener { }
        .build()

audioManager.requestAudioFocus(audioFocusRequest)
val wired = audioManager.availableCommunicationDevices.firstOrNull { it.type == TYPE_WIRED_HEADSET }
audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
audioManager.setCommunicationDevice(currentDevice)

Upvotes: 1

Views: 202

Answers (0)

Related Questions