SAF: App Inventor implementation of Storage Access Framework

After getting the URI, copy the document to the Shared folder /Documents or the ASD and then access and upload this file from there with the real (absolute or full) path.

See also here:

Goodday,Have created a read file block successfully which read the file as bytearray.

I can read the result into a label block

How to read it like array in for loop with indexing

Thanking you

Sorry, please elaborate.

Good day Sir,

Using SAF I read a binary file which contains numeric value as byte array

Using after read block I read the result into label and display the values, I can see the read values

Now i want to read directly from result (byte array) to a textbox one byte at a time in a while or for loop, how can I achieve it.

I tried to read the byte array to list but it says bad argument.

Hope I had explained my problem. I am replying through my phone, no access to my PC.

Thanking You for reply

Hi @vknow360 & All,
Writing my app to read text LOG.adi file (https://adif.org).
Now : how to convince Android to let SAF extenstion choose it for open using OpenSingleDocument ?
If I set AdiType to "text/*" and rename file to LOG.txt Android allows me to choose this file (it works fine) and other files (e.g. log.adi) are grayed-out and not available for selection.

What shall I set Aditype to to get Android allow me to chose only files with .adi extension ?

17 posts were split to a new topic: Companion issues if using extensions (on Android 13)

Dear Sunny @vknow360,
I use yr extension and it is great. Now I need to write my extension to process bytes read returned as result from GotReadResult after call to ReadBytesAsByteArray - the question is : what type is the result ?
Is it List result ? basically my intetion was to parse char[] result but I do not know where my error is ?
regards Kuba

SAF is open source, Why not check by yourself?

It returns byte[] as object.

1 Like

Dear @Kevinkun ,
could you show me how to declare Simplefunction (method) for my TEST extension that can directly take this result as byte[] . I can not "unwrap" that array from object :frowning:
Regards, Kuba
P.S. Yes, I've been looking into your code.

SAF How do you Create a Folder?

I would like to create a folder in Documents using SAF. I would like to do this to keep my different application's .csv files in organized locations. On the page dedicated to SAF " SAF: App Inventor implementation of Storage Access Framework"

@Narender_Kumar Narender_Kumar posted this statement:

"If anyone want to create a
empty folder after selecting the in "open Document Tree" by using "create document" .
then mimetype is following"
....
vnd.android.document/directory

There must be a little more to it. I have no problem using SAF now to save, copy, delete documents. But I still cannot create a folder.
Here is what I have tried.

The directory is the Documents folder.

But no clue how to create a directory.
Here is what I have tried.


I am not really sure what else to try, but this does not create a folder for me! Any ideas?

Thanks,
Jon

You can create dir in the document tree this way:

But if you want to create a dir which is not a direct child of document tree, then you will have to use BuildChildDocumentsUriUsingTree instead of BuildDocumentUriUsingTree.

Now Test1 will be created in Test dir.
Here Test is direct child of root Tree while Test1 is grandchild.

HOW DO MODIFY AND SAVE IN AI2 A BYTE ARRAY RECIEVED FROM Saf.ReadAsByteArray?

I'm able to read and than to write a content of a binary file using AsByteArray methods of SAF but maybe somebody knows in which way i can modify in AI2 a byte array received from SAF.ReadAsByteArray?
Any modification is converting this byte array in string and I'm receiving an error "java.lang string cannot be cast to byte[]" when i'm using SAF.WriteAsByteArray to save it (see an example below where i''m only substituting [ with the same [ - but if i pass the result of READ to WRITE without modification- everything is working).


There is no need to segment the result.
And, if you want to write file in asd then use CopyDocumentToASD block. You'll not have to worry about manual read and write.

maybe I was not able to explain my problem well.
I need to MODIFY the content of a binary file.
How can I modify a byte array variable returned by saf.ReadAsByteArray in order to be accepted by saf.WriteAsByteArray?

Unfortunately when you try to pass the modified string to WriteAsByteArray there is an error "String cannot be cast to byte".

It seems that WriteAsByteArray is expecting to receive Int8Array and not the string

Yes, it accepts byte array. :sweat_smile:

If I try to do any change of the "result" recieved from ReadAsByteArray and path the modified string to WriteAsByteArray - I receive an error "String cannot be cast to byte".
Can you recommend any workaround to bypath this problem?

Try using normal read and write functions. They return and accept strings.

Unfortunately i'm reading and writing a file with a binary data and your ReadAsByteArray was very useful for modifying of this byte stream.
Practicaly WriteAsByteArray has to check is the input is a string and in this case convert it in Int8Array.
Cound you add this functionality to the extension with my sponsorship support?
P.s. I like your extension and i was already sponsoring the possibility to read/write files bigger than 5mb

1 Like