private void syncCookie (Context context) {
CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);// 允许接受 Cookie
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeSessionCookie();// 移除
cookieManager.removeAllCookie();
} else {
cookieManager.removeSessionCookies(null);// 移除
cookieManager.removeAllCookies(null);
}
cookieManager.setCookie(url, "m_is_inapp=1");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.getInstance().sync();
} else {
cookieManager.flush();
}
}
注意url只能放你要注入的host,不要带path
|