Android Question WebView - net:ERR_ACCESS_DENIED

Arf

Well-Known Member
Licensed User
Longtime User
I am updating an old app that present an html from DirInternalCache in a WebView.
The device is running Android 13 and I have set TargetSDK to 33 and updated my installations.
The WebView doesn't load and reports net:ERR_ACCESS_DENIED.

I can see in the IDE the permissions for my app are:
1693141576133.png

I am not sure why the WRITE_EXTERNAL is there as I am using DirInternal, DirAssets and DirInternalCache only.

What do I need to do to fix the error?

Thanks
 

JohnC

Expert
Licensed User
Longtime User
I am not sure why the WRITE_EXTERNAL is there as I am using DirInternal, DirAssets and DirInternalCache only.
Some library that is being included into your project has the *ability* to use that permission even if your code doesn't actually make use of that ability.

You can add the below line to your manifest to cancel it out:
B4X:
RemovePermission(android.permission.WRITE_EXTERNAL_STORAGE)
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
I found THIS thread and moved the html and images to DirInternal instead of DirInternalCached and I have changed the call to:
B4X:
WebView1.LoadHtml(File.ReadString(File.DirInternal, "mainpage.html"))
however the images don't load when the html is loaded.

How can I get them to load? I have also tried loading from DirAssets but get the same result.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
that thread you referred to opens a large can of worms which you chose to ignore.

at the very least, webview needs to know where your resources are. i'm guessing you
did not tell it; therefore no images are loaded. assuming you are using <img> tags to
load your images, put your images (and other resources) back in dirassets and use something
similar to the following:
B4X:
<img src='file:///android_asset/filename.jpg'>
for the images.
it still works in 33 and in this particular, simple case (given my understanding of your post.)
if your use case is more complicated, other remedies may be required.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
Thanks @drgottjr
I will re-read the thread when I have more time and try figure out the right thing to do, it was not clear to me if a workaround is OK or a total change of strategy is better, my expertise in the html area is weak I'm afraid. My usage case is very simple - just showing a basic html doc with text and images, I can make whatever change is best for future proofing, I just need to know what I am aiming for.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
in many cases, the original post in a thread reveals just the tip of the iceberg. what i suggested is not a workaround (it's the original method), and there is no way to futureproof android. you can follow the rules to the extreme and still get crushed somewhere down the line. android's documentation claims that webview is not a substitute for a browser, yet every 3 days there is an updated webview. it started out as a dependent child of chrome (if you got rid of chrome somehow, webview wouldn't run without it), and - little by little - has almost become its own father. as such, it becomes subject to rules similar to those governing chrome. one such rule has to do with loading resources and the dangers of allowing them to be loaded. it is a big and powerful view.
 
Upvote 0
Top