androidx.webkit


The androidx.webkit library is a static library you can add to your Android application in order to use android.webkit APIs that are not available for older platform versions.

Requirements

The minimum sdk version to use this library is 14.

How to declare the dependencies to use the library

Please check the release notes for instructions to add the latest release to your build.gradle file.

Public bug tracker

If you find bugs in the androidx.webkit library or want to request new features, please do so here.

Sample apps

Please check out the WebView samples on GitHub for a showcase of a handful of androidx.webkit APIs.

For more APIs, check out the sample app in the AndroidX repo.

Migrating to androidx.webkit

For static methods:

Old code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
   WebView.startSafeBrowsing(appContext, callback);
}

New code:

if (WebViewFeature.isFeatureSupported(WebViewFeature.START_SAFE_BROWSING)) {
   WebViewCompat.startSafeBrowsing(appContext, callback);
}

Or, if you are using a non-static method:

Old code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
   myWebView.postVisualStateCallback(requestId, callback);
}

New code:

if (WebViewFeature.isFeatureSupported(WebViewFeature.VISUAL_STATE_CALLBACK)) {
   WebViewCompat.postVisualStateCallback(myWebView, requestId, callback);
}

Annotations

Profile.ExperimentalUrlPrefetch

Denotes that the UrlPrefetch API surface is experimental.

WebSettingsCompat.ExperimentalBackForwardCache

Denotes that the BackForwardCache API surface is experimental.

WebSettingsCompat.ExperimentalSpeculativeLoading

Denotes that the SpeculativeLoading API surface is experimental.

WebViewCompat.ExperimentalAsyncStartUp

Denotes that the startUpWebView API surface is experimental.

Interfaces

BlockingStartUpLocation

The code location where UI thread blocking WebView startup was triggered.

OutcomeReceiverCompat

Callback interface intended for use when an asynchronous operation may result in a failure.

Profile

A Profile represents one browsing session for WebView.

ProfileStore

Manages any creation, deletion for Profile.

ScriptHandler

This interface represents the return result from addDocumentStartJavaScript.

WebViewAssetLoader.PathHandler

A handler that produces responses for a registered path.

WebViewCompat.VisualStateCallback

Callback interface supplied to postVisualStateCallback for receiving notifications about the visual state.

WebViewCompat.WebMessageListener

This listener receives messages sent on the JavaScript object which was injected by addWebMessageListener.

WebViewCompat.WebViewStartUpCallback

Callback interface for startUpWebView.

WebViewStartUpResult

Result object associated with onSuccess.

Classes

CookieManagerCompat

Compatibility version of android.webkit.CookieManager

DropDataContentProvider

WebView provides partial support for Android Drag and Drop allowing images, text and links to be dragged out of a WebView.

JavaScriptReplyProxy

This class represents the JavaScript object injected by WebViewCompat#addWebMessageListener.

NoVarySearchHeader

The No-Vary-Search data specifies a set of rules that define how a URL's query parameters will affect cache matching.

ProcessGlobalConfig

Process Global Configuration for WebView.

ProxyConfig

Config for setProxyOverride.

ProxyConfig.Builder

ProxyConfig builder.

ProxyConfig.ProxyRule

Class that holds a scheme filter and a proxy URL.

ProxyController

Manages setting and clearing a process-specific override for the Android system-wide proxy settings that govern network requests made by android.webkit.WebView.

SafeBrowsingResponseCompat

Compatibility version of SafeBrowsingResponse.

ServiceWorkerClientCompat

Base class for clients to capture Service Worker related callbacks, see ServiceWorkerControllerCompat for usage example.

ServiceWorkerControllerCompat

Manages Service Workers used by WebView.

ServiceWorkerWebSettingsCompat

Manages settings state for all Service Workers.

SpeculativeLoadingParameters

Parameters for customizing the prefetch.

SpeculativeLoadingParameters.Builder

A builder class to use to construct the SpeculativeLoadingParameters.

TracingConfig

Holds tracing configuration information and predefined settings for TracingController.

TracingConfig.Builder

Builder used to create TracingConfig objects.

TracingController

Manages tracing of WebViews.

URLUtilCompat

Compatibility versions of methods in android.webkit.URLUtil.

UserAgentMetadata

Holds user-agent metadata information and uses to generate user-agent client hints.

UserAgentMetadata.BrandVersion

Class that holds brand name, major version and full version.

UserAgentMetadata.BrandVersion.Builder

Builder used to create BrandVersion objects.

UserAgentMetadata.Builder

Builder used to create UserAgentMetadata objects.

WebMessageCompat

The Java representation of the HTML5 PostMessage event.

WebMessagePortCompat

The Java representation of the HTML5 message ports.

WebMessagePortCompat.WebMessageCallbackCompat

The listener for handling MessagePort events.

WebResourceErrorCompat

Compatibility version of WebResourceError.

WebResourceRequestCompat

Compatibility version of WebResourceRequest.

WebSettingsCompat

Compatibility version of android.webkit.WebSettings

WebViewAssetLoader

Helper class to load local files including application's static assets and resources using http(s):// URLs inside a android.webkit.WebView class.

WebViewAssetLoader.AssetsPathHandler

Handler class to open a file from assets directory in the application APK.

WebViewAssetLoader.Builder

A builder class for constructing WebViewAssetLoader objects.

WebViewAssetLoader.InternalStoragePathHandler

Handler class to open files from application internal storage.

WebViewAssetLoader.ResourcesPathHandler

Handler class to open a file from resources directory in the application APK.

WebViewClientCompat

Compatibility version of android.webkit.WebViewClient.

WebViewCompat

Compatibility version of android.webkit.WebView

WebViewFeature

Utility class for checking which WebView Support Library features are supported on the device.

WebViewMediaIntegrityApiStatusConfig

Configuration to set API enablement status for site origins through override rules.

WebViewMediaIntegrityApiStatusConfig.Builder

Builds a WebViewMediaIntegrityApiStatusConfig having a default API status and a map of origin pattern rules to their respective API status.

WebViewRenderProcess

WebViewRenderProcess provides an opaque handle to a WebView renderer.

WebViewRenderProcessClient

Used to receive callbacks on WebView renderer events.

WebViewStartUpConfig

Configuration object for startUpWebView.

WebViewStartUpConfig.Builder

Exceptions

PrefetchException

Super class for all asynchronous exceptions produced by Profile prefetch operations.

PrefetchNetworkException

Class for network &server related Exceptions produced by Profile prefetch operations.