SAF: App Inventor implementation of Storage Access Framework

You cannot open / pick from the ASD on Android 11 (because this dir is no longer visible on Android 11), also not unsing SAF.

But if the fileName is known (in my example loop.ogg) you can copy it from the ASD to the Shared folder /Ringtones (of course without WRITE permission):

grafik

If the fileName in unknown, you can list all relevant audio files from the ASD and pick the sound file from a ListPicker.

4 Likes

Thanks, I see it works with media files, but I also need pdfs and some doc/docx.

2 Likes

thank you,
and how would I have to configure the parameters to make it work:opensinglefile

2 Likes

title can be anything.
category must be android.intent.category.OPENABLE .
type is the mime type of what you want to browse. For pdf it should be application/* and extraMimeType should be a list of acceptable mime types such as application/pdf in this case.

Selected document's uri will be returned in GotUri method.

3 Likes

then it would work like this:

it did not let me place the extraMineTypes block.

2 Likes

That parameter accepts a list.
Also, you will get uri from that event so there is absolutely no need to reassign the wrong value.

2 Likes

I'm sorry I'm not an expert, I don't understand very well where to put the file path.

1 Like

as far as I understand, the OpenSingleDocument method lets you select a single document (in your case the pdf document)

OpenSingleDocument
Prompts user to select a single file

so what happens after using that method and selecting that file? which uri do you get in the GotUri event? that uri you have to use to for example display the pdf

Taifun

2 Likes

Thank you very much, now I understand!
This block configuration works. I can select a pdf file and I can see the uri in the label I have put. The problem I have now is when viewing the pdf. I pass the uri to activitystarter, it opens the pdf application, but does not open the file.

1 Like

you can try to convert the uri into a filename and try that filename with the activity starter... my file extension offers the method GetFileName for this https://puravidaapps.com/file.php
in case that method does not work for you (because actually it was created to Get path and filename from media content uri), you also can use the corresponding method from the filetools extension by @vknow360 https://community.kodular.io/t/filetools-some-tools-to-work-with-files/40051

probably it would be nice to have such method in the SAF extension directly?

btw. to simplify your blocks you can move all blocks from the Button2.Click event into the GotUri event...

Taifun

1 Like

Thank you Taifun,
I tried converting the uri to a file path with your extension and it didn't work, but it did work with Filetools as you told me.
Also reducing the blocks will work fine for me, just testing now, to see the label I put it like this.

Still, I can't get the pdfs to open with SAF. Maybe it's because of what @vknow360 was saying earlier. I don't know.
I am attaching the blocks for anyone if anyone sees any errors in them.

There is some misunderstanding, I guess.
You can't open any kind of file with SAF, you can only get access to files and read and write them.
Obviously you can render pdf files with Uri obtained from SAF with the help of extensions available in your own app.

4 Likes

I understand, I had been told that the problem of not being able to open pdfs was because of android 11 read/write permissions, and I thought that with SAF I could access this type of files with read permissions in this case.

1 Like

So as you said here, now you are able to open pdf files with the help of external applications.

1 Like

@vknow360 not exactly, what I was telling Taifun is that when I select the pdf file with SAF and get the Uri, I put it in the DataUri of ActivityStarter and it did not open the file. Then he suggested me to try to convert it to a normal path like file:///storage/emulated/0/... with its extension or with Filetools. And getting the path didn't work with TaifunFile and Filetools did (only the Uri to path), but even putting this path in the activitystarter DataUri still doesn't open pdfs (with android 11, this same thing on my tablet with android 8 opens pdfs without problems).

1 Like

He has a similar problem:

But, unfortunately, I haven't checked anything till yet.

1 Like

Yes it must be the same. I'm in no hurry, if one day it's available great!
Thank you very much anyway!

1 Like

@vknow360
Hello, Sunny
When you can, of course.
Thanks for your help.

Hi Toni, I found a solution for my application. Hope this can help you.
All the best.

1 Like

This only works because the PDF file is created (downloaded) by the app itself.
If the file has already been manually saved in this folder (/Download) by yourself or by another app, this will not work.