Android Question Hang Up Incoming Calls

jgbozza

Member
Licensed User
Longtime User
I've seen some examples in the forum but they don't seem to work with a Mxt Tablet.

I added to manifest and created a service named PhoneCalling started at the main activity startup.

B4X:
AddPermission("android.permission.CALL_PHONE")

Here's the code:
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
End Sub
Sub Service_Create
    PE.Initialize("PE")
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber)
    Log(Intent.ExtrasToString)
    KillCall
End Sub
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

Has someone faced the same problem and got this to work ?
 

bsnqt

Active Member
Licensed User
Longtime User
The code above should work (KillCall).

Use PhoneStateListener ("PSL").
B4X:
Sub PSL_onCallStateChanged (State As Int, incomingNumber As String)
     KillCall
End Sub

Try to add this:
B4X:
AddPermission("android.permission.READ_PHONE_STATE")
(you may not need it, as you are using PhoneEvents).
And also the following:
B4X:
AddPermission(android.permission.MODIFY_PHONE_STATE)

Also make sure if your Service is still running when you receive the call. For this you may want to create a Sticky Service (search for Erel's post on this).

Let us know if you can fix it and it works.
 
Upvote 0
Top