B4J Question [Solved] Webview load html-File with Image

D

Deleted member 103

Guest
Hi,

I've been looking for a solution all afternoon and can't find it, so I'm asking here with a new thread.

I would like to load an Html file in which images are also displayed.
The file loading works without problems like this:
B4X:
WebView1.LoadHtml(File.ReadString(File.DirAssets, "file.html"))
but it shows no pictures.

The line that shows the picture in B4a is:
src="file:///android_asset/image.png"

The line that shows the picture in B4i is:
src="image.png"

But how should the line that the image should display in B4j:
src="???????? image.png"

I also found this thread, but I don't get along.
 

DonManfred

Expert
Licensed User
Longtime User
I also found this thread, but I don't get along.
As for b4j you need to create the fileuri...
B4X:
File.GetUri(File.DirAssets, FileName)

Have you tried to define the correct uri in your html file?
 
Upvote 0
D

Deleted member 103

Guest
As for b4j you need to create the fileuri...
B4X:
File.GetUri(File.DirAssets, FileName)

Have you tried to define the correct uri in your html file?
Unfortunately I do not understand how that should define.
 
Upvote 0
D

Deleted member 103

Guest
Thanks Manfred, but that is not practical.
The Html file should work in every installation folder.
 
Upvote 0
D

Deleted member 103

Guest
I'm sorry, I thought my question was understandable. :(
In any case, my solution now looks like this:

The line that shows the picture in B4j is:
src="######/image.png"

and my code is:
B4X:
    Dim str As String = File.ReadString(File.DirAssets, "file.html")
    Dim DirAssets As String = File.GetUri(File.DirAssets, "file.html")
    str = str.Replace("######", DirAssets.Replace("file.html",""))

    WebView1.LoadHtml(str)
 
Upvote 0
Top