Android webview Mixed Content无法显示图片解决
2016-12-25 19:46
651 查看
转自:http://blog.csdn.net/crazy_zihao/article/details/51557425
前言
在使用WebView加载https资源文件时,如果认证证书不被Android认可,那么会出现无法成功加载对应资源问题。那么,我们就要针对这一状况作出对应的处理。解决步骤
1. 启用mixed content
在Android5.0中,WebView方面做了些修改,如果你的系统target api为21以上:系统默认禁止了mixed content和第三方cookie。可以使用setMixedContentMode() 和 setAcceptThirdPartyCookies()以分别启用。
系统现在可以智能选择HTML文档的portion来绘制。这种新特性可以减少内存footprint并改进性能。若要一次性渲染整个HTML文档,可以调用这个方法enableSlowWholeDocumentDraw()
如果你的app的target api低于21:系统允许mixed content和第三方cookie,并且总是一次性渲染整个HTML文档。
在使用WebView的类中添加如下代码:
[html] view plain copy
print?
// android 5.0以上默认不支持Mixed Content
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(
WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
2. 设置WebView接受所有网站的证书
在认证证书不被Android所接受的情况下,我们可以通过设置重写WebViewClient的onReceivedSslError方法在其中设置接受所有网站的证书来解决,具体代码如下:[html] view plain copy
print?
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view,
SslErrorHandler handler, SslError error) {
// TODO Auto-generated method stub
// handler.cancel();// Android默认的处理方式
handler.proceed();// 接受所有网站的证书
// handleMessage(Message msg);// 进行其他处理
}
});
注:在重写
WebViewClient的
onReceivedSslError方法时,注意一定要去除
onReceivedSslError方法的
super.onReceivedSslError(view, handler, error);,否则设置无效。
相关文章推荐
- 解决android webview https图片不显示问题
- Android webview加载https网页时http图片无法显示
- android通过webView加载第三方h5应用,无法加载图片和播放视频的解决方法
- Android webview加载https网页时图片无法加载显示问题
- 解决android webview中图片不显示问题
- 关于Android WebView显示html网页图片无法自适应(PS第一次写博客)
- 解决webview 无法显示图片
- Android WebView加载网页不显示图片解决办法
- 快速解决android webview https图片不显示的问题
- 【Android】WebView不能显示图片的问题
- Android 3.0 以上系统 webView 无法在html中传值的解决办法
- Android 使用Webview无法播放视频问题的解决办法
- android用WebView显示包含文字和图片的本地网页(支持放大缩小)
- android webview中的html代码 @media screen 在低版本系统下显示不正常的解决办法
- Android中 在显示ImageView时图片上面和下面都出现一段空白区间的解决办法
- Android 环境WebView中图片自适应显示
- android webview 显示空白页问题解决
- android之WebView解决如何显示中文及使页面自适应手机分辨
- Android中webview显示HTML长按选择时无法显示选中文字
- android 2.3 webView select控件 无法及时显示optionLabel的BUG