Constructor and Description |
---|
CookieManager() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
acceptCookie()
Gets whether the application's
WebView instances send and accept
cookies. |
abstract boolean |
acceptThirdPartyCookies(WebView webview)
Gets whether the
WebView should allow third party cookies to be set. |
static boolean |
allowFileSchemeCookies()
Gets whether the application's
WebView instances send and accept
cookies for file scheme URLs. |
protected abstract boolean |
allowFileSchemeCookiesImpl()
Implements
allowFileSchemeCookies() . |
protected Object |
clone()
Creates and returns a copy of this object.
|
abstract void |
flush()
Ensures all cookies currently accessible through the getCookie API are
written to persistent storage.
|
abstract String |
getCookie(String url)
Gets the cookies for the given URL.
|
abstract String |
getCookie(String url,
boolean privateBrowsing)
See
getCookie(String) . |
String |
getCookie(WebAddress uri)
Gets cookie(s) for a given uri so that it can be set to "cookie:" in http
request header.
|
static CookieManager |
getInstance()
Gets the singleton CookieManager instance.
|
abstract boolean |
hasCookies()
Gets whether there are stored cookies.
|
abstract boolean |
hasCookies(boolean privateBrowsing)
See
hasCookies() . |
abstract void |
removeAllCookie()
Deprecated.
Use
removeAllCookies(ValueCallback) instead. |
abstract void |
removeAllCookies(ValueCallback<Boolean> callback)
Removes all cookies.
|
abstract void |
removeExpiredCookie()
Deprecated.
The WebView handles removing expired cookies automatically.
|
abstract void |
removeSessionCookie()
Deprecated.
use
removeSessionCookies(ValueCallback) instead. |
abstract void |
removeSessionCookies(ValueCallback<Boolean> callback)
Removes all session cookies, which are cookies without an expiration
date.
|
abstract void |
setAcceptCookie(boolean accept)
Sets whether the application's
WebView instances should send and
accept cookies. |
static void |
setAcceptFileSchemeCookies(boolean accept)
Sets whether the application's
WebView instances should send and
accept cookies for file scheme URLs. |
protected abstract void |
setAcceptFileSchemeCookiesImpl(boolean accept)
Implements
setAcceptFileSchemeCookies(boolean) . |
abstract void |
setAcceptThirdPartyCookies(WebView webview,
boolean accept)
Sets whether the
WebView should allow third party cookies to be set. |
abstract void |
setCookie(String url,
String value)
Sets a cookie for the given URL.
|
abstract void |
setCookie(String url,
String value,
ValueCallback<Boolean> callback)
Sets a cookie for the given URL.
|
protected Object clone() throws CloneNotSupportedException
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
clone
in class Object
CloneNotSupportedException
- if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.Cloneable
public static CookieManager getInstance()
public abstract void setAcceptCookie(boolean accept)
WebView
instances should send and
accept cookies.
By default this is set to true and the WebView accepts cookies.
When this is true
setAcceptThirdPartyCookies
and
setAcceptFileSchemeCookies
can be used to control the policy for those specific types of cookie.
accept
- whether WebView
instances should send and accept
cookiespublic abstract boolean acceptCookie()
WebView
instances send and accept
cookies.WebView
instances send and accept cookiespublic abstract void setAcceptThirdPartyCookies(WebView webview, boolean accept)
WebView
should allow third party cookies to be set.
Allowing third party cookies is a per WebView policy and can be set
differently on different WebView instances.
Apps that target Build.VERSION_CODES.KITKAT
or below
default to allowing third party cookies. Apps targeting
Build.VERSION_CODES.LOLLIPOP
or later default to disallowing
third party cookies.
public abstract boolean acceptThirdPartyCookies(WebView webview)
WebView
should allow third party cookies to be set.public abstract void setCookie(String url, String value)
url
- the URL for which the cookie is to be setvalue
- the cookie as a string, using the format of the 'Set-Cookie'
HTTP response headerpublic abstract void setCookie(String url, String value, ValueCallback<Boolean> callback)
This method is asynchronous.
If a ValueCallback
is provided,
onReceiveValue()
will be called on the current
thread's Looper
once the operation is complete.
The value provided to the callback indicates whether the cookie was set successfully.
You can pass null
as the callback if you don't need to know when the operation
completes or whether it succeeded, and in this case it is safe to call the method from a
thread without a Looper.
url
- the URL for which the cookie is to be setvalue
- the cookie as a string, using the format of the 'Set-Cookie'
HTTP response headercallback
- a callback to be executed when the cookie has been setpublic abstract String getCookie(String url)
url
- the URL for which the cookies are requestedpublic abstract String getCookie(String url, boolean privateBrowsing)
getCookie(String)
.url
- the URL for which the cookies are requestedprivateBrowsing
- whether to use the private browsing cookie jarpublic String getCookie(WebAddress uri)
uri
- the WebAddress for which the cookies are requestedpublic abstract void removeSessionCookie()
removeSessionCookies(ValueCallback)
instead.public abstract void removeSessionCookies(ValueCallback<Boolean> callback)
This method is asynchronous.
If a ValueCallback
is provided,
onReceiveValue()
will be called on the current
thread's Looper
once the operation is complete.
The value provided to the callback indicates whether any cookies were removed.
You can pass null
as the callback if you don't need to know when the operation
completes or whether any cookie were removed, and in this case it is safe to call the
method from a thread without a Looper.
callback
- a callback which is executed when the session cookies have been removed@Deprecated public abstract void removeAllCookie()
removeAllCookies(ValueCallback)
instead.public abstract void removeAllCookies(ValueCallback<Boolean> callback)
This method is asynchronous.
If a ValueCallback
is provided,
onReceiveValue()
will be called on the current
thread's Looper
once the operation is complete.
The value provided to the callback indicates whether any cookies were removed.
You can pass null
as the callback if you don't need to know when the operation
completes or whether any cookies were removed, and in this case it is safe to call the
method from a thread without a Looper.
callback
- a callback which is executed when the cookies have been removedpublic abstract boolean hasCookies()
public abstract boolean hasCookies(boolean privateBrowsing)
hasCookies()
.privateBrowsing
- whether to use the private browsing cookie jar@Deprecated public abstract void removeExpiredCookie()
public abstract void flush()
public static boolean allowFileSchemeCookies()
WebView
instances send and accept
cookies for file scheme URLs.WebView
instances send and accept cookies for
file scheme URLsprotected abstract boolean allowFileSchemeCookiesImpl()
allowFileSchemeCookies()
.public static void setAcceptFileSchemeCookies(boolean accept)
WebView
instances should send and
accept cookies for file scheme URLs.
Use of cookies with file scheme URLs is potentially insecure and turned
off by default.
Do not use this feature unless you can be sure that no unintentional
sharing of cookie data can take place.
Note that calls to this method will have no effect if made after a
WebView
or CookieManager instance has been created.
protected abstract void setAcceptFileSchemeCookiesImpl(boolean accept)
setAcceptFileSchemeCookies(boolean)
.