Android Question B4XPages permission

Sergey_New

Well-Known Member
Licensed User
Longtime User
Permission check:
Main:
    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?
 
Solution
Hi:

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)

josejad

Expert
Licensed User
Longtime User
Hi:

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)
 
Upvote 0
Solution

Sergey_New

Well-Known Member
Licensed User
Longtime User
you have to change Activity_PermissionResult with B4XPage_PermissionResult
In my main module:
B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
What and where should I write down?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
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.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
My goal is I want to apply example Erel to create a file upload page with a progress bar
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
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
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Solved a problem.
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.
 
Last edited:
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I found my error in the line
B4X:
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)
Everything works correctly.
 
Upvote 0
Top