0

I've some problem with showing static html file with extra images (store as assets), for example About.html.

<html>
 <body>
  <div style="text-align:center;">
   <p>Some text in utf-8</p>
   <img src="image.png"/>
  </div>
 <body>
<html>

In first approach I've tried to display my content as:

webView.loadUrl("file:///android_asset/About.html");

and almost everything worked ok. I saw image and my string, but not in utf-8. After some research I've tried to load my html in another way:

webView.loadDataWithBaseURL(null, dataContent, "text/html", "utf-8", null);  

After that strings are presented correctly, but I'm not be able to display images. It looks like webView are not able to load image from assets folder. Do you have any suggestions how can I display static html content (utf-8 + images)?

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
Gie
  • 1,907
  • 2
  • 24
  • 49

1 Answers1

4

When you use the "loadDataWithBaseURL" method you have to set the base URL. In your case it would be the Asset-Folder. So, try this:

    webView.loadDataWithBaseURL("file:///android_asset/", dataContent, "text/html", "utf-8", null);

In my test the text and the image was loaded correctly. Have a look at this question also: Using webView's loadDataWithBaseURL not loading images from sdcard

Community
  • 1
  • 1
Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92