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.3
Released: 2021-09-16T18:30:00Z
Last Updated: 2023-11-15T18:30:00Z
2.Blocks
3.Documentation
Events
ErrorOccurred | Event indicating error/exception has occurred and returns origin method and error message.methodName | text errorMessage | text |
DocumentCreated | Event invoked after creating document.Returns document's uri if operation was successful else returns error messageuriString | text |
GotWriteResult | Event invoked after writing to document.Returns document's uri if operation was successful else returns error messageresponse | text |
GotReadResult | Event invoked after reading from document.Returns content if operation was successful else returns error messageresult | any |
GotUri | Event invoked when user selects a document or tree from SAF file pickeruri | any uriString | text |
GotFilesList | Event invoked after getting files listfilesList | list |
GotCopyResult | Event invoked after getting copy document result.Response will be target document's uri if operation was successful else returns error messagesuccessful | boolean response | text |
GotMoveResult | Event invoked after getting move document result.Response will be target document's uri if operation was successful else returns error messagesuccessful | boolean response | text |
DocumentCopiedToFile | Event raised after getting 'CopyDocumentToFile' resultsuccessful | boolean response | text |
DocumentCopiedFromFile | Event raised after getting 'CopyDocumentFromFile' resultsuccessful | boolean response | text |
Methods
CreateFlags | Combines two flags and returns resulting flagf1 | number f2 | number |
StringFromUriObject | Convert uri to stringuri | any |
StringToUriObject | Converts string to uriuriString | text |
InitialDir | Returns uri which can be used as Initial Dir in SAF pickerdir | text |
OpenDocumentTree | Prompts user to select a document treetitle | text initialDir | text |
OpenSingleDocument | Prompts user to select a single filetitle | text initialDir | text type | text extraMimeTypes | list |
TakePersistableUriPermission | Take a persistable URI permission grant that has been offered. Once taken, the permission grant will be remembered across device reboots.uri | any flags | number |
IsTreeUri | Returns whether given uri is a tree uriuriString | text |
IsDocumentUri | Returns whether given uri is a document uriuriString | text |
IsChildDocumentUri | Returns whether second uri is child of first uriparentUri | text childUri | text |
GetTreeDocumentId | Returns document id of tree uri (should be either tree uri itself or a direct child uri)uriString | text |
GetDocumentId | Returns document id of an uri (should only be grand child)uriString | text |
BuildDocumentUriUsingTree | Builds document uri using tree uri and document idtreeUri | text documentId | text |
BuildChildDocumentsUriUsingTree | Builds child documents id using tree (documents which is child of parent document) uri and its parent document idtreeUri | text parentDocumentId | text |
GetDisplayName | Returns display name of given document uridocumentUri | text |
GetSize | Returns size (in bytes) of given document uridocumentUri | text |
GetLastModifiedTime | Returns last modified time (epoch) of given document uridocumentUri | text |
GetMimeType | Returns mime type of given document uridocumentUri | text |
IsCopySupported | Returns whether document can be copied or notdocumentUri | text |
IsMoveSupported | Returns whether document is movable or notdocumentUri | text |
IsDeleteSupported | Returns whether document is deletable or notdocumentUri | text |
IsRenameSupported | Returns whether document is deletable or notdocumentUri | text |
CreateDocument | Creates a new and empty document.If document already exists then an incremental value will be suffixed.parentDocumentUri | text fileName | text mimeType | text |
WriteToFile | Writes content as text to given uriuriString | text content | text |
WriteAsHexString | Writes content as HEX to given uriuriString | text content | text |
WriteAsByteArray | Writes byte array to given documenturiString | text byteArray | any |
DeleteDocument | Tries to delete document from given uri and returns resulturiString | text |
ReadFromFile | Reads from given document as texturiString | text |
ReadAsByteArray | Reads content of document as byte arrayuriString | text |
ReadAsHexString | Reads content of document as HEX stringuriString | text |
IsReadGranted | Returns whether read is available for given uriuri | text |
ReleasePermission | Relinquish a persisted URI permission granturi | text flags | number |
IsWriteGranted | Returns whether write is available for given uriuri | text |
ListFiles | Tries to list files from given dirdirUri | text dirDocumentId | text |
CopyDocument | Tries to copy document from source uri to target dirsourceUri | text targetParentUri | text |
MoveDocument | Tries to move document from source uri to target dirsourceUri | text sourceParentUri | text targetParentUri | text |
RenameDocument | Tries to rename a document and returns updated uridocumentUri | text displayName | text |
CopyDocumentToFile | Tries to copy document from source uri to specified foldersourceUri | text dirPath | text |
CopyDocumentFromFile | filePath | text targetParentUri | text |
ConvertStringToBytes | Converts text to bytes and return Byte Array object. It can be used with 'WriteAsByteArray' method.byteString | text |
CreateDocumentSync | Creates document on main thread and returns its uri immediately if operation was successful otherwise empty string is returnedparentDocumentUri | text fileName | text mimeType | 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.Usages
1.Open document tree
2.Get access (not necessary for one-time usage)
3.Build child document uri
- if document is direct child
- if document is grandchild
4.Read file/Set picture
Examples by Power Users
I am thankful to them for their efforts.
5.Download
Aix:
com.sunny.saf.aix (29.2 KB)
6.Open Source
7.Liked my work/Want to donate
Thank you
8. ChangeLog
ChangeLog Version 1.1
New Blocks
Changes
- Removed
category
param fromOpenSingleDocument
method GotCopyResult
andGotMoveResult
now return resulting/target document's uri
Bug Fixes
- Fixed issue in write methods
- Fixed null pointer exception when SAF picker was cancelled by user
ChangeLog Version 1.2
SAF: App Inventor implementation of Storage Access Framework - #331 by vknow360
ChangeLog Version 1.3
SAF: App Inventor implementation of Storage Access Framework - #360 by vknow360
Thank you.
Hope it helps!