Android WebView https请求问题。

在WebView 由http改成https时,遇到一个问题。

html改成了https ,但是图片地址由于用了CDN  地址并没有变为https,由此出现了一个5.0以上html不能加载cnd图片,但是sdk5.0以下就可以。估计是内核上的差别导致。


解决方案:在webview 初始化的时候 配置以下setting就可以了。加上如下代码。就可以正常显示了,虽然会有警告,但是并不碍事


 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }


/**
 * Used with {@link #setMixedContentMode}
 *
 * In this mode, the WebView will allow a secure origin to load content from any other origin,
 * even if that origin is insecure. This is the least secure mode of operation for the WebView,
 * and where possible apps should not set this mode.
 */
public static final int MIXED_CONTENT_ALWAYS_ALLOW = 0;

你可能感兴趣的:(Android)