Android Question ERR when loading WebView with HTML file that's in any directory except File.DirAssets

Andris

Active Member
Licensed User
Longtime User
I need to load a WebView with an HTML file, from a directory other than File.DirAssets. But in doing that, I'm always getting the following ERR_ACCESS_DENIED message within the WebView:


Here are the two pertinent lines in my code. I put simple text into info.html and place it in File.DirInternal. Then I load it into my WebView (wvEventInfo).

B4X:
    ...
    File.WriteString(File.DirInternal,"info.html","This should display in the WebView.")
    wvEventInfo.LoadUrl("file://" & File.Combine(File.DirInternal,"info.html"))
    ...

My targer SDK is 34. I'm aware that at some point, Google Android may no longer allow the LoadUrl function. Have we arrived at that point already? Otherwise, I'm stumped as to why I'm getting the error. I know I could just load the html into the WebView directly, with LoadHTML, but I can't do that because the HTML will have custom font CSS in it, which requires that the font.ttf file be in the same directory. I'd appreciate any help or comments on this.
 

teddybear

Well-Known Member
Licensed User
1.Use FIleProvider.GetFileUri to get the file url.
B4X:
    Dim p As FileProvider
    WebView1.loadurl(p.GetFileUri(File.Combine(File.DirInternal,"info.html")))
2.Or use webview.LoadHtml to read the html file
B4X:
WebView1.LoadHtml(File.ReadString(File.DirInternal,"info.html"))
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I'm aware that at some point, Google Android may no longer allow the LoadUrl function.
Where did you hear that this may happen?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is related to a change in the default value since Android 11. I will add a property to WebView. For now you need to use WebViewSettings library to change it:
B4X:
Dim settings As WebViewSettings
settings.setAllowFileAccess(WebView1, True)

 
Last edited:
Upvote 1

Andris

Active Member
Licensed User
Longtime User
Where did you hear that this may happen?
I saw it mentioned/discussed here on a forum in a couple of posts. However, I just researched it and found the best summary of webview.loadurl use as written by Grok:

Thanks for asking the question.
 
Last edited:
Upvote 0

Andris

Active Member
Licensed User
Longtime User
Can't believe the "new library" is alredy 13 years old! Thanks for all you've done to keep this amazing platform evolving.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…