this piece of code not work on android 13 maybe someone know how to make it work on android 13?
TelephonyManager.CALL_STATE_OFFHOOK -> {
// Call answered (in progress) Handle call answered state here
Timber.d("onPhoneState: CALL_STATE_OFFHOOK")
val mainActivity = getMainActivity()
val audioManager = mainActivity.getSystemService(Context.AUDIO_SERVICE) as AudioManager?
audioManager?.mode = AudioManager.MODE_IN_CALL
audioManager?.isSpeakerphoneOn = true
}
To turnon speaker when phonecall is in progress via kotlin
In Android 10 and above: Direct control over the speakerphone during calls is restricted for security reasons. Consider these approaches: