This module provides the capability of managing watch faces on wearables. Your app can call the APIs in this module to add watch faces to wearables and generate preview images for watch face configurations.
Since: 26.0.1
isWatchFaceSupport(): Promise<boolean>
Checks whether the current device supports the APIs related to watch faces. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
Returns
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the check result. The value true indicates that the function is supported, and the value false indicates that the function is not supported. |
Example:
import { watchFace } from '@kit.WearEngine';
import { BusinessError } from '@kit.BasicServicesKit';
watchFace.isWatchFaceSupport().then((isSupport: boolean) => {
console.info(`Succeeded in checking watch face support, result is ${isSupport}.`);
}).catch((error: BusinessError) => {
console.error(`Failed to check watch face support. Code is ${error.code}, message is ${error.message}.`);
}) getWatchFaceManager(context: common.UIAbilityContext): WatchFaceManager
Obtains a WatchFaceManager instance.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| context | common.UIAbilityContext | Yes | Ability context. |
Returns
| Type | Description |
|---|---|
| WatchFaceManager | WatchFaceManager instance. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
Example:
import { watchFace } from '@kit.WearEngine';
let watchFaceManager: watchFace.WatchFaceManager = watchFace.getWatchFaceManager(this.getUIContext().getHostContext());
console.info(`Succeeded in getting watch face manager.`); Watch face management class, which is returned by watchFace.getWatchFaceManager.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
addWatchFace(config: WatchFaceConfigUnion): Promise<void>
Adds a watch face to a wearable. This API uses a promise to return the result.
System capability: SystemCapability.Health.WatchFace
Model restriction: This API can be used only in the stage model.
Since: 26.0.1
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| config | WatchFaceConfigUnion | Yes | Watch face configuration. |
Returns
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
Example:
import { watchFace } from '@kit.WearEngine';
import { BusinessError } from '@kit.BasicServicesKit';
let watchFaceManager: watchFace.WatchFaceManager = watchFace.getWatchFaceManager(this.getUIContext().getHostContext());
// Construct the watch face configuration of the vibrant style.
let config: watchFace.WatchFaceConfigUnion = {
defaultStyle: watchFace.Style.VIBRANT,
isCurrentAppFormsOnly: true
}
// Add the watch face to the wearable.
watchFaceManager.addWatchFace(config).then(() => {
console.info(`Succeeded in adding watch face.`);
}).catch((error: BusinessError) => {
console.error(`Failed to add watch face. Code is ${error.code}, message is ${error.message}.`);
}) generatePreviews(configs: WatchFaceConfigUnion[]): Promise<image.PixelMap[]>
Generates a preview image based on the input watch face configuration array. This API uses a promise to return the result.
System capability: SystemCapability.Health.WatchFace
Model restriction: This API can be used only in the stage model.
Since: 26.0.1
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| configs | WatchFaceConfigUnion[] | Yes | Watch face configuration array. |
Returns
| Type | Description |
|---|---|
| Promise<image.PixelMap[]> | Promise used to return the preview image. The returned PixelMap object is managed by the caller. After using the object, call release() in a timely manner to release resources to prevent memory leaks on wearables with limited memory. |
Error codes:
For details about the error codes, please refer to Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
Example:
import { watchFace } from '@kit.WearEngine';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
let watchFaceManager: watchFace.WatchFaceManager = watchFace.getWatchFaceManager(this.getUIContext().getHostContext());
// Construct multiple watch face configurations.
let configs: watchFace.WatchFaceConfigUnion[] = [
{
defaultStyle: watchFace.Style.VIBRANT,
containers: {
[watchFace.Position.TOP_LEFT]: {
options: [watchFace.ContainerOption1x1.STEPS]
},
[watchFace.Position.BOTTOM_LEFT]: {
options: [watchFace.ContainerOption2x2.BATTERY]
}
}
},
{
defaultStyle: watchFace.Style.CLASSIC
}
]
// Generate a preview image for the watch face configuration.
watchFaceManager.generatePreviews(configs).then((previews: image.PixelMap[]) => {
console.info(`Succeeded in generating previews, number is ${previews.length}.`);
previews.forEach((preview: image.PixelMap) => {
// Release the PixelMap resources after use to prevent memory leaks.
preview.release();
})
}).catch((error: BusinessError) => {
console.error(`Failed to generate previews. Code is ${error.code}, message is ${error.message}.`);
}) type WatchFaceConfigUnion = VibrantWatchFaceConfig | ClassicWatchFaceConfig
Union type of watch face styles.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Type | Description |
|---|---|
| VibrantWatchFaceConfig | Watch face configuration of the vibrant style. |
| ClassicWatchFaceConfig | Watch face configuration of the classic style. |
Watch face configuration of the vibrant style.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| defaultStyle | Style.VIBRANT | No | No | Default style of the watch face. |
| containers | VibrantContainersConfig | No | Yes | Container configuration of the vibrant style. If this parameter is not set, the default configuration is used. |
| isCurrentAppFormsOnly | boolean | No | Yes | Indicates whether to display only the 2 × 2 widget of the current third-party app. The value true indicates that only the 2 × 2 widget of the current third-party app is displayed, and the value false indicates that other widgets are displayed after the user taps to enter the customization screen. |
Watch face configuration of the classic style.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| defaultStyle | Style.CLASSIC | No | No | Default style of the watch face. |
| containers | ClassicContainersConfig | No | Yes | Container configuration of the classic style. If this parameter is not set, the default configuration is used. |
| isCurrentAppFormsOnly | boolean | No | Yes | Indicates whether to display only the 2 × 2 component of the current third-party app. The value true indicates that only the 2 × 2 widget of the current third-party app is displayed, and the value false indicates that other widgets are displayed after the user taps to enter the customization screen. |
Enumeration of watch face styles.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Value | Description |
|---|---|---|
| VIBRANT | 2 | Vibrant style. |
| CLASSIC | 3 | Classic style. |
Enumeration of watch face container positions.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Value | Description |
|---|---|---|
| TOP_LEFT | 'top_left' | Upper left position. |
| TOP_CENTER | 'top_center' | Upper middle position. |
| TOP_RIGHT | 'top_right' | Upper right position. |
| MIDDLE_LEFT | 'middle_left' | Middle left position. |
| MIDDLE_CENTER | 'middle_center' | Middle position. |
| MIDDLE_RIGHT | 'middle_right' | Middle right position. |
| BOTTOM_LEFT | 'bottom_left' | Lower left position. |
| BOTTOM_CENTER | 'bottom_center' | Lower middle position. |
| BOTTOM_RIGHT | 'bottom_right' | Lower right position. |
Component container configuration class of the vibrant style.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| Position.TOP_LEFT | ContainerConfig1x1 | No | Yes | Container configuration in the upper left position. If this parameter is not set, the default configuration is used. |
| Position.BOTTOM_LEFT | ContainerConfig2x2 | No | Yes | Container configuration in the lower left position. If this parameter is not set, the default configuration is used. |
| Position.MIDDLE_RIGHT | ContainerConfig1x1 | No | Yes | Container configuration in the middle right position. If this parameter is not set, the default configuration is used. |
| Position.BOTTOM_RIGHT | ContainerConfig1x1 | No | Yes | Container configuration in the lower right position. If this parameter is not set, the default configuration is used. |
Component container configuration class of the classic style.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| Position.BOTTOM_LEFT | ContainerConfig2x2 | No | Yes | Container configuration in the lower left position. If this parameter is not set, the default configuration is used. |
| Position.MIDDLE_RIGHT | ContainerConfig1x1 | No | Yes | Container configuration in the middle right position. If this parameter is not set, the default configuration is used. |
| Position.BOTTOM_RIGHT | ContainerConfig1x1 | No | Yes | Container configuration in the lower right position. If this parameter is not set, the default configuration is used. |
1 × 1 control container configuration class.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| defaultOptions | ContainerOption1x1 | No | Yes | Default component container options. If this parameter is not specified, the first option in options is used. |
| options | ContainerOption1x1[] | No | Yes | Options of the component container. |
2 × 2 component container configuration class.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| defaultForm | FormInfo | No | Yes | Default component container options. You can specify a widget as the default component container. If this parameter is not specified, the value of defaultOptions is used. |
| defaultOptions | ContainerOption2x2 | No | Yes | Default component container options. If this parameter is not specified, the first option in options is used. |
| options | ContainerOption2x2[] | No | Yes | Options of the component container. |
The defaultForm and defaultOptions parameters are mutually exclusive. If both are provided, defaultForm takes precedence.
Widget information class. For details, please refer to Form Kit Introduction.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| moduleName | string | No | No | Module to which the widget belongs. |
| abilityName | string | No | No | Ability to which the widget is redirected. |
| name | string | No | No | Widget name. |
Options available for the 1 × 1 component container.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Value | Description |
|---|---|---|
| WORKOUT | 7 | Workout icon, which can be tapped to go to the corresponding app screen. |
| WORKOUT_RECORDS | 8 | Workout record, which can be tapped to go to the corresponding data screen. |
| VO2MAX | 9 | Maximum oxygen uptake (VO2 max) data, which can be tapped to go to the corresponding data screen. |
| ACTIVITY_RECORDS | 10 | Activity record progress, which can be tapped to go to the corresponding data screen. |
| MOVEMENT | 11 | Activity data, which can be tapped to go to the corresponding data screen. |
| EXERCISE | 12 | Workout data, which can be tapped to go to the corresponding data screen. |
| STAND | 13 | Standing time data, which can be tapped to go to the corresponding data screen. |
| STEPS | 14 | Step count data, which can be tapped to go to the corresponding data screen. |
| EMOTIONS | 15 | Emotion data, which can be tapped to go to the corresponding data screen. |
| STRESS_VALUE | 16 | Stress value data, which can be tapped to go to the corresponding data screen. |
| HEART_RATE_VALUE | 17 | Heart rate value data, which can be tapped to go to the corresponding data screen. |
| SPO2 | 18 | SpO2 data, which can be tapped to go to the corresponding data screen. |
| SLEEP_DURATION | 19 | Sleep duration data, which can be tapped to go to the corresponding data screen. |
| 20 | WeChat icon, which can be tapped to go to WeChat. | |
| ALIPAY | 21 | Alipay icon, which can be tapped to go to Alipay. |
| TEMP | 22 | Temperature data, which can be tapped to go to the corresponding data screen. |
| AQI | 23 | Air quality index (AQI) data, which can be tapped to go to the corresponding data screen. |
| UV_INDEX | 24 | UV data, which can be tapped to go to the corresponding data screen. |
| SUNRISE_SUNSET | 25 | Sunrise/Sunset time and data, which can be tapped to go to the corresponding data screen. |
| MOONRISE_MOONSET | 26 | Moonrise/Moonset time and data, which can be tapped to go to the corresponding data screen. |
| MOON_PHASE | 27 | Moon phase data, which can be tapped to go to the corresponding data screen. |
| ALTITUDE | 28 | Altitude data, which can be tapped to go to the corresponding data screen. |
| AIR_PRESSURE | 29 | Atmospheric pressure data, which can be tapped to go to the corresponding data screen. |
| DATE | 30 | Date data, which can be tapped to go to the corresponding data screen. |
| LUNAR_DATE | 32 | Lunar calendar date data, which can be tapped to go to the corresponding data screen. |
| WORLD_CLOCK | 33 | World clock data, which can be tapped to go to the corresponding data screen. |
| STOPWATCH | 34 | Stopwatch icon, which can be tapped to go to the corresponding app screen. |
| TIMER | 35 | Timer icon, which can be tapped to go to the corresponding app screen. |
| ALARM | 36 | Alarm icon, which can be tapped to go to the corresponding app screen. |
| COMPASS | 37 | Compass icon, which can be tapped to go to the corresponding app screen. |
| BATTERY | 38 | Battery level data, which can be tapped to go to the corresponding data screen. |
| WECHAT_PAY | 76 | WeChat Pay icon, which can be tapped to go to the WeChat Pay screen. |
Options available for the 2 × 2 component container.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Health.WatchFace
Since: 26.0.1
| Name | Value | Description |
|---|---|---|
| WORKOUT | 59 | Workout data, which can be tapped to go to the corresponding data screen. |
| RECOVERY | 60 | Recovery progress data, which can be tapped to go to the corresponding data screen. |
| ACTIVITY_RECORDS | 61 | Activity record progress, which can be tapped to go to the corresponding data screen. |
| ACTIVITY_DATA | 62 | Activity data, which can be tapped to go to the corresponding data screen. |
| EMOTIONS | 63 | Emotion data, which can be tapped to go to the corresponding data screen. |
| STRESS_LEVEL | 64 | Stress value data, which can be tapped to go to the corresponding data screen. |
| HEART_RATE_VALUE | 65 | Heart rate value data, which can be tapped to go to the corresponding data screen. |
| SPO2 | 66 | SpO2 data, which can be tapped to go to the corresponding data screen. |
| RECENT_SLEEP | 67 | Recent sleep data, which can be tapped to go to the corresponding data screen. |
| MEDIA_PLAYER | 68 | Media player data, which can be tapped to go to the corresponding data screen. |
| TODAY_WEATHER | 69 | Today's weather data, which can be tapped to go to the corresponding data screen. |
| MOON_PHASE | 70 | Moon phase data, which can be tapped to go to the corresponding data screen. |
| WEATHER_COMBO | 71 | Weather combo data, which can be tapped to go to the corresponding data screen. |
| UPCOMING_EVENTS | 72 | Upcoming event data, which can be tapped to go to the corresponding data screen. |
| BATTERY | 73 | Battery level data, which can be tapped to go to the corresponding data screen. |
| CUTE_PET_MYSTERY_BOX | 74 | Random animation of adorable pets. |
| EMOTIONAL_PET | 75 | Adorable pet animation based on the user's mood, which can be tapped to go to the corresponding data screen. |