Android Question webview.loadhtml

ggkuwait

Member
Licensed User
Longtime User
Trying to load and view some HTML that contains an image (question.gif) but when I compile I get the message file question.gif not used and the loadhtml command does not work. is there something I have missed. I have added the file using the file manager.
 

walterf25

Expert
Licensed User
Longtime User
Trying to load and view some HTML that contains an image (question.gif) but when I compile I get the message file question.gif not used and the loadhtml command does not work. is there something I have missed. I have added the file using the file manager.

In order to help you it is better to provide the code or at least the relevant portion of the code you are working with.


cheers,
Walter
 
Upvote 0

ggkuwait

Member
Licensed User
Longtime User
The code is:

Webview1.Initialize("")
Webview1.LoadHtml("<html><body><img src='file:///android_asset/question.jpg'/></body></html>")
Cheers
gg
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You have to add the webview to the activity before you load the HTML
B4X:
Webview1.Initialize("")
Activity.AddView(Webview1, 0dip, 0dip, 100%x, 100%y)
Webview1.LoadHtml("<html><body><img src='file:///android_asset/question.jpg'/></body></html>")
 
Last edited:
Upvote 0

ggkuwait

Member
Licensed User
Longtime User
You have to add the webview to the activity before you load the HTML
B4X:
Webview1.Initialize("")
Activity.AddView(Webview1, 0dip, 0dip, 100%x, 100%y)
Webview1.LoadHtml("<html><body><img src='file:///android_asset/question.jpg'/></body></html>")
Thank u works a treat
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
A more recent update - it looks like that in later versions of Android you can no longer access items from the DirAssets folder in a WebView LoadHTML statement. I guess that this might be a security issue.

This indirect method works though if you copy the file to the internal directory first though.

B4X:
File.Copy(File.DirAssets,"ic_menu_home.png",File.DirInternal,"ic_menu_home.png")
Dim HTML As String
HTML=$"
<HTML>
<BODY>
<img src='file://${File.DirInternal}/ic_menu_home.png' >
Use the Home Icon to return to the Account Summary.
</BODY>
</HTML>
"$
    WebView1.Enabled=True
    WebView1.Visible=True
    WebView1.Invalidate
    WebView1.LoadHtml(HTML)

Derek
 
Upvote 0
Top