Android Question How to Reject OR Answer a call with InCallService

S.M.R

Member
It has been a while since I delved into all the details but I can assure you that regular apps cannot reject or answer phones on recent versions of Android.
So what is the solution?

Does that mean there is no way in the B4a?!!

No Library?!
No Code?!
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
About this Android limitation... Erel mean we must have (ask for) PERMISSIONs (and google maybe not give us - but may be will give)... new phones like Samsung, XIAOMI... etc... have Phone-Catalog of those Companies that has the feature of rejecting unknown phones or not included in Phone Catalog...

at manifest... for sure you will need these...
B4X:
AddPermission("android.permission.CALL_PHONE")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.READ_CONTACTS")
AddPermission("android.permission.ANSWER_PHONE_CALLS")
AddPermission("android.permission.READ_CALL_LOG")

but at the code....
it is about how will do that... and what will work with the version of Android...

B4X:
Sub ENDCALL
    If howend="EndCall" Then 'AVER>27
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim tm As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom"))
    Dim success As Boolean = tm.RunMethod("endCall", Null)
    If success=False Then
            Dim success As Boolean = tm.RunMethod("endCall", Null)
    End If
    Else
        KillCall
    End If
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

Have in mind that the.... ending a phone call is "easy" but reading the incoming will be tricky from version to version...
 
Last edited:
Upvote 0
Top