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

TrustedWebActivityIntentBuilder

open class TrustedWebActivityIntentBuilder
kotlin.Any
   ↳ androidx.browser.trusted.TrustedWebActivityIntentBuilder

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

Summary

Constants

static String

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 String

Extra for the share data, see setShareParams.

static String

Extra for the share target, see setShareParams.

static String

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

<init>(@NonNull uri: Uri)

Creates a Builder given the required parameters.

Public methods

open TrustedWebActivityIntent
build(@NonNull session: CustomTabsSession)

Builds an instance of session

open CustomTabsIntent

Builds a CustomTabsIntent based on provided parameters.

open Uri

Returns the Uri to be launched with this Builder.

open TrustedWebActivityIntentBuilder

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

open TrustedWebActivityIntentBuilder
setColorScheme(colorScheme: Int)

Sets the color scheme, see CustomTabsIntent.Builder#setColorScheme.

open TrustedWebActivityIntentBuilder
setColorSchemeParams(colorScheme: Int, @NonNull params: CustomTabColorSchemeParams)

Sets CustomTabColorSchemeParams for the given color scheme.

open TrustedWebActivityIntentBuilder

Sets the navigation bar color, see CustomTabsIntent.Builder#setNavigationBarColor.

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

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

open TrustedWebActivityIntentBuilder
setSplashScreenParams(@NonNull splashScreenParams: Bundle)

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

open TrustedWebActivityIntentBuilder

Sets the color applied to the toolbar and the status bar, see CustomTabsIntent.Builder#setToolbarColor.

Constants

EXTRA_ADDITIONAL_TRUSTED_ORIGINS

static val EXTRA_ADDITIONAL_TRUSTED_ORIGINS: String

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.

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

EXTRA_SHARE_DATA

static val EXTRA_SHARE_DATA: String

Extra for the share data, see setShareParams.

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

EXTRA_SHARE_TARGET

static val EXTRA_SHARE_TARGET: String

Extra for the share target, see setShareParams.

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

EXTRA_SPLASH_SCREEN_PARAMS

static val EXTRA_SPLASH_SCREEN_PARAMS: String

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.

Value: "androidx.browser.trusted.EXTRA_SPLASH_SCREEN_PARAMS"

Public constructors

<init>

TrustedWebActivityIntentBuilder(@NonNull uri: Uri)

Creates a Builder given the required parameters.

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

Public methods

build

@NonNull open fun build(@NonNull session: CustomTabsSession): TrustedWebActivityIntent

Builds an instance of session

buildCustomTabsIntent

@NonNull open fun buildCustomTabsIntent(): CustomTabsIntent

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

getUrl

@NonNull open fun getUrl(): Uri

Returns the Uri to be launched with this Builder.

setAdditionalTrustedOrigins

@NonNull open fun setAdditionalTrustedOrigins(@NonNull origins: MutableList<String!>): TrustedWebActivityIntentBuilder

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 to validate additional origins asynchronously, but that would delay launching the Trusted Web Activity.

setColorScheme

@NonNull open fun setColorScheme(colorScheme: Int): TrustedWebActivityIntentBuilder

Sets the color scheme, see CustomTabsIntent.Builder#setColorScheme. 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.

setColorSchemeParams

@NonNull open fun setColorSchemeParams(colorScheme: Int, @NonNull params: CustomTabColorSchemeParams): TrustedWebActivityIntentBuilder

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.

setNavigationBarColor

@NonNull open fun setNavigationBarColor(color: Int): TrustedWebActivityIntentBuilder

Sets the navigation bar color, see CustomTabsIntent.Builder#setNavigationBarColor.

setShareParams

@NonNull open fun setShareParams(@NonNull shareTarget: ShareTarget, @NonNull shareData: ShareData): TrustedWebActivityIntentBuilder

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 ShareTarget: A ShareData object containing the data to be sent to the Web Share Target.

setSplashScreenParams

@NonNull open fun setSplashScreenParams(@NonNull splashScreenParams: Bundle): TrustedWebActivityIntentBuilder

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, 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

@NonNull open fun setToolbarColor(color: Int): TrustedWebActivityIntentBuilder

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