Same as this question and many others from a few years ago: how to turn speaker on/off programmatically in android 4.0
It seems that Android has changed the way it handl
In Android Pie, I had the same problem. I resolved it using an InCallService with
setAudioRoute(ROUTE_SPEAKER)
Your app needs to be Default phone app.