Android Question Answer call Automaticaly - Android 8

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

I know that in formu was this theme discussed, but I want ask for certain:

1. It is possible answer call programmaticaly in Android >=v.8 via apps written in B4A?

2. I chceck in my phone (Android 8) this code:
B4X:
Dim rp As RuntimePermissions
If rp.Check("android.permission.ANSWER_PHONE_CALLS")=False Then
ToastMessageShow("1-Hands free-Answer call programmaticaly is impossible",False)
Else
ToastMessageShow("2-Hands free-Answer call programmaticaly is possible",False)
End If
And I get answer: 1-Hands free-Answer call programmaticaly is impossible
Can I take this message as 100% that is not possible to answer call in this phone programmaticaly with B4A v83.0 possibilities?

3. Do you think that next version of Android or next version of B4A will allow this functionality? (answer call programmaticaly). (I dont know if next development of this functionality depend only on Android or if this funcionality depend on version B4a too). I hope that I describe this question right - I love B4A too much and I am only asking for the future of this functionality.

Thank you very much,
petr4ppc
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
The code you posted is incorrect. See the runtime permissions tutorial.

1. You should add the permission with AddPermission in the manifest editor and request it at runtime.
2. You should then call TelecomManager.acceptRingingCall.

Something like:
B4X:
If Phone.SdkVersion >= 26 Then
 Dim ctxt As JavaObject
 ctxt.InitializeContext
 Dim telecom As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom"))
 telecom.RunMethod("acceptRingingCall", Null)
End If
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you very much Erel, please I get in logs this:
B4X:
main_buttontry_click (java line: 3984)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at xxx.app.mobile.main._buttontry_click(main.java:3984)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6291)
    at android.view.View$PerformClick.run(View.java:24931)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7425)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.SecurityException: Neither user 10123 nor current process has android.permission.ANSWER_PHONE_CALLS.
    at android.os.Parcel.readException(Parcel.java:1946)
    at android.os.Parcel.readException(Parcel.java:1892)
    at com.android.internal.telecom.ITelecomService$Stub$Proxy.acceptRingingCall(ITelecomService.java:1380)
    at android.telecom.TelecomManager.acceptRingingCall(TelecomManager.java:1266)
    ... 17 more

I have in manifest editor this:
B4X:
AddPermission(android.permission.ANSWER_PHONE_CALLS)
  AddPermission("android.permission.CALL_PHONE")
 AddPermission(android.permission.READ_PHONE_STATE)

please for advice

See the runtime permissions tutorial.
Yes, thank you I will chceck it
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
I am checking it and please for advice what I can set in "rp" list of permission?
Because there is not "permission.ANSWER_PHONE_CALLS"

B4X:
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.-------------------)

Best regards,
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
B4X:
Sub button_click
    Dim rp As RuntimePermissions
    rp.CheckAndRequest("android.permission.ANSWER_PHONE_CALLS")
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
 
        If Result = True Then
            ToastMessageShow(Permission & "-OK", True)
             Else
                 ToastMessageShow(Permission & "-KO", True)
         
        End If

End Sub

After push button is APP going to PAUSE MODE. Please what I am doing wrong?

If I try this:
B4X:
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
    wait for Activity_PermissionResult(permission As String, result As Boolean)
    If result=True Then
        ToastMessageShow("OKKK",True)
    Else
        ToastMessageShow("KOOO",True)
    End If

Then I get result. So the trouble is with adding "android.permission.ANSWER_PHONE_CALLS", why?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should never have an Activity_PermissionResult sub. Watch the video tutorial.

Tested with this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim rp As RuntimePermissions
   rp.CheckAndRequest("android.permission.ANSWER_PHONE_CALLS")
   wait for Activity_PermissionResult(permission As String, result As Boolean)
   Log(result)
End Sub
It works properly. Make sure to add the permission with the manifest editor.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
I saw video and thank you very much for this video.

In manifest I have:
B4X:
AddPermission(android.permission.ANSWER_PHONE_CALLS)

and I am trying it with this code:
B4X:
Sub buttontryit_click
   Dim rp As RuntimePermissions
   rp.CheckAndRequest("android.permission.ANSWER_PHONE_CALLS")
   wait for Activity_PermissionResult(permission As String, result As Boolean)
   Log(result)
End Sub

After pushing button the app is going to PAUSE MODE and I see nothing in LOG.
It is possible that my Phone is bad? Huawei Y6 2018, Android 8.0.0

Best regards
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Erel, I shame.
I have not set right SDK version in manifest editor. All permission is now possible to SET as you wrote.
Best regards, thank you very much
p4ppc
 
Upvote 0
Top