Android APIs
Added in API level 9
public interface

CookieStore

java.net.CookieStore

Class Overview

A CookieStore object is a repository for cookies. CookieManager will store cookies of every incoming HTTP response into CookieStore, and retrieve cookies for every outgoing HTTP request.Expired HttpCookies should be removed from this store by themselves.

Summary

Public Methods
abstract void add(URI uri, HttpCookie cookie)
Saves a HTTP cookie to this store.
abstract List<HttpCookie> get(URI uri)
Retrieves cookies that match the specified URI.
abstract List<HttpCookie> getCookies()
Get all cookies in cookie store which are not expired.
abstract List<URI> getURIs()
Get a set of URIs, which is composed of associated URI with all the cookies in the store.
abstract boolean remove(URI uri, HttpCookie cookie)
Remove the specified cookie from the store.
abstract boolean removeAll()
Clear this cookie store.

Public Methods

public abstract void add (URI uri, HttpCookie cookie)

Added in API level 9

Saves a HTTP cookie to this store. This is called for every incoming HTTP response. A cookie may or may not has an associated URI. If not, the cookie's domain and path attribute will show cradleland. If there is an associated URI and no domain and path attribute are speicifed for the cookie, the given URI will indicate where this cookie comes from. If a cookie corresponding to the given URI already exists, then it is replaced with the new one.

Parameters
uri the uri associated with the specified cookie. A null value indicates the cookie is not associated with a URI
cookie the cookie to be stored

public abstract List<HttpCookie> get (URI uri)

Added in API level 9

Retrieves cookies that match the specified URI. Return not expired cookies. For every outgoing HTTP request, this method will be called.

Parameters
uri the uri this cookie associated with. If null, this cookie will not be associated with an URI
Returns
List<HttpCookie> an immutable list of HttpCookies, return empty list if no cookies match the given URI
Throws
NullPointerException if uri is null

public abstract List<HttpCookie> getCookies ()

Added in API level 9

Get all cookies in cookie store which are not expired.

Returns
List<HttpCookie> an empty list if there's no http cookie in store, or an immutable list of cookies

public abstract List<URI> getURIs ()

Added in API level 9

Get a set of URIs, which is composed of associated URI with all the cookies in the store.

Returns
List<URI> zero-length list if no cookie in the store is associated with any URIs, otherwise an immutable list of URIs.

public abstract boolean remove (URI uri, HttpCookie cookie)

Added in API level 9

Remove the specified cookie from the store.

Parameters
uri the uri associated with the specified cookie. If the cookie is not associated with an URI when added, uri should be null; otherwise the uri should be non-null.
cookie the cookie to be removed
Returns
boolean true if the specified cookie is contained in this store and removed successfully

public abstract boolean removeAll ()

Added in API level 9

Clear this cookie store.

Returns
boolean true if any cookies were removed as a result of this call.