Idea is to enable speakers on the phone while the user is on the call.
So first I listen for TelephonyManager.CALL_STATE_OFFHOOK
state, then with 2 seconds delay I call following code piece:
val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
if (!audioManager.isSpeakerphoneOn) {
audioManager.mode = AudioManager.MODE_IN_CALL
audioManager.isSpeakerphoneOn = true
}
This works well on Samsung, but for some reason, does not work on Huawei P20 Pro
. Any ideas?
You will probably not take no for an answer. But I think you are out of luck here. I have seen multiple occurrences of the problem you are describing and no fixes are described. In any case, it is clear that the standard Android Audiomanager does not work for Huawei phones. (for now, Huawei may come with a fix in the future)
However, I did find this link to a so called 'Audio Engine' in the documentation of Huawei. The documentation is not that elaborate, but you might just try to explore the library.
Still, that might work, but you'd have to detect which brand of phone you're using, that might be outside your scope and introduce other defects, but it is a possibility.