Android folders writable

Hi everyone!
What are the folders in Android where I can write without permissions?
For example, if I want to save a settings file, where do I save it?

I tried with “SpecialFolder.Resources” but the app hangs and no longer responds.

The line:
Var f As FolderItem = SpecialFolder.Resources.Child("data.txt")
I don’t do anything else at the moment. I don’t read, I don’t write, nothing. Only this line and the app no longer responds.

Any help?
Thanks,
Gabriel

Hi Gabriele

I would make sure SpecialFolder.Resources exists before trying to get a child item.

I think that all specialFolders of the type Documents, ApplicationSupport, etc., all correspond to the App’s data folder on Android, where perennial data can be saved, but this remains to be verified.

https://developer.android.com/reference/android/content/pm/ApplicationInfo#dataDir

In my first tests, I install a Sqlite database in the SpecialFolder.Documents and it seems ok.

You can see the real folder path in the debugger. I haven’t yet had time to look at the path of all the specialFolders to see the difference.

EDIT : I think this dataDir is safe and secure.

Here’s the full path for my Android app if I use specialfolder.documents for my database: /data/data/com.myApp.myAppName/files/myDb.sqlite

chatGPT:

dataDir is the path to the application’s data directory on the file system. This directory is application-specific and is used to store the application’s persistent data files, such as SQLite databases, shared preferences and application-specific files. The contents of this directory are accessible only to your application, ensuring a measure of security and confidentiality.
The typical path is /data/data/<package_name>, where <package_name> is the package name of your application.

Xojo SpecialFolder / FolderItem Classes are currently undocumented / sub documented for iOS and Android (or maybe with some problem of visibility, finding)

SpecialFolder, for example, there are columns for Windows, macOS and Linux only.

Resources, paths and use cases are not clear for those platforms.

@Geoff_Perlman

Thanks. I will look into that.

1 Like

We do document in the Notes section what those each mean on Mobile. Their actual locations in the file system are irrelevant since you can’t access them any way except via SpecialFolder.

It sounds like you want to be using SpecialFolder.ApplicationSupport or SpecialFolder.Documents.

SpecialFolder.Resources will only exist if you have a Copy File Step that is copying stuff there. And you should not be writing there regardless.

People are used to ApplicationData or SharedApplicationData.

The ApplicationSupport is not even in the list, the docs need a review for UX

FolderName Windows macOS Linux
ApplicationData \Users\UserName\AppData\Roaming|/Users/UserName/Library/Application Support /home/UserName/
Applications \Program Files\ or \Program Files (x86)|/Applications Nil
Bin Nil /bin /bin/
Caches C:\Users\UserName\AppData\Local\Microsoft\Windows\INetCache|/Users/UserName/Library/Caches /home/UserName/.cache/
Cookies \Users\UserName\AppData\Local\Microsoft\Windows\INetCookies|/Users/UserName/Library/Cookies Nil
CurrentWorkingDirectory Current working directory (depends on the location of the application). When run from Xojo, it is the path to Xojo. In a built app, it is the path to the built app. Current working directory (depends on the location of the application). Usually /.
Desktop \Users\UserName\Desktop|/Users/UserName/Desktop /home/UserName/Desktop/
Documents \Users\UserName\Documents|/Users/UserName/Documents /home/UserName/Documents/
Etc Nil /private/etc /etc/
Extensions \Windows\System32|Nil Nil
Favorites \Users\UserName\Favorites|/Users/UserName/Library/Favorites Nil
Fonts \Windows\Fonts|/System/Library/Fonts Nil
GetFromDomainAndCode (domain as Integer, fourCharCode as String) Raises PlatformNotSupportedException Pass a class constant for the domain and a four-character code of a specific FolderItem. The constants are: DomainSystem (currently folders inside ‘/System’), DomainLocal (currently folders inside ‘/Library’), DomainUser (currently folders inside the user’s home folder) Raises PlatformNotSupportedException
History \Users\UserName\AppData\Local\Microsoft\Windows\History|/Users/UserName/Sites Nil
Home Nil /Users /home/
InternetCache \Users\UserName\AppData\Local\Microsoft\Windows\INetCache|/Users/UserName/Library/Caches /home/UserName/.cache
Library Nil /Library /lib/
Mount Nil /Volumes /mnt/
Movies \Users\UserName\Videos|/Users/UserName/Movies /home/UserName/Videos/
Music \Users\UserName\Music|/Users/UserName/Music /home/UserName/Music/
NetworkPlaces \Users\UserName\AppData\Roaming\Microsoft\Windows\Network Shortcuts|Nil Nil
Pictures \Users\UserName\Pictures|/Users/UserName/Pictures /home/UserName/Pictures/
Preferences \Users\UserName\AppData\Roaming|/Users/UserName/Library/Preferences - On macOS, use SpecialFolder.ApplicationData to save your own files or directly call CFPreferences to save preferences files here. /home/UserName/
Printers \Users\UserName\AppData\Roaming\Microsoft\Windows\Printer Shortcuts|/System/Library/Printers Nil
RecentItems \Users\UserName\AppData\Roaming\Microsoft\Windows\Recent|/Users/UserName/Library/Recent Documents Nil
Resources MyApp Folder\Resources MyApp.app/Contents/Resources MyApp Folder/Resources
SBin Nil /sbin /sbin/
SendTo \Users\UserName\AppData\Roaming\Microsoft\Windows\SendTo|Nil Nil
SharedApplicationData \ProgramData|/Library/Application Support Nil
SharedApplications \Program Files\Common Files\ or \Program Files (x86)\Common Files|Nil Nil
SharedDesktop \Users\Public\Desktop|Nil Nil
SharedDocuments \Users\Public\Documents|/Users/Shared Nil
SharedFavorites \Users\UserName\Favorites|Nil Nil
SharedPreferences \ProgramData|/Library/Preferences Nil
SharedStartupItems \ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp|Nil Nil
SharedTemplates \ProgramData\Microsoft\Windows\Templates|Nil Nil
StartupItems \Users\UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup|Nil Nil
System \Windows\System32|/System Nil
Templates \Users\UserName\AppData\Roaming\Microsoft\Windows\Templates|Nil Nil
Temporary \Users\UserName\AppData\Local\Temp|/private/var/folders/gp/…/T/TemporaryItems (varies) /tmp/
Trash(relativeToVolume As FolderItem=Nil) \Users\UserName\Desktop\Recycle Bin|/Users/UserName/.Trash Nil
UserBin Nil /usr/bin /usr/bin/
UserHome \Users\UserName\ (Points to OneDrive if activated) /Users/UserName /home/UserName/
UserLibrary Nil /Users/UserName/Library /usr/lib/
UserSBin Nil /usr/sbin /usr/sbin/
Var (Removed in 2019r1 - Use Variable instead) n/a n/a n/a
Variable Nil /private/var /var/
VariableLog Nil /private/var/log /var/log/
Windows \Windows|Nil Nil

You are quoting the Desktop list instead of the Mobile list:

Mobile

Mobile has these properties:

  • ApplicationSupport
  • Caches
  • Documents
  • ExternalStorage (This property is supported for Android only.)
  • Resources (This property is supported for Android only.)
  • Temporary
1 Like

That’s not a property list. It is a lost note floating somewhere in the page.

The class start with a list of values and OS columns, I missed iOS and Android and lots of N/A where it does not fit

If you want to separate Desktop, Mobile and Web, follow the same design, with sessions on the page, and a clear header “Desktop” for the first table, Mobile for the second and Web for the 3rd. One after the other.

On the top, in the first explanations about the class, explain the differences and list the hyperlinks to the sessions of each platform.

Extra notes comes after the tables on each session.

1 Like

The Notes are separated, the first table specifically says above it:

These are the properties that are available on Desktop, Web and Console projects.

It doesn’t make sense to put iOS, Android or Mobile in that table as they are not Desktop, Web or Console projects (have just a few properties).

Note: I don’t like how the SpecialFoder document page either. The table is too big for small screens.

You can open an Issue with your recommendations to make that page easier for users.

1 Like

The UX of the docs in this class is a mess.

A proper redesign following some standards and getting things easy to find without confusion since the first few lines is a must.

AFAIK, Geoff is already studying enhancements for that page.

There don’t seem to many places where you can save a file and access with other Apps later on.
However, if you save to SpecialFolder.ExternalStorage.Child(“data.txt”), you can access the file from a PC with the Android device connected via USB for file transfer.

What I would like to do is to create a file in the phone’s Downloads folder. This doesn’t appear to be possible without 3rd-party API classes.