Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing image in assets from HTML not working

I'm trying to display an image in a WebView in an Android app. The image exists in the assets folder of my Android project. The HTML is programmatically built and has this image ref in it:

The HTML is loaded into the WebView using:

webView.loadDataWithBaseURL( urlStr, htmlText, "text/html", "utf-8", urlStr );

urlStr = a base url needed to find other resources. htmlText = the programmatically generate HTML

The WebView loads the HTML fine, but the image is displayed as "missing". I have verified that the image exists at that location in the assets. Nevertheless it does not appear in the WebView.

I have seen numerous postings and tutorials saying that this should work, but it doesn't for me. This is on a 3.2 Android tablet. Anyone know if this only works on some versions of Android? Any thoughts about why it doesn't work in my case? Thanks.

like image 440
btschumy Avatar asked Feb 21 '23 01:02

btschumy


1 Answers

enter image description here

 webView.loadDataWithBaseURL("file:///android_asset/", sourse, "text/html", "UTF-8", null);
like image 70
Georgy Gobozov Avatar answered Mar 01 '23 08:03

Georgy Gobozov