How do you create a new file using file picker and write to it?

Try this example (tested companion and compiled on Android 16)
crudtextfiles.aia (4.7 KB)

I used File component, TinyDB, Spinner and Listpicker.

(Note: I did not provide for user being able to add directories, nor test if a text file is edited by other apps)

Thank you, I try to play with this.

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.

My example app does both of these things...

Yes it does

If you want to create a file or a sub directory your user will have to type in the name.

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. :wink:

Well, the user will first have to create a file to be able to select it!

Admittedly, perhaps my example was not obvious enough in its workflow...

CRUD > create, read, update, delete

  1. create a file
  2. read a file (that has been created)
  3. update and save as necessary
  4. delete (I did not include this part of crud)

See also here:

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.

Would this be a reasonable approach considering the limitations?

  • Read text files using the file picker from the device.

  • Save text files using the sharing component (this was suggested earlier in this thread, but I wanted to explore local possibilities first).

Will this likely to work on iOS, when the file picker is implemented?

  • Yes you can read files using the File component after selecting the file with a FilePicker

  • Where will you save the "file" to, in order to share it, or would you be happy just sharing the file content ?

Can't help with iOS

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.

:person_shrugging:

oh well

:question:

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.

Sorry, I don't understand the question mark.
I read all the previous messages and I think I understand the restrictions.

I did not try, but I was hoping that using the "sharing" component from the "social" group would work.
Screen Shot 2026-02-23 at 09.12.09

I think, I can get away by sharing a message, but I will also try to look into sharing a file created by the app.
Screen Shot 2026-02-23 at 09.21.03

Then read my answer again.

No, I've shown you a simple way to solve this problem on Android 11+.


Btw, on iOS (26.3), sharing a (text) file actually seems to work (Companion & IPA).

Correction: only with Companion!

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".

No, requesting WRITE permissions on Android < 11 is absolutely not a problem, not even in the Play Store. I never claimed otherwise.

Yes, and that seems to be confirmed for the time being, at least for the IPA.