# ComplicationDataSourceInfoRetriever

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever "View this page in Java")

<br />

```
class ComplicationDataSourceInfoRetriever : AutoCloseable
```

<br />

*** ** * ** ***

Retrieves[Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result)for a watch face's complications.

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

Further calls to[retrieveComplicationDataSourceInfo](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray))may be made using the same instance of this class, but[close](https://developer.android.com/reference/kotlin/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                                                                                                                                                                                                                  |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[ComplicationDataSourceInfoRetriever.Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result) Results for[retrieveComplicationDataSourceInfo](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray)). |
| `class `[ComplicationDataSourceInfoRetriever.ServiceDisconnectedException](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException)` : `[Exception](https://developer.android.com/reference/java/lang/Exception.html) Exception thrown if the service disconnects.                                                                                   |

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

|                                                                                                                             ### Public functions                                                                                                                              |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `open `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                          | [close](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#close())`()` Releases the connection to the complication system used by this class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `suspend `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ComplicationDataSourceInfoRetriever.Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result)`>?` | [retrieveComplicationDataSourceInfo](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrieveComplicationDataSourceInfo(android.content.ComponentName,kotlin.IntArray))`(` ` watchFaceComponent: `[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)`,` ` watchFaceComplicationIds: `[IntArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html) `)` Requests[Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result)for the specified complication ids on the specified watch face.                                                                                                                                                                                                                                                                                                                                                                                            |
| `suspend `[ComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData)`?`                                                                                                                                   | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = 30)` [retrievePreviewComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever#retrievePreviewComplicationData(android.content.ComponentName,androidx.wear.watchface.complications.data.ComplicationType))`(` ` complicationDataSourceComponent: `[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)`,` ` complicationType: `[ComplicationType](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationType) `)` Requests preview[ComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData)for a complication data source[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)and[ComplicationType](https://developer.android.com/reference/kotlin/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)  

```
ComplicationDataSourceInfoRetriever(context: Context)
```  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|---------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html) | the current context |

## Public functions

### close

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

```
open fun close(): Unit
```

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[retrieveComplicationDataSourceInfo](https://developer.android.com/reference/kotlin/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

```
suspend fun retrieveComplicationDataSourceInfo(
    watchFaceComponent: ComponentName,
    watchFaceComplicationIds: IntArray
): Array<ComplicationDataSourceInfoRetriever.Result>?
```

Requests[Result](https://developer.android.com/reference/kotlin/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                                                     |
|--------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `watchFaceComponent: `[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)  | the ComponentName of the WatchFaceService for which info is being requested |
| `watchFaceComplicationIds: `[IntArray](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html) | ids of the complications that info is being requested for                   |

|                                                                                                                               Returns                                                                                                                               |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[ComplicationDataSourceInfoRetriever.Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result)`>?` | An array of[Result](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.Result). If the look up fails null will be returned. |

|                                                                                                                             Throws                                                                                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [androidx.wear.watchface.complications.ComplicationDataSourceInfoRetriever.ServiceDisconnectedException](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException) | if the service disconnected during the call. |

### retrievePreviewComplicationData

```
@RequiresApi(value = 30)
suspend fun retrievePreviewComplicationData(
    complicationDataSourceComponent: ComponentName,
    complicationType: ComplicationType
): ComplicationData?
```

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

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

|                                                              Returns                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ComplicationData](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/ComplicationData)`?` | The preview[ComplicationData](https://developer.android.com/reference/kotlin/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                                                                                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [androidx.wear.watchface.complications.ComplicationDataSourceInfoRetriever.ServiceDisconnectedException](https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/ComplicationDataSourceInfoRetriever.ServiceDisconnectedException) | if the service disconnected during the call. |