Android Question Correct place to store text files that can be read/write

TonyVerberne

Member
Licensed User
Longtime User
Hi,
After checking the B4X docs I can't figure out where to store text files that will be used to populate spinners in my app. The files must be read/write (i.e. modifiable).
I would appreciate any help.
Tony
 

josejad

Expert
Licensed User
Longtime User
Hi Tony:

This is an Erel's suggestion:


This example can be useful too:
 
Upvote 1

aeric

Expert
Licensed User
Longtime User
Instead of text file, I prefer to use keyvaluestore.

 
Upvote 0

TonyVerberne

Member
Licensed User
Longtime User
Hi Tony:

This is an Erel's suggestion:


This example can be useful too:
Thanks Jose. However, I want to incorporate initial versions of some text files into the app when I build it. These should then be accessible to the user and be editable. Imagine a list of plants or flowers. Such a list could be added to by the user. In the past text/data files could be included into the Files folder prior to compilation but these files are not writeable I think. Any further suggestions would be appreciated.

Tony
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
However, I want to incorporate initial versions of some text files into the app when I build it
So, then just copy from dirassets to XUI.DefaultFolder when you open the app for the first time. You can write in XUI.DefaultFolder

If you mean you need the user access with a file explorer to the folder to copy his own files, then check the second link I posted.

ExternalStorage - Allows accessing external (secondary) storages. Requires the user to first select the target folder. Once the user selected a folder, your app can read and write from that folder. Doesn't require any permission.
Not all folders are accessible with ExternalStorage in Android 11+. Specifically, root, Android/data and Download are not accessible: more information.

SaveAs- this code, the opposite of ContentChooser or the simpler version of ExternalStorage. Allows the user to choose the place where the file will be saved. Simple to work with and doesn't require permissions. Possible alternative to the external storage permission, which is mostly no longer available.

RuntimePermissions.GetSafeDirDefaultExternal - A folder on the secondary storage, where your app can access without permissions. The path is a bit cumbersome (Log it to see).
 
Upvote 0
Top