Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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 ?

like image 665
Ninad Avatar asked Apr 27 '15 06:04

Ninad


People also ask

How to display image in WebView Android?

html. String res = ""; File file = new File(Environment. getExternalStorageDirectory()+"/Test. html"); try { FileInputStream in = new FileInputStream(file); if (in !=

Why is my WebView not working?

You might often face issues in updating the chrome and Android System Webview. To fix this problem, you can reboot your device, check your internet connection, stop auto-updating all apps, clear Google Playstore cache, and storage, leave the beta testing program, and manually update Android WebView app from Playstore.


1 Answers

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.

like image 129
Vrashabh Irde Avatar answered Sep 28 '22 10:09

Vrashabh Irde