SAF: App Inventor implementation of Storage Access Framework

I guess he did not mean to link any resource but just referring the java.io system.

6 Likes

For Real :star_struck:

That is the Best Extension, Good Job :sunglasses: :+1:

3 Likes

Epic work @vknow360 :slight_smile:

3 Likes

As @ABG says, this looks important, but I am guessing that most developers (which includes me) are not in the lucky 10,000 on this one, and therefore haven't got a clue as to what this is about our how they might use it in their apps. The example blocks give an inkling, but don't really help. Could a better description be provided, in layman's terms, of What this extension does, Why/When/Where one might use it, and How it works in more detail?

I am certain the work adds value to the AI2 development experience, especially in these times of Google privacy concerns and file location lockdown, but there is little point saying "great extension" in a post, if I have no understanding of what it does.

10 Likes

Yes, SAF is quite complicated to understand because Google had no time to explain why they decided to strict app's access to file system. Most developers felt homely by using legacy "File" approach, but launching of Android 10 started causing troubles for them and SAF is the solution to most of their problems.
Using this, you can-

  1. access phone storage*
  2. access SD card*
  3. read from/write to files created by other apps
  4. help user in protecting his/her data and restrict Storage consumed by apps
  5. get access to files and folders which are important to your app.
    In this way, you needn't ask for MANAGE_EXTERNAL_STORAGE permission.
  6. work with non-media files too, such as creating a CSV file of user's data or accessing a PDF file

*: Android/data and Android/obb folders are exception

One major advantage I would like to emphasize is usage of URIs instead of paths.

9 Likes

Example 2

  1. Open document picker and create document


    (Since you now know how to take persistable permission, so I'll skip that part)

  2. Read and write to document

  3. List files

4 Likes

Developers might also find these links about SAF useful in addition to your nice explanation.

4 Likes

Thanks @vknow360 for your explanations, making more sense now as to what one can do with your extension.

5 Likes

Well I have fallen at the first hurdle....

Following your first image, when I click the button I am taken to the device's default file manager (or what looks like it), I went to the root folder, the file manager asked me to give permission to this area (to MIT Companion App), then returns me to the project with this error:

image

4 Likes

I forget to mention that direct child's id should be obtained using GetTreeDocumentId method.

4 Likes

Sorry, I used the wrong block :upside_down_face:

3 Likes

OK that all works. :+1:

Is there no way then, in order to get started, other than the user going into their file manager and granting a permission, to get the root or other folder (tree)? (Open Document Tree)

Perhaps a uri for the ASD ?

I can see how one can traverse through a file list to find sub (folders) trees, and then list files again and so on. An image component accepts a content uri to display an image. Is this going to be the same for other components needing a file?

4 Likes

No, user must grant access through Documents Picker.

I am not sure about this.
Image component works fine.
Same should be correct for audio and video player.

4 Likes

Understood :slight_smile:

4 Likes

SAF is only needed for → non-media files. Media files (jpg, png, mp3, m4a, mp4,...) can be accessed from all paths (outside of the ASD or privateDir) with READ permission.

5 Likes

The question was just about the content uri being read by other components, e.g. it works with the image component:

not had a chance to test some of the others yet.

4 Likes

Could you please provide an example of how one uses the flags in order to set persistent permissions? I presume this saves the user having to visit the document picker again when restarting the app?

4 Likes

With this extension you really have to bite through and some users might lose teeth in the process. :wink: :grinning:

6 Likes

I am prepared to champion those users, in order to save their teeth ;), and ask Sunny how all the various elements of this extension work.

5 Likes

Sure, here it is:

Also data gets kind of binded to the app and you don't lose access to it even after multiple reboots.

5 Likes