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_DISPLAY_MODE
Extra for the |
String |
EXTRA_SCREEN_ORIENTATION
Extra for the screenOrientation, see |
String |
EXTRA_SHARE_DATA
Extra for the share data, see |
String |
EXTRA_SHARE_TARGET
Extra for the share target, see |
String |
EXTRA_SPLASH_SCREEN_PARAMS
Extra for the Trusted Web Activity launch Intent to specify a |
Public constructors | |
---|---|
TrustedWebActivityIntentBuilder(Uri uri)
Creates a Builder given the required parameters. |
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_DISPLAY_MODE
public static final String EXTRA_DISPLAY_MODE
Extra for the TrustedWebActivityDisplayMode
, see setDisplayMode(TrustedWebActivityDisplayMode)
.
Constant Value: "androidx.browser.trusted.extra.DISPLAY_MODE"
EXTRA_SCREEN_ORIENTATION
public static final String EXTRA_SCREEN_ORIENTATION
Extra for the screenOrientation, see setScreenOrientation(int)
.
Constant Value: "androidx.browser.trusted.extra.SCREEN_ORIENTATION"
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 |
getDisplayMode
public TrustedWebActivityDisplayMode getDisplayMode ()
Returns TrustedWebActivityDisplayMode
set on this Builder.
Returns | |
---|---|
TrustedWebActivityDisplayMode |
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 affect 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 |
setDefaultColorSchemeParams
public TrustedWebActivityIntentBuilder setDefaultColorSchemeParams (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(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
params |
CustomTabColorSchemeParams : An instance of CustomTabColorSchemeParams .
|
Returns | |
---|---|
TrustedWebActivityIntentBuilder |
setDisplayMode
public TrustedWebActivityIntentBuilder setDisplayMode (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.
Parameters | |
---|---|
displayMode |
TrustedWebActivityDisplayMode |
Returns | |
---|---|
TrustedWebActivityIntentBuilder |
setNavigationBarColor
public TrustedWebActivityIntentBuilder setNavigationBarColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
Sets the navigation bar color, see CustomTabsIntent.Builder.setNavigationBarColor(int)
.
Parameters | |
---|---|
color |
int |
Returns | |
---|---|
TrustedWebActivityIntentBuilder |
setNavigationBarDividerColor
public TrustedWebActivityIntentBuilder setNavigationBarDividerColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
Sets the navigation bar divider color, see
CustomTabsIntent.Builder.setNavigationBarDividerColor(int)
.
Parameters | |
---|---|
color |
int |
Returns | |
---|---|
TrustedWebActivityIntentBuilder |
setScreenOrientation
public TrustedWebActivityIntentBuilder setScreenOrientation (int orientation)
Sets a screenOrientation. This can be used e.g. to enable the locking of an orientation
lock type ScreenOrientation
.
Parameters | |
---|---|
orientation |
int : A ScreenOrientation lock type for a Trusted Web Activity.
Not setting it means ScreenOrientation.DEFAULT will be used.
|
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)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
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 |