Android Question Male Call with speaker on

ronens

Member
Licensed User
hello
i tried to run this solution ( i red the other posts on it)
my app is making a call .
when i run on debug and add break point it work. but when i run it in full mode the speaker not open.

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))

Dim pc As PhoneCalls
StartActivity(pc.Call("01211111"))

any idea?
 

ronens

Member
Licensed User
hello
i tried to run this solution ( i red the other posts on it)
my app is making a call .
when i run on debug and add break point it work. but when i run it in full mode the speaker not open.

B4X:
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))

Dim pc As PhoneCalls
StartActivity(pc.Call("01211111"))
any idea?
 

ronens

Member
Licensed User
still not working

do i need to check phone state? if do is it in the same activity?
and is it the correct order in the code?
open the speaker and then making a call?

the goal is to open the speaker from beginning if its possible . i would like the customer will hear the ring back tone on he speaker ,
if it is not possible then open the speaker after the answer
 

ronens

Member
Licensed User
at this moment nothing work.
the speaker is not activate.

i run this code from activity
any idea?

B4X:
Sub MakeCallWithSpeaker(value As Boolean)
    Try
        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))

        Dim pc As PhoneCalls
        StartActivity(pc.Call("0541111222"))
    Catch
        Log(LastException)
    End Try
End Sub
 

ronens

Member
Licensed User
i tried the simple code from other posts
B4X:
Sub Button1_Click
    Msgbox("connecting","something's happening!")
    Dim pc As PhoneCalls
    StartActivity(pc.Call("0541112222"))
    'open speakerphone
    Dim rr As Reflector
    rr.Target = rr.GetContext
    rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String")
    rr.RunMethod2("setSpeakerphoneOn", True, "java.lang.boolean")
End Sub
when i am running it do nothing, it's not arrived to the code after the line:
Dim rr As Reflector
is it because the phone app is activate and my activity not?
 

ronens

Member
Licensed User
ok
for now i added new service to handle the speaker.
i start the service before making the call and it work ok
 

ronens

Member
Licensed User
some updates...
i tested the app on samsung galaxy s9 , and the speaker is not open.
any ideas?
 
Top