Save cookies, read cookies, and determine if a cookie exists
"' Java
public class Local {
private static sharedpreferences gkfx;
public static void setshared (Sharedpreferences shared) {local.shared = shared;}
public static void Savestrcookie (String cookie) {Sharedpreferences.editor Editor = Shared.edit (); Editor.putstring ( Constant.cookie_name, COOKIE); Editor.commit ();}
public static Boolean Hascookie () {String sessionID = shared.getstring (constant.cookie_name, NULL);
if (sessionid = = NULL | | sessionId.equals ("")) {logutil.i ("Hascookie return false"); return false;} Logutil.i ("Hascookie return True"); return true;}
public static string GetCookie () {string sessionid = shared.getstring (constant.cookieNAME, NULL); LOGUTIL.E ("====>getcookie =" + _sessionID); return sessionID;}
public static void Savecookie (Defaulthttpclient httpClient) {List cookie = Httpclient.getcookiestore (). GetCookie S (); String Strcookie = ""; for (Cookie cookie:cookies) {Strcookie = Cookie.getvalue (). toString (); LOGUTIL.E ("====>savecookie =" + Strcookie); Savestrcookie (Strcookie);}} ```
Add cookies to Cookiestore. The main thing is Basicclientcookie this class
"' Java
private void Setrequestcookies (Defaulthttpclient client) {
String cookie = Local.getcookie ();
LOG.I ("Cookie VALUE", cookie);
if (! Textutils.isempty (cookie)) {
Basicclientcookie C = new Basicclientcookie (Constant.cookie_name,
Cookies);
C.setversion (0);
C.setpath ("/");
C.setdomain (Constant.cookie_domain);
Client.getcookiestore (). Addcookie (c);
}
}```