ComplicationDataSourceService


public abstract class ComplicationDataSourceService extends Service


Class for sources of complication data.

A complication data source service must implement onComplicationRequest to respond to requests for updates from the complication system.

Manifest requirements:

  • The manifest declaration of this service must include an intent filter for android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST.

  • A ComplicationDataSourceService must include a meta-data tag with android.support.wearable.complications.SUPPORTED_TYPES in its manifest entry.

The value of android.support.wearable.complications.SUPPORTED_TYPES should be a comma separated list of types supported by the data source, from this table:

Androidx class Tag name
GoalProgressComplicationData GOAL_PROGRESS
LongTextComplicationData LONG_TEXT
MonochromaticImageComplicationData ICON
PhotoImageComplicationData LARGE_IMAGE
RangedValueComplicationData RANGED_TEXT
ShortTextComplicationData SHORT_TEXT
SmallImageComplicationData SMALL_IMAGE
WeightedElementsComplicationData WEIGHTED_ELEMENTS

The order in which types are listed has no significance. In the case where a watch face supports multiple types in a single complication slot, the watch face will determine which types it prefers.

For example, a complication data source that supports the RANGED_VALUE, SHORT_TEXT, and ICON types would include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="RANGED_VALUE,SHORT_TEXT,ICON" />

From android T onwards, it is recommended for ComplicationDataSourceServices to be direct boot aware because the system is able to fetch complications before the lock screen has been removed. To do this add android:directBootAware="true" to your service tag.

  • A provider can choose to trust one or more watch faces by including the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SAFE_WATCH_FACES"
android:value="com.pkg1/com.trusted.wf1,com.pkg2/com.trusted.wf2" />

The listed watch faces will not need com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA in order to receive complications from this provider. Also the provider may choose to serve different types to safe watch faces by including the following in its manifest:

<meta-data
android:name="androidx.wear.watchface.complications.datasource.SAFE_WATCH_FACE_SUPPORTED_TYPES"
android:value="ICON" />

In addition the provider can learn if a request is for a safe watchface by examining ComplicationRequest.isForSafeWatchFace. Note SAFE_WATCH_FACE_SUPPORTED_TYPES and isForSafeWatchFace are gated behind the privileged permission com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE.

  • A ComplicationDataSourceService should include a meta-data tag with android.support.wearable.complications.UPDATE_PERIOD_SECONDS in its manifest entry. The value of this tag is the number of seconds the complication data source would like to elapse between update requests.

Note that update requests are not guaranteed to be sent with this frequency. For complications with frequent updates they can also register a separate meta-data tag with androidx.wear.watchface.complications.data.source.IMMEDIATE_UPDATE_PERIOD_MILLISECONDS in their manifest which supports sampling at up to 1Hz when the watch face is visible and non-ambient, however this also requires the application to have the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE.

If a complication data source never needs to receive update requests beyond the one sent when a complication is activated, the value of this tag should be 0.

For example, a complication data source that would like to update at most every hour should include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="3600" />
  • A ComplicationDataSourceService can include a meta-data tag with android.support.wearable.complications.PROVIDER_CONFIG_ACTION its manifest entry to cause a configuration activity to be shown when the complication data source is selected.

The configuration activity must reside in the same package as the complication data source, and must register an intent filter for the action specified here, including android.support.wearable.complications.category.PROVIDER_CONFIG as well as Intent.CATEGORY_DEFAULT as categories.

Note back up and restore of any configuration data is left to the complication data source, see METADATA_KEY_CONFIG_RESTORE_SUPPORTED for more details.

The complication id being configured will be included in the intent that starts the config activity using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_ID.

The complication type that will be requested from the complication data source will also be included, using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_TYPE.

The complication data source's ComponentName will also be included in the intent that starts the config activity, using the extra key android.support.wearable.complications.EXTRA_CONFIG_PROVIDER_COMPONENT.

The config activity must call Activity.setResult with either Activity.RESULT_OK or Activity.RESULT_CANCELED before it is finished, to tell the system whether or not the complication data source should be set on the given complication.

It is possible to provide additional meta-data tag androidx.watchface.complications.datasource.DEFAULT_CONFIG_SUPPORTED in the service set to "true" to let the system know that the data source is able to provide complication data before it is configured.

  • The manifest entry for the service should also include an android:icon attribute. The icon provided there should be a single-color white icon that represents the complication data source. This icon will be shown in the complication data source chooser interface, and may also be included in ComplicationProviderInfo given to watch faces for display in their configuration activities.

  • The manifest entry should also include android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER" to ensure that only the system can bind to it.

Multiple complication data sources in the same APK are supported but in android R there's a soft limit of 100 data sources per APK. Above that the companion watchface editor won't support this complication data source app.

There's no need to call setDataSource for any the ComplicationData Builders because the system will append this value on your behalf.

Summary

Nested types

Callback for onComplicationRequest where only one of onComplicationData or onComplicationDataTimeline should be called.

Constants

static final @NonNull String

The intent action used to send update requests to the data source.

static final @NonNull String

Category for complication data source config activities.

static final @NonNull String

Extra used to supply the complication id to a complication data source configuration activity.

static final @NonNull String

Extra used to supply the complication type to a complication data source configuration activity.

static final @NonNull String

Extra used to supply the complication data source component to a complication data source configuration activity.

static final @NonNull String

Metadata key used to declare that the complication data source service supports backup and restore (B&R) of complication configuration data.

static final @NonNull String

Metadata key used to declare an action for a configuration activity for a complication data source.

static final @NonNull String

Metadata key.

static final @NonNull String

Metadata key used to request elevated frequency of onComplicationRequests when the watch face is visible and non-ambient.

static final @NonNull String

Metadata key used to declare a list of watch faces that may receive data from a complication data source before they are granted the RECEIVE_COMPLICATION_DATA permission.

static final @NonNull String

Metadata key used to declare supported complication types for safe watch faces.

static final @NonNull String

Metadata key used to declare supported complication types.

static final @NonNull String

Metadata key used to declare the requested frequency of update requests.

Public constructors

Public methods

abstract ComplicationData

A request for representative preview data for the complication, for use in the editor UI.

final IBinder
void
@MainThread
onComplicationActivated(
    int complicationInstanceId,
    @NonNull ComplicationType type
)

Called when a complication is activated.

void
@MainThread
onComplicationDeactivated(int complicationInstanceId)

Called when a complication is deactivated.

abstract void

Called when a complication data update is requested for the given complication id.

void

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face is visible and non-ambient.

void
@MainThread
onStopImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face ceases to be visible and non-ambient.

Inherited methods

From android.content.Context
boolean
final int
getColor(int p0)
final @NonNull ColorStateList
final @Nullable Drawable
getDrawable(int p0)
final @NonNull String
getString(int p0)
final @NonNull String
getString(int p0, @NonNull Object p1)
final @NonNull T
<T extends Object> getSystemService(@NonNull Class<@NonNull T> p0)
final @NonNull CharSequence
getText(int p0)
final @NonNull TypedArray
final @NonNull TypedArray
final @NonNull TypedArray
obtainStyledAttributes(int p0, @NonNull int[] p1)
final @NonNull TypedArray
obtainStyledAttributes(
    @Nullable AttributeSet p0,
    @NonNull int[] p1,
    int p2,
    int p3
)
void
void
sendBroadcastWithMultiplePermissions(
    @NonNull Intent p0,
    @NonNull String[] p1
)
From android.content.ContextWrapper
boolean
bindIsolatedService(
    @NonNull Intent p0,
    int p1,
    @NonNull String p2,
    @NonNull Executor p3,
    @NonNull ServiceConnection p4
)
boolean
boolean
boolean
boolean
bindService(
    @NonNull Intent p0,
    int p1,
    @NonNull Executor p2,
    @NonNull ServiceConnection p3
)
boolean
boolean
bindServiceAsUser(
    @NonNull Intent p0,
    @NonNull ServiceConnection p1,
    int p2,
    @NonNull UserHandle p3
)
int
int
@NonNull int[]
int
int
@NonNull int[]
int
checkPermission(@NonNull String p0, int p1, int p2)
int
int
checkUriPermission(@NonNull Uri p0, int p1, int p2, int p3)
int
checkUriPermission(
    @Nullable Uri p0,
    @Nullable String p1,
    @Nullable String p2,
    int p3,
    int p4,
    int p5
)
@NonNull int[]
checkUriPermissions(@NonNull List<@NonNull Uri> p0, int p1, int p2, int p3)
void

This method is deprecated. Deprecated in Java

@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull Context
@NonNull String[]
boolean
boolean
boolean
void
void
enforceCallingOrSelfUriPermission(
    @NonNull Uri p0,
    int p1,
    @NonNull String p2
)
void
void
void
enforcePermission(@NonNull String p0, int p1, int p2, @Nullable String p3)
void
enforceUriPermission(
    @NonNull Uri p0,
    int p1,
    int p2,
    int p3,
    @NonNull String p4
)
void
enforceUriPermission(
    @Nullable Uri p0,
    @Nullable String p1,
    @Nullable String p2,
    int p3,
    int p4,
    int p5,
    @Nullable String p6
)
@NonNull String[]
@NonNull Context
@NonNull ApplicationInfo
@NonNull AssetManager
@NonNull AttributionSource
@Nullable String
@NonNull Context
@NonNull File
@NonNull ClassLoader
@NonNull File
@NonNull ContentResolver
@NonNull File
@NonNull File
int
@NonNull File
getDir(@NonNull String p0, int p1)
@Nullable Display
@Nullable File
@NonNull File[]
@Nullable File
@NonNull File[]
@NonNull File[]
@NonNull File
@NonNull File
@NonNull Executor
@NonNull Looper
@NonNull File
@NonNull File
@NonNull File[]
@NonNull String
@NonNull String
@NonNull PackageManager
@NonNull String
@NonNull String
@Nullable ContextParams
@NonNull Resources
@NonNull SharedPreferences
@NonNull Object
String
@NonNull Resources.Theme
@NonNull Drawable

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

int

This method is deprecated. Deprecated in Java

void
boolean
boolean
boolean
boolean
boolean
@NonNull FileInputStream
@NonNull FileOutputStream
openFileOutput(@NonNull String p0, int p1)
@NonNull SQLiteDatabase
openOrCreateDatabase(
    @NonNull String p0,
    int p1,
    @NonNull SQLiteDatabase.CursorFactory p2
)
@NonNull SQLiteDatabase
@NonNull Drawable

This method is deprecated. Deprecated in Java

void
void
Intent
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    int p2
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    @Nullable String p2,
    @Nullable Handler p3
)
Intent
registerReceiver(
    @Nullable BroadcastReceiver p0,
    @NonNull IntentFilter p1,
    @Nullable String p2,
    @Nullable Handler p3,
    int p4
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
void
void
void
void
void
void
void
void
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable Bundle p2
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable BroadcastReceiver p2,
    @Nullable Handler p3,
    int p4,
    @Nullable String p5,
    @Nullable Bundle p6
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable Bundle p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable String p1,
    @Nullable String p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void
sendOrderedBroadcast(
    @NonNull Intent p0,
    int p1,
    @Nullable String p2,
    @Nullable String p3,
    @Nullable BroadcastReceiver p4,
    @Nullable Handler p5,
    @Nullable String p6,
    @Nullable Bundle p7,
    @Nullable Bundle p8
)
void
sendOrderedBroadcastAsUser(
    @NonNull Intent p0,
    @NonNull UserHandle p1,
    @Nullable String p2,
    @Nullable BroadcastReceiver p3,
    @Nullable Handler p4,
    int p5,
    @Nullable String p6,
    @Nullable Bundle p7
)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcast(
    @NonNull Intent p0,
    @Nullable BroadcastReceiver p1,
    @Nullable Handler p2,
    int p3,
    @Nullable String p4,
    @Nullable Bundle p5
)

This method is deprecated. Deprecated in Java

void
sendStickyOrderedBroadcastAsUser(
    @NonNull Intent p0,
    @NonNull UserHandle p1,
    @Nullable BroadcastReceiver p2,
    @Nullable Handler p3,
    int p4,
    @Nullable String p5,
    @Nullable Bundle p6
)

This method is deprecated. Deprecated in Java

void
setTheme(int p0)
void

This method is deprecated. Deprecated in Java

void

This method is deprecated. Deprecated in Java

void
startActivities(@NonNull Intent[] p0)
void
startActivities(@NonNull Intent[] p0, @Nullable Bundle p1)
void
void
@Nullable ComponentName
boolean
startInstrumentation(
    @NonNull ComponentName p0,
    @Nullable String p1,
    @Nullable Bundle p2
)
void
startIntentSender(
    @NonNull IntentSender p0,
    @Nullable Intent p1,
    int p2,
    int p3,
    int p4
)
void
startIntentSender(
    @NonNull IntentSender p0,
    @Nullable Intent p1,
    int p2,
    int p3,
    int p4,
    @Nullable Bundle p5
)
@Nullable ComponentName
boolean
void
void
void
void
void
updateServiceGroup(@NonNull ServiceConnection p0, int p1, int p2)
From android.app.Service
void
void
dump(
    @NonNull FileDescriptor p0,
    @NonNull PrintWriter p1,
    @NonNull String[] p2
)
final @NonNull Application
final int
void
void
void
void
void
void
onStart(@NonNull Intent p0, int p1)

This method is deprecated. Deprecated in Java

int
onStartCommand(@NonNull Intent p0, int p1, int p2)
void
void
onTimeout(int p0)
void
onTrimMemory(int p0)
boolean
final void
final void
startForeground(int p0, @NonNull Notification p1, int p2)
final void
stopForeground(boolean p0)

This method is deprecated. Deprecated in Java

final void
final void
final void
stopSelf(int p0)
final boolean

Constants

ACTION_COMPLICATION_UPDATE_REQUEST

public static final @NonNull String ACTION_COMPLICATION_UPDATE_REQUEST

The intent action used to send update requests to the data source. ComplicationDataSourceService must declare an intent filter for this action in the manifest.

CATEGORY_DATA_SOURCE_CONFIG

public static final @NonNull String CATEGORY_DATA_SOURCE_CONFIG

Category for complication data source config activities. The configuration activity for a complication complication data source must specify this category in its intent filter.

EXTRA_CONFIG_COMPLICATION_ID

public static final @NonNull String EXTRA_CONFIG_COMPLICATION_ID

Extra used to supply the complication id to a complication data source configuration activity.

EXTRA_CONFIG_COMPLICATION_TYPE

public static final @NonNull String EXTRA_CONFIG_COMPLICATION_TYPE

Extra used to supply the complication type to a complication data source configuration activity.

EXTRA_CONFIG_DATA_SOURCE_COMPONENT

public static final @NonNull String EXTRA_CONFIG_DATA_SOURCE_COMPONENT

Extra used to supply the complication data source component to a complication data source configuration activity.

METADATA_KEY_CONFIG_RESTORE_SUPPORTED

@RequiresApi(value = 34)
public static final @NonNull String METADATA_KEY_CONFIG_RESTORE_SUPPORTED

Metadata key used to declare that the complication data source service supports backup and restore (B&R) of complication configuration data. The system is responsible for backup and restore of the assignment of complications to watch faces, but responsibility for backup and restore for any complication data source configuration data is left to the data source.

If this flag is set to false, then the system will restore any complications using this provider in the "not configured" state, i.e. the complication will show a + sign with a tap action leading to the complication data source's configuration action as defined by METADATA_KEY_DATA_SOURCE_CONFIG_ACTION, instead of real data.

This is a boolean value, defaulting to true, which means apps are opted in by default but can explicitly opt out by setting this meta-data tag to false.

The value is ignored (equivalent to false) if the app does not enable Android B&R ( https://developer.android.com/guide/topics/data/backup). This value is also ignored prior to Android U.

METADATA_KEY_DATA_SOURCE_CONFIG_ACTION

public static final @NonNull String METADATA_KEY_DATA_SOURCE_CONFIG_ACTION

Metadata key used to declare an action for a configuration activity for a complication data source.

A ComplicationDataSourceService can include a meta-data tag with this name in its manifest entry to cause a configuration activity to be shown when the complication data source is selected.

The configuration activity must reside in the same package as the complication data source, and must register an intent filter for the action specified here, including CATEGORY_DATA_SOURCE_CONFIG as well as Intent.CATEGORY_DEFAULT as categories.

The complication id being configured will be included in the intent that starts the config activity using the extra key EXTRA_CONFIG_COMPLICATION_ID.

The complication type that will be requested from the complication data source will also be included, using the extra key EXTRA_CONFIG_COMPLICATION_TYPE.

The complication data source's ComponentName will also be included in the intent that starts the config activity, using the extra key EXTRA_CONFIG_DATA_SOURCE_COMPONENT.

The config activity must call Activity.setResult with either Activity.RESULT_OK or Activity.RESULT_CANCELED before it is finished, to tell the system whether or not the complication data source should be set on the given complication.

METADATA_KEY_DATA_SOURCE_DEFAULT_CONFIG_SUPPORTED

public static final @NonNull String METADATA_KEY_DATA_SOURCE_DEFAULT_CONFIG_SUPPORTED

Metadata key. Setting to "true" indicates to the system that this complication data source with a PROVIDER_CONFIG_ACTION metadata tag is able to provide complication data before it is configured. See METADATA_KEY_DATA_SOURCE_CONFIG_ACTION.

METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS

public static final @NonNull String METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS

Metadata key used to request elevated frequency of onComplicationRequests when the watch face is visible and non-ambient.

To do this ComplicationDataSourceService should include a meta-data tag with this name in its manifest entry. The value of this tag is the number of milliseconds the complication data source would like to elapse between onComplicationRequests requests when the watch face is visible and non-ambient.

Note in addition to this meta-data, the data source must also request the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE.

Note that update requests are not guaranteed to be sent with this frequency and a lower limit exists (initially 1 second).

METADATA_KEY_SAFE_WATCH_FACES

public static final @NonNull String METADATA_KEY_SAFE_WATCH_FACES

Metadata key used to declare a list of watch faces that may receive data from a complication data source before they are granted the RECEIVE_COMPLICATION_DATA permission. This allows the listed watch faces to set the complication data source as a default and have the complication populate when the watch face is first seen.

Only trusted watch faces that will set this complication data source as a default should be included in this list.

Note that if a watch face is in the same app package as the complication data source, it does not need to be added to this list.

The value of this tag should be a comma separated list of watch faces or packages. An entry can be a flattened component, as if ComponentName.flattenToString had been called, to declare a specific watch face as safe. An entry can also be a package name, as if ComponentName.getPackageName had been called, in which case any watch face under the app with that package name will be considered safe for this complication data source.

From Android T, if this provider has the privileged permission com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE, then ComplicationRequest.isForSafeWatchFace will be populated.

METADATA_KEY_SAFE_WATCH_FACE_SUPPORTED_TYPES

public static final @NonNull String METADATA_KEY_SAFE_WATCH_FACE_SUPPORTED_TYPES

Metadata key used to declare supported complication types for safe watch faces.

Gated behind the privileged permission `com.google.wear.permission.GET_IS_FOR_SAFE_WATCH_FACE', this overrides the METADATA_KEY_SUPPORTED_TYPES list for 'safe' watch faces. I.e. watch faces in the METADATA_KEY_SAFE_WATCH_FACES metadata list.

This means for example trusted watch faces could receive ComplicationType.SHORT_TEXT and untrusted ones ComplicationType.MONOCHROMATIC_IMAGE.

METADATA_KEY_SUPPORTED_TYPES

public static final @NonNull String METADATA_KEY_SUPPORTED_TYPES

Metadata key used to declare supported complication types.

A ComplicationDataSourceService must include a meta-data tag with this name in its manifest entry. The value of this tag should be a comma separated list of types supported by the complication data source. Types should be given as named as per the type fields in the ComplicationData, but omitting the "TYPE_" prefix, e.g. SHORT_TEXT, LONG_TEXT, RANGED_VALUE.

The order of types in METADATA_KEY_SUPPORTED_TYPES has no significance. During complication data source selection, each item in the complication slot's supported types is checked against entries in the data source's METADATA_KEY_SUPPORTED_TYPES and the first matching entry from the slot's support types (if any) is chosen. If there are no matches then this data source is not eligible to be selected in that slot.

For example, a complication data source that supports the RANGED_VALUE, SHORT_TEXT, and ICON type would include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
android:value="RANGED_VALUE,SHORT_TEXT,ICON" />

METADATA_KEY_UPDATE_PERIOD_SECONDS

public static final @NonNull String METADATA_KEY_UPDATE_PERIOD_SECONDS

Metadata key used to declare the requested frequency of update requests.

A ComplicationDataSourceService should include a meta-data tag with this name in its manifest entry. The value of this tag is the number of seconds the complication data source would like to elapse between update requests.

Note that update requests are not guaranteed to be sent with this frequency.

If a complication data source never needs to receive update requests beyond the one sent when a complication is activated, the value of this tag should be 0.

For example, a complication data source that would like to update every ten minutes should include the following in its manifest entry:

<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="600" />

Public constructors

ComplicationDataSourceService

Added in 1.0.0
public ComplicationDataSourceService()

Public methods

getPreviewData

Added in 1.0.0
public abstract ComplicationData getPreviewData(@NonNull ComplicationType type)

A request for representative preview data for the complication, for use in the editor UI. Preview data is assumed to be static per type. E.g. for a complication that displays the date and time of an event, rather than returning the real time it should return a fixed date and time such as 10:10 Aug 1st. This data may be cached by the system and the result should be constant based on the current locale.

This will be called on a background thread.

Parameters
@NonNull ComplicationType type

The type of complication preview data requested.

Returns
ComplicationData

Preview data for the given complication type.

onBind

Added in 1.0.0
public final IBinder onBind(@NonNull Intent intent)

onComplicationActivated

Added in 1.0.0
@MainThread
public void onComplicationActivated(
    int complicationInstanceId,
    @NonNull ComplicationType type
)

Called when a complication is activated.

This occurs when the watch face calls setActiveComplications, or when this data source is chosen for a complication which is already active.

This will usually be followed by a call to onComplicationRequest.

This will be called on the main thread.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

@NonNull ComplicationType type

The ComplicationType of the activated slot.

onComplicationDeactivated

Added in 1.0.0
@MainThread
public void onComplicationDeactivated(int complicationInstanceId)

Called when a complication is deactivated.

This occurs when the current watch face changes, or when the watch face calls setActiveComplications and does not include the given complication (usually because the watch face has stopped displaying it).

This will be called on the main thread.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

onComplicationRequest

Added in 1.0.0
@MainThread
public abstract void onComplicationRequest(
    @NonNull ComplicationRequest request,
    @NonNull ComplicationDataSourceService.ComplicationRequestListener listener
)

Called when a complication data update is requested for the given complication id.

In response to this request the result callback should be called with the data to be displayed. If the request can not be fulfilled or no update is needed then null should be passed to the callback.

The callback doesn't have be called within onComplicationRequest but it should be called soon after. If this does not occur within around 20 seconds (exact timeout length subject to change), then the system will unbind from this service which may cause your eventual update to not be received. However if ComplicationRequest.immediateResponseRequired is true then provider should try to deliver the response in under 100 milliseconds, if false the deadline is 20 seconds. ComplicationRequest.immediateResponseRequired will only ever be true if METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has the privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, and the complication is visible and non-ambient.

Parameters
@NonNull ComplicationRequest request

The details about the complication that has been requested.

@NonNull ComplicationDataSourceService.ComplicationRequestListener listener

The callback to pass the result to the system.

onStartImmediateComplicationRequests

Added in 1.1.0
@MainThread
public void onStartImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face is visible and non-ambient. A series of onComplicationRequests will follow where ComplicationRequest.immediateResponseRequired is true, ending with a call to onStopImmediateComplicationRequests.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.

onStopImmediateComplicationRequests

Added in 1.1.0
@MainThread
public void onStopImmediateComplicationRequests(int complicationInstanceId)

If a metadata key with METADATA_KEY_IMMEDIATE_UPDATE_PERIOD_MILLISECONDS is present in the manifest, and the provider has privileged permission com.google.android.wearable.permission.USE_IMMEDIATE_COMPLICATION_UPDATE, then onStartImmediateComplicationRequests will be called when the watch face ceases to be visible and non-ambient. No subsequent calls to onComplicationRequest where ComplicationRequest.immediateResponseRequired is true will be made unless the complication becomes visible and non-ambient again.

Parameters
int complicationInstanceId

The system's ID for the complication. Note this ID is distinct from the complication slot used by the watch face itself.