NavigationParameters.Builder


public final class NavigationParameters.Builder


A Builder for NavigationParameters.

Summary

Public constructors

Constructor for NavigationParameters builder which sets parameter defaults.

Public methods

@NonNull NavigationParameters.Builder

Adds an additional HTTP header to the request.

@NonNull NavigationParameters.Builder
addAdditionalHeaders(@NonNull Map<String, String> additionalHeaders)

Adds multiple additional HTTP headers to the request, as if addAdditionalHeader were called multiple times with each key-value pair of the map.

@NonNull NavigationParameters
@RequiresFeature(name = WebViewFeature.WEBVIEW_NAVIGATE_EXPERIMENTAL_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
build()

Use to finish building the NavigationParameters.

@NonNull NavigationParameters.Builder

Sets the referrer of the navigation.

@NonNull NavigationParameters.Builder
setShouldReplaceCurrentEntry(boolean shouldReplaceCurrentEntry)

If true, the navigation will replace the current entry in the WebView's history, meaning that the current entry will not be reachable through WebView#goBack.

Public constructors

Builder

Added in 1.17.0
public Builder()

Constructor for NavigationParameters builder which sets parameter defaults.

Public methods

addAdditionalHeader

Added in 1.17.0
public @NonNull NavigationParameters.Builder addAdditionalHeader(@NonNull String key, @NonNull String value)

Adds an additional HTTP header to the request. Note that if the header is set by default by this WebView, such as those controlling caching, accept types or the User-Agent, it may be overridden by this WebView's default.

Unlike headers passed to loadUrl, additional headers passed here are tied to the navigation, meaning that subsequent user triggered navigations to the same URL will not have those headers applied. If called multiple times for the same key, the latest value will be used.

Header keys must be RFC 2616-compliant.

addAdditionalHeaders

Added in 1.17.0
public @NonNull NavigationParameters.Builder addAdditionalHeaders(@NonNull Map<String, String> additionalHeaders)

Adds multiple additional HTTP headers to the request, as if addAdditionalHeader were called multiple times with each key-value pair of the map. See addAdditionalHeader for more information.

build

Added in 1.17.0
@RequiresFeature(name = WebViewFeature.WEBVIEW_NAVIGATE_EXPERIMENTAL_V1, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public @NonNull NavigationParameters build()

Use to finish building the NavigationParameters.

Returns
@NonNull NavigationParameters

built NavigationParameters object.

Throws
java.lang.UnsupportedOperationException

if the WEBVIEW_NAVIGATE_EXPERIMENTAL_V1 feature is not supported. This should be checked before use with isFeatureSupported.

setReferrer

public @NonNull NavigationParameters.Builder setReferrer(@Nullable String referrer)

Sets the referrer of the navigation.

The referrer is sent to the server in the Referer header and exposed to the page as document.referrer, subject to the default referrer policy, strict-origin-when-cross-origin: only its origin is sent for a cross-origin navigation, and nothing is sent if it's an https URL and the navigation is to an http URL.

Defaults to null, meaning the navigation has no referrer. A non-null referrer must be a valid http or https URL, otherwise navigate throws an IllegalArgumentException.

Use this rather than adding a Referer header with addAdditionalHeader, which is ignored.

This method is a no-op if isFeatureSupported returns false for WEBVIEW_NAVIGATE_REFERRER.

setShouldReplaceCurrentEntry

Added in 1.17.0
public @NonNull NavigationParameters.Builder setShouldReplaceCurrentEntry(boolean shouldReplaceCurrentEntry)

If true, the navigation will replace the current entry in the WebView's history, meaning that the current entry will not be reachable through WebView#goBack. Defaults to false.