1# @system.sensor (传感器) 2 3sensor模块提供订阅传感器数据基本能力,主要包含查询传感器的列表、订阅/取消传感器的数据、执行控制命令等。 4 5根据传感器的用途,可以将传感器分为六大类:运动类传感器、环境类传感器、方向类传感器、光线类传感器、健康类传感器、其他类传感器(如霍尔传感器),每一大类传感器包含不同类型的传感器,某种类型的传感器可能是单一的物理传感器,也可能是由多个物理传感器复合而成。 6 7 8> **说明:** 9> 10> - 从API Version 8开始,该接口不再维护,推荐使用新接口[`@ohos.sensor`](js-apis-sensor.md)。 11> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 12> - 该功能使用需要对应硬件支持,仅支持真机调试。 13 14 15## 导入模块 16 17 18``` 19import { Sensor } from '@kit.SensorServiceKit'; 20``` 21 22## Sensor.subscribeAccelerometer 23 24 subscribeAccelerometer(options: subscribeAccelerometerOptions): void 25 26观察加速度数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 27 28**系统能力**:SystemCapability.Sensors.Sensor.Lite 29 30**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限 31 32**参数**: 33 34| 参数名 | 类型 | 必填 | 说明 | 35| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 36| options | [subscribeAccelerometerOptions](#subscribeaccelerometeroptions) | 是 | 监听加速度传感器数据的回调函数的执行频率。 | 37 38**示例**: 39 40```ts 41import { Sensor, AccelerometerResponse, subscribeAccelerometerOptions } from '@kit.SensorServiceKit'; 42 43let accelerometerOptions: subscribeAccelerometerOptions = { 44 interval: 'normal', 45 success: (ret: AccelerometerResponse) => { 46 console.info('Succeeded in subscribing. X-axis data: ' + ret.x); 47 console.info('Succeeded in subscribing. Y-axis data: ' + ret.y); 48 console.info('Succeeded in subscribing. Z-axis data: ' + ret.z); 49 }, 50 fail: (data: string, code: number) => { 51 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 52 }, 53}; 54Sensor.subscribeAccelerometer(accelerometerOptions); 55``` 56 57> **说明:** 58> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 59 60## Sensor.unsubscribeAccelerometer 61 62unsubscribeAccelerometer(): void 63 64取消订阅加速度数据。 65 66**系统能力**:SystemCapability.Sensors.Sensor.Lite 67 68**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限 69 70**示例**: 71 72```ts 73Sensor.unsubscribeAccelerometer(); 74``` 75 76## Sensor.subscribeCompass 77 78 subscribeCompass(options: SubscribeCompassOptions): void 79 80订阅罗盘数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 81 82**系统能力**:SystemCapability.Sensors.Sensor.Lite 83 84**参数**: 85 86| 参数名 | 类型 | 必填 | 说明 | 87| ------- | --------------------------------------------------- | ---- | -------------------------------- | 88| options | [SubscribeCompassOptions](#subscribecompassoptions) | 是 | 当罗盘传感器数据发生变化时调用。 | 89 90**示例**: 91 92```ts 93import { Sensor, CompassResponse, SubscribeCompassOptions } from '@kit.SensorServiceKit'; 94 95let subscribeCompassOptions: SubscribeCompassOptions = { 96 success: (ret: CompassResponse) => { 97 console.info('Succeeded in subscribing. Get data direction:' + ret.direction); 98 }, 99 fail: (data: string, code: number) => { 100 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 101 }, 102}; 103Sensor.subscribeCompass(subscribeCompassOptions); 104``` 105 106> **说明:** 107> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 108 109## Sensor.unsubscribeCompass 110 111unsubscribeCompass(): void 112 113取消订阅罗盘。 114 115**系统能力**:SystemCapability.Sensors.Sensor.Lite 116 117**示例**: 118 119```ts 120Sensor.unsubscribeCompass(); 121``` 122 123## Sensor.subscribeProximity 124 125 subscribeProximity(options: SubscribeProximityOptions): void 126 127订阅距离感应数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 128 129**系统能力**:SystemCapability.Sensors.Sensor.Lite 130 131**参数**: 132 133| 参数名 | 类型 | 必填 | 说明 | 134| ------- | ------------------------------------------------------- | ---- | -------------------------------- | 135| options | [SubscribeProximityOptions](#subscribeproximityoptions) | 是 | 当距离传感器数据发生变化时调用。 | 136 137**示例**: 138 139```ts 140import { Sensor, ProximityResponse, SubscribeProximityOptions } from '@kit.SensorServiceKit'; 141 142let subscribeProximityOptions: SubscribeProximityOptions = { 143 success: (ret: ProximityResponse) => { 144 console.info('Succeeded in subscribing. Get data distance:' + ret.distance); 145 }, 146 fail: (data: string, code: number) => { 147 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 148 }, 149}; 150Sensor.subscribeProximity(subscribeProximityOptions); 151``` 152 153> **说明:** 154> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 155 156## Sensor.unsubscribeProximity 157 158unsubscribeProximity(): void 159 160取消订阅距离感应。 161 162**系统能力**:SystemCapability.Sensors.Sensor.Lite 163 164**示例**: 165 166```ts 167Sensor.unsubscribeProximity(); 168``` 169 170## Sensor.subscribeLight 171 172 subscribeLight(options: SubscribeLightOptions): void 173 174订阅环境光线感应数据变化。再次调用时,会覆盖前一次调用效果,即仅最后一次调用生效。 175 176**系统能力**:SystemCapability.Sensors.Sensor.Lite 177 178**参数**: 179 180| 参数名 | 类型 | 必填 | 说明 | 181| ------- | ----------------------------------------------- | ---- | ---------------------------------- | 182| options | [SubscribeLightOptions](#subscribelightoptions) | 是 | 当环境光传感器数据发生变化时调用。 | 183 184**示例**: 185 186```ts 187import { Sensor, LightResponse, SubscribeLightOptions } from '@kit.SensorServiceKit'; 188 189let subscribeLightOptions: SubscribeLightOptions = { 190 success: (ret: LightResponse) => { 191 console.info('Succeeded in subscribing. Get data intensity:' + ret.intensity); 192 }, 193 fail: (data: string, code: number) => { 194 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 195 }, 196}; 197Sensor.subscribeLight(subscribeLightOptions); 198``` 199 200> **说明:** 201> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 202 203## Sensor.unsubscribeLight 204 205unsubscribeLight(): void 206 207取消订阅环境光线感应。 208 209**系统能力**:SystemCapability.Sensors.Sensor.Lite 210 211**示例**: 212 213```ts 214Sensor.unsubscribeLight(); 215``` 216 217## Sensor.subscribeStepCounter 218 219 subscribeStepCounter(options: SubscribeStepCounterOptions): void 220 221订阅计步传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 222 223**系统能力**:SystemCapability.Sensors.Sensor.Lite 224 225**需要权限**:ohos.permission.ACTIVITY_MOTION 226 227**参数**: 228 229| 参数名 | 类型 | 必填 | 说明 | 230| ------- | ----------------------------------------------------------- | ---- | -------------------------------------- | 231| options | [SubscribeStepCounterOptions](#subscribestepcounteroptions) | 是 | 当步进计数器传感器数据发生变化时调用。 | 232 233**示例**: 234 235```ts 236import { Sensor, StepCounterResponse, SubscribeStepCounterOptions } from '@kit.SensorServiceKit'; 237 238let subscribeStepCounterOptions: SubscribeStepCounterOptions = { 239 success: (ret: StepCounterResponse) => { 240 console.info('Succeeded in subscribing. Get step value:' + ret.steps); 241 }, 242 fail: (data: string, code: number) => { 243 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 244 }, 245}; 246Sensor.subscribeStepCounter(subscribeStepCounterOptions); 247``` 248 249> **说明:** 250> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 251 252## Sensor.unsubscribeStepCounter 253 254unsubscribeStepCounter(): void 255 256取消订阅计步传感器。 257 258**系统能力**:SystemCapability.Sensors.Sensor.Lite 259 260**需要权限**:ohos.permission.ACTIVITY_MOTION 261 262**示例**: 263 264```ts 265Sensor.unsubscribeStepCounter(); 266``` 267 268 269## Sensor.subscribeBarometer 270 271subscribeBarometer(options: SubscribeBarometerOptions): void 272 273订阅气压计传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 274 275**系统能力**:SystemCapability.Sensors.Sensor.Lite 276 277**参数**: 278 279| 参数名 | 类型 | 必填 | 说明 | 280| ------- | ------------------------------------------------------- | ---- | ---------------------------------- | 281| options | [SubscribeBarometerOptions](#subscribebarometeroptions) | 是 | 当气压计传感器数据发生变化时调用。 | 282 283**示例**: 284 285```ts 286import { Sensor, BarometerResponse, SubscribeBarometerOptions } from '@kit.SensorServiceKit'; 287 288let subscribeBarometerOptions: SubscribeBarometerOptions = { 289 success: (ret: BarometerResponse) => { 290 console.info('Succeeded in subscribing. Get data value:' + ret.pressure); 291 }, 292 fail: (data: string, code: number) => { 293 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 294 }, 295}; 296Sensor.subscribeBarometer(subscribeBarometerOptions); 297``` 298 299> **说明:** 300> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 301 302 303## Sensor.unsubscribeBarometer 304 305unsubscribeBarometer(): void 306 307取消订阅气压计传感器。 308 309**系统能力**:SystemCapability.Sensors.Sensor.Lite 310 311**示例**: 312 313```ts 314Sensor.unsubscribeBarometer(); 315``` 316 317 318## Sensor.subscribeHeartRate 319 320 subscribeHeartRate(options: SubscribeHeartRateOptions): void 321 322订阅心率传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 323 324**系统能力**:SystemCapability.Sensors.Sensor.Lite 325 326**需要权限**:ohos.permission.READ_HEALTH_DATA 327 328**参数**: 329 330| 参数名 | 类型 | 必填 | 说明 | 331| ------- | ------------------------------------------------------- | ---- | -------------------------------- | 332| options | [SubscribeHeartRateOptions](#subscribeheartrateoptions) | 是 | 当心率传感器数据发生变化时调用。 | 333 334**示例**: 335 336```ts 337import { Sensor, HeartRateResponse, SubscribeHeartRateOptions } from '@kit.SensorServiceKit'; 338 339let subscribeHeartRateOptions: SubscribeHeartRateOptions = { 340 success: (ret: HeartRateResponse) => { 341 console.info('Succeeded in subscribing. Get heartrate value:' + ret.heartRate); 342 }, 343 fail: (data: string, code: number) => { 344 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 345 }, 346}; 347Sensor.subscribeHeartRate(subscribeHeartRateOptions); 348``` 349 350> **说明:** 351> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 352 353 354## Sensor.unsubscribeHeartRate 355 356unsubscribeHeartRate(): void 357 358取消订阅心率传感器。 359 360**系统能力**:SystemCapability.Sensors.Sensor.Lite 361 362**需要权限**:ohos.permission.READ_HEALTH_DATA 363 364**示例**: 365 366```ts 367Sensor.unsubscribeHeartRate(); 368``` 369 370## Sensor.subscribeOnBodyState 371 372 subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void 373 374订阅设备佩戴状态。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。 375 376**系统能力**:SystemCapability.Sensors.Sensor.Lite 377 378**参数**: 379 380| 参数名 | 类型 | 必填 | 说明 | 381| ------- | ----------------------------------------------------------- | ---- | ---------------------- | 382| options | [SubscribeOnBodyStateOptions](#subscribeonbodystateoptions) | 是 | 当穿着状态改变时调用。 | 383 384**示例**: 385 386```ts 387import { Sensor, OnBodyStateResponse, SubscribeOnBodyStateOptions } from '@kit.SensorServiceKit'; 388 389let subscribeOnBodyStateOptions: SubscribeOnBodyStateOptions = { 390 success: (ret: OnBodyStateResponse) => { 391 console.info('Succeeded in subscribing. Get on-body state value:' + ret.value); 392 }, 393 fail: (data: string, code: number) => { 394 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 395 }, 396}; 397Sensor.subscribeOnBodyState(subscribeOnBodyStateOptions); 398``` 399 400> **说明:** 401> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 402 403## Sensor.unsubscribeOnBodyState 404 405unsubscribeOnBodyState(): void 406 407取消订阅设备佩戴状态。 408 409**系统能力**:SystemCapability.Sensors.Sensor.Lite 410 411**示例**: 412 413```ts 414Sensor.unsubscribeOnBodyState(); 415``` 416 417## Sensor.getOnBodyState 418 419 getOnBodyState(options: GetOnBodyStateOptions): void 420 421获取设备佩戴状态。 422 423**系统能力**:SystemCapability.Sensors.Sensor.Lite 424 425**参数**: 426 427| 参数名 | 类型 | 必填 | 说明 | 428| ------- | ----------------------------------------------- | ---- | -------------------------- | 429| options | [GetOnBodyStateOptions](#getonbodystateoptions) | 是 | 获取传感器磨损状态时调用。 | 430 431**示例**: 432 433```ts 434import { Sensor, OnBodyStateResponse, GetOnBodyStateOptions } from '@kit.SensorServiceKit'; 435 436let getOnBodyStateOptions: GetOnBodyStateOptions = { 437 success: (ret: OnBodyStateResponse) => { 438 console.info('Succeeded in subscribing. On body state: ' + ret.value); 439 }, 440 fail: (data: string, code: number) => { 441 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 442 }, 443}; 444Sensor.getOnBodyState(getOnBodyStateOptions); 445``` 446 447## Sensor.subscribeDeviceOrientation<sup>6+</sup> 448 449 subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void 450 451观察设备方向传感器数据变化。 452 453针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效;针对同一个方法内,不支持多次调用。 454 455**系统能力**:SystemCapability.Sensors.Sensor.Lite 456 457**参数**: 458 459| 参数名 | 类型 | 必填 | 说明 | 460| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ | 461| options | [SubscribeDeviceOrientationOptions](#subscribedeviceorientationoptions6) | 是 | 用于监听设备方向传感器数据的回调函数的执行频率。 | 462 463**示例**: 464 465```ts 466import { Sensor, DeviceOrientationResponse, SubscribeDeviceOrientationOptions } from '@kit.SensorServiceKit'; 467 468let subscribeDeviceOrientationOptions: SubscribeDeviceOrientationOptions = { 469 interval: 'normal', 470 success: (ret: DeviceOrientationResponse) => { 471 console.info('Succeeded in subscribing. Alpha data: ' + ret.alpha); 472 console.info('Succeeded in subscribing. Beta data: ' + ret.beta); 473 console.info('Succeeded in subscribing. Gamma data: ' + ret.gamma); 474 }, 475 fail: (data: string, code: number) => { 476 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 477 } 478}; 479Sensor.subscribeDeviceOrientation(subscribeDeviceOrientationOptions); 480``` 481 482> **说明:** 483> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 484 485## Sensor.unsubscribeDeviceOrientation<sup>6+</sup> 486 487unsubscribeDeviceOrientation(): void 488 489取消订阅设备方向传感器数据。 490 491**系统能力**:SystemCapability.Sensors.Sensor.Lite 492 493**示例**: 494 495```ts 496Sensor.unsubscribeDeviceOrientation(); 497``` 498 499## Sensor.subscribeGyroscope<sup>6+</sup> 500 501 subscribeGyroscope(options: SubscribeGyroscopeOptions): void 502 503观察陀螺仪传感器数据变化。 504 505针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效;针对同一个方法内,不支持多次调用。 506 507**需要权限**:SystemCapability.Sensors.Sensor.Lite 508 509**系统能力**:ohos.permission.GYROSCOPE,该权限为系统权限 510 511**参数**: 512 513| 参数名 | 类型 | 必填 | 说明 | 514| ------- | -------------------------------------------------------- | ---- | ---------------------------------------------- | 515| options | [SubscribeGyroscopeOptions](#subscribegyroscopeoptions6) | 是 | 用于侦听陀螺仪传感器数据的回调函数的执行频率。 | 516 517**示例**: 518 519```ts 520import { Sensor, GyroscopeResponse, SubscribeGyroscopeOptions } from '@kit.SensorServiceKit'; 521 522let subscribeGyroscopeOptions: SubscribeGyroscopeOptions = { 523 interval: 'normal', 524 success: (ret: GyroscopeResponse) => { 525 console.info('Succeeded in subscribing. X-axis data: ' + ret.x); 526 console.info('Succeeded in subscribing. Y-axis data: ' + ret.y); 527 console.info('Succeeded in subscribing. Z-axis data: ' + ret.z); 528 }, 529 fail: (data: string, code: number) => { 530 console.error(`Failed to subscription. Code: ${code}, data: ${data}`); 531 } 532}; 533Sensor.subscribeGyroscope(subscribeGyroscopeOptions); 534``` 535 536> **说明:** 537> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。 538 539## Sensor.unsubscribeGyroscope<sup>6+</sup> 540 541unsubscribeGyroscope(): void 542 543取消订阅陀螺仪传感器数据。 544 545**系统能力**:SystemCapability.Sensors.Sensor.Lite 546 547**需要权限**:ohos.permission.GYROSCOPE,该权限为系统权限 548 549**示例**: 550 551```ts 552Sensor.unsubscribeGyroscope(); 553``` 554 555## subscribeAccelerometerOptions 556 557用于监听加速度传感器数据的回调函数的执行频率。 558 559**需要权限**:ohos.permission.ACCELEROMETER 560 561**系统能力**:SystemCapability.Sensors.Sensor.Lite 562 563| 名称 | 类型 | 必填 | 说明 | 564| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 565| interval | string | 是 | 频率参数,加速度的回调函数执行频率。<br/>默认为normal,可选值有:<br/>game:极高的回调频率,20ms/次,适用于游戏。<br/>ui:较高的回调频率,60ms/次,适用于UI更新。<br/>normal:普通的回调频率,200ms/次,低功耗。 | 566| success | [AccelerometerResponse](#accelerometerresponse) | 是 | 感应到加速度数据变化后的回调函数。 | 567| fail | Function | 否 | 接口调用失败的回调函数。 | 568 569## AccelerometerResponse 570 571感应到加速度数据变化后的回调函数。 572 573**需要权限**:ohos.permission.ACCELEROMETER 574 575**系统能力**:SystemCapability.Sensors.Sensor.Lite 576 577| 名称 | 类型 | 必填 | 说明 | 578| ---- | ------ | ---- | ------------- | 579| x | number | 是 | x轴的加速度。 | 580| y | number | 是 | y轴的加速度。 | 581| z | number | 是 | z轴的加速度。 | 582 583## SubscribeCompassOptions 584 585当罗盘传感器数据发生变化时调用。 586 587**系统能力**:SystemCapability.Sensors.Sensor.Lite 588 589| 名称 | 类型 | 必填 | 说明 | 590| ------- | ----------------------------------- | ---- | ------------------------------ | 591| success | [CompassResponse](#compassresponse) | 是 | 罗盘数据改变后触发的回调函数。 | 592| fail | Function | 否 | 接口调用失败的回调函数。 | 593 594## CompassResponse 595 596罗盘数据改变后触发的回调函数。 597 598**系统能力**:SystemCapability.Sensors.Sensor.Lite 599 600| 名称 | 类型 | 必填 | 说明 | 601| --------- | ------ | ---- | -------------------- | 602| direction | number | 是 | 设备面对的方向度数。 | 603 604## SubscribeProximityOptions 605 606当距离传感器数据发生变化时调用。 607 608**系统能力**:SystemCapability.Sensors.Sensor.Lite 609 610| 名称 | 类型 | 必填 | 说明 | 611| ------- | --------------------------------------- | ---- | ---------------------------------- | 612| success | [ProximityResponse](#proximityresponse) | 是 | 距离感应数据改变后调用的回调函数。 | 613| fail | Function | 否 | 接口调用失败的回调函数。 | 614 615## ProximityResponse 616 617距离感应数据改变后调用的回调函数。 618 619**系统能力**:SystemCapability.Sensors.Sensor.Lite 620 621| 名称 | 类型 | 必填 | 说明 | 622| -------- | ------ | ---- | ------------------------------------------ | 623| distance | number | 是 | 可见物体相对于设备显示屏的接近或远离状态。 | 624 625## SubscribeLightOptions 626 627当环境光传感器数据发生变化时调用。 628 629**系统能力**:SystemCapability.Sensors.Sensor.Lite 630 631| 名称 | 类型 | 必填 | 说明 | 632| ------- | ------------------------------- | ---- | ------------------------------ | 633| success | [LightResponse](#lightresponse) | 是 | 光线感应数据改变后的回调函数。 | 634| fail | Function | 否 | 接口调用失败的回调函数。 | 635 636## LightResponse 637 638光线感应数据改变后的回调函数。 639 640**系统能力**:SystemCapability.Sensors.Sensor.Lite 641 642| 名称 | 类型 | 必填 | 说明 | 643| --------- | ------ | ---- | --------------------- | 644| intensity | number | 是 | 光线强度,单位为lux。 | 645 646## SubscribeStepCounterOptions 647 648当步进计数器传感器数据发生变化时调用。 649 650**需要权限**:ohos.permission.ACTIVITY_MOTION 651 652**系统能力**:SystemCapability.Sensors.Sensor.Lite 653 654| 名称 | 类型 | 必填 | 说明 | 655| ------- | ------------------------------------------- | ---- | -------------------------------- | 656| success | [StepCounterResponse](#stepcounterresponse) | 是 | 计步传感器数据改变后的回调函数。 | 657| fail | Function | 否 | 接口调用失败的回调函数。 | 658 659## StepCounterResponse 660 661计步传感器数据改变后的回调函数。 662 663**需要权限**:ohos.permission.ACTIVITY_MOTION 664 665**系统能力**:SystemCapability.Sensors.Sensor.Lite 666 667| 名称 | 类型 | 必填 | 说明 | 668| ----- | ------ | ---- | -------------------------------- | 669| steps | number | 是 | 计步传感器重启后累计记录的步数。 | 670 671## SubscribeBarometerOptions 672 673当气压计传感器数据发生变化时调用。 674 675**系统能力**:SystemCapability.Sensors.Sensor.Lite 676 677| 名称 | 类型 | 必填 | 说明 | 678| ------- | --------------------------------------- | ---- | -------------------------------- | 679| success | [BarometerResponse](#barometerresponse) | 是 | 气压计传感器数据改变后的回调函数。 | 680| fail | Function | 否 | 接口调用失败的回调函数。 | 681 682## BarometerResponse 683 684气压计传感器数据改变后的回调函数。 685 686**系统能力**:SystemCapability.Sensors.Sensor.Lite 687 688| 名称 | 类型 | 必填 | 说明 | 689| -------- | ------ | ---- | ---------------------- | 690| pressure | number | 是 | 气压值,单位:帕斯卡。 | 691 692## SubscribeHeartRateOptions 693 694当心率传感器数据发生变化时调用。 695 696**需要权限**:ohos.permission.READ_HEALTH_DATA 697 698**系统能力**:SystemCapability.Sensors.Sensor.Lite 699 700| 名称 | 类型 | 必填 | 说明 | 701| ------- | --------------------------------------- | ---- | ----------------------------------------------- | 702| success | [HeartRateResponse](#heartrateresponse) | 是 | 心率传感器数据改变后的回调函数,默认频率5s/次。 | 703| fail | Function | 否 | 接口调用失败的回调函数。 | 704 705## HeartRateResponse 706 707心率传感器数据改变后的回调函数,默认频率5s/次。 708 709**需要权限**:ohos.permission.READ_HEALTH_DATA 710 711**系统能力**:SystemCapability.Sensors.Sensor.Lite 712 713| 名称 | 类型 | 必填 | 说明 | 714| --------- | ------ | ---- | -------- | 715| heartRate | number | 是 | 心率值。 | 716 717## SubscribeOnBodyStateOptions 718 719当穿着状态改变时调用。 720 721**系统能力**:SystemCapability.Sensors.Sensor.Lite 722 723| 名称 | 类型 | 必填 | 说明 | 724| ------- | ------------------------------------------- | ---- | -------------------------- | 725| success | [OnBodyStateResponse](#onbodystateresponse) | 是 | 穿戴状态改变后的回调函数。 | 726| fail | Function | 否 | 接口调用失败的回调函数。 | 727 728## OnBodyStateResponse 729 730传感器是否磨损。 731 732**系统能力**:SystemCapability.Sensors.Sensor.Lite 733 734| 名称 | 类型 | 必填 | 说明 | 735| ----- | ------- | ---- | ------------ | 736| value | boolean | 是 | 是否已佩戴。 | 737 738## GetOnBodyStateOptions 739 740 获取传感器磨损状态时调用。 741 742**系统能力**:SystemCapability.Sensors.Sensor.Lite 743 744| 名称 | 类型 | 必填 | 说明 | 745| -------- | ------------------------------------------- | ---- | ------------------------ | 746| success | [OnBodyStateResponse](#onbodystateresponse) | 是 | 接口调用成功的回调函数。 | 747| fail | Function | 否 | 接口调用失败的回调函数。 | 748| complete | Function | 否 | 接口调用结束的回调函数。 | 749 750## SubscribeDeviceOrientationOptions<sup>6+</sup> 751 752用于监听设备方向传感器数据的回调函数的执行频率。 753 754**系统能力**:SystemCapability.Sensors.Sensor.Lite 755 756| 名称 | 类型 | 必填 | 说明 | 757| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | 758| interval | string | 是 | 频率参数,设备方向传感器的回调函数执行频率。<br/>默认为normal,可选值有:<br/>- game:极高的回调频率,20ms/次,适用于游戏。<br/>- ui:较高的回调频率,60ms/次,适用于UI更新。<br/>- normal:普通的回调频率,200ms/次,低功耗。 | 759| success | [DeviceOrientationResponse](#deviceorientationresponse6) | 是 | 感应到设备方向传感器数据变化后的回调函数。 | 760| fail | Function | 否 | 接口调用失败的回调函数。 | 761 762## DeviceOrientationResponse<sup>6+</sup> 763 764感应到设备方向传感器数据变化后的回调函数。 765 766**系统能力**:SystemCapability.Sensors.Sensor.Lite 767 768| 名称 | 类型 | 必填 | 说明 | 769| ----- | ------ | ---- | ------------------------------------------------------------ | 770| alpha | number | 是 | 当设备坐标 X/Y 和地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha。 | 771| beta | number | 是 | 当设备坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。 | 772| gamma | number | 是 | 当设备 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。 | 773 774## SubscribeGyroscopeOptions<sup>6+</sup> 775 776用于侦听陀螺仪传感器数据的回调函数的执行频率。 777 778**需要权限**:ohos.permission.GYROSCOPE 779 780**系统能力**:SystemCapability.Sensors.Sensor.Lite 781 782| 名称 | 类型 | 必填 | 说明 | 783| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 784| interval | string | 是 | 频率参数,陀螺仪的回调函数执行频率。<br/>默认为normal,可选值有:<br/>game:极高的回调频率,20ms/次,适用于游戏。<br/>ui:较高的回调频率,60ms/次,适用于UI更新。<br/>normal:普通的回调频率,200ms/次,低功耗。 | 785| success | [GyroscopeResponse](#gyroscoperesponse6) | 是 | 感应到陀螺仪数据变化后的回调函数。 | 786| fail | Function | 否 | 接口调用失败的回调函数。 | 787 788## GyroscopeResponse<sup>6+</sup> 789 790感应到陀螺仪传感器数据变化后的回调函数。 791 792**需要权限**:ohos.permission.GYROSCOPE 793 794**系统能力**:SystemCapability.Sensors.Sensor.Lite 795 796| 名称 | 类型 | 必填 | 说明 | 797| ---- | ------ | ---- | ----------------- | 798| x | number | 是 | x轴的旋转角速度。 | 799| y | number | 是 | y轴的旋转角速度。 | 800| z | number | 是 | z轴的旋转角速度。 |