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.