WebSettingsCompat
class WebSettingsCompat
Compatibility version of android.webkit.WebSettings
Summary
Nested types |
|---|
@Retention(value = RetentionPolicy.CLASS)Denotes that the SpeculativeLoading API surface is experimental. |
@Retention(value = RetentionPolicy.CLASS)Denotes that the SpeculativeLoading API surface is experimental. |
Constants |
|
|---|---|
const Int |
AttributionRegistrationBehavior that allows apps to register app sources and app triggers from WebView. |
const Int |
AttributionRegistrationBehavior that allows apps to register app sources (sources associated with the app package name) and web triggers (triggers associated with the eTLD+1) from WebView. |
const Int |
AttributionRegistrationBehavior that disables source and trigger registration from WebView. |
const Int |
AttributionRegistrationBehavior that allows apps to register web sources and web triggers from WebView. |
const Int |
This property is deprecated. refer to |
const Int |
This property is deprecated. refer to |
const Int |
This property is deprecated. refer to |
const Int |
FORCE_DARK_AUTO = 1This property is deprecated. refer to |
const Int |
FORCE_DARK_OFF = 0This property is deprecated. refer to |
const Int |
FORCE_DARK_ON = 2This property is deprecated. refer to |
const Int |
Disables all speculative loading tech. |
const Int |
Enabled Prerender for this WebSettings, See Prerender to learn more. |
const Int |
The support level that allows WebAuthn requests for the app in which the WebView is embedded. |
const Int |
The support level that allows apps to make WebAuthn calls for any website. |
const Int |
The support level that disables WebAuthn requests from WebView. |
Public functions |
|
|---|---|
java-static Boolean |
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Returns whether cookie access during request intercept is enabled. |
java-static Int |
@RequiresFeature(name = WebViewFeature.ATTRIBUTION_REGISTRATION_BEHAVIOR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Read the current behavior for attribution registration. |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get the current status of BackForwardCache for this |
java-static BackForwardCacheSettings |
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get the current |
java-static Int |
@RequiresFeature(name = WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets the action mode menu items that are disabled, expressed in an integer field flag. |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether EnterpriseAuthenticationAppLinkPolicy is allowed to have any effect on WebView. |
java-static Int |
@RequiresFeature(name = WebViewFeature.FORCE_DARK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. refer to |
java-static Int |
@RequiresFeature(name = WebViewFeature.FORCE_DARK_STRATEGY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. refer to |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get the current status of |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.OFF_SCREEN_PRERASTER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether this WebView should raster tiles when it is offscreen but attached to a window. |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get the current status of PaymentRequest for the given |
java-static (Mutable)Set<String!> |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. The origin trial to disable the X-Requested-With feature has ended, so this API now just returns an empty set. |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.SAFE_BROWSING_ENABLE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets whether Safe Browsing is enabled. |
java-static Int |
@RequiresFeature(name = WebViewFeature.SPECULATIVE_LOADING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Gets speculative loading status for this |
java-static UserAgentMetadata |
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get the WebView's user-agent metadata which used to generate user-agent client hints. |
java-static Int |
@RequiresFeature(name = WebViewFeature.WEB_AUTHENTICATION, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Returns the support level for the given |
java-static WebViewMediaIntegrityApiStatusConfig |
@RequiresFeature(name = WebViewFeature.WEBVIEW_MEDIA_INTEGRITY_API_STATUS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Returns the |
java-static Boolean |
@RequiresFeature(name = WebViewFeature.ALGORITHMIC_DARKENING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Get if algorithmic darkening is allowed or not for this WebView. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.ALGORITHMIC_DARKENING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Control whether algorithmic darkening is allowed. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.ATTRIBUTION_REGISTRATION_BEHAVIOR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Control how WebView interacts with Attribution Reporting. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Enables BackForwardCache for the given |
java-static Unit |
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets the |
java-static Unit |
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This method controls if the relevant |
java-static Unit |
@RequiresFeature(name = WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Disables the action mode menu items according to |
java-static Unit |
@RequiresFeature(name = WebViewFeature.ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets whether EnterpriseAuthenticationAppLinkPolicy if set by admin is allowed to have any effect on WebView. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.FORCE_DARK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. The "force dark" model previously implemented by WebView was complex and didn't interoperate well with current Web standards for |
java-static Unit |
@RequiresFeature(name = WebViewFeature.FORCE_DARK_STRATEGY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. refer to |
java-static Unit |
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Enables support for |
java-static Unit |
@RequiresFeature(name = WebViewFeature.HYPERLINK_CONTEXT_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets which items appear in the context menu when a user long-presses a hyperlink. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.OFF_SCREEN_PRERASTER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets whether this WebView should raster tiles when it is offscreen but attached to a window. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Enables PaymentRequest for the given |
java-static Unit |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")This function is deprecated. The origin trial to disable the X-Requested-With feature has ended, so this API no longer does anything. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.SAFE_BROWSING_ENABLE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets whether Safe Browsing is enabled. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.SPECULATIVE_LOADING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets whether speculative loading status for this |
java-static Unit |
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets the WebView's user-agent metadata to generate user-agent client hints. |
java-static Unit |
@RequiresFeature(name = WebViewFeature.WEB_AUTHENTICATION, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets the support level for the given |
java-static Unit |
@RequiresFeature(name = WebViewFeature.WEBVIEW_MEDIA_INTEGRITY_API_STATUS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")Sets permissions provided through |
Constants
ATTRIBUTION_BEHAVIOR_APP_SOURCE_AND_APP_TRIGGER
const val ATTRIBUTION_BEHAVIOR_APP_SOURCE_AND_APP_TRIGGER = 3: Int
AttributionRegistrationBehavior that allows apps to register app sources and app triggers from WebView.
ATTRIBUTION_BEHAVIOR_APP_SOURCE_AND_WEB_TRIGGER
const val ATTRIBUTION_BEHAVIOR_APP_SOURCE_AND_WEB_TRIGGER = 1: Int
AttributionRegistrationBehavior that allows apps to register app sources (sources associated with the app package name) and web triggers (triggers associated with the eTLD+1) from WebView.
This is the default behavior.
ATTRIBUTION_BEHAVIOR_DISABLED
const val ATTRIBUTION_BEHAVIOR_DISABLED = 0: Int
AttributionRegistrationBehavior that disables source and trigger registration from WebView.
Note that the initial network call to the Attribution Source or Trigger URIs may still happen depending on the installed version of WebView, but any response is discarded and nothing will be stored on the device.
ATTRIBUTION_BEHAVIOR_WEB_SOURCE_AND_WEB_TRIGGER
const val ATTRIBUTION_BEHAVIOR_WEB_SOURCE_AND_WEB_TRIGGER = 2: Int
AttributionRegistrationBehavior that allows apps to register web sources and web triggers from WebView.
This option should only be used after applying to use web sources.
const val DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING = 2: Int
In this mode WebView content will be darkened by a user agent unless web page supports dark theme. WebView determines whether web pages supports dark theme by the presence of color-scheme metadata containing "dark" value. For example, <meta name="color-scheme" content="dark light">. If the metadata is not presented WebView content will be darkened by a user agent and prefers-color-scheme media query will evaluate to light.
See specification for more information.
| See also | |
|---|---|
setForceDarkStrategy |
const val DARK_STRATEGY_USER_AGENT_DARKENING_ONLY = 0: Int
In this mode WebView content will be darkened by a user agent and it will ignore the web page's dark theme if it exists. To avoid mixing two different darkening strategies, the prefers-color-scheme media query will evaluate to light.
See specification for more information.
| See also | |
|---|---|
setForceDarkStrategy |
const val DARK_STRATEGY_WEB_THEME_DARKENING_ONLY = 1: Int
In this mode WebView content will always be darkened using dark theme provided by web page. If web page does not provide dark theme support WebView content will be rendered with a default theme.
See specification for more information.
| See also | |
|---|---|
setForceDarkStrategy |
const val FORCE_DARK_AUTO = 1: Int
Enable force dark dependent on the state of the WebView parent view. If the WebView parent view is being automatically force darkened (@see android.view.View#setForceDarkAllowed), then WebView content will be rendered so as to emulate a dark theme. WebViews that are not attached to the view hierarchy will not be inverted.
If your app uses a dark theme, WebView will not be inverted. Similarly, if your app's theme inherits from a DayNight theme, WebView will not be inverted. In either of these cases, you should control the mode manually with FORCE_DARK_ON or FORCE_DARK_OFF.
See Force Dark documentation for more information.
| See also | |
|---|---|
setForceDark |
const val FORCE_DARK_OFF = 0: Int
Disable force dark, irrespective of the force dark mode of the WebView parent. In this mode, WebView content will always be rendered as-is, regardless of whether native views are being automatically darkened.
| See also | |
|---|---|
setForceDark |
const val FORCE_DARK_ON = 2: Int
Unconditionally enable force dark. In this mode WebView content will always be rendered so as to emulate a dark theme.
| See also | |
|---|---|
setForceDark |
SPECULATIVE_LOADING_DISABLED
@WebSettingsCompat.ExperimentalSpeculativeLoading
const val SPECULATIVE_LOADING_DISABLED = 0: Int
Disables all speculative loading tech. See this to learn more.
This is the default behavior.
SPECULATIVE_LOADING_PRERENDER_ENABLED
@WebSettingsCompat.ExperimentalSpeculativeLoading
const val SPECULATIVE_LOADING_PRERENDER_ENABLED = 1: Int
Enabled Prerender for this WebSettings, See Prerender to learn more.
WEB_AUTHENTICATION_SUPPORT_FOR_APP
const val WEB_AUTHENTICATION_SUPPORT_FOR_APP = 1: Int
The support level that allows WebAuthn requests for the app in which the WebView is embedded. See Digital Asset Links to learn how to associate an app with a website.
WEB_AUTHENTICATION_SUPPORT_FOR_BROWSER
const val WEB_AUTHENTICATION_SUPPORT_FOR_BROWSER = 2: Int
The support level that allows apps to make WebAuthn calls for any website. See Privileged apps to learn how to make WebAuthn calls for any website.
WEB_AUTHENTICATION_SUPPORT_NONE
const val WEB_AUTHENTICATION_SUPPORT_NONE = 0: Int
The support level that disables WebAuthn requests from WebView.
This is the default behavior.
Public functions
areCookiesIncludedInShouldInterceptRequest
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun areCookiesIncludedInShouldInterceptRequest(settings: WebSettings): Boolean
Returns whether cookie access during request intercept is enabled.
This method should only be called if isFeatureSupported returns true for COOKIE_INTERCEPT.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
getAttributionRegistrationBehavior
@RequiresFeature(name = WebViewFeature.ATTRIBUTION_REGISTRATION_BEHAVIOR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getAttributionRegistrationBehavior(settings: WebSettings): Int
Read the current behavior for attribution registration.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
getBackForwardCacheEnabled
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getBackForwardCacheEnabled(settings: WebSettings): Boolean
Get the current status of BackForwardCache for this WebSettings.
This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
Boolean |
Whether BackForwardCache is enabled or not. |
getBackForwardCacheSettings
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
java-static fun getBackForwardCacheSettings(settings: WebSettings): BackForwardCacheSettings
Get the current BackForwardCacheSettings for this WebSettings.
This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
BackForwardCacheSettings |
The current settings for the BackForwardCache. If the BackForwardCache feature is disabled, a default instance is returned instead. |
getDisabledActionModeMenuItems
@RequiresFeature(name = WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getDisabledActionModeMenuItems(settings: WebSettings): Int
Gets the action mode menu items that are disabled, expressed in an integer field flag. The default value is MENU_ITEM_NONE
This method should only be called if isFeatureSupported returns true for DISABLED_ACTION_MODE_MENU_ITEMS.
| Returns | |
|---|---|
Int |
all the disabled menu item flags combined with bitwise OR. |
getEnterpriseAuthenticationAppLinkPolicyEnabled
@RequiresFeature(name = WebViewFeature.ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getEnterpriseAuthenticationAppLinkPolicyEnabled(settings: WebSettings): Boolean
Gets whether EnterpriseAuthenticationAppLinkPolicy is allowed to have any effect on WebView.
See this for more information on EnterpriseAuthenticationAppLinkPolicy.
This method should only be called if isFeatureSupported returns true for ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY.
| Returns | |
|---|---|
Boolean |
|
@RequiresFeature(name = WebViewFeature.FORCE_DARK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fungetForceDark(settings: WebSettings): Int
Get the force dark mode for this WebView.
The default force dark mode is FORCE_DARK_AUTO.
This method should only be called if isFeatureSupported returns true for FORCE_DARK.
| Returns | |
|---|---|
Int |
the currently set force dark mode. |
| See also | |
|---|---|
setForceDark |
@RequiresFeature(name = WebViewFeature.FORCE_DARK_STRATEGY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fungetForceDarkStrategy(settings: WebSettings): Int
Get how content is darkened for this WebView.
The default force dark strategy is DARK_STRATEGY_PREFER_WEB_THEME_OVER_USER_AGENT_DARKENING
This method should only be called if isFeatureSupported returns true for FORCE_DARK_STRATEGY.
| Returns | |
|---|---|
Int |
the currently set force dark strategy. |
| See also | |
|---|---|
setForceDarkStrategy |
getHasEnrolledInstrumentEnabled
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getHasEnrolledInstrumentEnabled(settings: WebSettings): Boolean
Get the current status of hasEnrolledInstrument() method in PaymentRequest for the given WebSettings.
This method should only be called if isFeatureSupported returns true for PAYMENT_REQUEST.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
Boolean |
Whether |
getOffscreenPreRaster
@RequiresFeature(name = WebViewFeature.OFF_SCREEN_PRERASTER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getOffscreenPreRaster(settings: WebSettings): Boolean
Gets whether this WebView should raster tiles when it is offscreen but attached to a window.
This method should only be called if isFeatureSupported returns true for OFF_SCREEN_PRERASTER.
| Returns | |
|---|---|
Boolean |
|
getPaymentRequestEnabled
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getPaymentRequestEnabled(settings: WebSettings): Boolean
Get the current status of PaymentRequest for the given WebSettings.
This method should only be called if isFeatureSupported returns true for PAYMENT_REQUEST.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
Boolean |
Whether PaymentRequest is enabled. |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fungetRequestedWithHeaderOriginAllowList(settings: WebSettings): (Mutable)Set<String!>
Get the currently configured allow-list of origins, which is guaranteed to receive the X-Requested-With HTTP header on requests from the WebView owning the passed WebSettings.
Any origin not on this allow-list may not receive the header, depending on the current installed WebView provider.
The format of the strings in the allow-list follows the origin rules of addWebMessageListener.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
getSafeBrowsingEnabled
@RequiresFeature(name = WebViewFeature.SAFE_BROWSING_ENABLE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getSafeBrowsingEnabled(settings: WebSettings): Boolean
Gets whether Safe Browsing is enabled. See setSafeBrowsingEnabled.
This method should only be called if isFeatureSupported returns true for SAFE_BROWSING_ENABLE.
| Returns | |
|---|---|
Boolean |
|
getSpeculativeLoadingStatus
@RequiresFeature(name = WebViewFeature.SPECULATIVE_LOADING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalSpeculativeLoading
java-static fun getSpeculativeLoadingStatus(settings: WebSettings): Int
Gets speculative loading status for this WebSettings. This API is experimental, it may change in the future without notice. Please use accordingly.
This method should only be called if isFeatureSupported returns true for SPECULATIVE_LOADING.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
Int |
The current status for the speculative loading. It will to be one of |
getUserAgentMetadata
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getUserAgentMetadata(settings: WebSettings): UserAgentMetadata
Get the WebView's user-agent metadata which used to generate user-agent client hints.
See this for more information about User-Agent Client Hints.
This method should only be called if isFeatureSupported returns true for USER_AGENT_METADATA.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
getWebAuthenticationSupport
@RequiresFeature(name = WebViewFeature.WEB_AUTHENTICATION, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
java-static fun getWebAuthenticationSupport(settings: WebSettings): Int
Returns the support level for the given WebSettings
This method should only be called if isFeatureSupported returns true for WEB_AUTHENTICATION.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
| Returns | |
|---|---|
Int |
the current support level. |
getWebViewMediaIntegrityApiStatus
@RequiresFeature(name = WebViewFeature.WEBVIEW_MEDIA_INTEGRITY_API_STATUS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun getWebViewMediaIntegrityApiStatus(settings: WebSettings): WebViewMediaIntegrityApiStatusConfig
Returns the WebViewMediaIntegrityApiStatusConfig currently in use.
isAlgorithmicDarkeningAllowed
@RequiresFeature(name = WebViewFeature.ALGORITHMIC_DARKENING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun isAlgorithmicDarkeningAllowed(settings: WebSettings): Boolean
Get if algorithmic darkening is allowed or not for this WebView. The default is false.
| Returns | |
|---|---|
Boolean |
if the algorithmic darkening is allowed or not. |
| See also | |
|---|---|
setAlgorithmicDarkeningAllowed |
setAlgorithmicDarkeningAllowed
@RequiresFeature(name = WebViewFeature.ALGORITHMIC_DARKENING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setAlgorithmicDarkeningAllowed(settings: WebSettings, allow: Boolean): Unit
Control whether algorithmic darkening is allowed.
Note: This API and the behaviour described only apply to apps with targetSdkVersion ≥ TIRAMISU.
WebView always sets the media query prefers-color-scheme according to the app's theme attribute isLightTheme, i.e. prefers-color-scheme is light if isLightTheme is true or not specified, otherwise it is dark. This means that the web content's light or dark style will be applied automatically to match the app's theme if the content supports it.
Algorithmic darkening is disallowed by default.
If the app's theme is dark and it allows algorithmic darkening, WebView will attempt to darken web content using an algorithm, if the content doesn't define its own dark styles and doesn't explicitly disable darkening.
If Android is applying Force Dark to WebView then WebView will ignore the value of this setting and behave as if it were set to true.
The deprecated setForceDark and related API are no-ops in apps with targetSdkVersion ≥ TIRAMISU, but they still apply to apps with targetSdkVersion<TIRAMISU.
The below table summarizes how APIs work with different apps.
| App | Web content which uses prefers-color-scheme | Web content which does not use prefers-color-scheme |
|---|---|---|
App with isLightTheme True or not set |
Renders with the light theme defined by the content author. | Renders with the default styling defined by the content author. |
| App with Android forceDark in effect | Renders with the dark theme defined by the content author. | Renders with the styling modified to dark colors by an algorithm if allowed by the content author. |
App with isLightTheme False, targetSdkVersion<TIRAMISU, and has FORCE_DARK_AUTO |
Renders with the dark theme defined by the content author. | Renders with the default styling defined by the content author. |
App with isLightTheme False, targetSdkVersion ≥ TIRAMISU, and setAlgorithmicDarkening(false) |
Renders with the dark theme defined by the content author. | Renders with the default styling defined by the content author. |
App with isLightTheme False, targetSdkVersion ≥ TIRAMISU, and setAlgorithmicDarkening(true) |
Renders with the dark theme defined by the content author. | Renders with the styling modified to dark colors by an algorithm if allowed by the content author. |
To check if WebViewFeature.ALGORITHMIC_DARKENING is supported, isFeatureSupported should be called after WebView is created.
| Parameters | |
|---|---|
settings: WebSettings |
The WebSettings object to update. |
allow: Boolean |
allow algorithmic darkening or not. |
setAttributionRegistrationBehavior
@RequiresFeature(name = WebViewFeature.ATTRIBUTION_REGISTRATION_BEHAVIOR, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setAttributionRegistrationBehavior(settings: WebSettings, behavior: Int): Unit
Control how WebView interacts with Attribution Reporting.
WebView supports Attribution Reporting across apps and web pages by enabling the web content to register sources and triggers.
By default, attribution sources will be registered as attributed to the app, while triggers are attributed to the loaded web content (ATTRIBUTION_BEHAVIOR_APP_SOURCE_AND_WEB_TRIGGER). Apps should only need to change this default if they have a specific semantic for how they use WebView. In particular, in-app browsers should follow the steps to apply to the allowlist for registering web sources and then set the ATTRIBUTION_BEHAVIOR_WEB_SOURCE_AND_WEB_TRIGGER behavior.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
behavior: Int |
New behavior to use. |
setBackForwardCacheEnabled
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setBackForwardCacheEnabled(
settings: WebSettings,
backForwardCacheEnabled: Boolean
): Unit
Enables BackForwardCache for the given WebSettings.
This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
backForwardCacheEnabled: Boolean |
whether BackForwardCache should be enabled for this |
setBackForwardCacheSettings
@RequiresFeature(name = WebViewFeature.BACK_FORWARD_CACHE_SETTINGS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalBackForwardCacheSettings
java-static fun setBackForwardCacheSettings(
settings: WebSettings,
backForwardCacheSettings: BackForwardCacheSettings
): Unit
Sets the BackForwardCacheSettings for this WebSettings.
This method should only be called if isFeatureSupported returns true for BACK_FORWARD_CACHE_SETTINGS.
Calling this API will enable the BackForwardCache feature, which is equivalent to calling setBackForwardCacheEnabled with true.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
backForwardCacheSettings: BackForwardCacheSettings |
The new settings for the BackForwardCache. |
setCookiesIncludedInShouldInterceptRequest
@RequiresFeature(name = WebViewFeature.COOKIE_INTERCEPT, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setCookiesIncludedInShouldInterceptRequest(
settings: WebSettings,
enabled: Boolean
): Unit
This method controls if the relevant Cookie header will be added to the WebResourceRequest object passed to shouldInterceptRequest. It also enables the use of setCookies, which will otherwise be ignored.
Prefer using this method over calling CookieManager as part of intercepting requests if it is necessary to access cookies, as this approach will provide the correct set of cookies for the request.
This method should only be called if isFeatureSupported returns true for COOKIE_INTERCEPT.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
enabled: Boolean |
Whether cookie access during request intercept should be enabled. |
setDisabledActionModeMenuItems
@RequiresFeature(name = WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setDisabledActionModeMenuItems(settings: WebSettings, menuItems: Int): Unit
Disables the action mode menu items according to menuItems flag.
This method should only be called if isFeatureSupported returns true for DISABLED_ACTION_MODE_MENU_ITEMS.
| Parameters | |
|---|---|
settings: WebSettings |
The WebSettings object to update. |
menuItems: Int |
an integer field flag for the menu items to be disabled. |
setEnterpriseAuthenticationAppLinkPolicyEnabled
@RequiresFeature(name = WebViewFeature.ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setEnterpriseAuthenticationAppLinkPolicyEnabled(
settings: WebSettings,
enabled: Boolean
): Unit
Sets whether EnterpriseAuthenticationAppLinkPolicy if set by admin is allowed to have any effect on WebView.
EnterpriseAuthenticationAppLinkPolicy in WebView allows admins to specify authentication urls. When WebView is redirected to authentication url, and an app on the device has registered as the default handler for the url, that app is launched.
EnterpriseAuthenticationAppLinkPolicy is enabled by default.
See this for more information on EnterpriseAuthenticationAppLinkPolicy.
This method should only be called if isFeatureSupported returns true for ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY.
| Parameters | |
|---|---|
settings: WebSettings |
The WebSettings object to update. |
enabled: Boolean |
Whether EnterpriseAuthenticationAppLinkPolicy should be enabled. |
@RequiresFeature(name = WebViewFeature.FORCE_DARK, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static funsetForceDark(settings: WebSettings, forceDarkMode: Int): Unit
Set the force dark mode for this WebView.
This method should only be called if isFeatureSupported returns true for FORCE_DARK.
If equals to FORCE_DARK_ON then setForceDarkStrategy is used to specify darkening strategy.
| Parameters | |
|---|---|
forceDarkMode: Int |
the force dark mode to set. |
| See also | |
|---|---|
getForceDark |
@RequiresFeature(name = WebViewFeature.FORCE_DARK_STRATEGY, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static funsetForceDarkStrategy(settings: WebSettings, forceDarkBehavior: Int): Unit
Set how WebView content should be darkened.
This method should only be called if isFeatureSupported returns true for FORCE_DARK_STRATEGY.
The specified strategy is only used if force dark mode is on. See setForceDark.
| Parameters | |
|---|---|
forceDarkBehavior: Int |
the force dark strategy to set. |
| See also | |
|---|---|
getForceDarkStrategy |
setHasEnrolledInstrumentEnabled
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setHasEnrolledInstrumentEnabled(settings: WebSettings, enabled: Boolean): Unit
Enables support for hasEnrolledInstrument() method in PaymentRequest for the given WebSettings. This only has any effect if WebSettingsCompat.setPaymentRequestEnabled(settings, true) has been called.
When this setting is disabled, the PaymentRequest.hasEnrolledInstrument() method always returns false.
This method should only be called if isFeatureSupported returns true for PAYMENT_REQUEST.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
enabled: Boolean |
Whether |
setHyperlinkContextMenuItems
@RequiresFeature(name = WebViewFeature.HYPERLINK_CONTEXT_MENU_ITEMS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setHyperlinkContextMenuItems(
settings: WebSettings,
hyperlinkMenuItems: Int
): Unit
Sets which items appear in the context menu when a user long-presses a hyperlink. The default value is HyperlinkContextMenuItems.DISABLED which means no menu is shown.
The items are specified using bitwise flags. You can combine multiple items using the bitwise OR operator (`|`). For example:
// Show only "Copy link address" and "Open link". webSettings.setHyperlinkContextMenuItems( WebSettingsCompat.HyperlinkContextMenuItems.COPY_LINK_ADDRESS | WebSettingsCompat.HyperlinkContextMenuItems.OPEN_LINK);
| Parameters | |
|---|---|
settings: WebSettings |
The |
hyperlinkMenuItems: Int |
A bitwise combination of the following flags: |
setOffscreenPreRaster
@RequiresFeature(name = WebViewFeature.OFF_SCREEN_PRERASTER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setOffscreenPreRaster(settings: WebSettings, enabled: Boolean): Unit
Sets whether this WebView should raster tiles when it is offscreen but attached to a window. Turning this on can avoid rendering artifacts when animating an offscreen WebView on-screen. Offscreen WebViews in this mode use more memory. The default value is false. Please follow these guidelines to limit memory usage:
- WebView size should be not be larger than the device screen size.
- Limit use of this mode to a small number of WebViews. Use it for visible WebViews and WebViews about to be animated to visible.
This method should only be called if isFeatureSupported returns true for OFF_SCREEN_PRERASTER.
setPaymentRequestEnabled
@RequiresFeature(name = WebViewFeature.PAYMENT_REQUEST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setPaymentRequestEnabled(settings: WebSettings, enabled: Boolean): Unit
Enables PaymentRequest for the given WebSettings.
This feature requires adding the following snippet to the AndroidManifest.xml:
<queries> <intent> <action android:name="org.chromium.intent.action.PAY"/> </intent> <intent> <action android:name="org.chromium.intent.action.IS_READY_TO_PAY"/> </intent> <intent> <action android:name="org.chromium.intent.action.UPDATE_PAYMENT_DETAILS"/> </intent> </queries>
This is needed to allow WebView to query the device for the user's payment applications that are implemented according to the Android payment app developers guide.
- The
org.chromium.intent.action.PAYintent is necessary to let users make payments. - The
org.chromium.intent.action.IS_READY_TO_PAYintent is necessary to let the merchant website know if the user is ready to pay. - The
org.chromium.intent.action.UPDATE_PAYMENT_DETAILSintent is necessary for payment apps to support updating the price dynamically in response to the user selecting a different shipping address or option.
This method should only be called if isFeatureSupported returns true for PAYMENT_REQUEST.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
enabled: Boolean |
Whether PaymentRequestshould be enabled for this |
@RequiresFeature(name = WebViewFeature.REQUESTED_WITH_HEADER_ALLOW_LIST, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static funsetRequestedWithHeaderOriginAllowList(
settings: WebSettings,
allowList: (Mutable)Set<String!>
): Unit
Set an allow-list of origins to receive the X-Requested-With HTTP header from the WebView owning the passed WebSettings.
Historically, this header was sent on all requests from WebView, containing the app package name of the embedding app. Depending on the version of installed WebView, this may no longer be the case, as the header was deprecated in late 2022, and its use discontinued.
Apps can use this method to restore the legacy behavior for servers that still rely on the deprecated header, but it should not be used to identify the WebView to first-party servers under the control of the app developer.
The format of the strings in the allow-list follows the origin rules of addWebMessageListener.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
allowList: (Mutable)Set<String!> |
Set of origins to allow-list. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the allow-list contains a malformed origin. |
setSafeBrowsingEnabled
@RequiresFeature(name = WebViewFeature.SAFE_BROWSING_ENABLE, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setSafeBrowsingEnabled(settings: WebSettings, enabled: Boolean): Unit
Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links.
Safe Browsing can be disabled for all WebViews using a manifest tag (read general Safe Browsing info). The manifest tag has a lower precedence than this API.
Safe Browsing is enabled by default for devices which support it.
This method should only be called if isFeatureSupported returns true for SAFE_BROWSING_ENABLE.
| Parameters | |
|---|---|
settings: WebSettings |
The WebSettings object to update. |
enabled: Boolean |
Whether Safe Browsing is enabled. |
setSpeculativeLoadingStatus
@RequiresFeature(name = WebViewFeature.SPECULATIVE_LOADING, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@WebSettingsCompat.ExperimentalSpeculativeLoading
java-static fun setSpeculativeLoadingStatus(
settings: WebSettings,
speculativeLoadingStatus: Int
): Unit
Sets whether speculative loading status for this WebSettings. This API is experimental, it may change in the future without notice. Please use accordingly.
This method should only be called if isFeatureSupported returns true for SPECULATIVE_LOADING.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
speculativeLoadingStatus: Int |
The new status for the speculative loading. It will to be one of |
setUserAgentMetadata
@RequiresFeature(name = WebViewFeature.USER_AGENT_METADATA, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setUserAgentMetadata(settings: WebSettings, metadata: UserAgentMetadata): Unit
Sets the WebView's user-agent metadata to generate user-agent client hints.
UserAgentMetadata in WebView is used to populate user-agent client hints, they can provide the client’s branding and version information, the underlying operating system’s branding and major version, as well as details about the underlying device.
The user-agent string can be set with setUserAgentString, here are the details on how this API interacts it to generate user-agent client hints.
If the UserAgentMetadata is null and the overridden user-agent contains the system default user-agent, the system default value will be used.
If the UserAgentMetadata is null but the overridden user-agent doesn't contain the system default user-agent, only the low-entry user-agent client hints will be generated.
See this for more information about User-Agent Client Hints.
This method should only be called if isFeatureSupported returns true for USER_AGENT_METADATA.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
metadata: UserAgentMetadata |
the WebView's user-agent metadata. |
setWebAuthenticationSupport
@RequiresFeature(name = WebViewFeature.WEB_AUTHENTICATION, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
@UiThread
java-static fun setWebAuthenticationSupport(settings: WebSettings, support: Int): Unit
Sets the support level for the given WebSettings.
This method should only be called if isFeatureSupported returns true for WEB_AUTHENTICATION.
| Parameters | |
|---|---|
settings: WebSettings |
Settings retrieved from |
support: Int |
The new support level which this WebView will use. |
setWebViewMediaIntegrityApiStatus
@RequiresFeature(name = WebViewFeature.WEBVIEW_MEDIA_INTEGRITY_API_STATUS, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
java-static fun setWebViewMediaIntegrityApiStatus(
settings: WebSettings,
permissionConfig: WebViewMediaIntegrityApiStatusConfig
): Unit
Sets permissions provided through WebViewMediaIntegrityApiStatusConfig for using the WebView Integrity API.