WebView无法加载图像android

时间:2014-09-06 03:13:06

标签: android webview

<img src='http://lt.ltcx.net.cn:109/upload/image/XheditorProjData/2013/10/18/31c314e0-a76a-4a72-8f9e-991d73a44990.jpg' alt='' />

我想使用webview加载图片,这些是我的代码:

mWebView = (WebView) findViewById(R.id.webview);
    // 设置字符集编码
    mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
    mWebView.getSettings().setLayoutAlgorithm(
            LayoutAlgorithm.SINGLE_COLUMN);
    mWebView.getSettings().setBlockNetworkImage(false);
     mWebView.getSettings().setJavaScriptEnabled(true);
     mWebView.loadDataWithBaseURL(null, url, "text/html",
                "UTF-8", null);

但是图片无法显示。我使用HttpURLConnection读取二进制流来加载这个网址,它可以工作。我不知道为什么我不能用webview加载图片。

1 个答案:

答案 0 :(得分:5)

你在下面的logcat中得到了回复:

Mixed Content: The page at 'https://' was loaded over HTTPS, 
                 but requested an insecure image.

Webview cannot load the images with http request after 
                 android KITKAT, so we have to set the websetting.

我粘贴下面的代码,希望你能解决问题。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webview.getSettings().setMixedContentMode(
                        WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
 }
相关问题