Android Question Auto Answer Call

Jaco vd Walt

Member
Licensed User
Longtime User
I know that this has been discussed several times in the past, and up to now it seems like there was no solution. However according to the issue tracker from Google, since Android 8, this was resolved by means of using this code :

B4X:
  if(Build.VERSION.SDK_INT >= 26) {
                if(checkSelfPermission("android.permission.ANSWER_PHONE_CALLS") == PackageManager.PERMISSION_GRANTED) {
                        TelecomManager tm = (TelecomManager) this.getSystemService(Context.TELECOM_SERVICE);
                        if(tm != null)
                                tm.acceptRingingCall();
                }
        }

This is java code, and just before I test it using the javaobject method in b4a, I was wondering if there was a better way to do it in b4a ?

So to be clear, is there someone who could convert the code to b4a :)

Thanks !
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add the permission with AddPermission(android.permission.ANSWER_PHONE_CALLS) in the manifest editor.

Request it at runtime with rp.CheckAndRequest("android.permission.ANSWER_PHONE_CALLS")
You will need to answer from the service. You can use rp.Check to check whether you have permission or not.

B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim tm As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom"))
if tm.IsInitialized Then tm.RunMethod("acceptRingingCall", Null)
 
Upvote 0
Top