B4A Library AnswerPhone

I, can I automatically hang up a call with this library ?

if so, can you please provide a code snippet ?

Thanks
 
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
 
Hi Mohsend.
Work very fine ;)

Code:
'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
 
Hi Mohsen, maybe about function endcall i have problem that dont work.

The code is:

Code:
......
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
 
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
 
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.
 
Ok test done. And also so endcall dont work


Code:
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
 
Impossible to detect the reply moment, no formal API, maybe only in Android 5.0, seems, some new API were added...
 
Back
Top