Android - local image in webview

Stéphane Piette picture Stéphane Piette · May 25, 2011 · Viewed 89.9k times · Source

I'm trying to diplay a local image in my webview :

 String data = "<body>" + "<img src=\"file:///android_asset/large_image.png\"/></body>";
 webview.loadData(data, "text/html", "UTF-8");

This code doesn't display anything, instead of :

 webview.loadUrl("file:///android_asset/large_image.jpg");

This one works, but I need to have complex web page, not just a picture.

Any ideas ?

Answer

Sanjay Patel picture Sanjay Patel · May 26, 2011

Load Html file in Webview and put your image in asset folder and read that image file using Html.

<html>
  <table>
    <tr>
      <td>
        <img src="abc.gif" width="50px" alt="Hello">
      </td>
    </tr>
  </table>
</html>

Now Load that Html file in Webview

webview.loadUrl("file:///android_asset/abc.html");