TrustedWebActivityIntentBuilder


public class TrustedWebActivityIntentBuilder


Constructs instances of TrustedWebActivityIntent that can be used to start Trusted Web Activities (see TrustedWebUtils for more details).

Summary

Constants

static final String
EXTRA_ADDITIONAL_TRUSTED_ORIGINS = "android.support.customtabs.extra.ADDITIONAL_TRUSTED_ORIGINS"

Extra for the Trusted Web Activity launch Intent to specify a list of origins for the browser to treat as trusted, in addition to the origin of the launching URL.

static final String
EXTRA_DISPLAY_MODE = "androidx.browser.trusted.extra.DISPLAY_MODE"

Extra for the TrustedWebActivityDisplayMode, see setDisplayMode.

static final String
EXTRA_FILE_HANDLING_DATA = "androidx.browser.trusted.extra.FILE_HANDLING_DATA"

Extra for the opened files data, see setHandledFiles.

static final String
EXTRA_LAUNCH_HANDLER_CLIENT_MODE = "androidx.browser.trusted.extra.LAUNCH_HANDLER_CLIENT_MODE"

If a TWA is being launched using Launch Handler API, its client mode value is provided, see setLaunchHandlerClientMode.

static final String
EXTRA_ORIGINAL_LAUNCH_URL = "androidx.browser.trusted.extra.ORIGINAL_LAUNCH_URL"

If the TWA is being launched using a Protocol Handler, the original URL (with the custom scheme) is provided here, set using setOriginalLaunchUrl.

static final String
EXTRA_SCREEN_ORIENTATION = "androidx.browser.trusted.extra.SCREEN_ORIENTATION"

Extra for the screenOrientation, see setScreenOrientation.

static final String
EXTRA_SHARE_DATA = "androidx.browser.trusted.extra.SHARE_DATA"

Extra for the share data, see setShareParams.

static final String
EXTRA_SHARE_TARGET = "androidx.browser.trusted.extra.SHARE_TARGET"

Extra for the share target, see setShareParams.

static final String
EXTRA_SPLASH_SCREEN_PARAMS = "androidx.browser.trusted.EXTRA_SPLASH_SCREEN_PARAMS"

Extra for the Trusted Web Activity launch Intent to specify a Bundle of parameters for the browser to use in constructing a splash screen.

Public constructors

Creates a Builder given the required parameters.

Public methods

@NonNull TrustedWebActivityIntent

Builds an instance of TrustedWebActivityIntent.

@NonNull CustomTabsIntent

Builds a CustomTabsIntent based on provided parameters.

@NonNull TrustedWebActivityDisplayMode

Returns TrustedWebActivityDisplayMode set on this Builder.

@NonNull Uri

Returns the Uri to be launched with this Builder.

@NonNull TrustedWebActivityIntentBuilder

Sets a list of additional trusted origins that the user may navigate or be redirected to from the starting uri.

@NonNull TrustedWebActivityIntentBuilder
setColorScheme(int colorScheme)

Sets the color scheme, see setColorScheme.

@NonNull TrustedWebActivityIntentBuilder
setColorSchemeParams(
    int colorScheme,
    @NonNull CustomTabColorSchemeParams params
)

Sets CustomTabColorSchemeParams for the given color scheme.

@NonNull TrustedWebActivityIntentBuilder

Sets the default CustomTabColorSchemeParams.

@NonNull TrustedWebActivityIntentBuilder

Sets a TrustedWebActivityDisplayMode.

@NonNull TrustedWebActivityIntentBuilder

Sets the parameters for delivering launch files to the launch queue.

@NonNull TrustedWebActivityIntentBuilder
setLaunchHandlerClientMode(int launchHandlerClientMode)

Sets the parameter for delivering Launch Handler API client mode via a Trusted Web Activity.

@NonNull TrustedWebActivityIntentBuilder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull TrustedWebActivityIntentBuilder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull TrustedWebActivityIntentBuilder
setOriginalLaunchUrl(@NonNull Uri originalLaunchUrl)

Sets the original launch URL.

@NonNull TrustedWebActivityIntentBuilder
setScreenOrientation(int orientation)

Sets a screenOrientation.

@NonNull TrustedWebActivityIntentBuilder
setShareParams(
    @NonNull ShareTarget shareTarget,
    @NonNull ShareData shareData
)

Sets the parameters for delivering data to a Web Share Target via a Trusted Web Activity.

@NonNull TrustedWebActivityIntentBuilder
setSplashScreenParams(@NonNull Bundle splashScreenParams)

Sets the parameters of a splash screen shown while the web page is loading, such as background color.

@NonNull TrustedWebActivityIntentBuilder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

Constants

EXTRA_ADDITIONAL_TRUSTED_ORIGINS

Added in 1.2.0
public static final String EXTRA_ADDITIONAL_TRUSTED_ORIGINS = "android.support.customtabs.extra.ADDITIONAL_TRUSTED_ORIGINS"

Extra for the Trusted Web Activity launch Intent to specify a list of origins for the browser to treat as trusted, in addition to the origin of the launching URL. It is recommended to use TrustedWebActivityIntentBuilder instead of manually piecing the Intent together.

EXTRA_DISPLAY_MODE

Added in 1.2.0
public static final String EXTRA_DISPLAY_MODE = "androidx.browser.trusted.extra.DISPLAY_MODE"

Extra for the TrustedWebActivityDisplayMode, see setDisplayMode.

EXTRA_FILE_HANDLING_DATA

Added in 1.9.0-alpha03
public static final String EXTRA_FILE_HANDLING_DATA = "androidx.browser.trusted.extra.FILE_HANDLING_DATA"

Extra for the opened files data, see setHandledFiles.

EXTRA_LAUNCH_HANDLER_CLIENT_MODE

Added in 1.9.0-alpha03
public static final String EXTRA_LAUNCH_HANDLER_CLIENT_MODE = "androidx.browser.trusted.extra.LAUNCH_HANDLER_CLIENT_MODE"

If a TWA is being launched using Launch Handler API, its client mode value is provided, see setLaunchHandlerClientMode.

EXTRA_ORIGINAL_LAUNCH_URL

Added in 1.9.0-alpha03
public static final String EXTRA_ORIGINAL_LAUNCH_URL = "androidx.browser.trusted.extra.ORIGINAL_LAUNCH_URL"

If the TWA is being launched using a Protocol Handler, the original URL (with the custom scheme) is provided here, set using setOriginalLaunchUrl.

EXTRA_SCREEN_ORIENTATION

Added in 1.3.0
public static final String EXTRA_SCREEN_ORIENTATION = "androidx.browser.trusted.extra.SCREEN_ORIENTATION"

Extra for the screenOrientation, see setScreenOrientation.

EXTRA_SHARE_DATA

Added in 1.2.0
public static final String EXTRA_SHARE_DATA = "androidx.browser.trusted.extra.SHARE_DATA"

Extra for the share data, see setShareParams.

EXTRA_SHARE_TARGET

Added in 1.2.0
public static final String EXTRA_SHARE_TARGET = "androidx.browser.trusted.extra.SHARE_TARGET"

Extra for the share target, see setShareParams.

EXTRA_SPLASH_SCREEN_PARAMS

Added in 1.2.0
public static final String EXTRA_SPLASH_SCREEN_PARAMS = "androidx.browser.trusted.EXTRA_SPLASH_SCREEN_PARAMS"

Extra for the Trusted Web Activity launch Intent to specify a Bundle of parameters for the browser to use in constructing a splash screen. It is recommended to use TrustedWebActivityIntentBuilder instead of manually piecing the Intent together.

Public constructors

TrustedWebActivityIntentBuilder

Added in 1.2.0
public TrustedWebActivityIntentBuilder(@NonNull Uri uri)

Creates a Builder given the required parameters.

Parameters
@NonNull Uri uri

The web page to launch as Trusted Web Activity.

Public methods

build

Added in 1.2.0
public @NonNull TrustedWebActivityIntent build(@NonNull CustomTabsSession session)

Builds an instance of TrustedWebActivityIntent.

Parameters
@NonNull CustomTabsSession session

The CustomTabsSession to use for launching a Trusted Web Activity.

buildCustomTabsIntent

Added in 1.2.0
public @NonNull CustomTabsIntent buildCustomTabsIntent()

Builds a CustomTabsIntent based on provided parameters. Can be useful for falling back to Custom Tabs when Trusted Web Activity providers are unavailable.

getDisplayMode

Added in 1.2.0
public @NonNull TrustedWebActivityDisplayMode getDisplayMode()

Returns TrustedWebActivityDisplayMode set on this Builder.

getUri

Added in 1.2.0
public @NonNull Uri getUri()

Returns the Uri to be launched with this Builder.

setAdditionalTrustedOrigins

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setAdditionalTrustedOrigins(@NonNull List<String> origins)

Sets a list of additional trusted origins that the user may navigate or be redirected to from the starting uri. For example, if the user starts at https://www.example.com/page1 and is redirected to https://m.example.com/page2, and both origins are associated with the calling application via the Digital Asset Links, then pass "https://www.example.com/page1" as uri and Arrays.asList("https://m.example.com") as additionalTrustedOrigins. Alternatively, use validateRelationship to validate additional origins asynchronously, but that would delay launching the Trusted Web Activity.

setColorScheme

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setColorScheme(int colorScheme)

Sets the color scheme, see setColorScheme. In Trusted Web Activities color scheme may affect such UI elements as info bars and context menus.

Parameters
int colorScheme

Must be one of COLOR_SCHEME_SYSTEM, COLOR_SCHEME_LIGHT, and COLOR_SCHEME_DARK.

setColorSchemeParams

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setColorSchemeParams(
    int colorScheme,
    @NonNull CustomTabColorSchemeParams params
)

Sets CustomTabColorSchemeParams for the given color scheme. This allows, for example, to set two navigation bar colors - for light and dark scheme. Trusted Web Activity will automatically apply the correct color according to current system settings. For more details see setColorSchemeParams.

setDefaultColorSchemeParams

Added in 1.3.0
public @NonNull TrustedWebActivityIntentBuilder setDefaultColorSchemeParams(@NonNull CustomTabColorSchemeParams params)

Sets the default CustomTabColorSchemeParams. This will set a default color scheme that applies when no CustomTabColorSchemeParams specified for current color scheme via setColorSchemeParams.

Parameters
@NonNull CustomTabColorSchemeParams params

An instance of CustomTabColorSchemeParams.

setDisplayMode

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setDisplayMode(@NonNull TrustedWebActivityDisplayMode displayMode)

Sets a TrustedWebActivityDisplayMode. This can be used e.g. to enable immersive mode (see TrustedWebActivityDisplayMode.ImmersiveMode. Not setting it means TrustedWebActivityDisplayMode.DefaultMode will be used.

setFileHandlingData

Added in 1.9.0-alpha03
public @NonNull TrustedWebActivityIntentBuilder setFileHandlingData(@NonNull FileHandlingData fileHandlingData)

Sets the parameters for delivering launch files to the launch queue. A web application can declare "file_handlers" in its web manifest, enabling it to handle file opening requests from users. The opened files are then made available by the browser to the web app through the launch queue interface of the Launch Handler API. This method provides the support for file handling in Trusted Web Activities. FileHandlingData should contain the URI of a file opened by a user and captured by an intent filter declared in the app manifest. The app will pass read/write permissions for the file to the browser.

Parameters
@NonNull FileHandlingData fileHandlingData

A FileHandlingData object containing the data to be sent to browser launch queue.

setLaunchHandlerClientMode

Added in 1.9.0-alpha03
public @NonNull TrustedWebActivityIntentBuilder setLaunchHandlerClientMode(int launchHandlerClientMode)

Sets the parameter for delivering Launch Handler API client mode via a Trusted Web Activity.

Parameters
int launchHandlerClientMode

A string describing the client mode.

setNavigationBarColor

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull TrustedWebActivityIntentBuilder setNavigationBarColor(@ColorInt int color)

Sets the navigation bar color, see setNavigationBarColor.

setNavigationBarDividerColor

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull TrustedWebActivityIntentBuilder setNavigationBarDividerColor(@ColorInt int color)

Sets the navigation bar divider color, see setNavigationBarDividerColor.

setOriginalLaunchUrl

Added in 1.9.0-alpha03
public @NonNull TrustedWebActivityIntentBuilder setOriginalLaunchUrl(@NonNull Uri originalLaunchUrl)

Sets the original launch URL. This is used by Protocol Handlers to let the browser see the URL that was opened before being processed an modified (the original URL will usually have a custom data scheme and no host, as opposed to the full http/https location in the Intent data).

Parameters
@NonNull Uri originalLaunchUrl

The URL that was originally opened, before being processed and modified by a Protocol Handler.

setScreenOrientation

Added in 1.3.0
public @NonNull TrustedWebActivityIntentBuilder setScreenOrientation(int orientation)

Sets a screenOrientation. This can be used e.g. to enable the locking of an orientation lock type ScreenOrientation.

Parameters
int orientation

A ScreenOrientation lock type for a Trusted Web Activity. Not setting it means DEFAULT will be used.

setShareParams

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setShareParams(
    @NonNull ShareTarget shareTarget,
    @NonNull ShareData shareData
)

Sets the parameters for delivering data to a Web Share Target via a Trusted Web Activity.

Parameters
@NonNull ShareTarget shareTarget

A ShareTarget object describing the Web Share Target.

@NonNull ShareData shareData

A ShareData object containing the data to be sent to the Web Share Target.

setSplashScreenParams

Added in 1.2.0
public @NonNull TrustedWebActivityIntentBuilder setSplashScreenParams(@NonNull Bundle splashScreenParams)

Sets the parameters of a splash screen shown while the web page is loading, such as background color. See SplashScreenParamKey for a list of supported parameters. To provide the image for the splash screen, use transferSplashImage, prior to launching the intent. It is recommended to also show the same splash screen in the app as soon as possible, prior to establishing a CustomTabConnection. The Trusted Web Activity provider should ensure seamless transition of the splash screen from the app onto the top of webpage being loaded. The splash screen will be removed on the first paint of the page, or when the page load fails.

setToolbarColor

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull TrustedWebActivityIntentBuilder setToolbarColor(@ColorInt int color)

Sets the color applied to the toolbar and the status bar, see setToolbarColor. When a Trusted Web Activity is on the verified origin, the toolbar is hidden, so the color applies only to the status bar. When it's on an unverified origin, the toolbar is shown, and the color applies to both toolbar and status bar.