Skip to content

Most visited

Recently visited

navigation

WebViewDatabase

public abstract class WebViewDatabase
extends Object

java.lang.Object
   ↳ android.webkit.WebViewDatabase


This class allows developers to determine whether any WebView used in the application has stored any of the following types of browsing data and to clear any such stored data for all WebViews in the application.

  • Username/password pairs for web forms
  • HTTP authentication username/password pairs
  • Data entered into text fields (e.g. for autocomplete suggestions)

Summary

Public constructors

WebViewDatabase()

Public methods

abstract void clearFormData()

Clears any saved data for web forms.

abstract void clearHttpAuthUsernamePassword()

Clears any saved credentials for HTTP authentication.

abstract void clearUsernamePassword()

This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.

abstract String[] getHttpAuthUsernamePassword(String host, String realm)

Retrieves HTTP authentication credentials for a given host and realm from the WebViewDatabase instance.

static WebViewDatabase getInstance(Context context)
abstract boolean hasFormData()

Gets whether there is any saved data for web forms.

abstract boolean hasHttpAuthUsernamePassword()

Gets whether there are any saved credentials for HTTP authentication.

abstract boolean hasUsernamePassword()

This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.

abstract void setHttpAuthUsernamePassword(String host, String realm, String username, String password)

Stores HTTP authentication credentials for a given host and realm to the WebViewDatabase instance.

Inherited methods

From class java.lang.Object

Public constructors

WebViewDatabase

added in API level 22
WebViewDatabase ()

Public methods

clearFormData

added in API level 1
void clearFormData ()

Clears any saved data for web forms.

See also:

clearHttpAuthUsernamePassword

added in API level 1
void clearHttpAuthUsernamePassword ()

Clears any saved credentials for HTTP authentication. This method only clears the username and password stored in WebViewDatabase instance. The username and password are not read from the WebViewDatabase during onReceivedHttpAuthRequest(WebView, HttpAuthHandler, String, String). It is up to the app to do this or not.

The username and password used for http authentication might be cached in the network stack itself, and are not cleared when this method is called. WebView does not provide a special mechanism to clear HTTP authentication for implementing client logout. The client logout mechanism should be implemented by the Web site designer (such as server sending a HTTP 401 for invalidating credentials).

See also:

clearUsernamePassword

added in API level 1
void clearUsernamePassword ()

This method was deprecated in API level 18.
Saving passwords in WebView will not be supported in future versions.

Clears any saved username/password pairs for web forms. Note that these are unrelated to HTTP authentication credentials.

See also:

getHttpAuthUsernamePassword

added in API level 26
String[] getHttpAuthUsernamePassword (String host, 
                String realm)

Retrieves HTTP authentication credentials for a given host and realm from the WebViewDatabase instance.

Parameters
host String: the host to which the credentials apply

realm String: the realm to which the credentials apply

Returns
String[] the credentials as a String array, if found. The first element is the username and the second element is the password. Null if no credentials are found.

See also:

getInstance

added in API level 1
WebViewDatabase getInstance (Context context)

Parameters
context Context

Returns
WebViewDatabase

hasFormData

added in API level 1
boolean hasFormData ()

Gets whether there is any saved data for web forms.

Returns
boolean whether there is any saved data for web forms

See also:

hasHttpAuthUsernamePassword

added in API level 1
boolean hasHttpAuthUsernamePassword ()

Gets whether there are any saved credentials for HTTP authentication.

Returns
boolean whether there are any saved credentials

See also:

hasUsernamePassword

added in API level 1
boolean hasUsernamePassword ()

This method was deprecated in API level 18.
Saving passwords in WebView will not be supported in future versions.

Gets whether there are any saved username/password pairs for web forms. Note that these are unrelated to HTTP authentication credentials.

Returns
boolean true if there are any saved username/password pairs

See also:

setHttpAuthUsernamePassword

added in API level 26
void setHttpAuthUsernamePassword (String host, 
                String realm, 
                String username, 
                String password)

Stores HTTP authentication credentials for a given host and realm to the WebViewDatabase instance.

To use HTTP authentication, the embedder application has to implement onReceivedHttpAuthRequest(WebView, HttpAuthHandler, String, String), and call proceed(String, String) with the correct username and password.

The embedder app can get the username and password any way it chooses, and does not have to use WebViewDatabase.

Notes:

  • WebViewDatabase is provided only as a convenience to store and retrieve http authentication credentials. WebView does not read from it during HTTP authentication.
  • WebView does not provide a special mechanism to clear HTTP authentication credentials for implementing client logout. The client logout mechanism should be implemented by the Web site designer (such as server sending a HTTP 401 for invalidating credentials).
  • Parameters
    host String: the host to which the credentials apply

    realm String: the realm to which the credentials apply

    username String: the username

    password String: the password

    See also:

    This site uses cookies to store your preferences for site-specific language and display options.

    Get the latest Android developer news and tips that will help you find success on Google Play.

    * Required Fields

    Hooray!

    Browse this site in ?

    You requested a page in , but your language preference for this site is .

    Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

    This class requires API level or higher

    This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

    For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

    Take a one-minute survey?
    Help us improve Android tools and documentation.