# TestTileClient

Artifact: [androidx.wear.tiles:tiles-testing](https://developer.android.com/jetpack/androidx/releases/wear-tiles) [View Source](https://cs.android.com/search?q=file:androidx/wear/tiles/testing/TestTileClient.kt+class:androidx.wear.tiles.testing.TestTileClient) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

*** ** * ** ***

<br />

```
public final class TestTileClient<T extends TileService> implements TileClient
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/wear/tiles/client/TileClient` for testing purposes. This will pass calls through to the given instance of `https://developer.android.com/reference/androidx/wear/tiles/TileService`, handling all the service binding (via Robolectric), and serialization/deserialization.

Note that this class will not drive the full service lifecycle for the passed service instance. On the first call to any of these methods, it will call your service's `https://developer.android.com/reference/android/app/Service.html#onCreate()` method, however, it will never call `https://developer.android.com/reference/android/app/Service.html#onDestroy()`. Equally, where `https://developer.android.com/reference/androidx/wear/tiles/connection/DefaultTileClient` will unbind after a period of time, potentially destroying the service, this class wil Client will unbind, but not destroy the service. If you wish to test service destruction, you can instead call `https://developer.android.com/reference/android/app/Service.html#onDestroy()` on the passed in `service` instance.

## Summary

| ### Public constructors |
|---|
| `<T extends https://developer.android.com/reference/androidx/wear/tiles/TileService> https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#TestTileClient(androidx.wear.tiles.TileService,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull T service, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Build a `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient` for use with a given `https://developer.android.com/reference/java/util/concurrent/Executor.html` |
| `<T extends https://developer.android.com/reference/androidx/wear/tiles/TileService> https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#TestTileClient(androidx.wear.tiles.TileService,kotlinx.coroutines.CoroutineScope,kotlinx.coroutines.CoroutineDispatcher)( @https://developer.android.com/reference/androidx/annotation/NonNull T service, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html coroutineScope, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html coroutineDispatcher )` Build a `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient` for use with a coroutine dispatcher. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#requestApiVersion()()` Gets the API version supported by the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/tiles/ResourceBuilders.Resources>` | `[requestResources](https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#requestResources(androidx.wear.tiles.RequestBuilders.ResourcesRequest))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/tiles/RequestBuilders.ResourcesRequest requestParams )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/wear/tiles/client/TileClient#requestTileResourcesAsync(androidx.wear.tiles.RequestBuilders.ResourcesRequest)` instead. <br /> |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/tiles/TileBuilders.Tile>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#requestTile(androidx.wear.tiles.RequestBuilders.TileRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/tiles/RequestBuilders.TileRequest requestParams)` Request a tile payload from the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.Resources>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#requestTileResourcesAsync(androidx.wear.tiles.RequestBuilders.ResourcesRequest)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/tiles/RequestBuilders.ResourcesRequest requestParams )` Request a resource bundle from the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#sendOnTileAddedEvent()()` Send a Tile Added notification to the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#sendOnTileEnterEvent()()` Send a Tile Enter notification to the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#sendOnTileLeaveEvent()()` Send a Tile Leave notification to the connected TileService. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#sendOnTileRemovedEvent()()` Send a Tile Removed notification to the connected TileService. |

## Public constructors

### TestTileClient

```
public <T extends TileService> TestTileClient(
    @NonNull T service,
    @NonNull Executor executor
)
```

Build a `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient` for use with a given `https://developer.android.com/reference/java/util/concurrent/Executor.html`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T service` | An instance of the `https://developer.android.com/reference/androidx/wear/tiles/TileService` class to bind to. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | An `https://developer.android.com/reference/java/util/concurrent/Executor.html` to use when dispatching calls to the `https://developer.android.com/reference/androidx/wear/tiles/TileService`. |

### TestTileClient

```
public <T extends TileService> TestTileClient(
    @NonNull T service,
    @NonNull CoroutineScope coroutineScope,
    @NonNull CoroutineDispatcher coroutineDispatcher
)
```

Build a `https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient` for use with a coroutine dispatcher.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T service` | An instance of the `https://developer.android.com/reference/androidx/wear/tiles/TileService` class to bind to. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html coroutineScope` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` to use when dispatching calls to the `https://developer.android.com/reference/androidx/wear/tiles/TileService`. Cancelling the passed `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` will also cancel any pending work in this class. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html coroutineDispatcher` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` to use when dispatching work from this class. |

## Public methods

### requestApiVersion

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<@NonNull Integer> requestApiVersion()
```

Gets the API version supported by the connected TileService.

### requestResources

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.2.0)

```
public @NonNull ListenableFuture<@NonNull ResourceBuilders.Resources> [requestResources](https://developer.android.com/reference/androidx/wear/tiles/testing/TestTileClient#requestResources(androidx.wear.tiles.RequestBuilders.ResourcesRequest))(
    @NonNull RequestBuilders.ResourcesRequest requestParams
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/wear/tiles/client/TileClient#requestTileResourcesAsync(androidx.wear.tiles.RequestBuilders.ResourcesRequest)` instead.

Request a resource bundle from the connected TileService.

### requestTile

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<@NonNull TileBuilders.Tile> requestTile(@NonNull RequestBuilders.TileRequest requestParams)
```

Request a tile payload from the connected TileService.

### requestTileResourcesAsync

```
public @NonNull ListenableFuture<@NonNull ResourceBuilders.Resources> requestTileResourcesAsync(
    @NonNull RequestBuilders.ResourcesRequest requestParams
)
```

Request a resource bundle from the connected TileService.

### sendOnTileAddedEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<Void> sendOnTileAddedEvent()
```

Send a Tile Added notification to the connected TileService.

### sendOnTileEnterEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<Void> sendOnTileEnterEvent()
```

Send a Tile Enter notification to the connected TileService.

### sendOnTileLeaveEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<Void> sendOnTileLeaveEvent()
```

Send a Tile Leave notification to the connected TileService.

### sendOnTileRemovedEvent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-tiles#1.0.0)

```
public @NonNull ListenableFuture<Void> sendOnTileRemovedEvent()
```

Send a Tile Removed notification to the connected TileService.