Since Lollipop (API 21), WebView blocks all mixed content by default。
要更改此行为,当您定位API级别21或更高级别时,请使用:
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
In this mode, the WebView will attempt to be compatible with the
approach of a modern web browser with regard to mixed content. Some
insecure content may be allowed to be loaded by a secure origin and
other types of content will be blocked. The types of content are
allowed or blocked may change release to release and are not
explicitly defined.
在实践中,这应该允许加载图像,视频,音乐等 – 所有内容在被恶意第三方篡改/替换时具有主要安全威胁的可能性较低。
或者使用(强烈劝阻):
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
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.