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 |
static final String |
EXTRA_DISPLAY_OVERRIDE = "androidx.browser.trusted.extra.DISPLAY_OVERRIDE"Extra for the display override list, see |
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 |
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 |
static final String |
EXTRA_SCREEN_ORIENTATION = "androidx.browser.trusted.extra.SCREEN_ORIENTATION"Extra for the screenOrientation, see |
static final String |
EXTRA_SHARE_DATA = "androidx.browser.trusted.extra.SHARE_DATA"Extra for the share data, see |
static final String |
EXTRA_SHARE_TARGET = "androidx.browser.trusted.extra.SHARE_TARGET"Extra for the share target, see |
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 |
Public constructors |
|---|
|
Creates a Builder given the required parameters. |
Constants
EXTRA_ADDITIONAL_TRUSTED_ORIGINS
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
public static final String EXTRA_DISPLAY_MODE = "androidx.browser.trusted.extra.DISPLAY_MODE"
Extra for the TrustedWebActivityDisplayMode, see setDisplayMode.
EXTRA_DISPLAY_OVERRIDE
public static final String EXTRA_DISPLAY_OVERRIDE = "androidx.browser.trusted.extra.DISPLAY_OVERRIDE"
Extra for the display override list, see setDisplayOverrideList
EXTRA_FILE_HANDLING_DATA
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
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
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.
| See also | |
|---|---|
getOriginalLaunchUrl |
EXTRA_SCREEN_ORIENTATION
public static final String EXTRA_SCREEN_ORIENTATION = "androidx.browser.trusted.extra.SCREEN_ORIENTATION"
Extra for the screenOrientation, see setScreenOrientation.
EXTRA_SHARE_DATA
public static final String EXTRA_SHARE_DATA = "androidx.browser.trusted.extra.SHARE_DATA"
Extra for the share data, see setShareParams.
EXTRA_SHARE_TARGET
public static final String EXTRA_SHARE_TARGET = "androidx.browser.trusted.extra.SHARE_TARGET"
Extra for the share target, see setShareParams.
EXTRA_SPLASH_SCREEN_PARAMS
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
Public methods
build
public @NonNull TrustedWebActivityIntent build(@NonNull CustomTabsSession session)
Builds an instance of TrustedWebActivityIntent.
| Parameters | |
|---|---|
@NonNull CustomTabsSession session |
The |
buildCustomTabsIntent
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
public @NonNull TrustedWebActivityDisplayMode getDisplayMode()
Returns TrustedWebActivityDisplayMode set on this Builder.
getUri
public @NonNull Uri getUri()
Returns the Uri to be launched with this Builder.
setAdditionalTrustedOrigins
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
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 |
setColorSchemeParams
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
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 |
setDisplayMode
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.
setDisplayOverrideList
public @NonNull TrustedWebActivityIntentBuilder setDisplayOverrideList(
@Nullable List<TrustedWebActivityDisplayMode> displayOverrideList
)
Sets the display override fallback list for a Trusted Web Activity. Web applications can declare a "display_override" list to specify the preferred order of display modes. This is useful for more advanced display modes that may have limited browser support ({@see https://wicg.github.io/manifest-incubations/#display_override-member}). The browser will use the first display mode in the list that it supports, and fall back to the `display` manifest field if none are supported.
| Parameters | |
|---|---|
@Nullable List<TrustedWebActivityDisplayMode> displayOverrideList |
A list of |
setFileHandlingData
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 LaunchQueue interface of the Launch Handler API. LaunchQueue implementation depends on a browser receiving a TrustedWebActivityIntent. This method provides the support for file handling in Trusted Web Activities. FileHandlingData should contain the URIs list of files opened by a user and captured by an intent filter declared in the app manifest. API doesn't perform URI validation and it entirely dependents on a browser receiving a TrustedWebActivityIntent. The API passes read/write permissions for the files to the browser to allow the web application to read and write a file as it required by LaunchQueue interface specification.
| Parameters | |
|---|---|
@NonNull FileHandlingData fileHandlingData |
A |
setLaunchHandlerClientMode
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. |
public @NonNull TrustedWebActivityIntentBuildersetNavigationBarColor(@ColorInt int color)
Sets the navigation bar color, see setNavigationBarColor.
public @NonNull TrustedWebActivityIntentBuildersetNavigationBarDividerColor(@ColorInt int color)
Sets the navigation bar divider color, see setNavigationBarDividerColor.
setOriginalLaunchUrl
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. |
| See also | |
|---|---|
getOriginalLaunchUrl |
setScreenOrientation
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 |
setShareParams
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 |
@NonNull ShareData shareData |
A |
setSplashScreenParams
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.
public @NonNull TrustedWebActivityIntentBuildersetToolbarColor(@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.