Google is committed to advancing racial equity for Black communities. See how.

ComplicationProviderService

abstract class ComplicationProviderService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ androidx.wear.complications.ComplicationProviderService

Class for providers of complication data.

A provider service must implement onComplicationUpdate 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 ComplicationProviderService must include a meta-data tag with android.support.wearable.complications.SUPPORTED_TYPES in its manifest entry. The value of this tag should be a comma separated list of types supported by the provider. Types should be given as named as per the type fields in the , but omitting the "TYPE_" prefix, e.g. SHORT_TEXT, LONG_TEXT, RANGED_VALUE.

    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 provider 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"/>
    A ComplicationProviderService should include a meta-data tag with android.support.wearable.complications.UPDATE_PERIOD_SECONDS its manifest entry. The value of this tag is the number of seconds the provider would like to elapse between update requests.

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

    If a provider 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 provider 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"/>
    A ComplicationProviderService 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 provider is selected.

    The configuration activity must reside in the same package as the provider, 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.

    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 provider will also be included, using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_TYPE.

    The provider'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 or Activity#RESULT_CANCELED before it is finished, to tell the system whether or not the provider should be set on the given complication. 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 provider. This icon will be shown in the provider chooser interface, and may also be included in 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.

Summary

Nested classes
abstract

Callback for onComplicationUpdate.

Constants
static String

The intent action used to send update requests to the provider.

static String

Category for provider config activities.

static String

Extra used to supply the complication id to a provider configuration activity.

static String

Extra used to supply the complication type to a provider configuration activity.

static String

Extra used to supply the provider component to a provider configuration activity.

static String

Metadata key used to declare an action for a configuration activity for a provider.

static String

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

static String

Metadata key used to declare supported complication types.

static String

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

Public constructors

Class for providers of complication data.

Public methods
abstract ComplicationData?

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

open IBinder?
onBind(@NonNull intent: Intent)

open Unit
onComplicationActivated(complicationId: Int, type: Int)

Called when a complication is activated.

open Unit
onComplicationDeactivated(complicationId: Int)

Called when a complication is deactivated.

abstract Unit
onComplicationUpdate(complicationId: Int, @NonNull type: ComplicationType, @NonNull resultCallback: ComplicationProviderService.ComplicationUpdateCallback)

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

Constants

ACTION_COMPLICATION_UPDATE_REQUEST

static val ACTION_COMPLICATION_UPDATE_REQUEST: String

The intent action used to send update requests to the provider. Complication provider services must declare an intent filter for this action in the manifest.

Value: "android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"

CATEGORY_PROVIDER_CONFIG_ACTION

static val CATEGORY_PROVIDER_CONFIG_ACTION: String

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

Value: "android.support.wearable.complications.category.PROVIDER_CONFIG"

EXTRA_CONFIG_COMPLICATION_ID

static val EXTRA_CONFIG_COMPLICATION_ID: String

Extra used to supply the complication id to a provider configuration activity.

Value: "android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_ID"

EXTRA_CONFIG_COMPLICATION_TYPE

static val EXTRA_CONFIG_COMPLICATION_TYPE: String

Extra used to supply the complication type to a provider configuration activity.

Value: "android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_TYPE"

EXTRA_CONFIG_PROVIDER_COMPONENT

static val EXTRA_CONFIG_PROVIDER_COMPONENT: String

Extra used to supply the provider component to a provider configuration activity.

Value: "android.support.wearable.complications.EXTRA_CONFIG_PROVIDER_COMPONENT"

METADATA_KEY_PROVIDER_CONFIG_ACTION

static val METADATA_KEY_PROVIDER_CONFIG_ACTION: String

Metadata key used to declare an action for a configuration activity for a provider.

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

The configuration activity must reside in the same package as the provider, and must register an intent filter for the action specified here, including 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 provider will also be included, using the extra key EXTRA_CONFIG_COMPLICATION_TYPE.

The provider's ComponentName will also be included in the intent that starts the config activity, using the extra key EXTRA_CONFIG_PROVIDER_COMPONENT.

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

Value: "android.support.wearable.complications.PROVIDER_CONFIG_ACTION"

METADATA_KEY_SAFE_WATCH_FACES

static val METADATA_KEY_SAFE_WATCH_FACES: String

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

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

Note that if a watch face is in the same app package as the provider, 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 had been called, in which case any watch face under the app with that package name will be considered safe for this provider.

Value: "android.support.wearable.complications.SAFE_WATCH_FACES"

METADATA_KEY_SUPPORTED_TYPES

static val METADATA_KEY_SUPPORTED_TYPES: String

Metadata key used to declare supported complication types.

A ComplicationProviderService 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 provider. Types should be given as named as per the type fields in the , but omitting the "TYPE_" prefix, e.g. SHORT_TEXT, LONG_TEXT, RANGED_VALUE.

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 provider 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"/>
Value: "android.support.wearable.complications.SUPPORTED_TYPES"

METADATA_KEY_UPDATE_PERIOD_SECONDS

static val METADATA_KEY_UPDATE_PERIOD_SECONDS: String

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

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

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

If a provider 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 provider 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"/>
Value: "android.support.wearable.complications.UPDATE_PERIOD_SECONDS"

Public constructors

<init>

ComplicationProviderService()

Class for providers of complication data.

A provider service must implement onComplicationUpdate 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 ComplicationProviderService must include a meta-data tag with android.support.wearable.complications.SUPPORTED_TYPES in its manifest entry. The value of this tag should be a comma separated list of types supported by the provider. Types should be given as named as per the type fields in the , but omitting the "TYPE_" prefix, e.g. SHORT_TEXT, LONG_TEXT, RANGED_VALUE.

    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 provider 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"/>
    A ComplicationProviderService should include a meta-data tag with android.support.wearable.complications.UPDATE_PERIOD_SECONDS its manifest entry. The value of this tag is the number of seconds the provider would like to elapse between update requests.

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

    If a provider 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 provider 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"/>
    A ComplicationProviderService 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 provider is selected.

    The configuration activity must reside in the same package as the provider, 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.

    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 provider will also be included, using the extra key android.support.wearable.complications.EXTRA_CONFIG_COMPLICATION_TYPE.

    The provider'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 or Activity#RESULT_CANCELED before it is finished, to tell the system whether or not the provider should be set on the given complication. 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 provider. This icon will be shown in the provider chooser interface, and may also be included in 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.

Public methods

getPreviewData

@Nullable abstract fun getPreviewData(@NonNull type: ComplicationType): ComplicationData?

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 will be called on a background thread.

Parameters
type ComplicationType: The type of complication preview data requested.
Return
ComplicationData? Preview data for the given complication type.

onBind

@Nullable open fun onBind(@NonNull intent: Intent): IBinder?

onComplicationActivated

@UiThread open fun onComplicationActivated(
    complicationId: Int,
    type: Int
): Unit

Called when a complication is activated.

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

This will usually be followed by a call to onComplicationUpdate.

This will be called on the main thread.

onComplicationDeactivated

@UiThread open fun onComplicationDeactivated(complicationId: Int): Unit

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.

onComplicationUpdate

@UiThread abstract fun onComplicationUpdate(
    complicationId: Int,
    @NonNull type: ComplicationType,
    @NonNull resultCallback: ComplicationProviderService.ComplicationUpdateCallback
): Unit

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 onComplicationUpdate 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.

Parameters
complicationId Int: The id of the requested complication. Note this ID is distinct from ids used by the watch face itself.
type ComplicationType: The type of complication data requested.
resultCallback ComplicationProviderService.ComplicationUpdateCallback: The callback to pass the result to the system.