Unable to download a PDF file created with an API

Hi All,

My app creates a table of insulin doses in HTML for a nice screen view, and then optionally to an API (html2pdf.app) to create a PDF file, using the Web Component.

This works beautifully in the Companion, the file is written to the Companion's ASD and can be shared with a Sharing component no problem.

So I don't think the problem is with the API.

When I create an APK, everything works, up to the point the HTML file is sent to the API and it attempts to download it to the app's ASD. I get an error message "Error 908: The permission WRITE_EXTERNAL_STORAGE has been denied. Please enable it in the settings app." This is on both a Pixel running Android 12 beta, and a tablet running Android 11.

I looked in the APK manifest and deleted the WRITE_EXTERNAL_STORAGE, as I've seen suggested. Then the APK, when run, does ask for permission to access media and files, but then I get the same error message.

I also tried to direct the API file to the /storage/emulated/0/Download folder using the File MakeFullPath block and Shared scope, that didn't work.

So I gather this is a storage permissions problem. My question is whether anyone has a suggestion about how to do this with AI2's current version? Or if they thought the new Storage Access Framework extension would work (although I'm not sure I understand how I'd do that)?

Many thanks for any suggestions.

This is a known bug...
As workaround set the default file scope to Legacy in the Designer Screen settings

1 Like

Thanks! That worked perfectly. Much appreciated.

But how was it possible to remove WRITE_EXTERNAL_STORAGE in the Manifest? That could only be possible because DefaultFileScope was already set to Legacy in the Designer. Since only then WRITE_EXTERNAL_STORAGE is declared in the Manifest on devices with Android 11+.

So your statement that you removed WRITE permission from the Manifest doesn't seem to be true.

Sorry, I was incomplete in what I said. With DefaultFileScope set to App, the manifest showed:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:maxSdkVersion="29" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

What I meant was I deleted both of those.

With DefaultFileScope now set to Legacy, the manifest shows:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Yes, because with DefaultFileScope = App WRITE permission is only declared on devices with Android < 11 (API < 29).

But that's exactly how it should be, because WRITE permission is no longer available on devices with Android 11+. So declaring WRITE on devices running Android 11+ should have no effect. In this respect, this is illogical / wrong and of course a bug.

In fact, no permission at all should be requested for this.

Right! Which is why setting the DefaultFileScope to Legacy didn't seem intuitive. But at least it works until the bug is fixed.