# WebViewDatabase

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/webkit/WebViewDatabase#pubctors)\|[Methods](https://developer.android.com/reference/android/webkit/WebViewDatabase#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/webkit/WebViewDatabase#inhmethods)  

# WebViewDatabase

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/webkit/WebViewDatabase "View this page in Kotlin")\|Java

`
public


abstract
class
WebViewDatabase
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|--------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.webkit.WebViewDatabase |

<br />

*** ** * ** ***

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)

<br />

## Summary

|                                                                                                                                                                                            ### Public constructors                                                                                                                                                                                            ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase#WebViewDatabase())`() ` *This constructor is deprecated. This class should not be constructed by applications, use[getInstance(android.content.Context)](https://developer.android.com/reference/android/webkit/WebViewDatabase#getInstance(android.content.Context))instead to fetch the singleton instance.* |

|                                                                                                                                                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                     ||
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract void`                                                                                    | ` `[clearFormData](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearFormData())`() ` Clears any saved data for web forms.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` abstract void`                                                                                    | ` `[clearHttpAuthUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearHttpAuthUsernamePassword())`() ` Clears any saved credentials for HTTP authentication.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` abstract void`                                                                                    | ` `[clearUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearUsernamePassword())`() ` *This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` abstract `[String[]](https://developer.android.com/reference/java/lang/String)                    | ` `[getHttpAuthUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#getHttpAuthUsernamePassword(java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` host, `[String](https://developer.android.com/reference/java/lang/String)` realm) ` Retrieves HTTP authentication credentials for a given host and realm from the[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase)instance.                                                                                                                                                                                                  |
| ` static `[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase) | ` `[getInstance](https://developer.android.com/reference/android/webkit/WebViewDatabase#getInstance(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` abstract boolean`                                                                                 | ` `[hasFormData](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasFormData())`() ` Gets whether there is any saved data for web forms.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` abstract boolean`                                                                                 | ` `[hasHttpAuthUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasHttpAuthUsernamePassword())`() ` Gets whether there are any saved credentials for HTTP authentication.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` abstract boolean`                                                                                 | ` `[hasUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasUsernamePassword())`() ` *This method was deprecated in API level 18. Saving passwords in WebView will not be supported in future versions.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` abstract void`                                                                                    | ` `[setHttpAuthUsernamePassword](https://developer.android.com/reference/android/webkit/WebViewDatabase#setHttpAuthUsernamePassword(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` host, `[String](https://developer.android.com/reference/java/lang/String)` realm, `[String](https://developer.android.com/reference/java/lang/String)` username, `[String](https://developer.android.com/reference/java/lang/String)` password) ` Stores HTTP authentication credentials for a given host and realm to the[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase)instance. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### WebViewDatabase

Added in[API level 22](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public WebViewDatabase ()
```

<br />

**This constructor is deprecated.**   
This class should not be constructed by applications, use[getInstance(android.content.Context)](https://developer.android.com/reference/android/webkit/WebViewDatabase#getInstance(android.content.Context))instead to fetch the singleton instance.

<br />

<br />

## Public methods

### clearFormData

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void clearFormData ()
```

Clears any saved data for web forms.

<br />

**See also:**

- [hasFormData()](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasFormData())  

### clearHttpAuthUsernamePassword

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract 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](https://developer.android.com/reference/android/webkit/WebViewDatabase)during[WebViewClient.onReceivedHttpAuthRequest](https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedHttpAuthRequest(android.webkit.WebView,%20android.webkit.HttpAuthHandler,%20java.lang.String,%20java.lang.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).

<br />

**See also:**

- [getHttpAuthUsernamePassword(String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#getHttpAuthUsernamePassword(java.lang.String,%20java.lang.String))
- [setHttpAuthUsernamePassword(String, String, String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#setHttpAuthUsernamePassword(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String))
- [hasHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasHttpAuthUsernamePassword())  

### clearUsernamePassword

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract void clearUsernamePassword ()
```

<br />

**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.

<br />

**See also:**

- [WebView.savePassword(String, String, String)](https://developer.android.com/reference/android/webkit/WebView#savePassword(java.lang.String,%20java.lang.String,%20java.lang.String))
- [hasUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasUsernamePassword())  

### getHttpAuthUsernamePassword

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Retrieves HTTP authentication credentials for a given host and realm from the[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase)instance.

<br />

|                             Parameters                             ||
|---------|-----------------------------------------------------------|
| `host`  | `String`: the host to which the credentials apply <br />  |
| `realm` | `String`: the realm to which the credentials apply <br /> |

|                                                                                                                Returns                                                                                                                ||
|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String[]](https://developer.android.com/reference/java/lang/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. <br /> |

**See also:**

- [setHttpAuthUsernamePassword(String, String, String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#setHttpAuthUsernamePassword(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String))
- [hasHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasHttpAuthUsernamePassword())
- [clearHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearHttpAuthUsernamePassword())  

### getInstance

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static WebViewDatabase getInstance (Context context)
```

<br />

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

|                                              Returns                                              ||
|-------------------------------------------------------------------------------------------|--------|
| [WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase) | <br /> |

### hasFormData

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract boolean hasFormData ()
```

Gets whether there is any saved data for web forms.

<br />

|                             Returns                             ||
|-----------|------------------------------------------------------|
| `boolean` | whether there is any saved data for web forms <br /> |

**See also:**

- [clearFormData()](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearFormData())  

### hasHttpAuthUsernamePassword

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract boolean hasHttpAuthUsernamePassword ()
```

Gets whether there are any saved credentials for HTTP authentication.

<br />

|                          Returns                          ||
|-----------|------------------------------------------------|
| `boolean` | whether there are any saved credentials <br /> |

**See also:**

- [getHttpAuthUsernamePassword(String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#getHttpAuthUsernamePassword(java.lang.String,%20java.lang.String))
- [setHttpAuthUsernamePassword(String, String, String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#setHttpAuthUsernamePassword(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String))
- [clearHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearHttpAuthUsernamePassword())  

### hasUsernamePassword

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract boolean hasUsernamePassword ()
```

<br />

**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.

<br />

|                                Returns                                 ||
|-----------|-------------------------------------------------------------|
| `boolean` | `true`if there are any saved username/password pairs <br /> |

**See also:**

- [WebView.savePassword(String, String, String)](https://developer.android.com/reference/android/webkit/WebView#savePassword(java.lang.String,%20java.lang.String,%20java.lang.String))
- [clearUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearUsernamePassword())  

### setHttpAuthUsernamePassword

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Stores HTTP authentication credentials for a given host and realm to the[WebViewDatabase](https://developer.android.com/reference/android/webkit/WebViewDatabase)instance.

To use HTTP authentication, the embedder application has to implement[WebViewClient.onReceivedHttpAuthRequest](https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedHttpAuthRequest(android.webkit.WebView,%20android.webkit.HttpAuthHandler,%20java.lang.String,%20java.lang.String)), and call[HttpAuthHandler.proceed](https://developer.android.com/reference/android/webkit/HttpAuthHandler#proceed(java.lang.String,%20java.lang.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](https://developer.android.com/reference/android/webkit/WebViewDatabase).

Notes:
- [WebViewDatabase](https://developer.android.com/reference/android/webkit/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 <br />  |
| `realm`    | `String`: the realm to which the credentials apply <br /> |
| `username` | `String`: the username <br />                             |
| `password` | `String`: the password <br />                             |

**See also:**

- [getHttpAuthUsernamePassword(String, String)](https://developer.android.com/reference/android/webkit/WebViewDatabase#getHttpAuthUsernamePassword(java.lang.String,%20java.lang.String))
- [hasHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#hasHttpAuthUsernamePassword())
- [clearHttpAuthUsernamePassword()](https://developer.android.com/reference/android/webkit/WebViewDatabase#clearHttpAuthUsernamePassword())