Android Question Manage External Storage module problem

texwillerx

Member
Licensed User
Longtime User
Dear @agraham,

Thank you very much for your valuable module, your B4A program works perfectly.

I have used same code from your post in my program.

Unfortunately, all times, MES.Haspermission returns false: Both entering to get the permission and after the permission has gotten.

The code perfectly opens permission dialog. Although Haspermission is false, the permission on this page is true.

Unfortunately, MsgboxAsync creates problems, hence I have deleted it.

The log is also supplied.

Please help me to solve this problem.

Thanks and regards.

B4X:
    Dim SdkVersion As Int = device.SdkVersion
   
    ' Choose which permission to request in order to access external storgage
    If SdkVersion < 30 Then
        Log("SDK = " & SdkVersion & " : Requesting WRITE_EXTERNAL_STORAGE permission")
        Dim rp As RuntimePermissions
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
        Wait For activity_PermissionResult (Permission As String, Result As Boolean)
        Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)
    Else
        Log("SDK = " & SdkVersion & " : Requesting MANAGE_EXTERNAL_STORAGE permission")
        Log("On Entry MANAGE_EXTERNAL_STORAGE = " & MES.HasPermission)
        If Not(MES.HasPermission) Then
            'MsgboxAsync("This app requires access to all files, please enable the option", "Manage All Files")
            'Wait For Msgbox_Result(Res As Int)
            Log("Getting permission")
            MES.GetPermission
            Wait For MES_StorageAvailable
            Log("Permission gotten")
            Log("On exit MANAGE_EXTERNAL_STORAGE = " & MES.HasPermission)
        End If
    End If

B4X:
** Activity (main) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
SDK = 34 : Requesting MANAGE_EXTERNAL_STORAGE permission
On Entry MANAGE_EXTERNAL_STORAGE = false
Getting permission
** Activity (main) Resume **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Calling : MES_StorageAvailable
** Activity (main) Resume **
Permission gotten
On exit MANAGE_EXTERNAL_STORAGE = false
 

agraham

Expert
Licensed User
Longtime User
Your code looks OK.Have you got this in your manifest?
B4X:
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
If so then I'm afraid I have no idea. As far a I can see Android 14 hasn't restricted this permission but I can't test it as my latest device only has Android 13.
 
Last edited:
Upvote 0

texwillerx

Member
Licensed User
Longtime User
Thank you very much for your kind response.

Yes, I have these lines in my manifest.

Your example perfectly works in Android 14.

The problem is, MES does not recognise that the application already has the permission, hence,

MES.HasPermission

always returns false, although the app has this permission.

Regards
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
Is the package name set in GetPermission?

B4X:
Public Sub GetPermission
    If HasPermission Then
        RaiseEvent
        Return
    End If
    Dim in As Intent
    ' Be sure to reference your app package name in "pakageg:xxx"
    in.Initialize("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", "package:"  & Application.PackageName)
    StartActivityForResult(in)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…