求助,webview加载网页白屏
发布网友
发布时间:2022-04-19 19:13
我来回答
共1个回答
热心网友
时间:2023-04-24 06:30
现象描述:webview加载H5链接是https,而h5中是图片地址拼接,造成加载不出来,显示空白页面。
log日志:
chromium: [INFO:CONSOLE(0)] "Mixed Content: The page at ' https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002' was loaded over HTTPS, but requested an insecure image ' http://onehaiercms.oss-cn-qing.aliyuncs.com/2016/12/14/17-21-340871526087485.jpg' . This request has been blocked; the content must be served over HTTPS., source: https://iot.onehaier.com/v2/cms/advert.detail.h5?advertId=201612141722070002 (0)
原因:H5链接是:https,而里边图片地址是:http;
Android webview 从Lollipop(5.0)开始webview默认不允许混合模式,https当中不能加载http资源,需要设置开启。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}