Jaco vd Walt Member Licensed User Longtime User Sep 2, 2019 #1 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 : Code: Copy 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 !
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 : Code: Copy 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 Sep 2, 2019 #2 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. Code: Copy 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
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. Code: Copy Dim ctxt As JavaObject ctxt.InitializeContext Dim tm As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom")) if tm.IsInitialized Then tm.RunMethod("acceptRingingCall", Null)
Jaco vd Walt Member Licensed User Longtime User Sep 2, 2019 #3 Thank you for the prompt response, will test and advise the outcome for future users. Upvote 0
Jaco vd Walt Member Licensed User Longtime User Sep 2, 2019 #4 Thank you very much I can confirm that this works from Android 8 and up. The old method works for Android 6, and there is no solution for Android 7 if anyone else runs into this. Upvote 0
Thank you very much I can confirm that this works from Android 8 and up. The old method works for Android 6, and there is no solution for Android 7 if anyone else runs into this.
A Andrea307cc New Member Licensed User Longtime User Oct 5, 2019 #5 Dear, in android 9 how to do this! i run this code but nothing happens. Upvote 0
Jaco vd Walt Member Licensed User Longtime User Oct 5, 2019 #6 Did you add the permission, and check it with Runtime permissions ? Upvote 0
A Andrea307cc New Member Licensed User Longtime User Oct 6, 2019 #7 yes! but nothin happened Upvote 0