Android Question [Solved-Possibly] ExternalStorage EnterFolder

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

REF: Erel's ExternalStorage B4A Example.

I am at the earliest stage of working on an APP that requires the APP to automatically copy all text files in the "DownLoad" folder to a Temp Folder in "DirInternal".

My first issue is how to change from :
B4X:
Private Storage As ExternalStorage
EnterFolder(Storage.Root)
to
B4X:
Private Storage As ExternalStorage
EnterFolder(Storage.Root/"Download")
.

Alternatively
B4X:
Dim folder As ExternalFile = GetCurrentFolder/"Download")
EnterFolder(folder)

This of course is mixing Objects with strings.

With thanks in advance.
Regards Roger
 

agraham

Expert
Licensed User
Longtime User
I'm trying to bypass the user selecting the folder and force the App to do it.
You can't. the user must select the root folder at least once, it will be fine thereafter. You can check the folder (s)he has selected by looking at the Root global.

Note that if you target SDK30 or higher you won't be able to access the Download folder by this method.
Storage updates in Android 11 | Android Developers
Access to directories
You can no longer use the ACTION_OPEN_DOCUMENT_TREE intent action to request access to the following directories:
  • The root directory of the internal storage volume.
  • The root directory of each SD card volume that the device manufacturer considers to be reliable, regardless of whether the card is emulated or removable. A reliable volume is one that an app can successfully access most of the time.
  • The Download directory
Targeting SDK 29 or earlier you can access Download using normal File I/0 and
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)

If targeting SDK 30 or higher AND you don't need to put your app in the Play Store you can access Download using normal File I/0 and
Manage External Storage - access internal external storage >= SDK 30 | B4X Programming Forum

I don't think there is a way to directly access Download if need to put your SDK 30 app in the Play Store. There are probably other ways for the user to securely select a file but I have to admit that, other than the two ways above, I am totally confused about the whole file access situation in SDK 30 Andoid. ?
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You can't. the user must select the root folder at least once, it will be fine thereafter. You can check the folder (s)he has selected by looking at the Root global.

Note that if you target SDK30 or higher you won't be able to access the Download folder by this method.
Storage updates in Android 11 | Android Developers

Targeting SDK 29 or earlier you can access Download using normal File I/0 and
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)

If targeting SDK 30 or higher AND you don't need to put your app in the Play Store you can access Download using normal File I/0 and
Manage External Storage - access internal external storage >= SDK 30 | B4X Programming Forum

I don't think there is a way to directly access Download if need to put your SDK 30 app in the Play Store. There are probably other ways for the user to securely select a file but I have to admit that, other than the two ways above, I am totally confused about the whole file access situation in SDK 30 Andoid. ?


Thanks Agraham [Erel],
I Think I'm screwed, if it has you confused what chance do the dabblers like me have.

I might take up macrame as a hobby. ?

Regards Roger
PS A curse on Google.
 
Last edited:
Upvote 0
Top