CookieSyncManager.createInstance(context.getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeAllCookie();
cookieManager.setCookie(url, oldCookie);
cookieManager.setCookie(url, oldAuth);
CookieSyncManager.getInstance().sync();
需要注意的是,如果是设置两个或两个以上cookie值,需要单独设置,否则不成功;
另外WebView的getSettings().setJavaScriptEnabled(true)之类设置需要在设置Cookie之前设置。