Android Question Access Download Folder

Javier Alonso

Member
Licensed User
Longtime User
Hi, I am trying to read the content of the Download folder in the internal memory, without success. I followed the guidelines for runtimepermissions, I added the permissions in the manifest:
B4X:
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

I also asked for permission to write, I grant it, but File.ListFiles returns an uninitialised list, what supposedly means that the folder is not accesible
B4X:
    Private rp As RuntimePermissions

    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
  
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result <> False Then

            Dim arch As List
            arch = File.ListFiles(File.Combine(File.DirRootExternal, "Download"))
            If arch.IsInitialized Then
...

Could you help me, please?
 

JohnC

Expert
Licensed User
Longtime User
Try adding this to your manifest:

B4X:
<application android:requestLegacyExternalStorage="true">
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you need to add this to the manifest: SetApplicationAttribute(android:requestLegacyExternalStorage, true)

soon there will be no access to direxternal, so enjoy it while it lasts
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why do you have a tendency to duplicate answers given by others prior to yours. Isn't the answer given by @JohnC what you just duplicated in post #3
This comment is unhelpful and unneeded.

Actually the answer in post #3 is more complete and is very important.
 
Upvote 0

Javier Alonso

Member
Licensed User
Longtime User
Thank you, but I got a compiler error:

B4A Version: 10.2
Java Version: 8
Parsing code. (0.04s)
Building folders structure. (0.02s)
Compiling code. (0.35s)
Compiling layouts code. (0.02s)
Organizing libraries. (0.00s)
(AndroidX SDK)
Generating R file. Error
AndroidManifest.xml:19: error: No resource identifier found for attribute 'requestLegacyExternalStorage' in package 'android'

This is my manifest file:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetManifestAttribute("android:installLocation", "auto")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:largeHeap,"true")
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

Any ideas? Thanks
Javier
 
Upvote 0
Top