B4A Library AnswerPhone

basicuser27

Member
Licensed User
Longtime User
I, can I automatically hang up a call with this library ?

if so, can you please provide a code snippet ?

Thanks
 

mohsen nasrabady

Active Member
Licensed User
Longtime User
search forum you can listen to phone state with phone library in a service
when phone is in state RINGING then with this library answer or hangup phone
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Mohsend.
Work very fine ;)

B4X:
'Service module
Sub Process_Globals
    Dim PE As PhoneEvents
    Dim AP As AnswerPhone
    Dim P As Phone
End Sub
Sub Service_Create
    PE.InitializeWithPhoneState("PE",PhoneId)
 
    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)
    ToastMessageShow("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber, True)
    If State = "RINGING" Then
        'State Silent Mode
        P.SetRingerMode(P.RINGER_SILENT)
        AP.answercall
        ToastMessageShow("2 -- PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber, True)
    End If
 
End Sub
Sub Service_Destroy
   
End Sub
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Mohsen, maybe about function endcall i have problem that dont work.

The code is:

B4X:
......
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    ToastMessageShow("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber, False)
If IncomingNumber = "+3933XXXXXX" Then   
    If State = "RINGING" Then
        AP.answercall
        tempo.Initialize("tempo", 10000 )
        tempo.Enabled = True
    End If
End If
End Sub
 
 
 
Sub tempo_Tick
    ToastMessageShow("Finito Tempo",True)
    AP.endcall
  tempo.Enabled = False
End Sub

Work the answer but when time finish... endcall dont work.
Any idea ?
Thank you
 

mohsen nasrabady

Active Member
Licensed User
Longtime User
thnx for your help
maybe this method just reject call
do you test to reject call?
what is your device? i think in some new device (HTC and LG) not work
 

MarcoRome

Expert
Licensed User
Longtime User
I try in device: Huawei Y300 and no i dont reject call.
But simple i response ...adn after 10 second i will be close the call.
 

MarcoRome

Expert
Licensed User
Longtime User
Ok test done. And also so endcall dont work


B4X:
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    ToastMessageShow("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber, False)
If IncomingNumber = "+3933XXXXX" Then   
    If State = "RINGING" Then
        P.SetRingerMode(P.RINGER_SILENT)
        AP.endcall
    End If
End If
End Sub
 

peacemaker

Expert
Licensed User
Longtime User
Impossible to detect the reply moment, no formal API, maybe only in Android 5.0, seems, some new API were added...
 
Top