TrustedWebActivityServiceConnection

class 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 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 functions

Boolean

Checks whether notifications are enabled.

Unit
cancel(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(
    platformTag: String,
    platformId: Int,
    notification: Notification,
    channel: String
)

Requests a notification be shown.

Bundle?
sendExtraCommand(
    commandName: String,
    args: Bundle,
    callback: TrustedWebActivityCallback?
)

Passes a free-form command to the client.

Public functions

areNotificationsEnabled

Added in 1.2.0
fun areNotificationsEnabled(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+.

Returns
Boolean

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

Throws
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.

cancel

Added in 1.2.0
fun cancel(platformTag: String, platformId: Int): Unit

Requests a notification be cancelled.

Parameters
platformTag: String

The tag to identify the notification.

platformId: Int

The id to identify the notification.

Throws
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.

getComponentName

Added in 1.2.0
fun getComponentName(): ComponentName

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

Returns
ComponentName

The Trusted Web Activity client app component name.

getSmallIconBitmap

Added in 1.2.0
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 onGetSmallIconId.

Returns
Bitmap?

A Bitmap to be used for the small icon.

Throws
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.

getSmallIconId

Added in 1.2.0
fun getSmallIconId(): Int

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
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.

notify

Added in 1.2.0
fun notify(
    platformTag: String,
    platformId: Int,
    notification: Notification,
    channel: String
): Boolean

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
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.

sendExtraCommand

Added in 1.3.0
fun sendExtraCommand(
    commandName: String,
    args: Bundle,
    callback: TrustedWebActivityCallback?
): Bundle?

Passes a free-form command to the client. onExtraCommand will be called. The client may not know how to deal with the command, in which case null may be returned.

Parameters
commandName: String

Name of the command to execute.

args: Bundle

Arguments to the command.

callback: TrustedWebActivityCallback?

Callback that may be used to return data, depending on the command.

Returns
Bundle?

The result Bundle, or null if the command could not be executed.

Throws
android.os.RemoteException

If the Service dies while responding to the request.

java.lang.SecurityException

If verification with the TrustedWebActivityService fails.