How to load an img tag in webView in Android?

Qadir Hussain picture Qadir Hussain · Jan 9, 2013 · Viewed 8.2k times · Source

I want to load the following HTML code in the Android webview.

<!DOCTYPE html>
<html>
<body style = "text-align:center">

<img src="http://XXXXXXXX.com/books_snaps/UR335/1.jpg" alt="pageNo" 

height="100%" width="100%"> 

</body>
</html>

where http://XXXXXXXX.com/books_snaps/UR335/1.jpg is a image link. I want to load this image in <img> tag of above HTML. How can I embed above HTML code in webview of Android?

Answer

Sanket Kachhela picture Sanket Kachhela · Jan 9, 2013
String htmlString = "<!DOCTYPE html><html><body style = \"text-align:center\"><img src=\"http://shiaislamicbooks.com/books_snaps/UR335/1.jpg\" alt=\"pageNo\" height=\"100%\" width=\"100%\"></body></html>";
webview.loadDataWithBaseURL(null,htmlString,"text/html","UTF-8","about:blank");

Also, you need to add the internet permission,

<uses-permission android:name="android.permission.INTERNET" />