public final class

CookieManager

extends Object
java.lang.Object
   ↳ android.webkit.CookieManager

Class Overview

CookieManager manages cookies according to RFC2109 spec.

Summary

Public Methods
synchronized boolean acceptCookie()
Return whether cookie is enabled
String getCookie(String url)
Get cookie(s) for a given url so that it can be set to "cookie:" in http request header.
synchronized static CookieManager getInstance()
Get a singleton CookieManager.
synchronized boolean hasCookies()
Return true if there are stored cookies.
void removeAllCookie()
Remove all cookies
void removeExpiredCookie()
Remove all expired cookies
void removeSessionCookie()
Remove all session cookies, which are cookies without expiration date
synchronized void setAcceptCookie(boolean accept)
Control whether cookie is enabled or disabled
void setCookie(String url, String value)
Set cookie for a given url.
Protected Methods
Object clone()
Creates and returns a copy of this Object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public synchronized boolean acceptCookie ()

Return whether cookie is enabled

Returns
  • TRUE if accept cookie

public String getCookie (String url)

Get cookie(s) for a given url so that it can be set to "cookie:" in http request header.

Parameters
url The url needs cookie
Returns
  • The cookies in the format of NAME=VALUE [; NAME=VALUE]

public static synchronized CookieManager getInstance ()

Get a singleton CookieManager. If this is called before any WebView is created or outside of WebView context, the caller needs to call createInstance(Context) first.

Returns
  • CookieManager =

public synchronized boolean hasCookies ()

Return true if there are stored cookies.

public void removeAllCookie ()

Remove all cookies

public void removeExpiredCookie ()

Remove all expired cookies

public void removeSessionCookie ()

Remove all session cookies, which are cookies without expiration date

public synchronized void setAcceptCookie (boolean accept)

Control whether cookie is enabled or disabled

Parameters
accept TRUE if accept cookie

public void setCookie (String url, String value)

Set cookie for a given url. The old cookie with same host/path/name will be removed. The new cookie will be added if it is not expired or it does not have expiration which implies it is session cookie.

Parameters
url The url which cookie is set for
value The value for set-cookie: in http response header

Protected Methods

protected Object clone ()

Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.