# 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)

*** ** * ** ***


```
class TrustedWebActivityServiceConnection
```

<br />

*** ** * ** ***

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

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

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#areNotificationsEnabled(java.lang.String)(channelName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Checks whether notifications are enabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#cancel(java.lang.String,int)(platformTag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, platformId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Requests a notification be cancelled. |
| `https://developer.android.com/reference/android/content/ComponentName.html` | `https://developer.android.com/reference/kotlin/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://developer.android.com/reference/android/graphics/Bitmap.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#getSmallIconBitmap()()` Requests a bitmap of a small icon to be used for the notification small icon. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#getSmallIconId()()` Requests an Android resource id to be used for the notification small icon. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#notify(java.lang.String,int,android.app.Notification,java.lang.String)( platformTag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, platformId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, notification: https://developer.android.com/reference/android/app/Notification.html, channel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Requests a notification be shown. |
| `https://developer.android.com/reference/android/os/Bundle.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityServiceConnection#sendExtraCommand(java.lang.String,android.os.Bundle,androidx.browser.trusted.TrustedWebActivityCallback)( commandName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, args: https://developer.android.com/reference/android/os/Bundle.html, callback: https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityCallback? )` Passes a free-form command to the client. |

## Public functions

### areNotificationsEnabled

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

```
fun areNotificationsEnabled(channelName: String): Boolean
```

Checks whether notifications are enabled.

| Parameters |
|---|---|
| `channelName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the channel to check enabled status. Only used on Android O+. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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)

```
fun cancel(platformTag: String, platformId: Int): Unit
```

Requests a notification be cancelled.

| Parameters |
|---|---|
| `platformTag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag to identify the notification. |
| `platformId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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)

```
fun getComponentName(): ComponentName
```

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

| Returns |
|---|---|
| `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)

```
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 `https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityService#onGetSmallIconId()`.

| Returns |
|---|---|
| `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)

```
fun getSmallIconId(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | 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)

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

Requests a notification be shown.

| Parameters |
|---|---|
| `platformTag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag to identify the notification. |
| `platformId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The id to identify the notification. |
| `notification: https://developer.android.com/reference/android/app/Notification.html` | The notification. |
| `channel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the channel in the Trusted Web Activity client app to display the notification on. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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)

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

Passes a free-form command to the client. `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `commandName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Name of the command to execute. |
| `args: https://developer.android.com/reference/android/os/Bundle.html` | Arguments to the command. |
| `callback: https://developer.android.com/reference/kotlin/androidx/browser/trusted/TrustedWebActivityCallback?` | Callback that may be used to return data, depending on the command. |

| Returns |
|---|---|
| `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. |