SAF: App Inventor implementation of Storage Access Framework

Is any way to get uri of USB drive automatically after it plugged in exists?

Not the best idea, but yet it is possible in this way.

com.sunny.usb.aix (7.2 KB)

5 Likes

Wow. Usb detector.. I didn't see this extension before. Thank you very much.

1 Like

Sorry, but still not undesrtand, how uri obtained automatically in your example. As I understand, OpenDocumentTree did that, but do I need to open file manager and choose file to get GotUri event result? Or AvailableStorage directories? But, the last one shows direct links, not the uriString.

Yes it is not possible to get mounted path of USB automatically so we need user to pick the drive himself. You can try saving the uri in tinyDb but I am worried if Android will mount usb to same location next time.

Your UsbDetector - is a miracle, really.

As a result, after around 5 seconds after usb drive attached, video on my usb drive starts to play automatically. As I understand, it will not work after particular version of Android, but Android 7 allow to do that. 8 - no. My device controlled by Android 7 (single-board computer), so I solved this part of my issue, thank you very much.

Btw, it worked on Android TV too (if version below 8)

2 Likes

Hi @vknow360. Can you tell, this extension can support from which android version?

The minimum requirement android version to use this extension? Many thanks.

Hi @zmd94 ,
Extension works on Android 5 and above versions.

Alright. Thank you for the clarification.

Next question, I can't find how to use this extension to check whether the required file is exist? Can you tell me how?

Sorry to ask, but can you tell why and for what you want to use SAF?
I am sure this will help in solving your query.

I want to check whether file is exist in user Download folder. Next, I want to move it into app specifir dir.

Then you should use TaifunFile or FileTools extension.

I already tried TaifulFile, yet it is not working with android 11 user.

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

SAF and the extension works on Android 4.4 (API 19, KitKat) and above, but the minSdkVersion is set to API 21 (Android 5.0). So it can't be used unless the minSdkVersion is changed in the Manifest (to API 19).

I know you know, but I still want to point it out for the others.

1 Like

@vknow360, great extension but I still find it difficult to understand. Could you add more information in your documentation (SAF: App Inventor implementation of Storage Access Framework), so people like me can also understand what each method does. For eaxmple what does "getTreeDocumentId" do?

A specific question for now: is there a way to check if a file exists (in /Documents/) and if it exists, then get that file and write to it else createDocument.
I read on the forum somewhere that writing to a file with SAF is not possible, I would need TaifunFile or FileTools, is that correct?

I appreciate any help.

1 Like

Where did you read this? Post a link.
Btw, it's not true.

sorry Anke, you're right I should have added a link, I can't find it anymore. Btw. I managed to save text to a file now. In DocumentCreated I save the uriString in a global variable so the next time I can check if that variable is not empty and don't do createDocument again.

Because it most likely doesn't exist. :wink: