However, the main point of my question is about accessing files created by users and this approach does not seem to handle that (at least this is what I get from the note at the end of your message).
I checked that on Android 9 I can edit the created file (and I do not even have to create it from the app, I can access it if I type in the file name with path directly), but as I understand this may not be the case on newer Android versions.
It would also be good if this could be done in a somewhat interactive way. It is not really user friendly to ask them to type in the file name with a complete path. Isn't this what file picker is for?
Here's a simple app that lets you pick any (text) file – even one not created by the app – copy it to /Documents on Android 11+ without requiring storage permissions, and then have full access to it.
Of course, on Android < 11, WRITE_EXTERNAL_STORAGE permission must be requested. This generally applies to all directories except the ASD and PrivateDir.
I don't want to be ungrateful and I appreciate the help, but I really do not see how. If I click on "open" without doing anything else, an empty screen comes up. Maybe I missed something, but I cannot choose a file without me creating it first. When I open a normal text editor and select "open", it will bring up a search screen and I can choose a file that I want to edit. This is the functionality I am after.
If I want to open a file in any user friendly app, I do not have to type in anything. I simply use a file explorer from inside the app and click on the file I want to open.
If I want to save a file, I can choose a directory and type only the file name. I can even choose an existing file and edit the name or overwrite it (after a prompt if I really want to do this). This is what I call a user friendly approach.
I understand that I have to work doing it and I appreciate the help I get.
What I don't understand is why the file picker (which, as far as I see is exactly for this purpose) does not work.
Even in Anke's example (and in the examples in my previous posts), some juggling is needed to get the file name out of the uri returned by the file picker to be able to write to it.
The real file path wouldn't help you either, since you can't overwrite this file on Android 11+. As I've already explained, you first need to copy the file to one of the shared folders (e.g., /Documents) to gain full access, including write permissions.
Otherwise SAF (or MANAGE_EXTERNAL_STORAGE) must be used.
Achieving the desired functionality on iOS will likely remain a pipe dream.
The FilePicker uses the SAF (Storage Access Framework) and works with a contenturi instead of a file path. There is good and not so good here. The good is that the filepicker can more or less access any file you pick from shared storage. The not so good is that there is not much else you can do from your app using the filepicker. You can create a (empty) file, but you cannot do anything with it from your app. As previously mentioned by @Taifun in this topic, the filepicker operates "outside" of the app so does not apply any ownership rights for your app for the files it creates. There are several missing pieces of the SAF that would be needed for filepicker to be truly useful, in the way you want it.
Instead, you have to workaround using the File component, as I have shown.
I gave up on saving the file on the device, I am happy to simply share it and let the user figure out how to store it.
The general idea is that the app will do something (the technicalities are not important) with the text file and the result is something that can be used with another app I am developing. Also, the result can be of general interest, so some users might want to share it with others.
When I use the app, I probably will email it to myself or save it to my google drive, from where I can download.
And again: The text file must be created by the app itself in order to be shared (at least on Android 11+). Furthermore, a real path (absolute or full path) is required; it won't work with a contentUri.
While the IPA file can be used to share text files created with Companion, it cannot share files created with the IPA (compiled app). This text file appears to be created, but it cannot be found. @ewpatton
I read your answer and I think we talk about the same thing, I am just not using the proper terms.
I try again:
I will try the following workflow:
Read files using the file picker.
Do something and get a text object as a result.
Share this text as a message using the sharing component and let the user decide what to do with it.
Yes, I looked at your example you showed, but you yourself mentioned limitations in your other messages (which I also read).
It asks for writing permissions (for Android < 11), which according to another post of yours would likely result in not being accepted on the google play store.
I am looking for a solution that will likely work also on iOS and you said in a post that achieving my original goals will "likely remain a pipe dream".