SAF, open a text file that I've added to /Documents but created in another place

Trying to use the SAF Extension to read test.txt, but can't seem to read a text file I've inserted into the documents folder from another app. I'm using the SAF_CreateText File demo (thanks @ChrisWard ) with added button1 and button1 block shown. The demo app works as intended otherwise.

Textbox output...
"No content provider: test.txt"

You first need to select the file with Open_Document, so you can get the uriString to the file, in order to read it.

Thanks for the super quick reply and forgive my ignorance. I tried the following do no avail. Do you have an example?

You need to read this topic:

and review all the examples therein.

Example blocks

image

OK, Thanks! I've gotten to where I can create a folder, create a document, write to that document and read that document. Unfortunately, i can't open a similar document that wasn't created within the app and I seem to have to get permission to access the folder each time I open the app. I tried to use the following to take control automatically after storing the uri in a tinydb. Two questions, is there a way to give the app access to say the documents folder forever once it has been initially granted by the user? Can I open text files that were created outside of the app... ever? Thanks in advance!

I'm hopeful this can help someone.


Set permissions works, but isn't persistent if I restart the app.
Make File Works
Write File Works
Read File Works
Open Old Not sure if it works, but it appears to
Read Old "Permission Denial" must "obtain access using ACTION_OPEN_DOCUMENT or related APIs"
Anyone have any thoughts on that error?

Before looking at your more complex approach, are you able to read and write to a foreign txt file using the OpenDocument method I provided above, as a basic example ?

I was unable to make that work.

Which part does not work?

Try this, tested compiled on Android 15.

SAFReadWrite.aia (31.3 KB)

(my text files were created on my computer, and copied over to my device by usb, then I built the apk)

To get full access (on Android 11+) to all text files in /Documents that were not created by the app itself, copy all text files to the ASD via SAF, remove all text files in /Documents via SAF, and then copy or move all text files back to /Documents. After that, the app will have full access to these files without SAF (on Android 11+, of course, without READ / WRITE permission).

1 Like