# TrustedWebUtils

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/customtabs/TrustedWebUtils.java+class:androidx.browser.customtabs.TrustedWebUtils) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

*** ** * ** ***


```
public class TrustedWebUtils
```

<br />

*** ** * ** ***

Class for utilities and convenience calls for opening a qualifying web page as a Trusted Web Activity. Trusted Web Activity is a fullscreen UI with no visible browser controls that hosts web pages meeting certain criteria. The full list of qualifications is at the implementing browser's discretion, but minimum recommended set is for the web page :

- To have declared delegate_permission/common.handle_all_urls relationship with the launching client application ensuring 1:1 trust between the Android native and web components. See https://developers.google.com/digital-asset-links/ for details.
- To work as a reliable, fast and engaging standalone component within the launching app's flow.
- To be accessible and operable even when offline.

Fallback behaviors may also differ with implementation. Possibilities are launching the page in a custom tab, or showing it in browser UI. Browsers are encouraged to use `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback#onRelationshipValidationResult(int,android.net.Uri,boolean,android.os.Bundle)` for sending details of the verification results.

## Summary

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/customtabs/TrustedWebUtils#EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY() = "android.support.customtabs.extra.LAUNCH_AS_TRUSTED_WEB_ACTIVITY"` Boolean extra that triggers a `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent` launch to be in a fullscreen UI with no browser controls. |

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/androidx/browser/customtabs/TrustedWebUtils#areSplashScreensSupported(android.content.Context,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html version )` Returns whether the splash screens feature is supported by the given package. |
| `static void` | `[launchAsTrustedWebActivity](https://developer.android.com/reference/androidx/browser/customtabs/TrustedWebUtils#launchAsTrustedWebActivity(android.content.Context,androidx.browser.customtabs.CustomTabsIntent,android.net.Uri))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent customTabsIntent, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityIntentBuilder` instead. <br /> |
| `static boolean` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/browser/customtabs/TrustedWebUtils#transferSplashImage(android.content.Context,java.io.File,java.lang.String,java.lang.String,androidx.browser.customtabs.CustomTabsSession)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html fileProviderAuthority, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession session )` Transfers the splash image to a Custom Tabs provider. |

## Constants

### EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String EXTRA_LAUNCH_AS_TRUSTED_WEB_ACTIVITY = "android.support.customtabs.extra.LAUNCH_AS_TRUSTED_WEB_ACTIVITY"
```

Boolean extra that triggers a `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent` launch to be in a fullscreen UI with no browser controls.

## Public methods

### areSplashScreensSupported

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static boolean areSplashScreensSupported(
    @NonNull Context context,
    @NonNull String packageName,
    @NonNull String version
)
```

Returns whether the splash screens feature is supported by the given package. Note: you can call this method prior to connecting to a `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsService`. This way, if true is returned, the splash screen can be shown as soon as possible.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | `https://developer.android.com/reference/android/content/Context.html` to use. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | The package name of the Custom Tabs provider to check. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html version` | The splash screen version/feature you are testing for support. Use a value from `https://developer.android.com/reference/androidx/browser/trusted/splashscreens/SplashScreenVersion`. |

| Returns |
|---|---|
| `boolean` | Whether the specified Custom Tabs provider supports the specified splash screen feature/version. |

### launchAsTrustedWebActivity

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static void [launchAsTrustedWebActivity](https://developer.android.com/reference/androidx/browser/customtabs/TrustedWebUtils#launchAsTrustedWebActivity(android.content.Context,androidx.browser.customtabs.CustomTabsIntent,android.net.Uri))(
    @NonNull Context context,
    @NonNull CustomTabsIntent customTabsIntent,
    @NonNull Uri uri
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityIntentBuilder` instead.

Launch the given `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent` as a Trusted Web Activity. The given `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent` should have a valid `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession` associated with it during construction. Once the Trusted Web Activity is launched, browser side implementations may have their own fallback behavior (e.g. Showing the page in a custom tab UI with toolbar) based on qualifications listed above or more.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | `https://developer.android.com/reference/android/content/Context.html` to use while launching the `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent customTabsIntent` | The `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsIntent` to use for launching the Trusted Web Activity. Note that all customizations in the given associated with browser toolbar controls will be ignored. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | The web page to launch as Trusted Web Activity. |

### transferSplashImage

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
@WorkerThread
public static boolean transferSplashImage(
    @NonNull Context context,
    @NonNull File file,
    @NonNull String fileProviderAuthority,
    @NonNull String packageName,
    @NonNull CustomTabsSession session
)
```

Transfers the splash image to a Custom Tabs provider. The reading and decoding of the image happens synchronously, so it's recommended to call this method on a worker thread. This method should be called prior to launching the Activity. Pass additional parameters, such as background color, using `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityIntentBuilder#setSplashScreenParams(android.os.Bundle)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | `https://developer.android.com/reference/android/content/Context.html` to use. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/File.html file` | `https://developer.android.com/reference/java/io/File.html` with the image. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html fileProviderAuthority` | authority of `https://developer.android.com/reference/androidx/core/content/FileProvider` used to generate an URI for the file. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName` | Package name of Custom Tabs provider. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession session` | `https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession` established with the Custom Tabs provider. |

| Returns |
|---|---|
| `boolean` | True if the image was received and processed successfully. |