SAF: App Inventor implementation of Storage Access Framework

1.Introduction

Description: Basically AI2 wrapper of Storage Access Framework. Using this extension, you can get read and/or write access to a single document or tree document (and all of its children recursively).
Latest Version: 1
Released:  September 17, 2021
Last Updated:  September 17, 2021

2.Blocks

image
image
image
image
image
image
image

3.Documentation

Docs for: SAF

Events

DocumentCreated

Event invoked after creating document.Returns document’s uri if operation was successful else returns error message

Params 

uriString | text


GotCopyResult

Event invoked after getting copy document result.Response will be target document’s uri if operation was successful else returns error message

Params 

successful | boolean
response | text


GotFilesList

Event invoked after getting files list

Params 

filesList | list


GotMoveResult

Event invoked after getting move document result.Response will be target document’s uri if operation was successful else returns error message

Params 

successful | boolean
response | text


GotReadResult

Event invoked after reading from document.Returns content if operation was successful else returns error message

Params 

result | text


GotUri

Event invoked when user selects a document or tree from SAF file picker

Params 

uri | any
uriString | text


GotWriteResult

Event invoked after writing to document.Returns document’s uri if operation was successful else returns error message

Params 

response | text


Methods

BuildChildDocumentsUriUsingTree

Builds child documents id using tree (documents which is child of parent document) uri and its parent document id

Params 

treeUri | text

parentDocumentId | text

Return type : text


BuildDocumentUriUsingTree

Builds document uri using tree uri and document id

Params 

treeUri | text

documentId | text

Return type : text


CopyDocument

Tries to copy document from source uri to target dir

Params 

sourceUri | text

targetParentUri | text


CreateDocument

Creates a new and empty document.If document already exists then an incremental value will be suffixed.

Params 

parentDocumentUri | text

fileName | text

mimeType | text


CreateFlags

Combines two flags and returns resulting flag

Params 

f1 | number

f2 | number

Return type : number


DeleteDocument

Tries to delete document from given uri and returns result

Params 

uriString | text

Return type : boolean


GetDisplayName

Returns display name of given document uri

Params 

documentUri | text

Return type : text


GetDocumentId

Returns document id of an uri (should only be grand child)

Params 

uriString | text

Return type : text


GetLastModifiedTime

Returns last modified time (epoch) of given document uri

Params 

documentUri | text

Return type : text


GetMimeType

Returns mime type of given document uri

Params 

documentUri | text

Return type : text


GetSize

Returns size (in bytes) of given document uri

Params 

documentUri | text

Return type : text


GetTreeDocumentId

Returns document id of tree uri (should be either tree uri itself or a direct child uri)

Params 

uriString | text

Return type : text


IsChildDocumentUri

Returns whether second uri is child of first uri

Params 

parentUri | text

childUri | text

Return type : boolean


IsDocumentUri

Returns whether given uri is a document uri

Params 

uriString | text

Return type : boolean


IsReadGranted

Returns whether read is available for given uri

Params 

uri | text

Return type : boolean


IsTreeUri

Returns whether given uri is a tree uri

Params 

uriString | text

Return type : boolean


IsWriteGranted

Returns whether write is available for given uri

Params 

uri | text

Return type : boolean


ListFiles

Tries to list files from given dir

Params 

dirUri | text

dirDocumentId | text


MoveDocument

Tries to move document from source uri to target dir

Params 

sourceUri | text

sourceParentUri | text

targetParentUri | text


OpenDocumentTree

Prompts user to select a document tree

Params 

title | text

initialDir | text


OpenSingleDocument

Prompts user to select a single file

Params 

title | text

category | text

type | text

extraMimeTypes | list


ReadFromFile

Reads from given uri

Params 

uriString | text


ReleasePermission

Relinquish a persisted URI permission grant

Params 

uri | text

flags | number


RenameDocument

Tries to rename a document and returns updated uri

Params 

documentUri | text

displayName | text

Return type : text


StringFromUriObject

Convert uri to string

Params 

uri | any

Return type : text


StringToUriObject

Converts string to uri

Params 

uriString | text

Return type : any


TakePersistableUriPermission

Take a persistable URI permission grant that has been offered. Once taken, the permission grant will be remembered across device reboots.

Params 

uri | any

flags | number


WriteToFile

Writes to given uri

Params 

uriString | text

content | text


Properties

DocumentDirMimeType

Returns mime type of document dir

Property Type : read-only
Accepts : text


FlagGrantReadPermission

Flag to get write permission

Property Type : read-only
Accepts : number


FlagGrantWritePermission

Flag to get read permission

Property Type : read-only
Accepts : number


Docs for: SAF

Events

DocumentCreated

Event invoked after creating document.Returns document’s uri if operation was successful else returns error message

Params 

uriString | text


GotCopyResult

Event invoked after getting copy document result.Response will be target document’s uri if operation was successful else returns error message

Params 

successful | boolean
response | text


GotFilesList

Event invoked after getting files list

Params 

filesList | list


GotMoveResult

Event invoked after getting move document result.Response will be target document’s uri if operation was successful else returns error message

Params 

successful | boolean
response | text


GotReadResult

Event invoked after reading from document.Returns content if operation was successful else returns error message

Params 

result | text


GotUri

Event invoked when user selects a document or tree from SAF file picker

Params 

uri | any
uriString | text


GotWriteResult

Event invoked after writing to document.Returns document’s uri if operation was successful else returns error message

Params 

response | text


Methods

BuildChildDocumentsUriUsingTree

Builds child documents id using tree (documents which is child of parent document) uri and its parent document id

Params 

treeUri | text

parentDocumentId | text

Return type : text


BuildDocumentUriUsingTree

Builds document uri using tree uri and document id

Params 

treeUri | text

documentId | text

Return type : text


CopyDocument

Tries to copy document from source uri to target dir

Params 

sourceUri | text

targetParentUri | text


CreateDocument

Creates a new and empty document.If document already exists then an incremental value will be suffixed.

Params 

parentDocumentUri | text

fileName | text

mimeType | text


CreateFlags

Combines two flags and returns resulting flag

Params 

f1 | number

f2 | number

Return type : number


DeleteDocument

Tries to delete document from given uri and returns result

Params 

uriString | text

Return type : boolean


GetDisplayName

Returns display name of given document uri

Params 

documentUri | text

Return type : text


GetDocumentId

Returns document id of an uri (should only be grand child)

Params 

uriString | text

Return type : text


GetLastModifiedTime

Returns last modified time (epoch) of given document uri

Params 

documentUri | text

Return type : text


GetMimeType

Returns mime type of given document uri

Params 

documentUri | text

Return type : text


GetSize

Returns size (in bytes) of given document uri

Params 

documentUri | text

Return type : text


GetTreeDocumentId

Returns document id of tree uri (should be either tree uri itself or a direct child uri)

Params 

uriString | text

Return type : text


IsChildDocumentUri

Returns whether second uri is child of first uri

Params 

parentUri | text

childUri | text

Return type : boolean


IsDocumentUri

Returns whether given uri is a document uri

Params 

uriString | text

Return type : boolean


IsReadGranted

Returns whether read is available for given uri

Params 

uri | text

Return type : boolean


IsTreeUri

Returns whether given uri is a tree uri

Params 

uriString | text

Return type : boolean


IsWriteGranted

Returns whether write is available for given uri

Params 

uri | text

Return type : boolean


ListFiles

Tries to list files from given dir

Params 

dirUri | text

dirDocumentId | text


MoveDocument

Tries to move document from source uri to target dir

Params 

sourceUri | text

sourceParentUri | text

targetParentUri | text


OpenDocumentTree

Prompts user to select a document tree

Params 

title | text

initialDir | text


OpenSingleDocument

Prompts user to select a single file

Params 

title | text

category | text

type | text

extraMimeTypes | list


ReadFromFile

Reads from given uri

Params 

uriString | text


ReleasePermission

Relinquish a persisted URI permission grant

Params 

uri | text

flags | number


RenameDocument

Tries to rename a document and returns updated uri

Params 

documentUri | text

displayName | text

Return type : text


StringFromUriObject

Convert uri to string

Params 

uri | any

Return type : text


StringToUriObject

Converts string to uri

Params 

uriString | text

Return type : any


TakePersistableUriPermission

Take a persistable URI permission grant that has been offered. Once taken, the permission grant will be remembered across device reboots.

Params 

uri | any

flags | number


WriteToFile

Writes to given uri

Params 

uriString | text

content | text


Properties

DocumentDirMimeType

Returns mime type of document dir

Property Type : read-only
Accepts : text


FlagGrantReadPermission

Flag to get write permission

Property Type : read-only
Accepts : number


FlagGrantWritePermission

Flag to get read permission

Property Type : read-only
Accepts : number


4.Downloads

Aix: com.sunny.saf.aix (25.5 KB)
You can find usage examples in AI2 Community.
https://community.appinventor.mit.edu/t/saf-app-inventor-implementation-of-storage-access-framework/41603

 

5.Liked my work/Want to donate :heart:

Thank you :hugs:

 

Hope it helps! :slightly_smiling_face:

 
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments