Private rp As RuntimePermissions
For Each permission As String In Array(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Return
End If
Next
loadFile(FileName)
Next, I read the text file using the procedure loadFile(FileName)
It works in B4A.
If you place this code in the B4XMainPage module the code works.
If you place this code in the Main B4XPages module the code does not work.
I need to complete this procedure before opening B4XMainPage.
The permissions in the manifest are set.
How to do it right?
From Runtime Permissions 1. Edit: In B4XPages the permission result event signature is: Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
(you have to change Activity_PermissionResult with B4XPage_PermissionResult)
From Runtime Permissions 1. Edit: In B4XPages the permission result event signature is: Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
(you have to change Activity_PermissionResult with B4XPage_PermissionResult)
Does this not work for you ? . In the B4XMainPage (Page Create Sub)
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
Private rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For B4XPage_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Return
End If
loadFile(FileName)
side note: you don't need to use For Each loop if only checking a single permission.
Solved a problem.
The B4XMainPage page was used to show the file loading. Upon completion of the download, I closed the current page and opened the page that I had previously assumed to be B4XMainPage.
I set the permissions in the main menu like this:
Main:
Sub Process_Globals
Private rp As RuntimePermissions
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
pm.Initialize(Activity)
For Each permission As String In Array(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Return
End If
Next
End Sub
I hurried.
I launched an application with the same name as on B4A, where the permission was already installed.
The question remains, how to correctly set the permission in the B4XPage project so that it is possible to read a file located in a folder with the project name?
I ask the community for help.
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
It was necessary to do this:
B4XMainPage module:
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'load the layout to Root
Root.LoadLayout("Login")
Page2.Initialize
B4XPages.AddPage("Page 2", Page2)
Page3.Initialize
B4XPages.AddPage("Page 3", Page3)
Private rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For b4xpage_PermissionResult(permission As String, Result As Boolean)
@José J. Aguilar gave you the right code in post #2 and @mangojack gave you the same correct code in post #10 already. You should not credit yourself with the solution.