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