Android Question [RESOLVED] Turn the SpeakerPhone on is API 25+

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

Anyone have any issues with turning on the speaker phone in Android 7.1 (API 25)

I have tried all the methods on the forum but cannot seem to get it working. I have it working up to API 24.

Regards

John.
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
I should have been more specific in my question.

When we are making a phone call we want the speakerphone on during the call, it part of the functionality of the app. It work's fine until API 25.

e.g code run in main work up too API 24, does not seem to work on API 25

B4X:
Dim rr As Reflector
rr.Target = rr.GetContext
rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String")
rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")

Regards

John.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
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

Regards

John.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
there still seems to be an issue with the above code in API 25, we just tested and it does not turn on the speakerphone.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

Here is an update.

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)

Regards

John.
 
Upvote 0
Top