yaronbic yaronbic - 2 months ago 30
Android Question

Android WebView doesn't show image

I have an html file locally with local images. I'm trying to display it using

webView.loadDataWithBaseURL(contentPath, content, "text/html", "UTF-8", null);

where contentPath is the file path and the content is the actual html.
It is showing the html fine but the problem is I have images inside it that don't show. an example is

<img src="images/philippines-map.png" class="full_page_image" alt="full page image for Philippines map" style="max-width:100%">

I checked and the location is right. Instead of the image it is showing a box with the alt text inside it. Anyone knows what's going on?

here are the variables initiation code

contentPath = context.getFilesDir() + "/" + pageFolderName + "/" + pageName;

content is initiated by

StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(contentPath)), "ISO-8859-1"));
String line;
while ((line = reader.readLine()) != null) {

content = fileData.toString();


Change webView.loadDataWithBaseURL(contentPath, content, "text/html", "UTF-8", null); to webView.loadDataWithBaseURL("file://" + contentPath, content, "text/html", "UTF-8", null);.