Android Question File.DirRootExternal vs RP.GetSafeDirDefaultExternal

PoulDK

Member
Licensed User
Longtime User
Hi,
I have found repeated recommendation, specifically with the newer android requirements, to no longer use File.DirRootExternal.
However these recommendations all lead to long storage folder names which include "/b4a.example/files",
and really believe me: I have been searching and reading (lengthy days) forever trying to find the info.
I am a very enthusiastic fan of B4A, but for production purposes I do not want the apps that I deliver/develop to hold that (b4a) mandatory name.
What is the way to get back using access to "/root/sdcard" or "/storage/emulated/0" for building data folders, like other apps seem to be able to do ?
Regards, Poul
 

PoulDK

Member
Licensed User
Longtime User
Ah, see... something new to learn every day, thanks @roumei !
Still however does not bring it back to the source folders of /root/sdcard, enabling to access documents, pictures, music etc
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Still however does not bring it back to the source folders of /root/sdcard ...
I might be misunderstanding your point, but "Yes, it does". "File.DirRootExternal" is the "/root/sdcard" source folder (maybe a different name on different devices) that provides access to the device's internal storage. So, leaving all questions of access permissions aside (which unfortunately we cannot always do) you can use a statement like this ...
B4X:
File.MakeDir(File.DirRootExternal, "My Folder")
This will create the folder "root/sdcard/My Folder" and seems to answer the question that you pose in your first post ...
What is the way to get back using access to "/root/sdcard" or "/storage/emulated/0" for building data folders, like other apps seem to be able to do ?
 
Upvote 0

PoulDK

Member
Licensed User
Longtime User
Hi @Brian Dean , thanks for the response, however the Q starts with: recommendation is to NOT use File.DirRootExternal anymore!
thus what can be used otherwise to get into the /root/sdcard base folders?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
(the) ... recommendation is to NOT use File.DirRootExternal anymore!
Ok - I see you confusion. Well, that is not a B4A restriction. The progressively tighter controls on memory access are being set by Google. B4A does not restrict you in any way, but works within Google's rules. The ability to read and write to storage outside of an app's private area is disappearing and applies to everybody, so the phrase "like other apps seem to be able to do" will no longer be true.
 
Upvote 0

PoulDK

Member
Licensed User
Longtime User
That will become interesting... Android(Google) restricting access to base folder (doc, pics etc) for their own apps... and not allowing 3rd parties (like MSword) to access those locations! seems to me something for a good challenging cartel legal case
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You should be able to access both External(built-in) storage and removable (SD card and USB) storage using the ExternalStorage class


which implements the Storage Access Framework. This requires the user to select a base folder for the folder tree that an app can see - and it can be the root of the storage. File access is restricted to using streams but you can create and delete folders and files, and you can always copy a file to private storage to play with it and then copy it back if you need random access.

There will be a permission for certain approved apps to access all files in the storage for apps that can show they need it. If you are not putting the app in the Play Store you could use this permission in your own apps regardless - I will probably be doing so.
 
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Thank you, @agraham . That is the clearest and most comprehensive coverage that I have seen of this topic so far, and it turns up on the forum almost twice a week!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…