I'd like something:
s="
<body>
<img src='"+R.drawable.picture+"'>
</body>";
How can I do this?
After some experimenting I found that the following HTML worked on Android 2.3.1 (but not on older versions):
<img src="file:///android_res/drawable/example.png"/>
The really cool part is that the image file was actually in the directory drawable-hdpi
but the resource manager provides the image in the standard directory drawable
.
You can only do such a thing if our image is inside your /assets
folder. Also, you must load your html with a baseUrl that's inside your assets folder.
You can use WebView.loadUrl()
or WebView.loadDataWithBaseURL()
:
webView.loadUrl("file:///android_asset/file.html");
or
webView.loadDataWithBaseURL("file:///android_asset/", "<img src='file.jpg' />", "text/html", "utf-8", null);
(file.jpg should be inside your assets folder)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With