ComplicationDataSourceInfoRetriever


public final class ComplicationDataSourceInfoRetriever implements AutoCloseable


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

Nested types

Results for retrieveComplicationDataSourceInfo.

Exception thrown if the service disconnects.

Public constructors

Public methods

void

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

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

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

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

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

Public constructors

ComplicationDataSourceInfoRetriever

Added in 1.0.0
public ComplicationDataSourceInfoRetriever(@NonNull Context context)
Parameters
@NonNull Context context

the current context

Public methods

close

Added in 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 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(
    @NonNull ComponentName watchFaceComponent,
    @NonNull 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
@NonNull ComponentName watchFaceComponent

the ComponentName of the WatchFaceService for which info is being requested

@NonNull 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.

retrievePreviewComplicationData

@RequiresApi(value = 30)
public final ComplicationData retrievePreviewComplicationData(
    @NonNull ComponentName complicationDataSourceComponent,
    @NonNull 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
@NonNull ComponentName complicationDataSourceComponent

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

@NonNull 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.