Android Question RP.CheckAndRequest(RP.PERMISSION_WRITE_EXTERNAL_STORAGE) is not working correctly.

joazzz

Member
Licensed User
Longtime User
If MLfiles does not exist, PERMISSION_WRITE_EXTERNAL_STORAGE always returns False.
B4A Version 11.80
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim LocRP As RuntimePermissions
    Dim LocUnusedML As MLfiles  '***If the LocUnusedML declaration variable is removed, the result is always False.***
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim PhoneVer As Phone
    If PhoneVer.SdkVersion >= 23 Then '23:Android v6.0
        If LocRP.Check(LocRP.PERMISSION_WRITE_EXTERNAL_STORAGE) = False Then
            LocRP.CheckAndRequest(LocRP.PERMISSION_WRITE_EXTERNAL_STORAGE)
            Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
            xui.MsgboxAsync(Result,"Result:")
            '***If the LocUnusedML declaration variable is removed, the result is always False.***
        End If
    End If
    
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
    ExitApplication
End Sub
 

Attachments

  • TestPermission.zip
    9.3 KB · Views: 92

zed

Active Member
Licensed User
hi Joazz, By adding a permission in the manifest, for me it works correctly.

in the manifest : AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
 

Attachments

  • TestPermission_ok.zip
    9.3 KB · Views: 86
Upvote 0

Spavlyuk

Active Member
Licensed User
See notes for API levels 29 and 30:
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You also need a manifest entry to obtain the permission. It is added automatically if you reference certain paths in your code. Press the 'List Permissions' button at the bottom of the logs pane to see if the IDE has added the permission. As I don't know what MLfiles is check with and without your MLFiles declaration.
 
Upvote 0

joazzz

Member
Licensed User
Longtime User
I got it.
Adding the permission to the manifest solved it.
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
Or
Use File.DirRootExternal in source code. ex) If PhoneVer.SdkVersion < 29 Then StrPath = File.DirRootExternal
thank you.
 
Last edited:
Upvote 0
Top