Skip to main content

Trusted Web Activity - Android

A Trusted Web Activity (TWA) ↗ (https://developer.chrome.com/docs/android/trusted-web-activity) enables Android apps to display web content in full-screen mode using Chrome, without any browser UI elements. Unlike WebView, TWAs run in the user's browser context, allowing better performance, access to browser features (like push notifications and background sync), and shared cookies, permissions, and storage between the app and the browser.

important

To enable Trusted Web Activity, contact your integration manager with the app’s package name and certificate hash.

DID YOU KNOW?

Trusted Web Activity support is project-independent and applies at the app level — based on the package name and signing certificate only.

Configuring for Trusted Web Activity in the SDK

When configuring the SDK, supply an activity setting to the config like this:

final Config.Payments configPayments = Config.Payments.getDefault()
.withActivity(Config.Payments.Activity.forTrustedWebActivity());

This ensures that the Trusted Web Activity will be used by the payment flow.

warning

Trusted Web Activity availability depends on the device's system configuration, i.e. a compatible browser needs to be installed. If TWA support is not available, then the SDK falls back to one of the default activity types for payments (e.g. Custom Tabs or WebView, depending on the environment).

An example of the TWA in action:

(Optional) Orientation locking

Trusted Web Activity natively supports orientation locking when it's shown on the screen. This can be setup during the configuration step with these lines:

final Config.Payments configPayments = Config.Payments.getDefault()
.withActivityOrientationLock(
// orientation setting
);

Orientation setting is one of the following values:

  • Config.Payments.ACTIVITY_ORIENTATION_LOCK_PORTRAIT - forces the TWA to be displayed in portrait mode.
  • Config.Payments.ACTIVITY_ORIENTATION_LOCK_LANDSCAPE - forces the TWA to be displayed in landscape mode.
  • null - disables the orientation locking.

(Optional) Adding a customizable splash screen

Trusted Web Activity also supports a customizable splash screen that's shown right before the TWA itself. To enable it, modify the configuration setting we added earlier:

final Config.Payments configPayments = Config.Payments.getDefault()
.withActivity(Config.Payments.Activity.forTrustedWebActivityWithImage(
// image settings go here
));

An example of the TWA splash screen:

Setting an image for the splash screen

Image can be supplied via two methods: a drawable ID and a filepath to the image:

  • A drawable ID:

    important

    The drawable needs to be added to the Android resource manually beforehand.

    final Config.Payments configPayments = Config.Payments.getDefault()
    .withActivity(Config.Payments.Activity.forTrustedWebActivityWithImage(
    Config.Payments.Activity.TrustedWebActivity.Image.forDrawableId(
    <your_drawable_id>
    )
    ));
    tip

    SVG format is also supported, but needs to be wrapped into a valid drawable XML.

  • A filepath:

    important

    The image file needs to be discoverable. Supports all major raster image formats.

    final Config.Payments configPayments = Config.Payments.getDefault()
    .withActivity(Config.Payments.Activity.forTrustedWebActivityWithImage(
    Config.Payments.Activity.TrustedWebActivity.Image.forFilepath(
    <filepath_to_your_splash_screen_image>
    )
    ));

note

If you're working with Unity, consider visiting this page for more details: Trusted Web Activity - Unity (Android).