简体   繁体   English

WebView无法加载图像Android

[英]WebView can't load image android

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

I want to use webview to load the image,these is my code: 我想使用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);

but image can't display.I use HttpURLConnection to read binary stream to load this url, it works.I don't know why can't I load image by using webview. 但是图像无法显示。我使用HttpURLConnection读取二进制流来加载此url,它可以正常工作。我不知道为什么无法使用webview加载图像。

You got the response in logcat below: 您在下面的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.

I paste the code below, hope you will solve the problem. 我将代码粘贴在下面,希望您能解决该问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM