Android webview加载https网页时图片无法加载显示问题

来源:互联网 发布:已知矩阵的秩求未知数 编辑:程序博客网 时间:2024/06/06 07:04

问题:
webview加载https网页,在android 5.0以上,如果图片内容是http的,那么是无法加载出来的。报错如下:

“Mixed Content: The page at ‘https://…’ was loaded over HTTPS,
but requested an insecure image ‘http://image…..jpg‘.
This content should also be served over HTTPS.”

原因:webview 从Lollipop(5.0)开始 webview默认不允许混合模式,https当中不能加载http资源,如果要加载,需单独设置开启。

解决方案:
加入如下代码:

if (Build.VERSION.SDK_INT >= 21) {               webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); }
1 0
原创粉丝点击