Home > OS >  Permission denied loading html from Downloads
Permission denied loading html from Downloads

Time:04-15

I'm loading HTML from the downloads folder on Android and showing it in a WebView. If the HTML there are some built-in HTML files that are in the assets for the app so I copy them to the Downloads folder and load them from there. These load just fine. If I try to load an HTML file that was copy into the Downloads folder via ADB it says ERR_PERMISSIONS_DENIED in the WebView. When adb shell and look at the file owners and privileges they are all the same so I can only think that Android remembers that my app put some of the files there and loads those but not the others?

I have android:requestLegacyExternalStorage="true" in my manifest and I'm requesting Manifest.permission.READ_EXTERNAL_STORAGE and Manifest.permission.WRITE_EXTERNAL_STORAGE when the app loads. What else do I need to do to make this work?

For context: I'm working on an app that connects to a custom BLE device and allows users to control various demo applications. We want the demos to be written by UX folks on our team using HTML and JavaScript so the app. To support this, the app has a WebView that just loads the index html. The UX folks need to be able to make changes and try new things. The easiest way for them to get it on the phone is to put them in the Downloads folder. I the app creates a folder in Downloads and copies any built-in demos from assets to that folder and then loads them from there. That way it can auto-detect any new demos the UX team adds.

CodePudding user response:

Android remembers that my app put some of the files there and loads those but not the others

On Android 11 (and perhaps 10), this is absolutely the case.

What else do I need to do to make this work?

The simplest solution is to stop using Downloads/. Instead, use the directory available as getExternalFilesDir(null) on Context. You have full read-write access there, and your designers can drag-and-drop files to that directory (Android/data/your.application.id/files/) if they're using a USB cable to transfer files from a desktop or notebook.

  • Related