Stéphane Piette Stéphane Piette - 1 month ago 11
Android Question

Android - local image in webview

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

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");  
Comments