TrustedWebActivityServiceConnection

class TrustedWebActivityServiceConnection
kotlin.Any
   ↳ androidx.browser.trusted.TrustedWebActivityServiceConnection

TrustedWebActivityServiceConnection 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#onGetSmallIconId().

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(@NonNull channelName: String)

Checks whether notifications are enabled.

Unit
cancel(@NonNull platformTag: String, platformId: Int)

Requests a notification be cancelled.

ComponentName

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

Bitmap?

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

Int

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

Boolean
notify(@NonNull platformTag: String, platformId: Int, @NonNull notification: Notification, @NonNull channel: String)

Requests a notification be shown.

Public methods

areNotificationsEnabled

fun areNotificationsEnabled(@NonNull channelName: String): Boolean

Checks whether notifications are enabled.

Parameters
channelName String: The name of the channel to check enabled status. Only used on Android O+.
Return
Boolean: Whether notifications or the notification channel is blocked for the client app.
Exceptions
RemoteException If the Service dies while responding to the request.
SecurityException If verification with the TrustedWebActivityService fails.

cancel

fun cancel(@NonNull platformTag: String, platformId: Int): Unit

Requests a notification be cancelled.

Parameters
platformTag String: The tag to identify the notification.
platformId String: The id to identify the notification.
Exceptions
RemoteException If the Service dies while responding to the request.
SecurityException If verification with the TrustedWebActivityService fails.

getComponentName

@NonNull fun getComponentName(): ComponentName

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

Return
ComponentName: The Trusted Web Activity client app component name.

getSmallIconBitmap

@Nullable fun getSmallIconBitmap(): Bitmap?

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#onGetSmallIconId.

Return
Bitmap?: A Bitmap to be used for the small icon.
Exceptions
RemoteException If the Service dies while responding to the request.
SecurityException If verification with the TrustedWebActivityService fails.

getSmallIconId

fun getSmallIconId(): Int

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

Return
Int: An Android resource id for the notification small icon. -1 if non found.
Exceptions
RemoteException If the Service dies while responding to the request.
SecurityException If verification with the TrustedWebActivityService fails.

notify

fun notify(@NonNull platformTag: String, platformId: Int, @NonNull notification: Notification, @NonNull channel: String): Boolean

Requests a notification be shown.

Parameters
platformTag String: The tag to identify the notification.
platformId String: The id to identify the notification.
notification String: The notification.
channel String: The name of the channel in the Trusted Web Activity client app to display the notification on.
Return
Boolean: Whether notifications or the notification channel are blocked for the client app.
Exceptions
RemoteException If the Service dies while responding to the request.
SecurityException If verification with the TrustedWebActivityService fails.