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 ()

Since: API Level 1

Return whether cookie is enabled

Returns
  • TRUE if accept cookie

public String getCookie (String url)

Since: API Level 1

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 ()

Since: API Level 1

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 ()

Since: API Level 1

Return true if there are stored cookies.

public void removeAllCookie ()

Since: API Level 1

Remove all cookies

public void removeExpiredCookie ()

Since: API Level 1

Remove all expired cookies

public void removeSessionCookie ()

Since: API Level 1

Remove all session cookies, which are cookies without expiration date

public synchronized void setAcceptCookie (boolean accept)

Since: API Level 1

Control whether cookie is enabled or disabled

Parameters
accept TRUE if accept cookie

public void setCookie (String url, String value)

Since: API Level 1

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 ()

Since: API Level 1

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.