fun toggleSpeaker(context: Context) {
isSpeakerPhoneSelected.value?.let {
val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.setSpeakerphoneOn = !it
isSpeakerPhoneSelected.value = !it
logDebug(context, it.toString().plus(audioManager.isSpeakerphoneOn.toString()))
}
}
The logger shows that the isSpeakerPhoneSelected value is toggling between true and false but isSpeakerphoneOn always returns false. This stopped working as of Android 12.
These are the versions in our build.gradle:
buildToolsVersion = "29.0.3"
minSdkVersion = 23
compileSdkVersion = 30
targetSdkVersion = 30
supportLibVersion = "28.0.0"
What is causing the isSpeakerphoneOn value not to change and how to fix this? I've been beating my head against the wall over this for some time now so I appreciate any suggestions :p Thanks!