Cookiesyncmanager.createinstance (_context);
Cookiemanager manager = Cookiemanager.getinstance ();
Manager.setacceptcookie (TRUE);
Manager.removesessioncookie ();
StringBuilder builder = null;
for (HttpCookie cookie:allcookies) {
Builder = new StringBuilder ();
Builder.append (Cookie.getname ());
Builder.append ("=");
Builder.append (Cookie.getvalue ());
Builder.append ("; Path= ");
Builder.append (Cookie.getpath ());
Builder.append ("; Domain= ");
Builder.append (Cookie.getdomain ());
Manager.setcookie (Xidibuyconstants.domain_xidibuy,
Builder.tostring ());
LOG.E (TAG, "Cookie:" + builder);
}
Cookiesyncmanager.getinstance (). sync ();
Attention:
1.//Manager.removesessioncookie (); In some versions of Android, the cookie will fail to save. Known 4.4 no problems, 4.3 have problems.
2. The server sends a cookie and sometimes wants to send some cookie that is deleted to overwrite the existing cookie.
However, in order to save time, some servers will send a cookie that contains only key and value, and does not contain path and domain. In this case, WebView will consider it to be two cookies and will not overwrite the existing cookie.
WebView When you save a cookie, it must be overwritten by the same key,path and domain.
So make sure that the server sends a cookie that contains key,path,domain otherwise it needs to be handled manually when it is saved.
WebView Cookie Settings