11

Been struggling with the audio manager after the latest Android 11 rollout to Samsungs. It has been working smoothly for several years now including all possible Android 10 devices and below.

Here is how we get the audio manager:

val audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager 

Previously it was like this:

audioManager?.let {
    it.isSpeakerphoneOn = it.isSpeakerphoneOn.not()
}

On clicking the "Speaker" button, we've changed the value for the speaker to opposite, and the speaker turned on/off perfectly. This stopped working on Android 11 (in particular we're testing on Samsung s10e with OneUI 3.0)

We've also tried to change mode to audio manager before turning on/off the speaker with no luck. Now we do this:

private fun enableSpeaker() {
    val audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
    if (audioManager != null) {
        if (!audioManager.isSpeakerphoneOn) {
            audioManager.isSpeakerphoneOn = true
            audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
        }
    }
}
private fun disableSpeaker() {
    val audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
    if (audioManager != null) {
        if (audioManager.isSpeakerphoneOn) {
            audioManager.isSpeakerphoneOn = false
            audioManager.mode = AudioManager.MODE_NORMAL
        }
    }
}

In this case it starts to work inside of our app while the call is being handled by VoIP providers (like Zoiper, for example), but not the native calling app from Samsung on Android 11.

In particular done tests on already two Samsung Galaxy s10e with Android 11 (OneUI 3.0).

Any help is much appreciated.

  • 1
    A fellow VoIP developer here, will also look into this and keep you up to date. Have no complaints about it yet. What VoIP library do you use? Or only tried Zoiper? And what version? – jobbert Feb 09 '21 at 16:10
  • It's not a voip solution. Call is happening simultaneously via either native dialer or some void solution (like Zoiper for example, we're heavily using it for tests, but it's not part of our solution) – Stepan Radiboh Feb 10 '21 at 21:09
  • Seems odd, according to the official documentation, .isSpeakerphoneOn is still supported and **not** deprecated. – J. M. Arnold Feb 15 '21 at 18:50
  • Could be it's has something to do with the Samsung dialer itself capturing the audio manager in OneUI 3.0, not sure though. Haven't managed to figure it out yet. As it works with other VoIP dialers – Stepan Radiboh Feb 16 '21 at 21:01
  • We faced with isSpeakerphoneOn incorrectly working on Android 11 in case a headset (via Bluetooth) is connected to the device – Aliaksei Mar 19 '21 at 11:22

1 Answers1

0

Set the mode before setting isSpeakerphoneOn

private fun enableSpeaker() {
    val audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
    if (audioManager != null) {
        if (!audioManager.isSpeakerphoneOn) {
            audioManager.mode = AudioManager.MODE_IN_COMMUNICATION
            audioManager.isSpeakerphoneOn = true
        }
    }
}
private fun disableSpeaker() {
    val audioManager = activity?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
    if (audioManager != null) {
        if (audioManager.isSpeakerphoneOn) {
            audioManager.mode = AudioManager.MODE_NORMAL            
            audioManager.isSpeakerphoneOn = false

        }
    }
}
user16930239
  • 6,319
  • 2
  • 9
  • 33