Android 12 Developer Preview is here! Try it out, and give us your feedback!

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.

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

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

static val CATEGORY_PROVIDER_CONFIG: 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_C