'WebView.LoadHtml file access error Android 30 Xamarin

I have a Hybrid app I rebuilt after setting the Target Android version to API 30, per a new warning that Google now requires this, and am trying it on a Tablet with Android 11. Originally following an old hybrid sample app, my app copies files from the resources to the file system. This seems to work, as no exceptions are thrown from the File operations. The first thing it does is display a splash screen from an HTML file copied from the afore-mentioned resource copy, using the LoadHtml function of a created WebView, and giving it a URL formatted like this:

file:///data/data/com.mycompanyname.myappnameandroid/files/Content/Splash.html

LoadHtml doesn't throw an exception, but then the screen displays an error message referencing this path and the error "ERR_ACCESS_DENIED". This file does reference CSS files copied to the same directory (referenced like "<link rel="stylesheet" href="site.css" /> " in the HTML header). It will continue on to display the main app pages, but it apparently failed to load CSS files and so forth, as all the styling and scripting is missing. What do I need to change to make this work?

Searching, I find talk of "Scoped Storage", but I can't make any sense of it. I'm hoping there is a simple fix.



Solution 1:[1]

There is a simple fix. Add the following to your set up of the WebView:

    webView.Settings.AllowFileAccess = true;

Apparently the default changed from true to false.

Thanks to this posting for the clue: Load file into webView with scoped storage

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jtsoftware