SAF: App Inventor implementation of Storage Access Framework

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 ?

If you've copied another text file into / Documents, you should be able to list / read / delete it with my test app as well. Is there a problem with that?

I posted the blocks.

2 Likes

In your blocks I see SAF1 and SAF2, why ?

if you want to reuse an event like in the example the GotUri event (once called from method OpenDocument Tree and again from method OpenSingleDocument) you have 2 options

  1. you can drag the extension twice into the working area and use the blocks like shown in the screenshot, or
  2. use a global variable together with an if statement in the GotUri event like this
    if global variable = task1
    then do what you want to do for task1
    else do what you want to do for task2

Taifun

2 Likes

My OpenSingleDocument block has Category, Anke's block has not

https://github.com/vknow360/SAF/tree/beta