Android Question Close call button when is calling, possibile?

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello everyone, I would like to create an app that allows me to make a sequence of phone calls to be interrupted while it is ringing after about 5 seconds, every 5 seconds the app must call a number entered in a list of numbers and when it closes the call switch to next number, the problem lies in blocking the call in progress, being that during the call the app goes in the background there is a method to intercept the end call button from the code or to be able to close the call automatically? I am using the phone library to make the call but I don't find how to close it automatically after a few seconds.


B4X:
#Region  Project Attributes
    #ApplicationLabel: Auto_Chiamate
    #VersionCode: 1
    #VersionName: 1.0
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: True
    #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private btnchiama As Button
    Private rp As RuntimePermissions
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnchiama_Click
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For Activity_PermissionResult ( Permission As String, Result As Boolean)
    If Result Then
    Dim p As PhoneCalls
    StartActivity(p.Call("xxxxxxxx"))
    Else
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
try this:
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
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
try this:
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
ricevo questo errore:
B4X:
starter_v5 (java line: 161)
java.lang.NoSuchMethodException: java.lang.Object.endCall []
    at java.lang.Class.getMethod(Class.java:2072)
    at java.lang.Class.getDeclaredMethod(Class.java:2050)
    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
    at b4a.example.starter._v5(starter.java:161)
    at b4a.example.starter._timerkill_tick(starter.java:205)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7948)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
TelephonyInterface = r.RunMethod("getITelephony") r.Target = TelephonyInterface r.RunMethod("endCall")
based on the SO link the endCall is part of TelecomManager

@fifiddu70 Try it this way. Does it work?
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

Please note:
At the same time the original endCall() method under TelephonyManager is now protected by MODIFY_PHONE_STATE permission, and can no longer be invoked by non-system Apps by reflection without the permission (otherwise a Security Exception will be triggered).
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
 
Upvote 0
Top