1.WebView必不可少的一句
webView.setWebViewClient(new WebViewClient());
2.http和https混合支持
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
3.添加 Cookie
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setCookie(url, cookie);
4.删除 Cookie
CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
}
else{
CookieSyncManager.createInstance(Application.getInstance());
CookieSyncManager.getInstance().sync();
}
网友评论