业务原理啥的就不讲了,直接上代码
代码语言:javascript复制 /**
* 同步cookie
* @param url 要加载的地址链接
*/
private void syncCookie(String url) {
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeAllCookie();
//设置cookie
cookieManager.setCookie(url, SpUtil.getString(GlobalConstant.JESSION_ID));
//获取Cookie
String mCookie = cookieManager.getCookie(url);
//打印查看
LogUtil.i(mCookie);
//sync
CookieSyncManager.getInstance().sync();
}
这个方法要在mWebview.loadUrl之前调用