I think this may solve it. Code below works up API 24, anyone got API 25 like to try it ?
B4X:
Private Sub setSpeakerPhone(value As Boolean)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim audioManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array(ctxt.GetField("AUDIO_SERVICE")))
Dim audioManagerStatic As JavaObject
audioManagerStatic.InitializeStatic("android.media.AudioManager")
Dim originalMode As Int = audioManager.RunMethod("getMode",Null)
If value Then
audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_IN_CALL")))
Else
audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_NORMAL")))
End If
audioManager.RunMethod("setSpeakerphoneOn", Array(value))
' // restore original mode
audioManager.RunMethod("setMode", Array(originalMode))
End Sub
I went out and purchased 2 different phones this morning, both with Android 7.1.1, a Vodafone Smart E8 and V8, it works on both of them perfectly. The phone that it was tested on originally was a :Manufacturer OnePlus, Model ONEPLUS A3003,Product OnePlus3,API Level 25 which is does not work on.
So there you have it, you need lots of phone for this type of work !!! (20+ now at this stage)