SAF: App Inventor implementation of Storage Access Framework

@Taifun
yes, with the same blocks that I put here in the screen shots

What I don't understand is that in my mobile (with android 11) I install any app to view pdfs (Readera, Adobe, Drive, Liberar, etc...) and I can open them from any visible directory in which they are stored. And with my appinventor app I can't tell any pdf viewer (only Librera) to open the path of a file I give it.

If you know the file path then it should be possible to send it to the external app.
But as you are trying to work with SAF which provides you content uri specific to your so you need to add uri read and/or write permission to the intent to open the external app.
It is not possible with ActivityStarter currently.

1 Like

Using only ActivityStarter and a direct path like file:///storage/emulated/0/Mydocs/Text.pdf does not open the file. However the pdfs app does open that file.

The truth is that I get lost in these things.

Ok, can you post an example for read/write a text file in /storage/emulated/0/Documents with SAF ?

Excuse me I'm not an super expert, I have a problem, I created an DIR Tiket an DIR download, where I will download files, but I would like to move these files in the private dir of the app (/ Storage / Emulated / 0 / Dowload / Tiket To_ / Storage / Emulated / 0 / Android / Date / Dir app / files), and honestly I didn't understand how to use SAF you can help me with a practical example, thank you very much

To download files to the ASD is not a task for the SAF extension ... just use the web component to download directly to the ASD...

Taifun

Please try something yourself... there are example blocks in the beginning of this thread... and if you got stuck, post a screenshot of your relevant blocks...

Taifun

1 Like

I tried, see post 56.

Yes you tried, but without understanding correct order of blocks.

Maybe just scroll to next post by Taifun and you can make a good progress.

I'm sorry, but it's not my fault that I didn't get it right, I'm 76 years old

That can't stop you from getting things right.
Just proceed in correct direction and you will find it working. :smile:

You have created a useful extension, I wonder why you don't want to help everyone use it?
Probably when you get to my age you can understand me

1 Like

I tried this code, but I got this message
java.lang.string cannot be cast to android.net.uri

the flags socket of the TakePersistableUriPermission method requires the CreateFlags method, see also the example in the first post of this thread
also it looks like you have to use the StringToUriObject method, too...

also it would help very much to show us the Do it results...

Taifun

3 Likes

I can not find StorageAccessFramework in SAF1 extension
Also these blocks do not run (invalid uri)

I renamed extension after importing in AI2.
At least check the blocks once.

Are you sure the file you want to access exists? Is document's uri correct? Did you try listing the files from that folder?

@patel Here is a test APK to list / read / delete text files from /Documents with SAF:

Copy these files in the folder → /Documents of your test device (before you open the app):
file1.txt (19 Bytes)
file2.txt (19 Bytes)
file3.txt (19 Bytes)
test.csv (27 Bytes)

Check this app on different devices and Android versions.
Video from a Pixel 2XL (Android 11):

Blocks

5 Likes

@Anke, I'm sure my file exist in documents folder, I can read it and your textfiles with your app, can you attach the aia ?