SAF: App Inventor implementation of Storage Access Framework

i have suceeded checking the file is exist or not using File component. Now i will delete the file if it is exist. Does delete function from File component work on android 11+? or should i use delete function from SAF component?

It'll not work unless file is created by your app. So you should use SAF to delete the file instead.

1 Like

i see... but how can i delete the file using SAF? because i need to get documentUri in order to delete that file. AFAIK i can only get documentUri by opening it first. or does your component have function that create documentUri if i input treeUri + filename?

It is the recommended way to obtain document uri.
However you can try to build document uri manually with BuildDocumentUriUsingTree block.

i see
in BuildDocumentUriUsingTree block, there are 2 input parameters, the treeUri (i can get this parameter by using OpenDocumentTree block) and documentId. Is documentId the same as filename?

That depends upon whether file is direct child or grandchild of tree.
I would like to know directory structure before making any comment on it.

the tree i am creating is root/mydirectory/filename.txt

Show your blocks.

Sunny, what is the mime type for the xml files kml and gpx?

These are text files used for geolocation.

I have tried all of these 'standard' mimes:

mimetype
but the file is only recognized if I convert the suffix of the actual file from kml or gpx to txt.

The question is can kml and/or gpx files be selected using this Block?

Thanks. --Steve

Try application/vnd.google-earth.kml+xml and application/gpx+xml.

From Keyhole Markup Language - Wikipedia and gpx mime type? - Phoca Forum.

thanks for the idea. I saw it but now I tried it and it is not recognized. I expect kml is just not an option as a text file in SAF.

1 Like

Probably because you have specified text/* as primary mime type. Can you try with application/* ?

1 Like

as the primary mime type or with these shown below I get a display of all the files in Documents that are kml, gpx and txt grayed out. (The txt files are now grayed out too).

vnd

Thank you for the suggestion. It still does not allow kml and gpx, those files are displayed but not recognized/selectable.

If I use My_File to access a kml file then copy the kml and change the suffix to txt; the file is recognized as txt and reads perfectly.

1 Like

Thank you Anke. Unfortunately this is not working either.

The picker is able to select txt files but not kml . To test if there is something about the kml files already in Documents I downloaded KML_Samples.kml to my PC; used USB to move the file to my Documents. Your example file fails to 'pick' it along with any other kml or gpx; however txt files 'pick' just fine.

I get the following error No apps can perform this action. Picker won't pick KML_Samples.kml.

even though I am also using the OpenDocumentTreeBlock.

Samsung A13 with Android 13.

Any other ideas?

Anke's blocks work for me.
application/vnd.google-earth.kml+xml

Please show the blocks.

1 Like

No, it should work.

Thank you Anke, replacing the . with / worked. I suspect I need new bifocals. Appreciate the help from both @Anke and @vknow360 . :smile: