SAF: App Inventor implementation of Storage Access Framework

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

And again:

So please answer this question: Does it work for you with my test app?

Your app works well in my phone, I copied your text files into / Documents, I was able to list / read / delete them, but I'm not able to create my app using your blocks. I don't want list the folder, I want open a single document, read it and save changes.

1 Like

I believe the simplest way to do that is:

2 Likes

Thank you, this code runs well, but there is a way to avoid picking list ? Now I know the uristring of my file that I want read.

Is the app just for your own use?
If not, how do you know the file exists on the user's device? In other words, where did this file come from?

yes, the app is for my own use, I'm not a developer, I know the file exists because I put it in my phone. I tried reading the file using the uristring, but I think there is a permissions problem

Show your blocks.