# ComplicationDataSourceInfoRetriever

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

*** ** * ** ***


```
public final class ComplicationDataSourceInfoRetriever implements AutoCloseable
```

<br />

*** ** * ** ***

Retrieves `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result` for a watch face's complications.

To use construct an instance and call `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)` which returns an array of `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result` objects.

Further calls to `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)` may be made using the same instance of this class, but `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#close()` must be called when it is no longer needed. Once release has been called, further retrieval attempts will fail.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result` Results for `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)`. |
| `public final class https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException extends https://developer.android.com/reference/java/lang/Exception.html` Exception thrown if the service disconnects. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#ComplicationDataSourceInfoRetriever(android.content.Context)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#close()()` Releases the connection to the complication system used by this class. |
| `final ComplicationDataSourceInfoRetriever.Result[]` | `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html watchFaceComponent, @https://developer.android.com/reference/androidx/annotation/NonNull int[] watchFaceComplicationIds )` Requests `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result` for the specified complication ids on the specified watch face. |
| `final https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationData` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 30) https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrievePreviewComplicationData(android.content.ComponentName,androidx.wear.watchface.complications.data.ComplicationType)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html complicationDataSourceComponent, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationType complicationType )` Requests preview `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationData` for a complication data source `https://developer.android.com/reference/android/content/ComponentName.html` and `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationType`. |

## Public constructors

### ComplicationDataSourceInfoRetriever

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

```
public ComplicationDataSourceInfoRetriever(@NonNull Context context)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the current context |

## Public methods

### close

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

```
public void close()
```

Releases the connection to the complication system used by this class. This must be called when the retriever is no longer needed.

Any outstanding or subsequent futures returned by `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)` will resolve with null.

This class implements the Java `AutoClosable` interface and may be used with try-with-resources.

### retrieveComplicationDataSourceInfo

```
public final ComplicationDataSourceInfoRetriever.Result[] retrieveComplicationDataSourceInfo(
    @NonNull ComponentName watchFaceComponent,
    @NonNull int[] watchFaceComplicationIds
)
```

Requests `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result` for the specified complication ids on the specified watch face. When the info is received, the listener will receive a callback for each id. These callbacks will occur on the main thread.

This will only work if the package of the current app is the same as the package of the specified watch face.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html watchFaceComponent` | the ComponentName of the WatchFaceService for which info is being requested |
| `@https://developer.android.com/reference/androidx/annotation/NonNull int[] watchFaceComplicationIds` | ids of the complications that info is being requested for |

| Returns |
|---|---|
| `ComplicationDataSourceInfoRetriever.Result[]` | An array of `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result`. If the look up fails null will be returned. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException` | if the service disconnected during the call. |

### retrievePreviewComplicationData

```
@RequiresApi(value = 30)
public final ComplicationData retrievePreviewComplicationData(
    @NonNull ComponentName complicationDataSourceComponent,
    @NonNull ComplicationType complicationType
)
```

Requests preview `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationData` for a complication data source `https://developer.android.com/reference/android/content/ComponentName.html` and `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationType`. Note if `null` is returned `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfo#fallbackPreviewData()` can be used to generate fallback preview data based on the name and icon of the provider.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/ComponentName.html complicationDataSourceComponent` | The `https://developer.android.com/reference/android/content/ComponentName.html` of the complication data source from which preview data is requested. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationType complicationType` | The requested `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationType` for the preview data. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationData` | The preview `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationData` or `null` if the complication data source component doesn't exist, or if it doesn't support complicationType, or if the remote service doesn't support this API. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException` | if the service disconnected during the call. |