本模块提供运动场景化服务。
起始版本: 5.0.0(12)
import { healthService } from '@kit.HealthServiceKit';
此模块为healthService子模块,需通过healthService.workout方式使用。
实时三环数据。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.0.0(12)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| steps | number | 否 | 否 | 步数。 |
| stepsGoal | number | 否 | 是 | 步数目标(若未设置过,无法读取到运动健康App中展示的默认目标)。 |
| activeCalories | number | 否 | 否 | 活动热量。 单位:cal |
| activeCaloriesGoal | number | 否 | 是 | 活动热量目标,默认值为运动健康App中展示的默认目标。 单位:cal |
| exercise | number | 否 | 否 | 锻炼时长。 单位:min |
| exerciseGoal | number | 否 | 是 | 锻炼时长目标,默认值为运动健康App中展示的默认目标。 单位:min |
| activeHours | number | 否 | 否 | 活动小时数(某个小时时段内进行身体活动超过一分钟,该时段被标记为活动小时)。 |
| activeHoursGoal | number | 否 | 是 | 活动小时数目标(某个小时时段内进行身体活动超过一分钟,该时段被标记为活动小时),默认值为运动健康App中展示的默认目标。 |
type ConfigType = number | string | boolean
联动配置项类型。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 类型 | 说明 |
|---|---|
| number | 表示值类型为数字,可取任意值。 |
| string | 表示值类型为字符串,可取任意值。 |
| boolean | 表示值类型为布尔类型,可取true或false,具体含义以实际使用场景为准。 |
联动设备状态。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| deviceId | string | 否 | 否 | 设备ID。 |
| state | number | 否 | 否 | 设备状态。 |
| deviceName | string | 否 | 是 | 设备名称,若未填写,默认为空。 |
联动运动目标。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| type | number | 否 | 否 | 目标类型,取值参考:TargetType。 |
| value | number | 否 | 否 | 目标值。 |
联动类型。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| COURSE_LINK | 0 | 课程联动。 |
| ACTIVITY_LINK | 1 | 运动联动。 |
联动开启结果码。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| SUCCESS | 0 | 联动开启成功。 |
| WORKOUT_WORKING | 1 | 联动已开始。 |
| NO_SUPPORTED_DEVICE | 2 | 无可支持联动的设备。 |
| DEVICE_BUSY | 3 | 联动设备忙碌。 |
联动开启结果。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| startCode | StartCode | 否 | 否 | 联动开启结果码。 |
| deviceState | DeviceState[] | 否 | 否 | 联动设备状态。 |
运动状态信息。
系统能力: SystemCapability.Health.HealthService
起始版本: 6.1.1(24)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| sportType | number | 否 | 否 | 运动类型,参见锻炼记录类型常量子数据类型id。 |
| sportState | SportState | 否 | 否 | 运动状态。 |
运动状态类型。
系统能力: SystemCapability.Health.HealthService
起始版本: 6.1.1(24)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| IDLE | 0 | 初始化。 |
| READY | 1 | 就绪。 |
| RUNNING | 2 | 运动中。 |
| PAUSED | 3 | 暂停。 |
| STOPPED | 4 | 停止。 |
联动目标类型。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 值 | 说明 |
|---|---|---|
| NONE | 0 | 无目标。 |
| DISTANCE | 1 | 距离。 |
| CALORIE | 2 | 卡路里。 |
| TIME | 3 | 时长。 |
| SKIPPING_TIMES | 4 | 跳绳次数。 |
联动配置项。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
| 名称 | 类型 | 只读 | 可选 | 说明 |
|---|---|---|---|---|
| linkageType | LinkageType | 否 | 否 | 联动类型。 |
| sportType | number | 否 | 否 | 运动类型,参见锻炼记录类型常量子数据类型id。 |
| activityGoals | Goal[] | 否 | 是 | 联动运动目标,若未填写,默认为空。 |
| extensionConfig | Record<string, ConfigType> | 否 | 是 | 扩展配置项,若未填写,默认为空。 |
config(workoutConfig: WorkoutConfig): Promise<void>
配置联动,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| workoutConfig | WorkoutConfig | 是 | 联动配置项。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. |
| 1009104003 | Illegal command. Called when workout not in stopped or idle state. |
| 1009104999 | System internal error. |
示例:
import { healthService, healthStore } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
let workoutOptions: healthService.workout.WorkoutConfig = {
linkageType: healthService.workout.LinkageType.COURSE_LINK,
sportType: healthStore.exerciseSequenceHelper.running.EXERCISE_TYPE.id
};
await healthService.workout.config(workoutOptions);
hilog.info(0x0000, 'testTag', 'Succeeded in configuring workout');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to configure workout. Code: ${err.code}, message: ${err.message}`);
} start(): Promise<StartResult>
开启联动,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<StartResult> | Promise对象,返回联动开启结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 1009104001 | Sport service busy. Workout is already started by other application. |
| 1009104002 | Unsupported sport type. |
| 1009104003 | Illegal command. Called when workout in sporting, paused or stopped state. |
| 1009104004 | Permission verification error. Application has no permission, such as Motion Permission. |
| 1009104999 | System internal error. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
await healthService.workout.start();
hilog.info(0x0000, 'testTag', 'Succeeded in starting workout');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to start workout. Code: ${err.code}, message: ${err.message}`);
} pause(): Promise<void>
暂停联动,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 1009104003 | Illegal command. Called when workout in ready, paused or stopped state. |
| 1009104999 | System internal error. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
await healthService.workout.pause();
hilog.info(0x0000, 'testTag', 'Succeeded in pausing workout');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to pause workout. Code: ${err.code}, message: ${err.message}`);
} resume(): Promise<void>
恢复联动,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 1009104003 | Illegal command. Called when workout in ready, sporting or stopped state. |
| 1009104999 | System internal error. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
await healthService.workout.resume();
hilog.info(0x0000, 'testTag', 'Succeeded in resuming workout');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to resume workout. Code: ${err.code}, message: ${err.message}`);
} stop(): Promise<void>
停止联动,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 1009104003 | Illegal command. Called when workout is not started. |
| 1009104999 | System internal error. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
await healthService.workout.stop();
hilog.info(0x0000, 'testTag', 'Succeeded in stopping workout');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to stop workout. Code: ${err.code}, message: ${err.message}`);
} onData(dataType: healthStore.DataType, listener: Callback<SampleReal[]>): Promise<void>
注册指定联动运动数据监听,建议最多订阅三种类型的数据,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dataType | healthStore.DataType | 是 | 联动运动数据类型。 |
| listener | Callback<SampleReal[]> | 是 | 回调函数,返回联动运动数据。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
示例:
import { healthService, healthStore } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleReal[]> = (sampleReals) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving data. The sampleReals size is ${sampleReals.length}`);
};
const realTimeMotionDataType: healthStore.DataType = {
id: 50004
};
await healthService.workout.onData(realTimeMotionDataType, callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to onData. Code: ${err.code}, message: ${err.message}`);
} onData(dataType: undefined, listener: Callback<SampleReal[]>): Promise<void>
注册所有联动运动数据监听,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dataType | undefined | 是 | 监听所有联动运动数据类型。 |
| listener | Callback<SampleReal[]> | 是 | 回调函数,返回联动运动数据。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleReal[]> = (sampleReals) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving data. The sampleReals size is ${sampleReals.length}`);
};
await healthService.workout.onData(undefined, callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to onData. Code: ${err.code}, message: ${err.message}`);
} offData(dataType: healthStore.DataType, listener: Callback<SampleReal[]>): Promise<void>
取消指定联动运动数据的监听,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dataType | healthStore.DataType | 是 | 联动运动数据类型。 |
| listener | Callback<SampleReal[]> | 是 | 回调函数,返回联动运动数据。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3.Parameter verification failed. |
示例:
import { healthService, healthStore } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleReal[]> = (sampleReals) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving data. The sampleReals size is ${sampleReals.length}`);
};
await healthService.workout.offData(healthStore.healthDataTypes.WORKOUT, callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to offData. Code: ${err.code}, message: ${err.message}`);
} offData(dataType: undefined, listener: Callback<SampleReal[]>): Promise<void>
取消所有联动运动数据的监听,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dataType | undefined | 是 | 取消监听所有联动运动数据类型。 |
| listener | Callback<SampleReal[]> | 是 | 回调函数,返回联动运动数据。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Parameter verification failed. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleReal[]> = (sampleReals) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving data. The sampleReals size is ${sampleReals.length}`);
};
await healthService.workout.offData(undefined, callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to offData. Code: ${err.code}, message: ${err.message}`);
} onEvent(event: "*", listener: Callback<SampleEvent>): Promise<void>
注册联动设备事件监听,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
设备行为差异: 该接口在Phone、Tablet中可正常调用,在Wearable中返回401错误码。
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event | string | 是 | 联动设备事件类型,支持的事件为:"*",当联动设备运动状态改变时,触发该事件。 |
| listener | Callback<SampleEvent> | 是 | 回调函数,返回联动设备事件。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleEvent> = (event) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving event. Event data: ${event.eventData}, event id: ${event.eventId}`);
};
await healthService.workout.onEvent('*', callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to onEvent. Code: ${err.code}, message: ${err.message}`);
} offEvent(event: "*", listener: Callback<SampleEvent>): Promise<void>
取消联动设备事件的监听,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
设备行为差异: 该接口在Phone、Tablet中可正常调用,在Wearable中返回401错误码。
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event | string | 是 | 联动设备事件类型,支持的事件为:"*",当联动设备运动状态改变时,触发该事件。 |
| listener | Callback<SampleEvent> | 是 | 回调函数,返回联动设备事件。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Parameter verification failed. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const callback: Callback<healthService.SampleEvent> = (event) => {
hilog.info(0x0000, 'testTag', `Succeeded in receiving event. Event data: ${event.eventData}, event id: ${event.eventId}`);
};
await healthService.workout.offEvent('*', callback);
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to offEvent. Code: ${err.code}, message: ${err.message}`);
} readActivityReport(): Promise<ActivityReport>
读取实时三环数据,需要DAILY_ACTIVITIES数据类型权限,使用Promise异步回调。
元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Health.HealthService
起始版本: 5.0.0(12)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<ActivityReport> | Promise对象,返回实时三环数据。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const result: healthService.workout.ActivityReport = await healthService.workout.readActivityReport();
hilog.info(0x0000, 'testTag', 'Succeeded in reading ActivityReport');
Object.keys(result).forEach(key => {
hilog.info(0x0000, 'testTag', `the ${key} is ${result[key]}`);
});
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to read ActivityReport. Code: ${err.code}, message: ${err.message}`);
} sendData(sampleReal: SampleReal[]): Promise<void>
下发融合运动数据到联动设备,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
设备行为差异: 该接口在Phone、Tablet中可正常调用,在Wearable中返回401错误码。
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| sampleReal | SampleReal[] | 是 | 融合运动数据。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const sampleReal: healthService.SampleReal = {
dataType: { id: 50004 },
time: 1695740400000, // 2023-09-26 23:00:00,
fields: {
hr: 90
}
};
await healthService.workout.sendData([sampleReal]);
hilog.info(0x0000, 'testTag', 'Succeeded in sending data.');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to send data. Code: ${err.code}, message: ${err.message}`);
} sendEvent(event: SampleEvent): Promise<void>
下发控制事件到联动设备,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
设备行为差异: 该接口在Phone、Tablet中可正常调用,在Wearable中返回401错误码。
起始版本: 5.1.0(18)
模型约束: 此接口仅可在Stage模型下使用。
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event | SampleEvent | 是 | 联动控制事件。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise<void> | Promise对象,无返回结果。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码和通用错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
const sampleEvent: healthService.SampleEvent = {
eventId: 800400002,
eventLevel: 0,
eventData: 'start'
};
await healthService.workout.sendEvent(sampleEvent);
hilog.info(0x0000, 'testTag', 'Succeeded in sending event.');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to send event. Code: ${err.code}, message: ${err.message}`);
} getCurrentSportInfo(): Promise<SportInfo>
获取运动状态,使用Promise异步回调。
系统能力: SystemCapability.Health.HealthService
起始版本: 6.1.1(24)
模型约束: 此接口仅可在Stage模型下使用。
返回值:
| 类型 | 说明 |
|---|---|
| Promise<SportInfo> | Promise对象,返回运动状态信息。 |
错误码:
以下错误码的详细介绍请参见运动健康服务ArkTS API错误码。
| 错误码ID | 错误信息 |
|---|---|
| 201 | Permission verification failed. Require workout management permission.Refer to the development documentation for permission request. |
示例:
import { healthService } from '@kit.HealthServiceKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
await healthService.workout.getCurrentSportInfo();
hilog.info(0x0000, 'testTag', 'Succeeded in getting current sportInfo');
} catch (err) {
hilog.error(0x0000, 'testTag', `Failed to getting current sportInfo'. Code: ${err.code}, message: ${err.message}`);
}