# TrustedWebActivityServiceConnection

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/trusted/TrustedWebActivityServiceConnection.java+class:androidx.browser.trusted.TrustedWebActivityServiceConnection) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

*** ** * ** ***


```
public final class TrustedWebActivityServiceConnection
```

<br />

*** ** * ** ***

TrustedWebActivityServiceConnection is used by a Trusted Web Activity provider to wrap calls to the `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService` in the client app. All of these calls except `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#getComponentName()` forward over IPC to corresponding calls on `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService`, eg `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#getSmallIconId()` forwards to `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService#onGetSmallIconId()`.

These IPC calls are synchronous, though the `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService` method may hit the disk. Therefore it is recommended to call them on a background thread (without StrictMode).

## Summary

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#areNotificationsEnabled(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channelName)` Checks whether notifications are enabled. |
| `void` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#cancel(java.lang.String,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html platformTag, int platformId)` Requests a notification be cancelled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ComponentName.html` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#getComponentName()()` Gets the `https://developer.android.com/reference/android/content/ComponentName.html` of the connected Trusted Web Activity client app. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#getSmallIconBitmap()()` Requests a bitmap of a small icon to be used for the notification small icon. |
| `int` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#getSmallIconId()()` Requests an Android resource id to be used for the notification small icon. |
| `boolean` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#notify(java.lang.String,int,android.app.Notification,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html platformTag, int platformId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html channel )` Requests a notification be shown. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityServiceConnection#sendExtraCommand(java.lang.String,android.os.Bundle,androidx.browser.trusted.TrustedWebActivityCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html commandName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html args, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityCallback callback )` Passes a free-form command to the client. |

## Public methods

### areNotificationsEnabled

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public boolean areNotificationsEnabled(@NonNull String channelName)
```

Checks whether notifications are enabled.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html 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 |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |

### cancel

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public void cancel(@NonNull String platformTag, int platformId)
```

Requests a notification be cancelled.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html platformTag` | The tag to identify the notification. |
| `int platformId` | The id to identify the notification. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |

### getComponentName

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public @NonNull ComponentName getComponentName()
```

Gets the `https://developer.android.com/reference/android/content/ComponentName.html` of the connected Trusted Web Activity client app.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/ComponentName.html` | The Trusted Web Activity client app component name. |

### getSmallIconBitmap

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#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 `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService#onGetSmallIconId()`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Bitmap.html` | A `https://developer.android.com/reference/android/graphics/Bitmap.html` to be used for the small icon. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |

### getSmallIconId

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#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 |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |

### notify

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

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

Requests a notification be shown.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html platformTag` | The tag to identify the notification. |
| `int platformId` | The id to identify the notification. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/Notification.html notification` | The notification. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html 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 |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |

### sendExtraCommand

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/browser#1.3.0)

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

Passes a free-form command to the client. `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService#onExtraCommand(java.lang.String,android.os.Bundle,androidx.browser.trusted.TrustedWebActivityCallbackRemote)` will be called. The client may not know how to deal with the command, in which case `null` may be returned.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html commandName` | Name of the command to execute. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html args` | Arguments to the command. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityCallback callback` | Callback that may be used to return data, depending on the command. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Bundle.html` | The result `https://developer.android.com/reference/android/os/Bundle.html`, or `null` if the command could not be executed. |

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/RemoteException.html` | If the Service dies while responding to the request. |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | If verification with the TrustedWebActivityService fails. |