Android Files amid the mess

Does anyone know of an essay/article/blog on reading and writing files on Android, restricting it to working with current Android versions without using features which are likely to get turned off in a future release?

I have read many articles on scoped (whatever that means) storage, things which tell you what to do to get legacy access which will probably die in the next release, etc etc. The whole thing seems a confusing mess.

As there appears to be no public “Data” directory, like “Documents” or “Pictures”, I would like to be able to set up a sub-directory structure within Documents for programmes to use and interact, and users to be able to find and work with these files when the phone is plugged into a computer. Security is immaterial!

Any ideas please?
Chester Wilson

Does this work for you?

Elvind, but while that gives me the directoty (which may or may not be
available to a user depending upon android version and setting of
various parameters!) it does not give me what I need to get permission
from the user to be able to write files in that directory.

there is something that allows you to give a directory name, ask the
user for permission to access that directory, read from and write to
that directory, and get some form of token so that you don’t have to do
this every bl…dy (can’t expand this - despite this being an AUSTRALIAN group, it knocks it back!) time you want to access that directory! If I am
extremely lucky this does not require setting flags and parameters to
force android to use some antediluvian file access technique which their
clever little prickles have deemed detrimented, and will let me use
that programme into the future without having to upgrade it with every
damned android release!

I just don’t know where to find it!


I don’t know much about Android / mobile, but @davidn has done a huge amount in that area.

He has his Kastri library here : GitHub - DelphiWorlds/Kastri: Cross-platform library for Delphi

and it says he has other (experimental) work here : GitHub - DelphiWorlds/Playground: Stuff I'm working on that I *may* make public

and one of the Demos is a MediaManager related to photo/video : Playground/Demos/MediaManager at main · DelphiWorlds/Playground · GitHub

That mentions permissions and working with storage … might be worth looking at …
(I dunno if media work differently to general file access)

MediaManager is related to Photos and Videos. Specifically on iOS: using the Photos framework. On Android, it uses ContentResolver to query the albums/photos/videos

Regarding file access on Android: Unless an app absolutely needs to share access with other apps, or the OS, I’d stick with using GetDocumentsPath (i.e. local to the app). Otherwise, you could look at some of the info, here:

1 Like

A post was split to a new topic: Decrypting a file

Chester, I think what you are looking for is code like the following, so need to specifically ask for permissions depending on what services you want to use
It’s also important to ensure any data files you want to use are in your manifest file even if empty
So In the uses section or relevant section put them in an IF ANDROID block somewhere
Androidapi.Jni.Os, Androidapi.Helpers,

I have the following in a form create event

FPermissionWrite := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE); //Значение на запись
FPermissionRead := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE);
PermissionsService.RequestPermissions([FPermissionWrite, FPermissionRead], nil);
sdataPath := System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,[your file name]);
// or on external GetSharedDocumentsPath ‘LeaseFD.fds’);
then write code to set the path and make sure the file exists
if sdataPath =‘’ then
sdataPath := System.IOUtils.TPath.Combine(System.IOUtils.tpath.GetSharedDocumentsPath,‘[your file name]’);

If these are sent to download or documents directories that Android will ask the user for permission to access the app and if the the is in the shared documents path ask again most likely when they execute the app.
In the manifest file you set the directory the files to be installed usually in the documents path the data path under the app files directory which is invisible to users for obvious reasons

Not sure if this helps

Let’s see if I can simplify my requirements into something legible!

Programme: (PeteA) tracks small furry critters in the Australian Bush by observation on foot, by road
or plane. It creates a .csv file with the locations and other data, and can take photos - NOT wanted in the standard android Photos collection. In the initial version, it created \PeteA\ and this worked well.

I would like to put these files in the \documents\ subdirectory, in suitable subdirectories, eg
\documents\PeteA, with further subdirectories below this as desired by the user.

These files, while they can be accessed by other programmes on the android system, and more usually taken off by plugging the phone/tablet into a computer and taking them from there.

With the current mess that android has made of its files, I am forced to put the files in a directory
like \android\emulated\0\com.embarcadero\PeteA (or something like this), which is an accursed nuisance for people to hunt for from their computers!

I find that I can create the \documents\PeteA\ subdirectory, and can write files to it. Unfortunately when I try to read files from this subdirectory (GetDirectory) I get a variable number of files, from zero to about half the files which were written.

I have read the scoped storage stuff. To me, being medical, “scoped” means something like “Old Bill had a bad cough. I scoped him last friday and found his lung cancer. Pity!”

Like everyone else, I have no idea what restrictions and other weird ideas android will bring in the next 10 versions, and would like to be able to write code that will not have to be altered every year or two with the next (and the next . . .) storage ideas!

Some time ago, and I do not know where it was, to my frustration, there was some code on the net which told android that the user wanted access to a particular directory, asking the user if he was happy to grant access to that directory via a message sent to that user at the time. Then this code returned some kind of token which allowed future access by this programme to that subdirectory (though this was lost when the programme was uninstalled/reinstalled, I think). Has anyone any memory of this?

Do you think android would be happy to consider an unprotected directory (eg \data), for those of us who have no need for security (the tablet is miles from the nearest internet after all!) with full access at our own risk? Or am I just too old-fashioned?