Skip to content Skip to sidebar Skip to footer

Images Not Loading In Android Webview

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 onCr

Solution 1:

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.


Solution 2:

Just use this line of code. I think your problem will be solved.

     webView.getSettings().setDomStorageEnabled(true);
     webView.getSettings().setAppCacheEnabled(true);
     webView.getSettings().setLoadsImagesAutomatically(true);
     webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

You may need this one as well, if you are lazy-loading content:

      webView.getSettings().setJavaScriptEnabled(true);

Solution 3:

I had similar problem in Android 9.0. The images in the site's html were using http instead of https. Then I changed all the http with https and everything worked! It was very easy to change the http to https using a sql query in mySql.

I am giving the query if it helps anyone!

UPDATE table_name SET column_name = replace(column_name, '<img src="http://', '<img src="https://')

Solution 4:

I suspect that the issue might be your webview client. Use this instead:

webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.i(TAG, "Processing webview url click...");
                view.loadUrl(url);
                return true;
            }

            public void onPageFinished(WebView view, String url) {
                Log.i(TAG, "Finished loading URL: " +url);
                if (pDialog.isShowing()) {
                    pDialog.dismiss();
                }
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Log.e(TAG, "Error: " + description);
                Toast.makeText(FundCardWeb.this, "Page Load Error" + description, Toast.LENGTH_SHORT).show();

            }
        });

Solution 5:

for me the combination of adding those did it:

webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setLoadsImagesAutomatically(true);

I don't like adding unneccesery cod when so I didn't use:

webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

Post a Comment for "Images Not Loading In Android Webview"