Setup: I get an URI of the directory in shared storage using procedure described here: Access documents and other files from shared storage / Grant access to a directory's contents.
Question: How to create a file inside this directory?
More details:
The guide mentioned above explains, how to list files in this directory, open some file for reading or modification and also how to delete it. All this using (Edit: actually guide does not explain it also, but just how to delete or modify files obtained interactively with ContentResolver
.ACTION_OPEN_DOCUMENT
). But I cannot see, how to create some file inside this directory.
Two candidates, which I can imagine, could help me with the job are: ContentResolver.insert()
or ParcelFileDescriptor(file, MODE_CREATE)
, but I cannot figure out how I could use them in this situation.
I should also mention, that I know about the possibility to create the file, when user interactively selects the file name and location, but it is not good solution for me. In my context I need to create several files inside one folder. All files should be accessible/modifiable/deletable by user from outside of my application, thus "shared storage". And the files are named and located within their "main" directory according to some conventions, so I don't want the user to explicitly provide me the name for each file, but just the location of "main directory".