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

WatchFaceConfigIntentHelper

class WatchFaceConfigIntentHelper
kotlin.Any
   ↳ androidx.wear.remote.interactions.WatchFaceConfigIntentHelper

Helper functions for use by watch face configuration activities. In general, there are two distinct users:

  • ones creating Intents
  • ones receiving and responding to those Intents.

To register a configuration activity for a watch face, add a <meta-data> entry to the watch face component in its Android Manifest file with an intent action to be fired to start the activity. The following meta-data will register the com.example.watchface.CONFIG_DIGITAL action to be started when configuring a watch face on the wearable device:

&lt;meta-data
android:name="com.google.android.wearable.watchface.wearableConfigurationAction"
android:value="com.example.watchface.CONFIG_DIGITAL" /&gt;

To register a configuration activity to be started on a companion phone, add the following alternative meta-data entry to the watch face component:

&lt;meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
android:value="com.example.watchface.CONFIG_DIGITAL" /&gt;

The activity should have an intent filter which lists the action specified in the meta-data block above, in addition to the two categories present in the following example:

&lt;activity android:name=".MyWatchFaceConfigActivity"&gt;
&lt;intent-filter&gt;
&lt;action android:name="com.example.watchface.CONFIG_DIGITAL" /&gt;
&lt;category android:name=
"com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION" /&gt;
&lt;category android:name="android.intent.category.DEFAULT" /&gt;
&lt;/intent-filter&gt;
&lt;/activity&gt;

For phone side configuration activities, substitute the category com.google.android.wearable.watchface.category.COMPANION_CONFIGURATION for com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION.

Summary

Companion functions
String?
getPeerIdExtra(watchFaceIntent: Intent)

This method is for retrieving the ID of the currently connected device from the given Intent.

ComponentName?

This method is for retrieving the extended data of watch face ComponentName from the given Intent.

Intent
putPeerIdExtra(watchFaceIntent: Intent, peerId: String)

This method is adding the ID of the currently connected device to the given Intent.

Intent
putWatchFaceComponentExtra(watchFaceIntent: Intent, componentName: ComponentName)

This method is for adding the extended data of watch face ComponentName to the given Intent.

Companion functions

getPeerIdExtra

@JvmStatic @Nullable fun getPeerIdExtra(watchFaceIntent: Intent): String?

This method is for retrieving the ID of the currently connected device from the given Intent.

Parameters
watchFaceIntent: Intent The intent holding config activity launch.
Return
the value of an item previously added with putPeerIdExtra, or null if no value was found.

getWatchFaceComponentExtra

@JvmStatic @Nullable fun getWatchFaceComponentExtra(watchFaceIntent: Intent): ComponentName?

This method is for retrieving the extended data of watch face ComponentName from the given Intent. ComponentName is being used to identify the APK and the class of the watch face service.

Parameters
watchFaceIntent: Intent The intent holding config activity launch.
Return
the value of an item previously added with putWatchFaceComponentExtra, or null if no value was found.

putPeerIdExtra

@JvmStatic @NonNull fun putPeerIdExtra(
    watchFaceIntent: Intent,
    peerId: String
): Intent

This method is adding the ID of the currently connected device to the given Intent.

Parameters
watchFaceIntent: Intent The intent holding config activity launch.
peerId: String The string representing peer ID to be added as an extra.

putWatchFaceComponentExtra

@JvmStatic @NonNull fun putWatchFaceComponentExtra(
    watchFaceIntent: Intent,
    componentName: ComponentName
): Intent

This method is for adding the extended data of watch face ComponentName to the given Intent.

Parameters
watchFaceIntent: Intent The intent holding config activity launch.
componentName: ComponentName The component name of the watch face to be added as an extra.