The Android Developer Challenge is back! Submit your idea before December 2.

TrustedWebActivityServiceWrapper

public class TrustedWebActivityServiceWrapper
extends Object

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


TrustedWebActivityServiceWrapper is used by a Trusted Web Activity provider to wrap calls to the TrustedWebActivityService in the client app. All of these calls except getComponentName() forward over IPC to corresponding calls on TrustedWebActivityService, eg getSmallIconId() forwards to TrustedWebActivityService.getSmallIconId().

These IPC calls are synchronous, though the TrustedWebActivityService method may hit the disk. Therefore it is recommended to call them on a background thread (without StrictMode).

Summary

Public methods

boolean areNotificationsEnabled(String channelName)

Checks whether notifications are enabled.

void cancel(String platformTag, int platformId)

Requests a notification be cancelled.

ComponentName getComponentName()

Gets the ComponentName of the connected Trusted Web Activity client app.

Bitmap getSmallIconBitmap()

Requests a bitmap of a small icon to be used for the notification small icon.

int getSmallIconId()

Requests an Android resource id to be used for the notification small icon.

boolean notify(String platformTag, int platformId, Notification notification, String channel)

Requests a notification be shown.

Inherited methods

Public methods

areNotificationsEnabled

public boolean areNotificationsEnabled (String channelName)

Checks whether notifications are enabled.

Parameters
channelName String: The name of the channel to check enabled status. Only used on Android O+.

Returns
boolean Whether notifications or the notification channel is blocked for the client app.

cancel

public void cancel (String platformTag, 
                int platformId)

Requests a notification be cancelled.

Parameters
platformTag String: The tag to identify the notification.

platformId int: The id to identify the notification.

Throws
SecurityException If verification with the TrustedWebActivityService fails.

getComponentName

public ComponentName getComponentName ()

Gets the ComponentName of the connected Trusted Web Activity client app.

Returns
ComponentName The Trusted Web Activity client app component name.

getSmallIconBitmap

public Bitmap getSmallIconBitmap ()

Requests a bitmap of a small icon to be used for the notification small icon. The bitmap is decoded on the side of Trusted Web Activity client using the resource id from TrustedWebActivityService.getSmallIconId().

Returns
Bitmap A Bitmap to be used for the small icon.

Throws
SecurityException If verification with the TrustedWebActivityService fails.

getSmallIconId

public int getSmallIconId ()

Requests an Android resource id to be used for the notification small icon.

Returns
int An Android resource id for the notification small icon. -1 if non found.

Throws
SecurityException If verification with the TrustedWebActivityService fails.

notify

public boolean notify (String platformTag, 
                int platformId, 
                Notification notification, 
                String channel)

Requests a notification be shown.

Parameters
platformTag String: The tag to identify the notification.

platformId int: The id to identify the notification.

notification Notification: The notification.

channel String: The name of the channel in the Trusted Web Activity client app to display the notification on.

Returns
boolean Whether notifications or the notification channel are blocked for the client app.

Throws
SecurityException If verification with the TrustedWebActivityService fails.