图像未加载到android webview中 [英] Images not loading in android webview

查看:96
本文介绍了图像未加载到android webview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在android应用的网络视图中加载网站.

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.

onCreate的代码如下所示.

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);
}

更多注意事项,当我使用web.getSettings().setJavaScriptEnabled(false)将javascript设置为false时;图片会加载,并发出警告,应启用javascript才能正常运行该网站.

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.

此网站受CloudFlare保护,这可能是图像未加载到android网络视图中的原因吗?

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

推荐答案

添加

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.

这篇关于图像未加载到android webview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆