mask mask - 1 year ago 80
Android Question

loadDataWithBaseURL does not load images which are part of html page

I am battling with this issue for a long time, dug around Google and SO but still no luck. Finally, I am out here to get your help, please advise or help.

My problem with the following source code is that it only displays string content the images do not display instead it shows white rectangle or sometimes a blue image with question mark.

Q: How to display images?

Here is my code:

private void openURL() {

DefaultHttpClient client = new HttpsRequest(getApplicationContext());
HttpGet get = new HttpGet(getUrlField().getText().toString());
// Execute the GET call and obtain the response
HttpResponse getResponse;
try {
getResponse = client.execute(get);
HttpEntity responseEntity = getResponse.getEntity();

String content = EntityUtils.toString(responseEntity);
getWebView().loadDataWithBaseURL(null, content, "text/html", "utf-8",

} catch (ClientProtocolException e) {
WSLog.e(THIS_FILE, "HTTP Error.");
} catch (IOException e) {
WSLog.e(THIS_FILE, "Url Load Error.");

webView output:

enter image description here

Answer Source

With the help of Vasarat and few modification from my side helped me to answer this question. I have modified the following code line as

getWebView().loadDataWithBaseURL("", content, "text/html", "UTF-8","about:blank");

This modification gave me the perfect output as expected.

Please fallow the comments to understand details about the issue.

Note: I have used http in the base url instead https.....Please let me know if I can use https. webview.Loadurl() with https url works fine if API level is 10 or above but it shows blank page for API level 8.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download