ComplicationDataSourceInfoRetriever

public final class ComplicationDataSourceInfoRetriever


Retrieves Result for a watch face's complications.

To use construct an instance and call retrieveComplicationDataSourceInfo which returns an array of Result objects.

Further calls to retrieveComplicationDataSourceInfo may be made using the same instance of this class, but close must be called when it is no longer needed. Once release has been called, further retrieval attempts will fail.

Summary

Public constructors

Public methods

void

Releases the connection to the complication system used by this class.

final ComplicationDataSourceInfoRetriever.Result[]
retrieveComplicationDataSourceInfo(
    ComponentName watchFaceComponent,
    int[] watchFaceComplicationIds
)

Requests Result for the specified complication ids on the specified watch face.

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

Requests preview ComplicationData for a complication data source ComponentName and ComplicationType.

Public constructors

ComplicationDataSourceInfoRetriever

public final ComplicationDataSourceInfoRetriever(Context context)
Parameters
Context context

the current context

Public methods

close

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 retrieveComplicationDataSourceInfo 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(
    ComponentName watchFaceComponent,
    int[] watchFaceComplicationIds
)

Requests 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
ComponentName watchFaceComponent

the ComponentName of the WatchFaceService for which info is being requested

int[] watchFaceComplicationIds

ids of the complications that info is being requested for

Returns
ComplicationDataSourceInfoRetriever.Result[]

An array of Result. If the look up fails null will be returned.

Throws
androidx.wear.watchface.complications.ComplicationDataSourceInfoRetriever.ServiceDisconnectedException

if the service disconnected during the call.

retrievePreviewComplicationData

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

Requests preview ComplicationData for a complication data source ComponentName and ComplicationType. Note if null is returned ComplicationDataSourceInfo.fallbackPreviewData can be used to generate fallback preview data based on the name and icon of the provider.

Parameters
ComponentName complicationDataSourceComponent

The ComponentName of the complication data source from which preview data is requested.

ComplicationType complicationType

The requested ComplicationType for the preview data.

Returns
ComplicationData

The preview 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

if the service disconnected during the call.