hi you all,
i've to do a call, i use the following code:
B4X:
Dim intent1 As Intent
intent1.Initialize("android.intent.action.CALL", "tel:999")
StartActivity(intent1)
on my phone it works on another smartphone it doesnt work.
it is the right code to do a call?
I mean, the olny thing i ve to think is that i use an old code and maybe there is a better code to do a call.
Hoping to have explained the problem.
thank you.
hi, because i have the same problem, i would like to clarify that on android version lower than 10, the code worked fine for me while it fails from android 10; this, despite the permission added in the manifesto as advised by JohnC. Is there anything else I forgot to add to make the call successful?
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
AddPermission(android.permission.CALL_PHONE)
'End of default text.
B4XMainPage:
B4XMainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
Dim intent1 As Intent
intent1.Initialize("android.intent.action.CALL", "tel:089XXXXXXX")
StartActivity(intent1)
Log("call")
End Sub
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="30"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
AddPermission(android.permission.CALL_PHONE)
'End of default text.
B4XMainPage:
B4XMainPage:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
Dim intent1 As Intent
intent1.Initialize("android.intent.action.CALL", "tel:089XXXXXXX")
StartActivity(intent1)
Log("call")
End Sub
Later versions of Android you can't just add the permissions in the Manifest, you need to get specific permission from the user too.
Try this (inB4XPage_Created)
B4X:
Dim rplist As List
Dim rpPermission As String
rplist.Initialize
rplist.AddAll(Array As String(rp.PERMISSION_CALL_PHONE))
Do While rplist.Size > 0
rpPermission = rplist.Get(0)
rp.CheckAndRequest(rpPermission)
wait for B4XPage_PermissionResult(rpPermission As String, Result As Boolean)
If Result = True Then
rplist.RemoveAt(0)
Continue
End If
If Result = False Then
ExitApplication
End If
Loop
Sorry, I finally figured out that it was a permissions configuration problem on my phone (probably because the apk installs outside of playstore). On first run it crashed and went to grant call permissions at the settings level... then everything worked. JohnC, thanks for the assistance.
Later versions of Android you can't just add the permissions in the Manifest, you need to get specific permission from the user too.
Try this (inB4XPage_Created)
B4X:
Dim rplist As List
Dim rpPermission As String
rplist.Initialize
rplist.AddAll(Array As String(rp.PERMISSION_CALL_PHONE))
Do While rplist.Size > 0
rpPermission = rplist.Get(0)
rp.CheckAndRequest(rpPermission)
wait for B4XPage_PermissionResult(rpPermission As String, Result As Boolean)
If Result = True Then
rplist.RemoveAt(0)
Continue
End If
If Result = False Then
ExitApplication
End If
Loop
Hello,
I had the same problem and using your code it works well because it allows to offer authorization to use the phone for the application.
Question: Where should I ideally place this code, when the main page loads, or in Starter. If in Starter how to split the code.
THANKS