SAF: App Inventor implementation of Storage Access Framework

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.

Correct @Anke
I am also searching solution for opening a pdf file already stored in Documents folder.
Can the possible solution be -
to copy this file to ASD by using SAF extention by @vknow360 and then try opening it from ASD.?

Thank you @Clipper for the solution you share. I have tried it and it works!
but in my case I need to open pdfs that are in the internal storage of the mobile.

I understand, it is a different problem. Could it be fixed by having Activity Starter open a file explorer folder?

Hi Anke, you are right, it is a different problem.

For that solution is to grant temporary uri access to the external app which seems to be possible with ActivityStarter.

What do you mean by "internal storage". An app can only access its own (private) internal storage (privateDir).

/data/user/0/<packageName>/files/

For example:
/storage/emulated/0/Documents
or any directory from:
/storage/emulated/0/....

This is a folder in the external storage (and also one of the Shared folders).
To open / access non-media files, that are not created by the app itself, from the external storage (or even from a Shared folder) you need SAF.

See here:

that's what I tried as I put here in the photo. Unless you mean something different or another way....
saf

Button2 click has nothing to do with SAF.
You only got the filePath with SAF and the FileTools extension.