TrustedWebActivityServiceConnection


public final 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 methods

boolean

Checks whether notifications are enabled.

void
cancel(@NonNull String platformTag, int platformId)

Requests a notification be cancelled.

@NonNull ComponentName

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

@Nullable 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 String platformTag,
    int platformId,
    @NonNull Notification notification,
    @NonNull String channel
)

Requests a notification be shown.

@Nullable Bundle
sendExtraCommand(
    @NonNull String commandName,
    @NonNull Bundle args,
    @Nullable TrustedWebActivityCallback callback
)

Passes a free-form command to the client.

Public methods

areNotificationsEnabled

Added in 1.2.0
public boolean areNotificationsEnabled(@NonNull String channelName)

Checks whether notifications are enabled.

Parameters
@NonNull String channelName

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
public void cancel(@NonNull String platformTag, int platformId)

Requests a notification be cancelled.

Parameters
@NonNull String platformTag

The tag to identify the notification.

int platformId

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
public @NonNull ComponentName getComponentName()

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

Returns
@NonNull ComponentName

The Trusted Web Activity client app component name.

getSmallIconBitmap

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

Returns
@Nullable 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
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
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
public boolean notify(
    @NonNull String platformTag,
    int platformId,
    @NonNull Notification notification,
    @NonNull String channel
)

Requests a notification be shown.

Parameters
@NonNull String platformTag

The tag to identify the notification.

int platformId

The id to identify the notification.

@NonNull Notification notification

The notification.

@NonNull String channel

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
public @Nullable Bundle sendExtraCommand(
    @NonNull String commandName,
    @NonNull Bundle args,
    @Nullable TrustedWebActivityCallback callback
)

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
@NonNull String commandName

Name of the command to execute.

@NonNull Bundle args

Arguments to the command.

@Nullable TrustedWebActivityCallback callback

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

Returns
@Nullable 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.