Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading package html + resources into webview

I would like to know how I can display a HTML page in webview with references to relative/local images. The goal is to have the html page and all linked images contained in the android application package itself.

Where would I need to place the assets (assets directory?) and how do I reference these so they load into the webview?

Thanx! Sven

like image 948
user302750 Avatar asked Jun 08 '10 05:06

user302750


1 Answers

You can put all html and images to assets directory, like:

assets\html\
  index.html
  image1.png
  image2.jpg

All references to the images in the html file should be in form of file:// url

<html>
<body>
  <img src="file:///android_asset/html/image1.png">
  <img src="file:///android_asset/html/image2.jpg">
</body>
</html>

After all, just load this HTML to WebView as usual:

   webView.loadUrl("file:///android_asset/html/index.html");
like image 70
uaraven Avatar answered Sep 30 '22 12:09

uaraven