• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @system.sensor (Sensor)
2
3The **Sensor** module provides APIs for querying the sensor list, subscribing to or unsubscribing from sensor data, and executing control commands.
4
5The sensors are classified into the following categories based on their functions: motion, environment, orientation, light, body, and other categories (such as Hall effect sensors). Each category includes different sensor types. A sensor type may be a single hardware sensor or a composite of multiple hardware sensors.
6
7
8> **NOTE**
9>
10> - The APIs of this module are no longer maintained since API version 8. You are advised to use [`@ohos.sensor`](js-apis-sensor.md) instead.
11> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
12> - This module requires hardware support and can only be debugged on real devices.
13
14
15## Modules to Import
16
17
18```
19import sensor from '@system.sensor';
20```
21
22## sensor.subscribeAccelerometer
23
24 subscribeAccelerometer(options: subscribeAccelerometerOptions): void
25
26Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
27
28**System capability**: SystemCapability.Sensors.Sensor.Lite
29
30**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)
31
32**Parameters**
33
34| Name | Type                                                        | Mandatory| Description                                      |
35| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
36| options | [subscribeAccelerometerOptions](#subscribeaccelerometeroptions) | Yes  | Type of data to return.|
37
38**Example**
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> **NOTE**
59> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
60
61## sensor.unsubscribeAccelerometer
62
63unsubscribeAccelerometer(): void
64
65Unsubscribes from data changes of the acceleration sensor.
66
67**System capability**: SystemCapability.Sensors.Sensor.Lite
68
69**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)
70
71**Example**
72
73```ts
74sensor.unsubscribeAccelerometer();
75```
76
77## sensor.subscribeCompass
78
79 subscribeCompass(options: SubscribeCompassOptions): void
80
81Subscribes to data changes of the compass sensor. If this API is called multiple times for the same application, the last call takes effect.
82
83**System capability**: SystemCapability.Sensors.Sensor.Lite
84
85**Parameters**
86
87| Name | Type                                               | Mandatory| Description                            |
88| ------- | --------------------------------------------------- | ---- | -------------------------------- |
89| options | [SubscribeCompassOptions](#subscribecompassoptions) | Yes  | Type of data to return.|
90
91**Example**
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> **NOTE**
109> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
110
111## sensor.unsubscribeCompass
112
113unsubscribeCompass(): void
114
115Unsubscribes from data changes of the compass sensor.
116
117**System capability**: SystemCapability.Sensors.Sensor.Lite
118
119**Example**
120
121```ts
122sensor.unsubscribeCompass();
123```
124
125## sensor.subscribeProximity
126
127 subscribeProximity(options: SubscribeProximityOptions): void
128
129Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.
130
131**System capability**: SystemCapability.Sensors.Sensor.Lite
132
133**Parameters**
134
135| Name | Type                                                   | Mandatory| Description                            |
136| ------- | ------------------------------------------------------- | ---- | -------------------------------- |
137| options | [SubscribeProximityOptions](#subscribeproximityoptions) | Yes  | Type of data to return.|
138
139**Example**
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> **NOTE**
157> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
158
159## sensor.unsubscribeProximity
160
161unsubscribeProximity(): void
162
163Unsubscribes from data changes of the proximity sensor.
164
165**System capability**: SystemCapability.Sensors.Sensor.Lite
166
167**Example**
168
169```ts
170sensor.unsubscribeProximity();
171```
172
173## sensor.subscribeLight
174
175 subscribeLight(options: SubscribeLightOptions): void
176
177Subscribes to data changes of the ambient light sensor. If this API is called multiple times, the last call takes effect.
178
179**System capability**: SystemCapability.Sensors.Sensor.Lite
180
181**Parameters**
182
183| Name | Type                                           | Mandatory| Description                              |
184| ------- | ----------------------------------------------- | ---- | ---------------------------------- |
185| options | [SubscribeLightOptions](#subscribelightoptions) | Yes  | Type of data to return.|
186
187**Example**
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> **NOTE**
205> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
206
207## sensor.unsubscribeLight
208
209unsubscribeLight(): void
210
211Unsubscribes from data changes of the ambient light sensor.
212
213**System capability**: SystemCapability.Sensors.Sensor.Lite
214
215**Example**
216
217```ts
218sensor.unsubscribeLight();
219```
220
221## sensor.subscribeStepCounter
222
223 subscribeStepCounter(options: SubscribeStepCounterOptions): void
224
225Subscribes to data changes of the step counter sensor. If this API is called multiple times for the same application, the last call takes effect.
226
227**System capability**: SystemCapability.Sensors.Sensor.Lite
228
229**Required permissions**: ohos.permission.ACTIVITY_MOTION
230
231**Parameters**
232
233| Name | Type                                                       | Mandatory| Description                                  |
234| ------- | ----------------------------------------------------------- | ---- | -------------------------------------- |
235| options | [SubscribeStepCounterOptions](#subscribestepcounteroptions) | Yes  | Type of data to return.|
236
237**Example**
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> **NOTE**
255> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
256
257## sensor.unsubscribeStepCounter
258
259unsubscribeStepCounter(): void
260
261Unsubscribes from data changes of the step counter sensor.
262
263**System capability**: SystemCapability.Sensors.Sensor.Lite
264
265**Required permissions**: ohos.permission.ACTIVITY_MOTION
266
267**Example**
268
269```ts
270sensor.unsubscribeStepCounter();
271```
272
273
274## sensor.subscribeBarometer
275
276subscribeBarometer(options: SubscribeBarometerOptions): void
277
278Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
279
280**System capability**: SystemCapability.Sensors.Sensor.Lite
281
282**Parameters**
283
284| Name | Type                                                   | Mandatory| Description                              |
285| ------- | ------------------------------------------------------- | ---- | ---------------------------------- |
286| options | [SubscribeBarometerOptions](#subscribebarometeroptions) | Yes  | Type of data to return.|
287
288**Example**
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> **NOTE**
306> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
307
308
309## sensor.unsubscribeBarometer
310
311unsubscribeBarometer(): void
312
313Unsubscribes from data changes of the barometer sensor.
314
315**System capability**: SystemCapability.Sensors.Sensor.Lite
316
317**Example**
318
319```ts
320sensor.unsubscribeBarometer();
321```
322
323
324## sensor.subscribeHeartRate
325
326 subscribeHeartRate(options: SubscribeHeartRateOptions): void
327
328Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect.
329
330**System capability**: SystemCapability.Sensors.Sensor.Lite
331
332**Required permissions**: ohos.permission.READ_HEALTH_DATA
333
334**Parameters**
335
336| Name | Type                                                   | Mandatory| Description                            |
337| ------- | ------------------------------------------------------- | ---- | -------------------------------- |
338| options | [SubscribeHeartRateOptions](#subscribeheartrateoptions) | Yes  | Type of data to return.|
339
340**Example**
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> **NOTE**
358> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
359
360
361## sensor.unsubscribeHeartRate
362
363unsubscribeHeartRate(): void
364
365Unsubscribes from data changes of the heart rate sensor.
366
367**System capability**: SystemCapability.Sensors.Sensor.Lite
368
369**Required permissions**: ohos.permission.READ_HEALTH_DATA
370
371**Example**
372
373```ts
374sensor.unsubscribeHeartRate();
375```
376
377## sensor.subscribeOnBodyState
378
379 subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void
380
381Subscribes to changes of the wearing state of a wearable device. If this API is called multiple times for the same application, the last call takes effect.
382
383**System capability**: SystemCapability.Sensors.Sensor.Lite
384
385**Parameters**
386
387| Name | Type                                                       | Mandatory| Description                  |
388| ------- | ----------------------------------------------------------- | ---- | ---------------------- |
389| options | [SubscribeOnBodyStateOptions](#subscribeonbodystateoptions) | Yes  | Type of data to return.|
390
391**Example**
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> **NOTE**
409> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
410
411## sensor.unsubscribeOnBodyState
412
413unsubscribeOnBodyState(): void
414
415Unsubscribes from changes of the wearing state of a wearable device.
416
417**System capability**: SystemCapability.Sensors.Sensor.Lite
418
419**Example**
420
421```ts
422sensor.unsubscribeOnBodyState();
423```
424
425## sensor.getOnBodyState
426
427 getOnBodyState(options: GetOnBodyStateOptions): void
428
429Obtains the wearing state of a wearable device.
430
431**System capability**: SystemCapability.Sensors.Sensor.Lite
432
433**Parameters**
434
435| Name | Type                                           | Mandatory| Description                      |
436| ------- | ----------------------------------------------- | ---- | -------------------------- |
437| options | [GetOnBodyStateOptions](#getonbodystateoptions) | Yes  | Type of data to return.|
438
439**Example**
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
460Subscribes to data changes of the device orientation sensor.
461
462If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event.
463
464**System capability**: SystemCapability.Sensors.Sensor.Lite
465
466**Parameters**
467
468| Name | Type                                                        | Mandatory| Description                                            |
469| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
470| options | [SubscribeDeviceOrientationOptions](#subscribedeviceorientationoptions6) | Yes  | Type of data to return.|
471
472**Example**
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> **NOTE**
493> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
494
495## sensor.unsubscribeDeviceOrientation<sup>6+</sup>
496
497unsubscribeDeviceOrientation(): void
498
499Unsubscribes from data changes of the device orientation sensor.
500
501**System capability**: SystemCapability.Sensors.Sensor.Lite
502
503**Example**
504
505```ts
506sensor.unsubscribeDeviceOrientation();
507```
508
509## sensor.subscribeGyroscope<sup>6+</sup>
510
511 subscribeGyroscope(options: SubscribeGyroscopeOptions): void
512
513Subscribes to data changes of the gyroscope sensor.
514
515If this API is called multiple times for the same application, the last call takes effect. However, this API cannot be called multiple times in one click event.
516
517**System capability**: SystemCapability.Sensors.Sensor.Lite
518
519**Required permissions**: ohos.permission.GYROSCOPE (a system permission)
520
521**Parameters**
522
523| Name | Type                                                    | Mandatory| Description                                          |
524| ------- | -------------------------------------------------------- | ---- | ---------------------------------------------- |
525| options | [SubscribeGyroscopeOptions](#subscribegyroscopeoptions6) | Yes  | Type of data to return.|
526
527**Example**
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> **NOTE**
548> To reduce performance overhead, you are advised to unsubscribe from the sensor data in the **onDestroy** callback.
549
550## sensor.unsubscribeGyroscope<sup>6+</sup>
551
552unsubscribeGyroscope(): void
553
554Unsubscribes from data changes of the gyroscope sensor.
555
556**System capability**: SystemCapability.Sensors.Sensor.Lite
557
558**Required permissions**: ohos.permission.GYROSCOPE (a system permission)
559
560**Example**
561
562```ts
563sensor.unsubscribeGyroscope();
564```
565
566## subscribeAccelerometerOptions
567
568Defines the type of data to return for a subscription to the acceleration sensor data.
569
570**Required permissions**: ohos.permission.ACCELEROMETER
571
572**System capability**: SystemCapability.Sensors.Sensor.Lite
573
574| Name    | Type                                           | Mandatory| Description                                                        |
575| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
576| interval | string                                          | Yes  | Execution frequency of the callback for returning the acceleration sensor data.<br>The default value is **normal**. The options are as follows:<br>**game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>**ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>**normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.|
577| success  | [AccelerometerResponse](#accelerometerresponse) | Yes  | Called when the acceleration sensor data changes.                          |
578| fail     | Function                                        | No  | Callback upon an API call failure.                                    |
579
580## AccelerometerResponse
581
582Defines the type of data to include in an **AccelerometerResponse** object.
583
584**Required permissions**: ohos.permission.ACCELEROMETER
585
586**System capability**: SystemCapability.Sensors.Sensor.Lite
587
588| Name| Type  | Mandatory| Description         |
589| ---- | ------ | ---- | ------------- |
590| x    | number | Yes  | Acceleration on the x-axis.|
591| y    | number | Yes  | Acceleration on the y-axis.|
592| z    | number | Yes  | Acceleration on the z-axis.|
593
594## SubscribeCompassOptions
595
596Defines the type of data to return for a subscription to the compass sensor data.
597
598**System capability**: SystemCapability.Sensors.Sensor.Lite
599
600| Name   | Type                               | Mandatory| Description                          |
601| ------- | ----------------------------------- | ---- | ------------------------------ |
602| success | [CompassResponse](#compassresponse) | Yes  | Called when the compass sensor data changes.|
603| fail    | Function                            | No  | Callback upon an API call failure.      |
604
605## CompassResponse
606
607Defines the type of data to include in a **CompassResponse** object.
608
609**System capability**: SystemCapability.Sensors.Sensor.Lite
610
611| Name     | Type  | Mandatory| Description                |
612| --------- | ------ | ---- | -------------------- |
613| direction | number | Yes  | Direction of the device, in degrees.|
614
615## SubscribeProximityOptions
616
617Defines the type of data to return for a subscription to the proximity sensor data.
618
619**System capability**: SystemCapability.Sensors.Sensor.Lite
620
621| Name   | Type                                   | Mandatory| Description                              |
622| ------- | --------------------------------------- | ---- | ---------------------------------- |
623| success | [ProximityResponse](#proximityresponse) | Yes  | Called when the proximity sensor data changes.|
624| fail    | Function                                | No  | Callback upon an API call failure.          |
625
626## ProximityResponse
627
628Defines the type of data to include in a **ProximityResponse** object.
629
630**System capability**: SystemCapability.Sensors.Sensor.Lite
631
632| Name    | Type  | Mandatory| Description                                      |
633| -------- | ------ | ---- | ------------------------------------------ |
634| distance | number | Yes  | Distance between a visible object and the device screen.|
635
636## SubscribeLightOptions
637
638Defines the type of data to return for a subscription to the ambient light sensor data.
639
640**System capability**: SystemCapability.Sensors.Sensor.Lite
641
642| Name   | Type                           | Mandatory| Description                          |
643| ------- | ------------------------------- | ---- | ------------------------------ |
644| success | [LightResponse](#lightresponse) | Yes  | Called when the ambient light sensor data changes.|
645| fail    | Function                        | No  | Callback upon an API call failure.      |
646
647## LightResponse
648
649Defines the type of data to include in a **LightResponse** object.
650
651**System capability**: SystemCapability.Sensors.Sensor.Lite
652
653| Name     | Type  | Mandatory| Description                 |
654| --------- | ------ | ---- | --------------------- |
655| intensity | number | Yes  | Light intensity, in lux.|
656
657## SubscribeStepCounterOptions
658
659Defines the type of data to return for a subscription to the step counter sensor data.
660
661**Required permissions**: ohos.permission.ACTIVITY_MOTION
662
663**System capability**: SystemCapability.Sensors.Sensor.Lite
664
665| Name   | Type                                       | Mandatory| Description                            |
666| ------- | ------------------------------------------- | ---- | -------------------------------- |
667| success | [StepCounterResponse](#stepcounterresponse) | Yes  | Called when the step counter sensor data changes.|
668| fail    | Function                                    | No  | Callback upon an API call failure.        |
669
670## StepCounterResponse
671
672Defines the type of data to include in a **StepCounterResponse** object.
673
674**Required permissions**: ohos.permission.ACTIVITY_MOTION
675
676**System capability**: SystemCapability.Sensors.Sensor.Lite
677
678| Name | Type  | Mandatory| Description                            |
679| ----- | ------ | ---- | -------------------------------- |
680| steps | number | Yes  | Number of counted steps after the sensor is restarted.|
681
682## SubscribeBarometerOptions
683
684Defines the type of data to return for a subscription to the barometer sensor data.
685
686**System capability**: SystemCapability.Sensors.Sensor.Lite
687
688| Name   | Type                                   | Mandatory| Description                            |
689| ------- | --------------------------------------- | ---- | -------------------------------- |
690| success | [BarometerResponse](#barometerresponse) | Yes  | Called when the barometer sensor data changes.|
691| fail    | Function                                | No  | Callback upon an API call failure.        |
692
693## BarometerResponse
694
695Defines the type of data to include in a **BarometerResponse** object.
696
697**System capability**: SystemCapability.Sensors.Sensor.Lite
698
699| Name    | Type  | Mandatory| Description                  |
700| -------- | ------ | ---- | ---------------------- |
701| pressure | number | Yes  | Pressure, in pascal.|
702
703## SubscribeHeartRateOptions
704
705Defines the type of data to return for a subscription to the heart rate sensor data.
706
707**Required permissions**: ohos.permission.READ_HEALTH_DATA
708
709**System capability**: SystemCapability.Sensors.Sensor.Lite
710
711| Name   | Type                                   | Mandatory| Description                                           |
712| ------- | --------------------------------------- | ---- | ----------------------------------------------- |
713| success | [HeartRateResponse](#heartrateresponse) | Yes  | Called when the heart rate sensor data changes. This callback is invoked every five seconds.|
714| fail    | Function                                | No  | Callback upon an API call failure.                       |
715
716## HeartRateResponse
717
718Defines the type of data to include in a **HeartRateResponse** object.
719
720**Required permissions**: ohos.permission.READ_HEALTH_DATA
721
722**System capability**: SystemCapability.Sensors.Sensor.Lite
723
724| Name     | Type  | Mandatory| Description    |
725| --------- | ------ | ---- | -------- |
726| heartRate | number | Yes  | Heart rate.|
727
728## SubscribeOnBodyStateOptions
729
730Defines the type of data to return for a subscription to the wearing state changes.
731
732**System capability**: SystemCapability.Sensors.Sensor.Lite
733
734| Name   | Type                                       | Mandatory| Description                      |
735| ------- | ------------------------------------------- | ---- | -------------------------- |
736| success | [OnBodyStateResponse](#onbodystateresponse) | Yes  | Called when the wearing state changes.|
737| fail    | Function                                    | No  | Callback upon an API call failure.  |
738
739## OnBodyStateResponse
740
741Defines the wearing state.
742
743**System capability**: SystemCapability.Sensors.Sensor.Lite
744
745| Name | Type   | Mandatory| Description        |
746| ----- | ------- | ---- | ------------ |
747| value | boolean | Yes  | Whether the wearable device is worn.|
748
749## GetOnBodyStateOptions
750
751 Defines the type of data to return for obtaining the wearing state.
752
753**System capability**: SystemCapability.Sensors.Sensor.Lite
754
755| Name    | Type                                       | Mandatory| Description                    |
756| -------- | ------------------------------------------- | ---- | ------------------------ |
757| success  | [OnBodyStateResponse](#onbodystateresponse) | Yes  | Callback upon a successful API call.|
758| fail     | Function                                    | No  | Callback upon an API call failure.|
759| complete | Function                                    | No  | Called when the API call is complete.|
760
761## SubscribeDeviceOrientationOptions<sup>6+</sup>
762
763Defines the type of data to return for a subscription to the device orientation sensor data.
764
765**System capability**: SystemCapability.Sensors.Sensor.Lite
766
767| Name    | Type                                                    | Mandatory| Description                                                        |
768| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ |
769| interval | string                                                   | Yes  | Interval at which the callback is invoked to return the device orientation sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.|
770| success  | [DeviceOrientationResponse](#deviceorientationresponse6) | Yes  | Called when the device orientation sensor data changes.                  |
771| fail     | Function                                                 | No  | Callback upon an API call failure.                                    |
772
773## DeviceOrientationResponse<sup>6+</sup>
774
775Defines the type of data to include in a **DeviceOrientationResponse** object.
776
777**System capability**: SystemCapability.Sensors.Sensor.Lite
778
779| Name | Type  | Mandatory| Description                                                        |
780| ----- | ------ | ---- | ------------------------------------------------------------ |
781| alpha | number | Yes  | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth.|
782| beta  | number | Yes  | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth.|
783| gamma | number | Yes  | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth.|
784
785## SubscribeGyroscopeOptions<sup>6+</sup>
786
787Defines the type of data to return for a subscription to the gyroscope sensor data.
788
789**Required permissions**: ohos.permission.GYROSCOPE
790
791**System capability**: SystemCapability.Sensors.Sensor.Lite
792
793| Name    | Type                                    | Mandatory| Description                                                        |
794| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
795| interval | string                                   | Yes  | Interval at which the callback is invoked to return the gyroscope sensor data.<br>The default value is **normal**. The options are as follows:<br>**game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>**ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>**normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.|
796| success  | [GyroscopeResponse](#gyroscoperesponse6) | Yes  | Called when the gyroscope sensor data changes.                          |
797| fail     | Function                                 | No  | Callback upon an API call failure.                                    |
798
799## GyroscopeResponse<sup>6+</sup>
800
801Defines the type of data to include in a **GyroscopeResponse** object.
802
803**Required permissions**: ohos.permission.GYROSCOPE
804
805**System capability**: SystemCapability.Sensors.Sensor.Lite
806
807| Name| Type  | Mandatory| Description             |
808| ---- | ------ | ---- | ----------------- |
809| x    | number | Yes  | Rotation angular velocity of the X axis.|
810| y    | number | Yes  | Rotation angular velocity of the Y axis.|
811| z    | number | Yes  | Rotation angular velocity of the Z axis.|
812