Automatic enabling of loud speaker

copiloto

Member
Licensed User
Longtime User
Hello,

I'm trying to automatically activate loud speaker when establishing a phone call so that it be a hands-free.

Could someone drive me how to?

Thanks you.
 

madSac

Active Member
Licensed User
Longtime User
B4X:
'Service module
Sub Process_Globals
    Dim PE As PhoneEvents
    Dim AC As AnswerCall
    Dim PhoneId As PhoneId
    
    
End Sub
Sub Service_Create
    PE.InitializeWithPhoneState("PE",PhoneId)
    AC.Initialize("AnswerCall")
    Log("Service created")
    
End Sub

Sub Service_Start
    Log("Service started.")
End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber)
    Log(Intent.ExtrasToString)
    ToastMessageShow(IncomingNumber,False)
       If AC.isRinging == True Then
        AC.AnswerPhone
        
    End If
    AC.enableSpeakerphone
End Sub
Sub Service_Destroy
    
End Sub
 
Upvote 0

copiloto

Member
Licensed User
Longtime User
Hi madSac,

Thanks for your example. I tried it, but unfortunately, answercall seems not to work too fine in my SG3... it seems to be a compatibility problem because PE_PhoneStateChanged doesn't activate when an incoming call is present.

Best regards.
 
Upvote 0

madSac

Active Member
Licensed User
Longtime User
Hi madSac,

Thanks for your example. I tried it, but unfortunately, answercall seems not to work too fine in my SG3... it seems to be a compatibility problem because PE_PhoneStateChanged doesn't activate when an incoming call is present.

Best regards.
in that case try registering an intent and then handling it in service create event. This will most probably work in every device.
 
Upvote 0

copiloto

Member
Licensed User
Longtime User
Hi madSac,

Finally answercall works! Simply your first post is enough. I didn't watch it was a service module and was seeing the same movie over and over... Loud speaker is the only thing it seems not to activate. Only it activates normal speaker (ear).

Thanks a lot!
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friend,

if I am receiving call, then is everything OK = I hear voice in SPEAKER

but

if I am making call


B4X:
    ac.enableSpeakerphone       
        Dim callingmyn As PhoneCalls
        StartActivity(callingmyn.Call(mynumber))

I am using
B4X:
ac.enableSpeakerphone

nothing happen, the voice IS NOT IN SPEAKER

please where I am doing mistake?
Thank you very much
 
Upvote 0
Top