Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

TrustedWebActivityIntentBuilder

public class TrustedWebActivityIntentBuilder
extends Object

java.lang.Object
   ↳ androidx.browser.trusted.TrustedWebActivityIntentBuilder


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

Summary

Constants

String 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.

String EXTRA_SHARE_DATA

Extra for the share data, see setShareParams(ShareTarget, ShareData).

String EXTRA_SHARE_TARGET

Extra for the share target, see setShareParams(ShareTarget, ShareData).

String 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

TrustedWebActivityIntentBuilder(Uri uri)

Creates a Builder given the required parameters.

Public methods

TrustedWebActivityIntent build(CustomTabsSession session)

Builds an instance of {@link TrustedWebActivityIntent].

CustomTabsIntent buildCustomTabsIntent()

Builds a CustomTabsIntent based on provided parameters.

Uri getUrl()

Returns the Uri to be launched with this Builder.

TrustedWebActivityIntentBuilder setAdditionalTrustedOrigins(List<String> origins)

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

TrustedWebActivityIntentBuilder setColorScheme(int colorScheme)

Sets the color scheme, see CustomTabsIntent.Builder.setColorScheme(int).

TrustedWebActivityIntentBuilder setColorSchemeParams(int colorScheme, CustomTabColorSchemeParams params)

Sets CustomTabColorSchemeParams for the given color scheme.

TrustedWebActivityIntentBuilder setNavigationBarColor(int color)

Sets the navigation bar color, see CustomTabsIntent.Builder.setNavigationBarColor(int).

TrustedWebActivityIntentBuilder setShareParams(ShareTarget shareTarget, ShareData shareData)

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

TrustedWebActivityIntentBuilder setSplashScreenParams(Bundle splashScreenParams)

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

TrustedWebActivityIntentBuilder setToolbarColor(int color)

Sets the color applied to the toolbar and the status bar, see CustomTabsIntent.Builder.setToolbarColor(int).

Inherited methods

Constants

EXTRA_ADDITIONAL_TRUSTED_ORIGINS

public static final String 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.

Constant Value: "android.support.customtabs.extra.ADDITIONAL_TRUSTED_ORIGINS"

EXTRA_SHARE_DATA

public static final String EXTRA_SHARE_DATA

Extra for the share data, see setShareParams(ShareTarget, ShareData).

Constant Value: "androidx.browser.trusted.extra.SHARE_DATA"

EXTRA_SHARE_TARGET

public static final String EXTRA_SHARE_TARGET

Extra for the share target, see setShareParams(ShareTarget, ShareData).

Constant Value: "androidx.browser.trusted.extra.SHARE_TARGET"

EXTRA_SPLASH_SCREEN_PARAMS

public static final String 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.

Constant Value: "androidx.browser.trusted.EXTRA_SPLASH_SCREEN_PARAMS"

Public constructors

TrustedWebActivityIntentBuilder

public TrustedWebActivityIntentBuilder (Uri uri)

Creates a Builder given the required parameters.

Parameters
uri Uri: The web page to launch as Trusted Web Activity.

Public methods

build

public TrustedWebActivityIntent build (CustomTabsSession session)

Builds an instance of {@link TrustedWebActivityIntent].

Parameters
session CustomTabsSession: The CustomTabsSession to use for launching a Trusted Web Activity.

Returns
TrustedWebActivityIntent

buildCustomTabsIntent

public 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.

Returns
CustomTabsIntent

getUrl

public Uri getUrl ()

Returns the Uri to be launched with this Builder.

Returns
Uri

setAdditionalTrustedOrigins

public TrustedWebActivityIntentBuilder setAdditionalTrustedOrigins (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 CustomTabsSession.validateRelationship(int, Uri, Bundle) to validate additional origins asynchronously, but that would delay launching the Trusted Web Activity.

Parameters
origins List

Returns
TrustedWebActivityIntentBuilder

setColorScheme

public TrustedWebActivityIntentBuilder setColorScheme (int colorScheme)

Sets the color scheme, see CustomTabsIntent.Builder.setColorScheme(int). In Trusted Web Activities color scheme may effect such UI elements as info bars and context menus.

Parameters
colorScheme int: Must be one of CustomTabsIntent.COLOR_SCHEME_SYSTEM, CustomTabsIntent.COLOR_SCHEME_LIGHT, and CustomTabsIntent.COLOR_SCHEME_DARK.

Returns
TrustedWebActivityIntentBuilder

setColorSchemeParams

public TrustedWebActivityIntentBuilder setColorSchemeParams (int colorScheme, 
                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 CustomTabsIntent.Builder.setColorSchemeParams(int, CustomTabColorSchemeParams).

Parameters
colorScheme int

params CustomTabColorSchemeParams

Returns
TrustedWebActivityIntentBuilder

setNavigationBarColor

public TrustedWebActivityIntentBuilder setNavigationBarColor (int color)

Sets the navigation bar color, see CustomTabsIntent.Builder.setNavigationBarColor(int).

Parameters
color int

Returns
TrustedWebActivityIntentBuilder

setShareParams

public TrustedWebActivityIntentBuilder setShareParams (ShareTarget shareTarget, 
                ShareData shareData)

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

Parameters
shareTarget ShareTarget: A ShareTarget object describing the Web Share Target.

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

Returns
TrustedWebActivityIntentBuilder

setSplashScreenParams

public TrustedWebActivityIntentBuilder setSplashScreenParams (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 TrustedWebUtils.transferSplashImage(Context, File, String, String, CustomTabsSession), 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.

Parameters
splashScreenParams Bundle

Returns
TrustedWebActivityIntentBuilder

setToolbarColor

public TrustedWebActivityIntentBuilder setToolbarColor (int color)

Sets the color applied to the toolbar and the status bar, see CustomTabsIntent.Builder.setToolbarColor(int). 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.

Parameters
color int

Returns
TrustedWebActivityIntentBuilder