End Call Incoming

arenaluigi

Well-Known Member
Licensed User
Longtime User
Hi Erel,

sorry for my bad english:D

I have the source android for the reject a call in eclipse.
I tried to create a library to use it in Basic4 but i can't.
If I send the sources working you, could try to create a library for us?:sign0085:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the same code with Reflection:
B4X:
Sub KillCall
   Dim r As Reflector
   r.Target = r.GetContext
   Dim TelephonyManager, TelephonyInterface As Object
   TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
   r.Target = TelephonyManager
   TelephonyInterface = r.RunMethod("getITelephony")
   r.Target = TelephonyInterface
   r.RunMethod("endCall")
End Sub

You should add this permission with the manifest editor:
B4X:
AddPermission("android.permission.CALL_PHONE")

Note that I haven't tested this code. You can use PhoneEvents to run this code when the phone rings.
 

KZero

Active Member
Licensed User
Longtime User
nice code
but there is anyway to use this code to accept the call and make the ringer silent ?
 

djpero

Member
Licensed User
Longtime User
Process_outgoing_calls

Can we use PROCESS_OUTGOING_CALLS to run application ?
 

koaunglay

Member
Licensed User
Longtime User
This is the same code with Reflection:
B4X:
Sub KillCall
   Dim r As Reflector
   r.Target = r.GetContext
   Dim TelephonyManager, TelephonyInterface As Object
   TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
   r.Target = TelephonyManager
   TelephonyInterface = r.RunMethod("getITelephony")
   r.Target = TelephonyInterface
   r.RunMethod("endCall")
End Sub

You should add this permission with the manifest editor:
B4X:
AddPermission("android.permission.CALL_PHONE")

Note that I haven't tested this code. You can use PhoneEvents to run this code when the phone rings.
Thanks Erel! Very nice!
That is work but it is ring about one second. So it show missed call.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim pe As PhoneEvents
    Dim ac As AnswerCall
    Dim phid As PhoneId
End Sub
Sub Service_Create
    pe.InitializeWithPhoneState("pe", phid)
    ac.Initialize("answercall")
   
End Sub


Sub pe_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    If IncomingNumber = "09797666203" Then
        KillCall
    Else
        ToastMessageShow(IncomingNumber, True)
        ac.LetPhoneRing(3000)
            If ac.isRinging == True Then
                ac.AnswerPhone
            End If
            ac.enableSpeakerphone
    End If
   
End Sub
Sub KillCall
   '    For This ---- You should add "AddPermission("android.permission.CALL_PHONE")" in manifest editor
   Dim r As Reflector
   r.Target = r.GetContext
   Dim TelephonyManager, TelephonyInterface As Object
   TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
   r.Target = TelephonyManager
   TelephonyInterface = r.RunMethod("getITelephony")
   r.Target = TelephonyInterface
   r.RunMethod("endCall")
End Sub
How should I do ? I mean no need to show missed call.
 

koaunglay

Member
Licensed User
Longtime User
I don't think that you can do anything about it. This code runs immediately when the incoming call is recognized.
Please one more help Erel!
B4X:
If IncomingNumber = "09797666203" Then   
    KillCall
End If
That was KillCall. But when I write with db it is not Killcall. It is ringing.
The Code is ....
B4X:
Sub pe_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
'''''                    Dim bnum As String
'''''                    bnum = IncomingNumber
'        For Block number from sq
        Main.c = Main.sq.ExecQuery("SELECT * FROM blacklist")
        For i = 0 To Main.c.RowCount - 1
            Main.c.Position = i
            Main.c.GetString("ph_num")
                            If Main.c.GetString("ph_num").Contains(IncomingNumber) Then    '     "09797666203" Then    /    IncomingNumber =
                                KillCall
                            Else
                                ToastMessageShow(IncomingNumber, True)
                                ac.LetPhoneRing(3000)
                                    If ac.isRinging == True Then
                                        ac.AnswerPhone
                                    End If
                                    ac.enableSpeakerphone
                            End If       
        Next   
        Main.c.Close

                   
End Sub
Please !!!!
 
Top