[FIXED] Images not loading in android webview

Issue

I am trying to load the site in an android app web view.

The site loads without the images ,all the images from the site are not loaded what could be the problem.

The code for onCreate is shown below.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    String url = getResources().getString(R.string.web_url);
    web = (WebView) findViewById(R.id.webview01);
    progressBar = (ProgressBar) findViewById(R.id.progressBar1);

    web.setWebViewClient(new myWebClient());
    web.getSettings().setJavaScriptEnabled(true);
    web.getSettings().setUseWideViewPort(true);
    web.loadUrl(url);
}

One more note, when i set javascript to false using web.getSettings().setJavaScriptEnabled(false); the images load giving a warning that javascript should be enabled to run the site properly.

This site is protected with CloudFlare ,could this be the reason images are not loaded in the android web view ?

Solution

Add

web.getSettings().setDomStorageEnabled(true);

This should work. Keep the rest as is.

Although a caveat, I don’t think its recommended to enable this by default, its disabled by default. The setting allows a website to store data and reuse it. So the images are not being loaded, because this site wasn’t allowed to store them on your device. This opens up a can of security concerns.

Answered By – Vrashabh Irde

Answer Checked By – Pedro (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published