解决android Webview报Mixed Content。。。的问题

测试给了一个bug,说网页中的图片显示不出来,刚开始以为是前端h5界面写的有问题,结果他又说ios没问题,那就是webview在坑队友了,立即链接adb ,打开logcat日志如下:
Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure image
 'http://xxx.png'. This request has been blocked; the content must be served over HTTPS."
看到log就知道是https加载的网页中用http去获取图片了;原因就是安卓5.0以后做了限制,解决方法就一行代码,websettings设置一下
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
       }
发布了117 篇原创文章 · 获赞 56 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/Jiang_Rong_Tao/article/details/89027765