Android Question PhoneStateChanged

Declan

Well-Known Member
Licensed User
I am using the following code in the Starter Service, but the PhoneStateChanged event does not trigger:
B4X:
Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    LogColor("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber, Colors.Magenta)
    LogColor(Intent.ExtrasToString, Colors.Magenta)
    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")
 
   LogColor("Call Killed", Colors.Magenta)
End Sub
I am running Android 5.1
I have added the following line to the Manifest:
B4X:
AddPermission("android.permission.CALL_PHONE")
 

Declan

Well-Known Member
Licensed User
Thanks, works great.
The phone rings once - how can I mute the ringer if a call does come in?
 
Top