Android 踩坑记Android

WebView加载图片失败

2016-12-07  本文已影响794人  Aegis

这个几率比较小, 但碰到还是比较蛋疼, 坑爹:

使用WebView加载一个https的URL, 而在在URL内有http前缀的资源文件, 此时, 在Android 6.0 以上会导致资源文件加载失败...

报错如下:

      "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."source: https://... (119)

这个错误是:
因为Android WebView 从Lollipop开始WebView默认不允许混合模式,https当中不能加载http资源,需要设置开启。

   webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

如此, 问题便解决了!!!

上一篇 下一篇

猜你喜欢

热点阅读