WebView loadDataWithBaseURL

airblaster

Active Member
Licensed User
Longtime User
Is there an equivalent to loadDataWithBaseURL for the WebView?
I'm loading data from an external URL that is not under my control (with permission of course). Without setting the BaseURL images etc are not displayed because relative URLs are used.
 

airblaster

Active Member
Licensed User
Longtime User
Figured it out myself.
In case anyone has the same problem, the idea is:

B4X:
r.Target = WebView1
r.RunMethod4("loadDataWithBaseURL", Array As Object ("http://www.google.de", html, Null, "UTF-8", Null), Array As String("java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"))
 
Upvote 0

airblaster

Active Member
Licensed User
Longtime User
Sorry, I forgot to mention an important detail:
The html data itself is loaded by a Third Party Android library, so I can't use LoadURL.
 
Upvote 0

Technicaone

Member
Licensed User
Longtime User
Figured it out myself.
In case anyone has the same problem, the idea is:

B4X:
r.Target = WebView1
r.RunMethod4("loadDataWithBaseURL", Array As Object ("http://www.google.de", html, Null, "UTF-8", Null), Array As String("java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"))

Thanks for posting this solution, this was required when we needed to loadHTML from a database that was from a live web site with relative image links. Worked perfectly!
 
Upvote 0

Technicaone

Member
Licensed User
Longtime User
Maybe in the future.

For now you can call it with this simple sub:
B4X:
Sub LoadDataWithBaseUrl(wv As WebView, BaseUrl As String, Html As String)
Dim jo As JavaObject = wv
jo.RunMethod("loadDataWithBaseURL", Array As Object(BaseUrl, Html, "text/html", "UTF8", null)
End Sub

Thanks

I used the following to solve my issue, is there any advantages or disadvantages between these two techniques?

B4X:
Dim r As Reflector
r.Target = wv1
r.RunMethod4("loadDataWithBaseURL", Array As Object ("http://THEDOMAIN", myHTML, Null, "UTF-8", Null), Array As String("java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"))
 
Upvote 0
Top