• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Sensor
2
3> **NOTE**
4>
5> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6
7
8## Modules to Import
9
10```js
11import sensor from '@ohos.sensor';
12```
13
14## sensor.on
15
16### ACCELEROMETER
17
18on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>,options?: Options): void
19
20Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
21
22**Required permissions**: ohos.permission.ACCELEROMETER
23
24**System capability**: SystemCapability.Sensors.Sensor
25
26**Parameters**
27
28| Name     | Type                                      | Mandatory  | Description                                      |
29| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
30| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
31| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
32| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
33
34**Example**
35  ```js
36  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
37      console.info('X-coordinate component: ' + data.x);
38      console.info('Y-coordinate component: ' + data.y);
39      console.info('Z-coordinate component: ' + data.z);
40  },
41      {interval: 10000000}
42  );
43  ```
44
45### LINEAR_ACCELERATION
46
47on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>, options?: Options): void
48
49Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
50
51**Required permissions**: ohos.permission.ACCELEROMETER
52
53**System capability**: SystemCapability.Sensors.Sensor
54
55**Parameters**
56| Name     | Type                                      | Mandatory  | Description                                      |
57| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
58| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
59| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes   | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
60| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
61
62**Example**
63  ```js
64  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){
65      console.info('X-coordinate component: ' + data.x);
66      console.info('Y-coordinate component: ' + data.y);
67      console.info('Z-coordinate component: ' + data.z);
68  },
69      {interval: 10000000}
70  );
71  ```
72
73### ACCELEROMETER_UNCALIBRATED
74
75on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>, options?: Options): void
76
77Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
78
79**Required permissions**: ohos.permission.ACCELEROMETER
80
81**System capability**: SystemCapability.Sensors.Sensor
82
83**Parameters**
84| Name     | Type                                      | Mandatory  | Description                                      |
85| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
86| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
87| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes   | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
88| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
89
90**Example**
91  ```js
92  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
93      console.info('X-coordinate component: ' + data.x);
94      console.info('Y-coordinate component: ' + data.y);
95      console.info('Z-coordinate component: ' + data.z);
96      console.info('X-coordinate bias: ' + data.biasX);
97      console.info('Y-coordinate bias: ' + data.biasY);
98      console.info('Z-coordinate bias: ' + data.biasZ);
99  },
100      {interval: 10000000}
101  );
102  ```
103
104### GRAVITY
105
106on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>,options?: Options): void
107
108Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect.
109
110**System capability**: SystemCapability.Sensors.Sensor
111
112**Parameters**
113| Name     | Type                                      | Mandatory  | Description                                   |
114| -------- | ---------------------------------------- | ---- | ------------------------------------- |
115| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.  |
116| callback | Callback<[GravityResponse](#gravityresponse)> | Yes   | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
117| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.       |
118
119**Example**
120  ```js
121  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
122      console.info('X-coordinate component: ' + data.x);
123      console.info('Y-coordinate component: ' + data.y);
124      console.info('Z-coordinate component: ' + data.z);
125  },
126      {interval: 10000000}
127  );
128  ```
129
130### GYROSCOPE
131
132on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>, options?: Options): void
133
134Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
135
136**Required permissions**: ohos.permission.GYROSCOPE
137
138**System capability**: SystemCapability.Sensors.Sensor
139
140**Parameters**
141| Name     | Type                                      | Mandatory  | Description                                      |
142| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
143| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.  |
144| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes   | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
145| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
146
147**Example**
148  ```js
149  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
150      console.info('X-coordinate component: ' + data.x);
151      console.info('Y-coordinate component: ' + data.y);
152      console.info('Z-coordinate component: ' + data.z);
153  },
154      {interval: 10000000}
155  );
156  ```
157
158### GYROSCOPE_UNCALIBRATED
159
160on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<GyroscopeUncalibratedResponse>, options?: Options): void
161
162Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
163
164**Required permissions**: ohos.permission.GYROSCOPE
165
166**System capability**: SystemCapability.Sensors.Sensor
167
168**Parameters**
169| Name     | Type                                      | Mandatory  | Description                                      |
170| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
171| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
172| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes   | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
173| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data.                          |
174
175**Example**
176  ```js
177  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
178      console.info('X-coordinate component: ' + data.x);
179      console.info('Y-coordinate component: ' + data.y);
180      console.info('Z-coordinate component: ' + data.z);
181      console.info('X-coordinate bias: ' + data.biasX);
182      console.info('Y-coordinate bias: ' + data.biasY);
183      console.info('Z-coordinate bias: ' + data.biasZ);
184  },
185      {interval: 10000000}
186  );
187  ```
188
189### SIGNIFICANT_MOTION
190
191on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>, options?: Options): void
192
193Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect.
194
195**System capability**: SystemCapability.Sensors.Sensor
196
197**Parameters**
198| Name     | Type                                      | Mandatory  | Description                                      |
199| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
200| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
201| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes   | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
202| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
203
204**Example**
205  ```js
206  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
207      console.info('Scalar data: ' + data.scalar);
208  },
209      {interval: 10000000}
210  );
211  ```
212
213### PEDOMETER_DETECTION
214
215on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>, options?: Options): void
216
217Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect.
218
219**Required permissions**: ohos.permission.ACTIVITY_MOTION
220
221**System capability**: SystemCapability.Sensors.Sensor
222
223**Parameters**
224| Name     | Type                                      | Mandatory  | Description                                      |
225| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
226| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
227| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes   | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
228| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
229
230**Example**
231  ```js
232  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
233      console.info('Scalar data: ' + data.scalar);
234  },
235      {interval: 10000000}
236  );
237  ```
238
239### PEDOMETER
240
241on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>, options?: Options): void
242
243Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect.
244
245**Required permissions**: ohos.permission.ACTIVITY_MOTION
246
247**System capability**: SystemCapability.Sensors.Sensor
248
249**Parameters**
250| Name     | Type                                      | Mandatory  | Description                                     |
251| -------- | ---------------------------------------- | ---- | --------------------------------------- |
252| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.  |
253| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes   | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
254| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.         |
255
256**Example**
257  ```js
258  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
259      console.info('Steps: ' + data.steps);
260  },
261      {interval: 10000000}
262  );
263  ```
264
265### AMBIENT_TEMPERATURE
266
267on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<AmbientTemperatureResponse>,  options?: Options): void
268
269Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect.
270
271**System capability**: SystemCapability.Sensors.Sensor
272
273**Parameters**
274| Name     | Type                                      | Mandatory  | Description                                      |
275| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
276| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
277| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes   | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
278| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
279
280**Example**
281  ```js
282  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
283      console.info('Temperature: ' + data.temperature);
284  },
285      {interval: 10000000}
286  );
287  ```
288
289### MAGNETIC_FIELD
290
291on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>,options?: Options): void
292
293Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.
294
295**System capability**: SystemCapability.Sensors.Sensor
296
297**Parameters**
298| Name     | Type                                      | Mandatory  | Description                                      |
299| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
300| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.|
301| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes   | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
302| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
303
304**Example**
305  ```js
306  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
307      console.info('X-coordinate component: ' + data.x);
308      console.info('Y-coordinate component: ' + data.y);
309      console.info('Z-coordinate component: ' + data.z);
310  },
311      {interval: 10000000}
312  );
313  ```
314
315### MAGNETIC_FIELD_UNCALIBRATED
316
317on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>, options?: Options): void
318
319Subscribes to data changes of the uncalibrated magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.
320
321**System capability**: SystemCapability.Sensors.Sensor
322
323**Parameters**
324| Name     | Type                                      | Mandatory  | Description                                      |
325| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
326| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
327| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes   | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
328| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
329
330**Example**
331  ```js
332  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
333      console.info('X-coordinate component: ' + data.x);
334      console.info('Y-coordinate component: ' + data.y);
335      console.info('Z-coordinate component: ' + data.z);
336      console.info('X-coordinate bias: ' + data.biasX);
337      console.info('Y-coordinate bias: ' + data.biasY);
338      console.info('Z-coordinate bias: ' + data.biasZ);
339  },
340      {interval: 10000000}
341  );
342  ```
343
344### PROXIMITY
345
346on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>,options?: Options): void
347
348Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.
349
350**System capability**: SystemCapability.Sensors.Sensor
351
352**Parameters**
353| Name     | Type                                      | Mandatory  | Description                                      |
354| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
355| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.  |
356| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes   | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
357| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
358
359**Example**
360  ```js
361  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
362      console.info('Distance: ' + data.distance);
363  },
364      {interval: 10000000}
365  );
366  ```
367
368### HUMIDITY
369
370on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>,options?: Options): void
371
372Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect.
373
374**System capability**: SystemCapability.Sensors.Sensor
375
376**Parameters**
377| Name     | Type                                      | Mandatory  | Description                                    |
378| -------- | ---------------------------------------- | ---- | -------------------------------------- |
379| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
380| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes   | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
381| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.        |
382
383**Example**
384  ```js
385  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
386      console.info('Humidity: ' + data.humidity);
387  },
388      {interval: 10000000}
389  );
390  ```
391
392### BAROMETER
393
394on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>,options?: Options): void
395
396Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
397
398**System capability**: SystemCapability.Sensors.Sensor
399
400**Parameters**
401| Name     | Type                                      | Mandatory  | Description                                      |
402| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
403| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.  |
404| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes   | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
405| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
406
407**Example**
408  ```js
409  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
410      console.info('Atmospheric pressure: ' + data.pressure);
411  },
412      {interval: 10000000}
413  );
414  ```
415
416### HALL
417
418on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>, options?: Options): void
419
420Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect.
421
422**System capability**: SystemCapability.Sensors.Sensor
423
424**Parameters**
425| Name     | Type                                      | Mandatory  | Description                                      |
426| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
427| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
428| callback | Callback<[HallResponse](#hallresponse)> | Yes   | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
429| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
430
431**Example**
432  ```js
433  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
434      console.info('Status: ' + data.status);
435  },
436      {interval: 10000000}
437  );
438  ```
439
440### AMBIENT_LIGHT
441
442on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>, options?: Options): void
443
444Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect.
445
446**System capability**: SystemCapability.Sensors.Sensor
447
448**Parameters**
449| Name     | Type                                      | Mandatory  | Description                                      |
450| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
451| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
452| callback | Callback<[LightResponse](#lightresponse)> | Yes   | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.    |
453| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
454
455**Example**
456  ```js
457  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
458      console.info(' Illumination: ' + data.intensity);
459  },
460      {interval: 10000000}
461  );
462  ```
463
464### ORIENTATION
465
466on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>, options?: Options): void
467
468Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect.
469
470**System capability**: SystemCapability.Sensors.Sensor
471
472**Parameters**
473| Name     | Type                                      | Mandatory  | Description                                      |
474| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
475| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.  |
476| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes   | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
477| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
478
479**Example**
480  ```js
481  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
482      console.info('The device rotates at an angle around the X axis: ' + data.beta);
483      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
484      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
485  },
486      {interval: 10000000}
487  );
488  ```
489
490### HEART_RATE
491
492on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>, options?: Options): void
493
494Subscribes to only one data change of the heart rate sensor.
495
496**Required permissions**: ohos.permission.READ_HEALTH_DATA
497
498**System capability**: SystemCapability.Sensors.Sensor
499
500**Parameters**
501
502| Name     | Type                                      | Mandatory  | Description                                      |
503| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
504| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.  |
505| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
506
507**Example**
508
509```js
510sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){
511    console.info("Heart rate: " + data.heartRate);
512},
513    {interval: 10000000}
514);
515```
516
517### ROTATION_VECTOR
518
519on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<RotationVectorResponse>,options?: Options): void
520
521Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect.
522
523**System capability**: SystemCapability.Sensors.Sensor
524
525**Parameters**
526| Name     | Type                                      | Mandatory  | Description                                      |
527| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
528| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
529| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes   | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
530| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
531
532**Example**
533  ```js
534  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
535      console.info('X-coordinate component: ' + data.x);
536      console.info('Y-coordinate component: ' + data.y);
537      console.info('Z-coordinate component: ' + data.z);
538      console.info('Scalar quantity: ' + data.w);
539  },
540      {interval: 10000000}
541  );
542  ```
543
544### WEAR_DETECTION
545
546on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>,options?: Options): void
547
548Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect.
549
550**System capability**: SystemCapability.Sensors.Sensor
551
552**Parameters**
553| Name     | Type                                      | Mandatory  | Description                                      |
554| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
555| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
556| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes   | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
557| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
558
559**Example**
560  ```js
561  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
562      console.info('Wear status: ' + data.value);
563  },
564      {interval: 10000000}
565  );
566  ```
567
568## sensor.once
569
570### ACCELEROMETER
571
572once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>): void
573
574Subscribes to only one data change of the acceleration sensor.
575
576**Required permissions**: ohos.permission.ACCELEROMETER
577
578**System capability**: SystemCapability.Sensors.Sensor
579
580**Parameters**
581| Name     | Type                                      | Mandatory  | Description                                      |
582| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
583| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.  |
584| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes   | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
585
586**Example**
587  ```js
588  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
589      console.info('X-coordinate component: ' + data.x);
590      console.info('Y-coordinate component: ' + data.y);
591      console.info('Z-coordinate component: ' + data.z);
592    }
593  );
594  ```
595
596### LINEAR_ACCELERATION
597
598once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>): void
599
600Subscribes to only one data change of the linear acceleration sensor.
601
602**Required permissions**: ohos.permission.ACCELEROMETER
603
604**System capability**: SystemCapability.Sensors.Sensor
605
606**Parameters**
607| Name     | Type                                      | Mandatory  | Description                                      |
608| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
609| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
610| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes   | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
611
612**Example**
613  ```js
614  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) {
615      console.info('X-coordinate component: ' + data.x);
616      console.info('Y-coordinate component: ' + data.y);
617      console.info('Z-coordinate component: ' + data.z);
618    }
619  );
620  ```
621
622### ACCELEROMETER_UNCALIBRATED
623
624once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>): void
625
626Subscribes to only one data change of the uncalibrated acceleration sensor.
627
628**Required permissions**: ohos.permission.ACCELEROMETER
629
630**System capability**: SystemCapability.Sensors.Sensor
631
632**Parameters**
633| Name     | Type                                      | Mandatory  | Description                                      |
634| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
635| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
636| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
637
638**Example**
639  ```
640  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
641      console.info('X-coordinate component: ' + data.x);
642      console.info('Y-coordinate component: ' + data.y);
643      console.info('Z-coordinate component: ' + data.z);
644      console.info('X-coordinate bias: ' + data.biasX);
645      console.info('Y-coordinate bias: ' + data.biasY);
646      console.info('Z-coordinate bias: ' + data.biasZ);
647    }
648  );
649  ```
650
651### GRAVITY
652
653once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>): void
654
655Subscribes to only one data change of the gravity sensor.
656
657**System capability**: SystemCapability.Sensors.Sensor
658
659**Parameters**
660| Name     | Type                                      | Mandatory  | Description                                     |
661| -------- | ---------------------------------------- | ---- | --------------------------------------- |
662| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.        |
663| callback | Callback<[GravityResponse](#gravityresponse)> | Yes   | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
664
665**Example**
666  ```js
667  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
668      console.info('X-coordinate component: ' + data.x);
669      console.info('Y-coordinate component: ' + data.y);
670      console.info('Z-coordinate component: ' + data.z);
671    }
672  );
673  ```
674
675### GYROSCOPE
676
677once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>): void
678
679Subscribes to only one data change of the gyroscope sensor.
680
681**Required permissions**: ohos.permission.GYROSCOPE
682
683**System capability**: SystemCapability.Sensors.Sensor
684
685**Parameters**
686| Name     | Type                                      | Mandatory  | Description                                      |
687| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
688| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.      |
689| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes   | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
690
691**Example**
692  ```js
693  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
694      console.info('X-coordinate component: ' + data.x);
695      console.info('Y-coordinate component: ' + data.y);
696      console.info('Z-coordinate component: ' + data.z);
697    }
698  );
699  ```
700
701### GYROSCOPE_UNCALIBRATED
702
703once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback<GyroscopeUncalibratedResponse>): void
704
705Subscribes to only one data change of the uncalibrated gyroscope sensor.
706
707**Required permissions**: ohos.permission.GYROSCOPE
708
709**System capability**: SystemCapability.Sensors.Sensor
710
711**Parameters**
712| Name     | Type                                      | Mandatory  | Description                                      |
713| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
714| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
715| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
716
717**Example**
718  ```js
719  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
720      console.info('X-coordinate component: ' + data.x);
721      console.info('Y-coordinate component: ' + data.y);
722      console.info('Z-coordinate component: ' + data.z);
723      console.info('X-coordinate bias: ' + data.biasX);
724      console.info('Y-coordinate bias: ' + data.biasY);
725      console.info('Z-coordinate bias: ' + data.biasZ);
726    }
727  );
728  ```
729
730### SIGNIFICANT_MOTION
731
732once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<SignificantMotionResponse>): void
733
734Subscribes to only one data change of the significant motion sensor.
735
736**System capability**: SystemCapability.Sensors.Sensor
737
738**Parameters**
739| Name     | Type                                      | Mandatory  | Description                                      |
740| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
741| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
742| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes   | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
743
744**Example**
745  ```js
746  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
747      console.info('Scalar data: ' + data.scalar);
748    }
749  );
750  ```
751
752### PEDOMETER_DETECTION
753
754once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<PedometerDetectionResponse>): void
755
756Subscribes to only one data change of the pedometer detection sensor.
757
758**Required permissions**: ohos.permission.ACTIVITY_MOTION
759
760**System capability**: SystemCapability.Sensors.Sensor
761
762**Parameters**
763| Name     | Type                                      | Mandatory  | Description                                      |
764| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
765| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
766| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes   | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
767
768**Example**
769  ```js
770  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
771      console.info('Scalar data: ' + data.scalar);
772    }
773  );
774  ```
775
776### PEDOMETER
777
778once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>): void
779
780Subscribes to only one data change of the pedometer sensor.
781
782**Required permissions**: ohos.permission.ACTIVITY_MOTION
783
784**System capability**: SystemCapability.Sensors.Sensor
785
786**Parameters**
787| Name     | Type                                      | Mandatory  | Description                                      |
788| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
789| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.       |
790| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes   | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
791
792**Example**
793  ```js
794  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
795      console.info('Steps: ' + data.steps);
796    }
797  );
798  ```
799
800### AMBIENT_TEMPERATURE
801
802once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<AmbientTemperatureResponse>): void
803
804Subscribes to only one data change of the ambient temperature sensor.
805
806**System capability**: SystemCapability.Sensors.Sensor
807
808**Parameters**
809| Name     | Type                                      | Mandatory  | Description                                      |
810| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
811| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
812| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes   | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
813
814**Example**
815  ```js
816  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
817      console.info('Temperature: ' + data.temperature);
818    }
819  );
820  ```
821
822### MAGNETIC_FIELD
823
824once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>): void
825
826Subscribes to only one data change of the magnetic field sensor.
827
828**System capability**: SystemCapability.Sensors.Sensor
829
830**Parameters**
831| Name     | Type                                      | Mandatory  | Description                                      |
832| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
833| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.  |
834| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes   | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
835
836**Example**
837  ```js
838  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
839      console.info('X-coordinate component: ' + data.x);
840      console.info('Y-coordinate component: ' + data.y);
841      console.info('Z-coordinate component: ' + data.z);
842    }
843  );
844  ```
845
846### MAGNETIC_FIELD_UNCALIBRATED
847
848once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>): void
849
850Subscribes to only one data change of the uncalibrated magnetic field sensor.
851
852**System capability**: SystemCapability.Sensors.Sensor
853
854**Parameters**
855| Name     | Type                                      | Mandatory  | Description                                      |
856| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
857| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
858| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
859
860**Example**
861  ```js
862  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
863      console.info('X-coordinate component: ' + data.x);
864      console.info('Y-coordinate component: ' + data.y);
865      console.info('Z-coordinate component: ' + data.z);
866      console.info('X-coordinate bias: ' + data.biasX);
867      console.info('Y-coordinate bias: ' + data.biasY);
868      console.info('Z-coordinate bias: ' + data.biasZ);
869    }
870  );
871  ```
872
873### PROXIMITY
874
875once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>): void
876
877Subscribes to only one data change of the proximity sensor.
878
879**System capability**: SystemCapability.Sensors.Sensor
880
881**Parameters**
882| Name     | Type                                      | Mandatory  | Description                                      |
883| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
884| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.      |
885| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes   | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
886
887**Example**
888  ```js
889  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) {
890      if (error) {
891          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
892          return;
893      }
894      console.info('Distance: ' + data.distance);
895    }
896  );
897  ```
898
899### HUMIDITY
900
901once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>): void
902
903Subscribes to only one data change of the humidity sensor.
904
905**System capability**: SystemCapability.Sensors.Sensor
906
907**Parameters**
908| Name     | Type                                      | Mandatory  | Description                                      |
909| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
910| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.        |
911| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes   | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
912
913**Example**
914  ```js
915  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
916      console.info('Humidity: ' + data.humidity);
917    }
918  );
919  ```
920
921### BAROMETER
922
923once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>): void
924
925Subscribes to only one data change of the barometer sensor.
926
927**System capability**: SystemCapability.Sensors.Sensor
928
929**Parameters**
930| Name     | Type                                      | Mandatory  | Description                                      |
931| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
932| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.      |
933| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes   | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
934
935**Example**
936  ```js
937  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
938      console.info('Atmospheric pressure: ' + data.pressure);
939    }
940  );
941  ```
942
943### HALL
944
945once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>): void
946
947Subscribes to only one data change of the Hall effect sensor.
948
949**System capability**: SystemCapability.Sensors.Sensor
950
951**Parameters**
952| Name     | Type                                      | Mandatory  | Description                                  |
953| -------- | ---------------------------------------- | ---- | ------------------------------------ |
954| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
955| callback | Callback<[HallResponse](#hallresponse)> | Yes   | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
956
957**Example**
958  ```js
959  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
960      console.info('Status: ' + data.status);
961    }
962  );
963  ```
964
965### AMBIENT_LIGHT
966
967once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>): void
968
969Subscribes to only one data change of the ambient light sensor.
970
971**System capability**: SystemCapability.Sensors.Sensor
972
973**Parameters**
974| Name     | Type                                      | Mandatory  | Description                                    |
975| -------- | ---------------------------------------- | ---- | -------------------------------------- |
976| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
977| callback | Callback<[LightResponse](#lightresponse)> | Yes   | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
978
979**Example**
980  ```js
981  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
982      console.info(' Illumination: ' + data.intensity);
983    }
984  );
985  ```
986
987### ORIENTATION
988
989once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>): void
990
991Subscribes to only one data change of the orientation sensor.
992
993**System capability**: SystemCapability.Sensors.Sensor
994
995**Parameters**
996| Name     | Type                                      | Mandatory  | Description                                      |
997| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
998| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.     |
999| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes   | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
1000
1001**Example**
1002  ```js
1003  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
1004      console.info('The device rotates at an angle around the X axis: ' + data.beta);
1005      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
1006      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
1007    }
1008  );
1009  ```
1010
1011### ROTATION_VECTOR
1012
1013once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<RotationVectorResponse>): void
1014
1015Subscribes to only one data change of the rotation vector sensor.
1016
1017**System capability**: SystemCapability.Sensors.Sensor
1018
1019**Parameters**
1020| Name     | Type                                      | Mandatory  | Description                                      |
1021| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1022| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
1023| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes   | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
1024
1025**Example**
1026  ```js
1027  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
1028      console.info('X-coordinate component: ' + data.x);
1029      console.info('Y-coordinate component: ' + data.y);
1030      console.info('Z-coordinate component: ' + data.z);
1031      console.info('Scalar quantity: ' + data.w);
1032    }
1033  );
1034  ```
1035
1036### HEART_RATE
1037
1038once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>): void
1039
1040Subscribes to only one data change of the heart rate sensor.
1041
1042**Required permissions**: ohos.permission.READ_HEALTH_DATA
1043
1044**System capability**: SystemCapability.Sensors.Sensor
1045
1046**Parameters**
1047| Name     | Type                                      | Mandatory  | Description                                      |
1048| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1049| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.      |
1050| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
1051
1052**Example**
1053  ```js
1054  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
1055      console.info("Heart rate: " + data.heartRate);
1056    }
1057  );
1058  ```
1059
1060### WEAR_DETECTION
1061
1062once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>): void
1063
1064Subscribes to only one data change of the wear detection sensor.
1065
1066**System capability**: SystemCapability.Sensors.Sensor
1067
1068**Parameters**
1069| Name     | Type                                      | Mandatory  | Description                                      |
1070| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1071| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
1072| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes   | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
1073
1074**Example**
1075  ```js
1076  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
1077      console.info("Wear status: "+ data.value);
1078    }
1079  );
1080  ```
1081
1082## sensor.off
1083
1084### ACCELEROMETER
1085
1086off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<AccelerometerResponse>): void
1087
1088Unsubscribes from sensor data changes.
1089
1090**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)
1091
1092**System capability**: SystemCapability.Sensors.Sensor
1093
1094**Parameters**
1095
1096| Name     | Type                                      | Mandatory  | Description                                      |
1097| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1098| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
1099| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
1100
1101**Example**
1102
1103```js
1104function callback(data) {
1105    console.info('x-coordinate component: ' + data.x);
1106    console.info('Y-coordinate component: ' + data.y);
1107    console.info('Z-coordinate component: ' + data.z);
1108}
1109sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
1110```
1111
1112### ACCELEROMETER_UNCALIBRATED
1113
1114off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback<AccelerometerUncalibratedResponse>): void
1115
1116Unsubscribes from sensor data changes.
1117
1118**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)
1119
1120**System capability**: SystemCapability.Sensors.Sensor
1121
1122**Parameters**
1123
1124| Name     | Type                                      | Mandatory  | Description                                      |
1125| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1126| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
1127| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes   | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
1128
1129**Example**
1130
1131```js
1132function callback(data) {
1133    console.info('X-coordinate component: ' + data.x);
1134    console.info('Y-coordinate component: ' + data.y);
1135    console.info('Z-coordinate component: ' + data.z);
1136    console.info('X-coordinate bias: ' + data.biasX);
1137    console.info('Y-coordinate bias: ' + data.biasY);
1138    console.info('Z-coordinate bias: ' + data.biasZ);
1139}
1140sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
1141```
1142
1143### AMBIENT_LIGHT
1144
1145off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightResponse>): void
1146
1147Unsubscribes from sensor data changes.
1148
1149**System capability**: SystemCapability.Sensors.Sensor
1150
1151**Parameters**
1152
1153| Name     | Type                                      | Mandatory  | Description                                      |
1154| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1155| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
1156| callback | Callback<[LightResponse](#lightresponse)> | Yes   | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.  |
1157
1158**Example**
1159
1160```js
1161function callback(data) {
1162    console.info(' Illumination: ' + data.intensity);
1163}
1164sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
1165```
1166
1167### AMBIENT_TEMPERATURE
1168
1169off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatureResponse>): void
1170
1171Unsubscribes from sensor data changes.
1172
1173**System capability**: SystemCapability.Sensors.Sensor
1174
1175**Parameters**
1176
1177| Name     | Type                                      | Mandatory  | Description                                      |
1178| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1179| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
1180| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes   | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
1181
1182**Example**
1183
1184```js
1185function callback(data) {
1186     console.info('Temperature: ' + data.temperature);
1187}
1188sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
1189```
1190
1191### AMBIENT_TEMPERATURE
1192
1193off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerResponse>): void
1194
1195Unsubscribes from sensor data changes.
1196
1197**System capability**: SystemCapability.Sensors.Sensor
1198
1199**Parameters**
1200
1201| Name     | Type                                      | Mandatory  | Description                                      |
1202| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1203| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**.|
1204| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes   | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
1205
1206**Example**
1207
1208```js
1209function callback(data) {
1210     console.info('Atmospheric pressure: ' + data.pressure);
1211}
1212sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
1213```
1214
1215### GRAVITY
1216
1217off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityResponse>): void
1218
1219Unsubscribes from sensor data changes.
1220
1221**System capability**: SystemCapability.Sensors.Sensor
1222
1223**Parameters**
1224
1225| Name     | Type                                      | Mandatory  | Description                                      |
1226| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1227| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**.   |
1228| callback | Callback<[GravityResponse](#gravityresponse)> | Yes   | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
1229
1230**Example**
1231
1232```js
1233function callback(data) {
1234    console.info('X-coordinate component: ' + data.x);
1235    console.info('Y-coordinate component: ' + data.y);
1236    console.info('Z-coordinate component: ' + data.z);
1237}
1238sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
1239```
1240
1241### GYROSCOPE
1242
1243off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeResponse>): void
1244
1245Unsubscribes from sensor data changes.
1246
1247**Required permissions**: ohos.permission.GYROSCOPE (a system permission)
1248
1249**System capability**: SystemCapability.Sensors.Sensor
1250
1251**Parameters**
1252
1253| Name     | Type                                      | Mandatory  | Description                                      |
1254| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1255| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**.|
1256| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes   | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
1257
1258**Example**
1259
1260```js
1261function callback(data) {
1262    console.info('X-coordinate component: ' + data.x);
1263    console.info('Y-coordinate component: ' + data.y);
1264    console.info('Z-coordinate component: ' + data.z);
1265}
1266sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
1267```
1268
1269### GYROSCOPE_UNCALIBRATED
1270
1271off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncalibratedResponse>): void
1272
1273Unsubscribes from sensor data changes.
1274
1275**Required permissions**: ohos.permission.GYROSCOPE (a system permission)
1276
1277**System capability**: SystemCapability.Sensors.Sensor
1278
1279**Parameters**
1280
1281| Name     | Type                                      | Mandatory  | Description                                      |
1282| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1283| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
1284| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes   | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
1285
1286**Example**
1287
1288```js
1289function callback(data) {
1290    console.info('X-coordinate component: ' + data.x);
1291    console.info('Y-coordinate component: ' + data.y);
1292    console.info('Z-coordinate component: ' + data.z);
1293}
1294sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
1295```
1296
1297### HALL
1298
1299off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>): void
1300
1301Unsubscribes from sensor data changes.
1302
1303**System capability**: SystemCapability.Sensors.Sensor
1304
1305**Parameters**
1306
1307| Name     | Type                                      | Mandatory  | Description                                      |
1308| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1309| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**.      |
1310| callback | Callback<[HallResponse](#hallresponse)> | Yes   | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
1311
1312**Example**
1313
1314```js
1315function callback(data) {
1316    console.info('Status: ' + data.status);
1317}
1318sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
1319```
1320
1321### HEART_RATE
1322
1323off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRateResponse>): void
1324
1325Unsubscribes from sensor data changes.
1326
1327**Required permissions**: ohos.permission.READ_HEALTH_DATA
1328
1329**System capability**: SystemCapability.Sensors.Sensor
1330
1331**Parameters**
1332
1333| Name     | Type                                      | Mandatory  | Description                                      |
1334| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1335| type     | [SensorType](#sensortype)[SensorType](#sensortype) | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**.|
1336| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
1337
1338**Example**
1339
1340```js
1341function callback(data) {
1342    console.info("Heart rate: " + data.heartRate);
1343}
1344sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
1345```
1346
1347### HUMIDITY
1348
1349off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityResponse>): void
1350
1351Unsubscribes from sensor data changes.
1352
1353**System capability**: SystemCapability.Sensors.Sensor
1354
1355**Parameters**
1356
1357| Name     | Type                                      | Mandatory  | Description                                      |
1358| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1359| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
1360| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes   | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
1361
1362**Example**
1363
1364```js
1365function callback(data) {
1366    console.info('Humidity: ' + data.humidity);
1367}
1368sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
1369```
1370
1371### LINEAR_ACCELERATION
1372
1373off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<LinearAccelerometerResponse>): void
1374
1375Unsubscribes from sensor data changes.
1376
1377**Required permissions**: ohos.permission.ACCELEROMETER
1378
1379**System capability**: SystemCapability.Sensors.Sensor
1380
1381**Parameters**
1382
1383| Name     | Type                                      | Mandatory  | Description                                      |
1384| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1385| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
1386| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
1387
1388**Example**
1389
1390```js
1391function callback(data) {
1392    console.info('X-coordinate component: ' + data.x);
1393    console.info('Y-coordinate component: ' + data.y);
1394    console.info('Z-coordinate component: ' + data.z);
1395}
1396sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
1397```
1398
1399### MAGNETIC_FIELD
1400
1401 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void
1402
1403Unsubscribes from sensor data changes.
1404
1405**System capability**: SystemCapability.Sensors.Sensor
1406
1407**Parameters**
1408
1409| Name             | Type                                      | Mandatory  | Description                                      |
1410| ---------------- | ---------------------------------------- | ---- | ---------------------------------------- |
1411| type             | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.|
1412| callbackcallback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes   | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
1413
1414**Example**
1415
1416```js
1417function callback(data) {
1418    console.info('X-coordinate component: ' + data.x);
1419    console.info('Y-coordinate component: ' + data.y);
1420    console.info('Z-coordinate component: ' + data.z);
1421}
1422sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
1423```
1424
1425### MAGNETIC_FIELD_UNCALIBRATED
1426
1427 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void
1428
1429Unsubscribes from sensor data changes.
1430
1431**System capability**: SystemCapability.Sensors.Sensor
1432
1433**Parameters**
1434
1435| Name     | Type                                      | Mandatory  | Description                                      |
1436| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1437| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
1438| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes   | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
1439
1440**Example**
1441
1442```js
1443function callback(data) {
1444    console.info('X-coordinate component: ' + data.x);
1445    console.info('Y-coordinate component: ' + data.y);
1446    console.info('Z-coordinate component: ' + data.z);
1447    console.info('X-coordinate bias: ' + data.biasX);
1448    console.info('Y-coordinate bias: ' + data.biasY);
1449    console.info('Z-coordinate bias: ' + data.biasZ);
1450}
1451sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
1452```
1453
1454### ORIENTATION
1455
1456 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback<OrientationResponse>): void
1457
1458Unsubscribes from sensor data changes.
1459
1460**System capability**: SystemCapability.Sensors.Sensor
1461
1462**Parameters**
1463
1464| Name     | Type                                      | Mandatory  | Description                                      |
1465| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1466| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**.|
1467| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes   | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
1468
1469**Example**
1470
1471```js
1472function callback(data) {
1473    console.info('The device rotates at an angle around the X axis: ' + data.beta);
1474    console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
1475    console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
1476}
1477sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
1478```
1479
1480### PEDOMETER
1481
1482off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerResponse>): void
1483
1484Unsubscribes from sensor data changes.
1485
1486**Required permissions**: ohos.permission.ACTIVITY_MOTION
1487
1488**System capability**: SystemCapability.Sensors.Sensor
1489
1490**Parameters**
1491
1492| Name     | Type                                      | Mandatory  | Description                                      |
1493| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1494| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. |
1495| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes   | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
1496
1497**Example**
1498
1499```js
1500function callback(data) {
1501    console.info('Steps: ' + data.steps);
1502}
1503sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
1504```
1505
1506### PEDOMETER_DETECTION
1507
1508off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void
1509
1510Unsubscribes from sensor data changes.
1511
1512**Required permissions**: ohos.permission.ACTIVITY_MOTION
1513
1514**System capability**: SystemCapability.Sensors.Sensor
1515
1516**Parameters**
1517
1518| Name     | Type                                      | Mandatory  | Description                                      |
1519| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1520| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
1521| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes   | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
1522
1523**Example**
1524
1525```js
1526function callback(data) {
1527    console.info('Scalar data: ' + data.scalar);
1528}
1529sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
1530```
1531
1532### PROXIMITY
1533
1534off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityResponse>): void
1535
1536Unsubscribes from sensor data changes.
1537
1538**System capability**: SystemCapability.Sensors.Sensor
1539
1540**Parameters**
1541
1542| Name     | Type                                      | Mandatory  | Description                                      |
1543| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1544| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**.|
1545| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes   | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
1546
1547**Example**
1548
1549```js
1550function callback(data) {
1551    console.info('Distance: ' + data.distance);
1552}
1553sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
1554```
1555
1556### ROTATION_VECTOR
1557
1558off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void
1559
1560Unsubscribes from sensor data changes.
1561
1562**System capability**: SystemCapability.Sensors.Sensor
1563
1564**Parameters**
1565
1566| Name     | Type                                      | Mandatory  | Description                                      |
1567| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1568| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
1569| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes   | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
1570
1571**Example**
1572
1573```js
1574function callback(data) {
1575    console.info('X-coordinate component: ' + data.x);
1576    console.info('Y-coordinate component: ' + data.y);
1577    console.info('Z-coordinate component: ' + data.z);
1578    console.info('Scalar quantity: ' + data.w);
1579}
1580sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
1581```
1582
1583### SIGNIFICANT_MOTION
1584
1585off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void
1586
1587Unsubscribes from sensor data changes.
1588
1589**System capability**: SystemCapability.Sensors.Sensor
1590
1591**Parameters**
1592
1593| Name     | Type                                      | Mandatory  | Description                                      |
1594| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1595| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
1596| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes   | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
1597
1598**Example**
1599
1600```js
1601function callback(data) {
1602    console.info('Scalar data: ' + data.scalar);
1603}
1604sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
1605```
1606
1607### WEAR_DETECTION
1608
1609off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearDetectionResponse>): void
1610
1611Unsubscribes from sensor data changes.
1612
1613**System capability**: SystemCapability.Sensors.Sensor
1614
1615**Parameters**
1616
1617| Name     | Type                                      | Mandatory  | Description                                      |
1618| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1619| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
1620| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes   | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
1621
1622**Example**
1623
1624```js
1625function accCallback(data) {
1626    console.info('Wear status: ' + data.value);
1627}
1628sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
1629```
1630
1631## sensor.transformCoordinateSystem
1632
1633transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void
1634
1635Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a callback to return the result.
1636
1637**System capability**: SystemCapability.Sensors.Sensor
1638
1639**Parameters**
1640
1641| Name             | Type                                      | Mandatory  | Description         |
1642| ---------------- | ---------------------------------------- | ---- | ----------- |
1643| inRotationVector | Array<number>                      | Yes   | Rotation vector to rotate.    |
1644| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.   |
1645| callback         | AsyncCallback<Array<number>> | Yes   | Callback used to return the rotation vector after being rotated.|
1646
1647**Example**
1648
1649```js
1650sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
1651    if (err) {
1652        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
1653        return;
1654    }
1655    console.info("Operation successed. Data obtained: " + data);
1656    for (var i=0; i < data.length; i++) {
1657        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
1658    }
1659 })
1660```
1661## sensor.transformCoordinateSystem
1662
1663transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
1664
1665Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.
1666
1667**System capability**: SystemCapability.Sensors.Sensor
1668
1669**Parameters**
1670
1671| Name             | Type                                      | Mandatory  | Description      |
1672| ---------------- | ---------------------------------------- | ---- | -------- |
1673| inRotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to rotate. |
1674| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.|
1675
1676**Return value**
1677
1678| Type                                | Description         |
1679| ---------------------------------- | ----------- |
1680| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|
1681
1682**Example**
1683
1684```js
1685const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
1686    promise.then((data) => {
1687        console.info("Operation successed.");
1688        for (var i=0; i < data.length; i++) {
1689            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
1690        }
1691    }).catch((err) => {
1692           console.info("Operation failed");
1693})
1694```
1695
1696## sensor.getGeomagneticField
1697
1698getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
1699
1700Obtains the geomagnetic field of a geographic location. This API uses a callback to return the result.
1701
1702**System capability**: SystemCapability.Sensors.Sensor
1703
1704**Parameters**
1705| Name            | Type                                      | Mandatory  | Description               |
1706| --------------- | ---------------------------------------- | ---- | ----------------- |
1707| locationOptions | [LocationOptions](#locationoptions)      | Yes   | Geographic location.            |
1708| timeMillis      | number                                   | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
1709| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes   | Callback used to return the geomagnetic field.          |
1710
1711**Example**
1712```js
1713sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
1714    if (err) {
1715        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
1716        return;
1717    }
1718    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
1719	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
1720		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
1721});
1722```
1723## sensor.getGeomagneticField
1724
1725getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
1726
1727Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.
1728
1729**System capability**: SystemCapability.Sensors.Sensor
1730
1731**Parameters**
1732| Name            | Type                                 | Mandatory  | Description               |
1733| --------------- | ----------------------------------- | ---- | ----------------- |
1734| locationOptions | [LocationOptions](#locationoptions) | Yes   | Geographic location.            |
1735| timeMillis      | number                              | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
1736
1737**Return value**
1738| Type                                      | Description     |
1739| ---------------------------------------- | ------- |
1740| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|
1741
1742**Example**
1743  ```js
1744  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
1745      promise.then((data) => {
1746          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
1747  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
1748  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
1749      }).catch((reason) => {
1750          console.info('Operation failed.');
1751  })
1752  ```
1753
1754## sensor.getAltitude
1755
1756getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
1757
1758Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a callback to return the result.
1759
1760**System capability**: SystemCapability.Sensors.Sensor
1761
1762**Parameters**
1763
1764| Name            | Type                         | Mandatory  | Description                  |
1765| --------------- | --------------------------- | ---- | -------------------- |
1766| seaPressure     | number                      | Yes   | Sea-level atmospheric pressure, in hPa.    |
1767| currentPressure | number                      | Yes   | Atmospheric pressure at the altitude where the device is located, in hPa.|
1768| callback        | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the altitude, in meters.   |
1769
1770**Example**
1771
1772  ```js
1773  sensor.getAltitude(0, 200, function(err, data)  {
1774      if (err) {
1775          console.error(
1776  "Operation failed. Error code: " + err.code + ", message: " + err.message);
1777          return;
1778      }
1779          console.info("Successed to get getAltitude interface get data: " + data);
1780  });
1781  ```
1782
1783## sensor.getAltitude
1784
1785getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
1786
1787Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a promise to return the result.
1788
1789**System capability**: SystemCapability.Sensors.Sensor
1790
1791**Parameters**
1792
1793| Name            | Type    | Mandatory  | Description                  |
1794| --------------- | ------ | ---- | -------------------- |
1795| seaPressure     | number | Yes   | Sea-level atmospheric pressure, in hPa.    |
1796| currentPressure | number | Yes   | Atmospheric pressure at the altitude where the device is located, in hPa.|
1797
1798**Return value**
1799
1800| Type                   | Description                |
1801| --------------------- | ------------------ |
1802| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|
1803
1804**Example**
1805
1806  ```js
1807  const promise = sensor.getAltitude(0, 200);
1808      promise.then((data) => {
1809          console.info(' sensor_getAltitude_Promise success', data);
1810      }).catch((err) => {
1811          console.error("Operation failed");
1812  })
1813  ```
1814
1815
1816## sensor.getGeomagneticDip
1817
1818getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
1819
1820Obtains the magnetic dip based on the inclination matrix. This API uses a callback to return the result.
1821
1822**System capability**: SystemCapability.Sensors.Sensor
1823
1824**Parameters**
1825
1826| Name              | Type                         | Mandatory  | Description            |
1827| ----------------- | --------------------------- | ---- | -------------- |
1828| inclinationMatrix | Array&lt;number&gt;         | Yes   | Inclination matrix.       |
1829| callback          | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the magnetic dip, in radians.|
1830
1831**Example**
1832
1833  ```js
1834  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
1835      if (err) {
1836          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
1837                        err.message);
1838          return;
1839      }
1840          console.info("Successed to get getGeomagneticDip interface get data: " + data);
1841  })
1842  ```
1843
1844## sensor.getGeomagneticDip
1845
1846getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
1847
1848Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.
1849
1850**System capability**: SystemCapability.Sensors.Sensor
1851
1852**Parameters**
1853
1854| Name              | Type                 | Mandatory  | Description     |
1855| ----------------- | ------------------- | ---- | ------- |
1856| inclinationMatrix | Array&lt;number&gt; | Yes   | Inclination matrix.|
1857
1858**Return value**
1859
1860| Type                   | Description            |
1861| --------------------- | -------------- |
1862| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|
1863
1864**Example**
1865
1866  ```js
1867  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
1868      promise.then((data) => {
1869          console.info(' getGeomagneticDip_promise successed', data);
1870      }).catch((err) => {
1871           console.error("Operation failed");
1872  })
1873  ```
1874
1875## sensor. getAngleModify
1876
1877getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
1878
1879Obtains the angle change between two rotation matrices. This API uses a callback to return the result.
1880
1881**System capability**: SystemCapability.Sensors.Sensor
1882
1883**Parameters**
1884
1885| Name                  | Type                                      | Mandatory  | Description                |
1886| --------------------- | ---------------------------------------- | ---- | ------------------ |
1887| currentRotationMatrix | Array&lt;number&gt;                      | Yes   | Current rotation matrix.         |
1888| preRotationMatrix     | Array&lt;number&gt;                      | Yes   | The other rotation matrix.           |
1889| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the angle change around the z, x, and y axes.|
1890
1891**Example**
1892
1893  ```js
1894  sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
1895      if (err) {
1896          console.error('Failed to register data, error code is: ' + err.code + ', message: ' +
1897                        err.message);
1898          return;
1899      }
1900      for (var i=0; i < data.length; i++) {
1901          console.info("data[" + i + "]: " + data[i]);
1902      }
1903  })
1904  ```
1905
1906
1907## sensor. getAngleModify
1908
1909getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
1910
1911Obtains the angle change between two rotation matrices. This API uses a promise to return the result.
1912
1913**System capability**: SystemCapability.Sensors.Sensor
1914
1915**Parameters**
1916
1917| Name                  | Type                 | Mandatory  | Description       |
1918| --------------------- | ------------------- | ---- | --------- |
1919| currentRotationMatrix | Array&lt;number&gt; | Yes   | Current rotation matrix.|
1920| preRotationMatrix     | Array&lt;number&gt; | Yes   | Rotation matrix.  |
1921
1922**Return value**
1923
1924| Type                                | Description                |
1925| ---------------------------------- | ------------------ |
1926| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes.|
1927
1928**Example**
1929
1930  ```js
1931  const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
1932      promise.then((data) => {
1933          console.info('getAngleModifiy_promise success');
1934          for (var i=0; i < data.length; i++) {
1935              console.info("data[" + i + "]: " + data[i]);
1936          }
1937      }).catch((reason) => {
1938          console.info("promise::catch", reason);
1939  })
1940  ```
1941
1942
1943## sensor.createRotationMatrix
1944
1945createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
1946
1947Converts a rotation vector into a rotation matrix. This API uses a callback to return the result.
1948
1949**System capability**: SystemCapability.Sensors.Sensor
1950
1951**Parameters**
1952
1953| Name           | Type                                      | Mandatory  | Description     |
1954| -------------- | ---------------------------------------- | ---- | ------- |
1955| rotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to convert.|
1956| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the rotation matrix.|
1957
1958**Example**
1959
1960  ```js
1961  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
1962      if (err) {
1963          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
1964                        err.message);
1965          return;
1966      }
1967      for (var i=0; i < data.length; i++) {
1968          console.info("data[" + i + "]: " + data[i]);
1969      }
1970  })
1971  ```
1972
1973
1974## sensor.createRotationMatrix
1975
1976createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
1977
1978Converts a rotation vector into a rotation matrix. This API uses a promise to return the result.
1979
1980**System capability**: SystemCapability.Sensors.Sensor
1981
1982**Parameters**
1983
1984| Name           | Type                 | Mandatory  | Description     |
1985| -------------- | ------------------- | ---- | ------- |
1986| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
1987
1988**Return value**
1989
1990| Type                                | Description     |
1991| ---------------------------------- | ------- |
1992| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|
1993
1994**Example**
1995
1996  ```js
1997  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
1998      promise.then((data) => {
1999          console.info('createRotationMatrix_promise success');
2000          for (var i=0; i < data.length; i++) {
2001              console.info("data[" + i + "]: " + data[i]);
2002          }
2003      }).catch((reason) => {
2004          console.info("promise::catch", reason);
2005  })
2006  ```
2007
2008
2009## sensor.createQuaternion
2010
2011createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
2012
2013Converts a rotation vector into a quaternion. This API uses a callback to return the result.
2014
2015**System capability**: SystemCapability.Sensors.Sensor
2016
2017**Parameters**
2018
2019| Name           | Type                                      | Mandatory  | Description     |
2020| -------------- | ---------------------------------------- | ---- | ------- |
2021| rotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to convert.|
2022| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the quaternion. |
2023
2024**Example**
2025
2026  ```js
2027  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
2028      if (err) {
2029          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
2030                        err.message);
2031          return;
2032      }
2033      for (var i=0; i < data.length; i++) {
2034          console.info("data[" + i + "]: " + data[i]);
2035      }
2036  })
2037  ```
2038
2039
2040## sensor.createQuaternion
2041
2042createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
2043
2044Converts a rotation vector into a quaternion. This API uses a promise to return the result.
2045
2046**System capability**: SystemCapability.Sensors.Sensor
2047
2048**Parameters**
2049
2050| Name           | Type                 | Mandatory  | Description     |
2051| -------------- | ------------------- | ---- | ------- |
2052| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
2053
2054**Return value**
2055
2056| Type                                | Description    |
2057| ---------------------------------- | ------ |
2058| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
2059
2060**Example**
2061
2062  ```js
2063  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
2064      promise.then((data) => {
2065          console.info('createQuaternion_promise successed');
2066          for (var i=0; i < data.length; i++) {
2067              console.info("data[" + i + "]: " + data[i]);
2068          }
2069      }).catch((err) => {
2070          console.info('promise failed');
2071  })
2072  ```
2073
2074
2075## sensor.getDirection
2076
2077getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
2078
2079Obtains the device direction based on the rotation matrix. This API uses a callback to return the result.
2080
2081**System capability**: SystemCapability.Sensors.Sensor
2082
2083**Parameters**
2084
2085| Name           | Type                                      | Mandatory  | Description                |
2086| -------------- | ---------------------------------------- | ---- | ------------------ |
2087| rotationMatrix | Array&lt;number&gt;                      | Yes   | Rotation matrix.           |
2088| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the rotation angle around the z, x, and y axes.|
2089
2090**Example**
2091
2092  ```js
2093  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
2094      if (err) {
2095          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
2096                        err.message);
2097          return;
2098      }
2099      for (var i = 1; i < data.length; i++) {
2100          console.info("sensor_getDirection_callback" + data[i]);
2101      }
2102  })
2103  ```
2104
2105
2106## sensor.getDirection
2107
2108getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
2109
2110Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.
2111
2112**System capability**: SystemCapability.Sensors.Sensor
2113
2114**Parameters**
2115
2116| Name           | Type                 | Mandatory  | Description     |
2117| -------------- | ------------------- | ---- | ------- |
2118| rotationMatrix | Array&lt;number&gt; | Yes   | Rotation matrix.|
2119
2120**Return value**
2121
2122| Type                                | Description                |
2123| ---------------------------------- | ------------------ |
2124| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes.|
2125
2126**Example**
2127
2128  ```js
2129  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
2130      promise.then((data) => {
2131          console.info('sensor_getAltitude_Promise success', data);
2132          for (var i = 1; i < data.length; i++) {
2133              console.info("sensor_getDirection_promise" + data[i]);
2134          }
2135      }).catch((err) => {
2136          console.info('promise failed');
2137  })
2138  ```
2139
2140
2141## sensor.createRotationMatrix
2142
2143createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
2144
2145Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a callback to return the result.
2146
2147**System capability**: SystemCapability.Sensors.Sensor
2148
2149**Parameters**
2150
2151| Name        | Type                                      | Mandatory  | Description     |
2152| ----------- | ---------------------------------------- | ---- | ------- |
2153| gravity     | Array&lt;number&gt;                      | Yes   | Gravity vector.|
2154| geomagnetic | Array&lt;number&gt;                      | Yes   | Geomagnetic vector.|
2155| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes   | Callback used to return the rotation matrix.|
2156
2157**Example**
2158
2159  ```js
2160  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
2161      if (err) {
2162          console.error('error code is: ' + err.code + ', message: ' + err.message);
2163          return;
2164      }
2165      console.info(JSON.stringify(data));
2166  })
2167  ```
2168
2169
2170## sensor.createRotationMatrix
2171
2172createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
2173
2174Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result.
2175
2176**System capability**: SystemCapability.Sensors.Sensor
2177
2178**Parameters**
2179
2180| Name        | Type                 | Mandatory  | Description     |
2181| ----------- | ------------------- | ---- | ------- |
2182| gravity     | Array&lt;number&gt; | Yes   | Gravity vector.|
2183| geomagnetic | Array&lt;number&gt; | Yes   | Geomagnetic vector.|
2184
2185**Return value**
2186
2187| Type                                      | Description     |
2188| ---------------------------------------- | ------- |
2189| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
2190
2191**Example**
2192
2193  ```js
2194  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
2195      promise.then((data) => {
2196          console.info(JSON.stringify(data));
2197      }).catch((err) => {
2198          console.info('promise failed');
2199  })
2200  ```
2201
2202
2203## SensorType
2204
2205Enumerates the sensor types.
2206
2207**System capability**: SystemCapability.Sensors.Sensor
2208
2209
2210| Name                                      | Default Value | Description         |
2211| ---------------------------------------- | ---- | ----------- |
2212| SENSOR_TYPE_ID_ACCELEROMETER             | 1    | Acceleration sensor.    |
2213| SENSOR_TYPE_ID_GYROSCOPE                 | 2    | Gyroscope sensor.    |
2214| SENSOR_TYPE_ID_AMBIENT_LIGHT             | 5    | Ambient light sensor.    |
2215| SENSOR_TYPE_ID_MAGNETIC_FIELD            | 6    | Magnetic field sensor.     |
2216| SENSOR_TYPE_ID_BAROMETER                 | 8    | Barometer sensor.    |
2217| SENSOR_TYPE_ID_HALL                      | 10   | Hall effect sensor.     |
2218| SENSOR_TYPE_ID_PROXIMITY                 | 12   | Proximity sensor.    |
2219| SENSOR_TYPE_ID_HUMIDITY                  | 13   | Humidity sensor.     |
2220| SENSOR_TYPE_ID_ORIENTATION               | 256  | Orientation sensor.     |
2221| SENSOR_TYPE_ID_GRAVITY                   | 257  | Gravity sensor.     |
2222| SENSOR_TYPE_ID_LINEAR_ACCELERATION       | 258  | Linear acceleration sensor.  |
2223| SENSOR_TYPE_ID_ROTATION_VECTOR           | 259  | Rotation vector sensor.   |
2224| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE       | 260  | Ambient temperature sensor.   |
2225| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | Uncalibrated magnetic field sensor.  |
2226| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED    | 263  | Uncalibrated gyroscope sensor. |
2227| SENSOR_TYPE_ID_SIGNIFICANT_MOTION        | 264  | Significant motion sensor.   |
2228| SENSOR_TYPE_ID_PEDOMETER_DETECTION       | 265  | Pedometer detection sensor.   |
2229| SENSOR_TYPE_ID_PEDOMETER                 | 266  | Pedometer sensor.     |
2230| SENSOR_TYPE_ID_HEART_RATE                | 278  | Heart rate sensor.     |
2231| SENSOR_TYPE_ID_WEAR_DETECTION            | 280  | Wear detection sensor.   |
2232| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281  | Uncalibrated acceleration sensor.|
2233
2234
2235## Response
2236
2237Describes the timestamp of the sensor data.
2238
2239**System capability**: SystemCapability.Sensors.Sensor
2240
2241| Name       | Type  | Readable  | Writable  | Description          |
2242| --------- | ------ | ---- | ---- | ------------ |
2243| timestamp | number | Yes   | Yes   | Timestamp when the sensor reports data.|
2244
2245
2246## AccelerometerResponse
2247
2248Describes the acceleration sensor data. It extends from [Response](#response).
2249
2250**System capability**: SystemCapability.Sensors.Sensor
2251
2252
2253| Name  | Type  | Readable  | Writable  | Description                    |
2254| ---- | ------ | ---- | ---- | ---------------------- |
2255| x    | number | Yes   | Yes   | Acceleration along the x-axis of the device, in m/s2.|
2256| y    | number | Yes   | Yes   | Acceleration along the y-axis of the device, in m/s2.|
2257| z    | number | Yes   | Yes   | Acceleration along the z-axis of the device, in m/s2.|
2258
2259
2260## LinearAccelerometerResponse
2261
2262Describes the linear acceleration sensor data. It extends from [Response](#response).
2263
2264**System capability**: SystemCapability.Sensors.Sensor
2265
2266
2267| Name  | Type  | Readable  | Writable  | Description                      |
2268| ---- | ------ | ---- | ---- | ------------------------ |
2269| x    | number | Yes   | Yes   | Linear acceleration along the x-axis of the device, in m/s2.|
2270| y    | number | Yes   | Yes   | Linear acceleration along the y-axis of the device, in m/s2.|
2271| z    | number | Yes   | Yes   | Linear acceleration along the z-axis of the device, in m/s2.|
2272
2273
2274## AccelerometerUncalibratedResponse
2275
2276Describes the uncalibrated acceleration sensor data. It extends from [Response](#response).
2277
2278**System capability**: SystemCapability.Sensors.Sensor
2279
2280
2281| Name   | Type  | Readable  | Writable  | Description                          |
2282| ----- | ------ | ---- | ---- | ---------------------------- |
2283| x     | number | Yes   | Yes   | Uncalibrated acceleration along the x-axis of the device, in m/s2.   |
2284| y     | number | Yes   | Yes   | Uncalibrated acceleration along the y-axis of the device, in m/s2.   |
2285| z     | number | Yes   | Yes   | Uncalibrated acceleration along the z-axis of the device, in m/s2.   |
2286| biasX | number | Yes   | Yes   | Uncalibrated acceleration bias along the x-axis of the device, in m/s2. |
2287| biasY | number | Yes   | Yes   | Uncalibrated acceleration bias along the y-axis of the device, in m/s2.|
2288| biasZ | number | Yes   | Yes   | Uncalibrated acceleration bias along the z-axis of the device, in m/s2. |
2289
2290
2291## GravityResponse
2292
2293Describes the gravity sensor data. It extends from [Response](#response).
2294
2295**System capability**: SystemCapability.Sensors.Sensor
2296
2297
2298| Name  | Type  | Readable  | Writable  | Description                      |
2299| ---- | ------ | ---- | ---- | ------------------------ |
2300| x    | number | Yes   | Yes   | Gravitational acceleration along the x-axis of the device, in m/s2.|
2301| y    | number | Yes   | Yes   | Gravitational acceleration along the y-axis of the device, in m/s2.|
2302| z    | number | Yes   | Yes   | Gravitational acceleration along the z-axis of the device, in m/s2.|
2303
2304
2305## OrientationResponse
2306
2307Describes the orientation sensor data. It extends from [Response](#response).
2308
2309**System capability**: SystemCapability.Sensors.Sensor
2310
2311
2312| Name   | Type  | Readable  | Writable  | Description               |
2313| ----- | ------ | ---- | ---- | ----------------- |
2314| alpha | number | Yes   | Yes   | Rotation angle of the device around the z-axis, in degrees.|
2315| beta  | number | Yes   | Yes   | Rotation angle of the device around the x-axis, in degrees.|
2316| gamma | number | Yes   | Yes   | Rotation angle of the device around the y-axis, in degrees.|
2317
2318
2319## RotationVectorResponse
2320
2321Describes the rotation vector sensor data. It extends from [Response](#response).
2322
2323**System capability**: SystemCapability.Sensors.Sensor
2324
2325
2326| Name  | Type  | Readable  | Writable  | Description       |
2327| ---- | ------ | ---- | ---- | --------- |
2328| x    | number | Yes   | Yes   | X-component of the rotation vector.|
2329| y    | number | Yes   | Yes   | Y-component of the rotation vector.|
2330| z    | number | Yes   | Yes   | Z-component of the rotation vector.|
2331| w    | number | Yes   | Yes   | Scalar.      |
2332
2333
2334## GyroscopeResponse
2335
2336Describes the gyroscope sensor data. It extends from [Response](#response).
2337
2338**System capability**: SystemCapability.Sensors.Sensor
2339
2340
2341| Name  | Type  | Readable  | Writable  | Description                 |
2342| ---- | ------ | ---- | ---- | ------------------- |
2343| x    | number | Yes   | Yes   | Angular velocity of rotation around the x-axis of the device, in rad/s.|
2344| y    | number | Yes   | Yes   | Angular velocity of rotation around the y-axis of the device, in rad/s.|
2345| z    | number | Yes   | Yes   | Angular velocity of rotation around the z-axis of the device, in rad/s.|
2346
2347
2348## GyroscopeUncalibratedResponse
2349
2350Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response).
2351
2352**System capability**: SystemCapability.Sensors.Sensor
2353
2354
2355| Name   | Type  | Readable  | Writable  | Description                      |
2356| ----- | ------ | ---- | ---- | ------------------------ |
2357| x     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.  |
2358| y     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.  |
2359| z     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.  |
2360| biasX | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.|
2361| biasY | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.|
2362| biasZ | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.|
2363
2364
2365## SignificantMotionResponse
2366
2367Describes the significant motion sensor data. It extends from [Response](#response).
2368
2369**System capability**: SystemCapability.Sensors.Sensor
2370
2371
2372| Name    | Type  | Readable  | Writable  | Description                                      |
2373| ------ | ------ | ---- | ---- | ---------------------------------------- |
2374| scalar | number | Yes   | Yes   | Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.|
2375
2376
2377## ProximityResponse
2378
2379Describes the proximity sensor data. It extends from [Response](#response).
2380
2381**System capability**: SystemCapability.Sensors.Sensor
2382
2383
2384| Name      | Type  | Readable  | Writable  | Description                          |
2385| -------- | ------ | ---- | ---- | ---------------------------- |
2386| distance | number | Yes   | Yes   | Proximity between the visible object and the device monitor. The value **0** means the two are close to each other, and **1** means that they are far away from each other.|
2387
2388
2389## LightResponse
2390
2391Describes the ambient light sensor data. It extends from [Response](#response).
2392
2393**System capability**: SystemCapability.Sensors.Sensor
2394
2395
2396| Name       | Type  | Readable  | Writable  | Description         |
2397| --------- | ------ | ---- | ---- | ----------- |
2398| intensity | number | Yes   | Yes   | Illumination, in lux.|
2399
2400
2401## HallResponse
2402
2403Describes the Hall effect sensor data. It extends from [Response](#response).
2404
2405**System capability**: SystemCapability.Sensors.Sensor
2406
2407
2408| Name  | Type| Readable| Writable| Description                                                        |
2409| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
2410| status | number   | Yes  | Yes  | Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value **0** means that a magnetic field does not exist, and a value greater than **0** means the opposite.|
2411
2412
2413## MagneticFieldResponse
2414
2415Describes the magnetic field sensor data. It extends from [Response](#response).
2416
2417**System capability**: SystemCapability.Sensors.Sensor
2418
2419
2420| Name| Type| Readable| Writable| Description                        |
2421| ---- | -------- | ---- | ---- | ---------------------------- |
2422| x    | number   | Yes  | Yes  | Magnetic field strength on the x-axis, in μT.|
2423| y    | number   | Yes  | Yes  | Magnetic field strength on the y-axis, in μT.|
2424| z    | number   | Yes  | Yes  | Magnetic field strength on the z-axis, in μT.|
2425
2426
2427## MagneticFieldUncalibratedResponse
2428
2429Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response).
2430
2431**System capability**: SystemCapability.Sensors.Sensor
2432
2433
2434| Name   | Type  | Readable  | Writable  | Description                    |
2435| ----- | ------ | ---- | ---- | ---------------------- |
2436| x     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the x-axis, in μT.  |
2437| y     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the y-axis, in μT.  |
2438| z     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the z-axis, in μT.  |
2439| biasX | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the x-axis, in μT.|
2440| biasY | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the y-axis, in μT.|
2441| biasZ | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the z-axis, in μT.|
2442
2443
2444## PedometerResponse
2445
2446Describes the pedometer sensor data. It extends from [Response](#response).
2447
2448**System capability**: SystemCapability.Sensors.Sensor
2449
2450
2451| Name   | Type  | Readable  | Writable  | Description      |
2452| ----- | ------ | ---- | ---- | -------- |
2453| steps | number | Yes   | Yes   | Number of steps a user has walked.|
2454
2455
2456## HumidityResponse
2457
2458Describes the humidity sensor data. It extends from [Response](#response).
2459
2460**System capability**: SystemCapability.Sensors.Sensor
2461
2462
2463| Name      | Type  | Readable  | Writable  | Description                                  |
2464| -------- | ------ | ---- | ---- | ------------------------------------ |
2465| humidity | number | Yes   | Yes   | Ambient relative humidity, in a percentage (%).|
2466
2467
2468## PedometerDetectionResponse
2469
2470Describes the pedometer detection sensor data. It extends from [Response](#response).
2471
2472**System capability**: SystemCapability.Sensors.Sensor
2473
2474
2475| Name    | Type  | Readable  | Writable  | Description                                      |
2476| ------ | ------ | ---- | ---- | ---------------------------------------- |
2477| scalar | number | Yes   | Yes   | Pedometer detection. This parameter specifies whether a user takes a step. The value **0** means that the user does not take a step, and **1** means that the user takes a step.|
2478
2479
2480## AmbientTemperatureResponse
2481
2482Describes the ambient temperature sensor data. It extends from [Response](#response).
2483
2484**System capability**: SystemCapability.Sensors.Sensor
2485
2486
2487| Name         | Type  | Readable  | Writable  | Description           |
2488| ----------- | ------ | ---- | ---- | ------------- |
2489| temperature | number | Yes   | Yes   | Ambient temperature, in degree Celsius.|
2490
2491
2492## BarometerResponse
2493
2494Describes the barometer sensor data. It extends from [Response](#response).
2495
2496**System capability**: SystemCapability.Sensors.Sensor
2497
2498
2499| Name      | Type  | Readable  | Writable  | Description          |
2500| -------- | ------ | ---- | ---- | ------------ |
2501| pressure | number | Yes   | Yes   | Atmospheric pressure, in pascal.|
2502
2503
2504## HeartRateResponse
2505
2506Describes the heart rate sensor data. It extends from [Response](#response).
2507
2508**System capability**: SystemCapability.Sensors.Sensor
2509
2510
2511| Name       | Type  | Readable  | Writable  | Description                   |
2512| --------- | ------ | ---- | ---- | --------------------- |
2513| heartRate | number | Yes   | Yes   | Heart rate, in beats per minute (bpm).|
2514
2515
2516## WearDetectionResponse
2517
2518Describes the wear detection sensor data. It extends from [Response](#response).
2519
2520**System capability**: SystemCapability.Sensors.Sensor
2521
2522
2523| Name   | Type  | Readable  | Writable  | Description                       |
2524| ----- | ------ | ---- | ---- | ------------------------- |
2525| value | number | Yes   | Yes   | Whether the device is being worn. The value **1** means that the device is being worn, and **0** means the opposite.|
2526
2527
2528## Options
2529
2530Describes the sensor data reporting frequency.
2531
2532**System capability**: SystemCapability.Sensors.Sensor
2533
2534| Name      | Type  | Description                         |
2535| -------- | ------ | --------------------------- |
2536| interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.|
2537
2538## RotationMatrixResponse
2539
2540Describes the response for setting the rotation matrix.
2541
2542**System capability**: SystemCapability.Sensors.Sensor
2543
2544| Name         | Type               | Readable  | Writable  | Description   |
2545| ----------- | ------------------- | ---- | ---- | ----- |
2546| rotation    | Array&lt;number&gt; | Yes   | Yes   | Rotation matrix.|
2547| inclination | Array&lt;number&gt; | Yes   | Yes   | Inclination matrix.|
2548
2549
2550## CoordinatesOptions
2551
2552Describes the coordinate options.
2553
2554**System capability**: SystemCapability.Sensors.Sensor
2555
2556| Name  | Type  | Readable  | Writable  | Description    |
2557| ---- | ------ | ---- | ---- | ------ |
2558| x    | number | Yes   | Yes   | X coordinate direction.|
2559| y    | number | Yes   | Yes   | Y coordinate direction.|
2560
2561
2562## GeomagneticResponse
2563
2564Describes a geomagnetic response object. It extends from [Response](#response).
2565
2566**System capability**: SystemCapability.Sensors.Sensor
2567
2568| Name             | Type  | Readable  | Writable  | Description                       |
2569| --------------- | ------ | ---- | ---- | ------------------------- |
2570| x               | number | Yes   | Yes   | North component of the geomagnetic field.                 |
2571| y               | number | Yes   | Yes   | East component of the geomagnetic field.                 |
2572| z               | number | Yes   | Yes   | Vertical component of the geomagnetic field.                |
2573| geomagneticDip  | number | Yes   | Yes   | Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.      |
2574| deflectionAngle | number | Yes   | Yes   | Magnetic declination, which is the angle between true north (geographic north) and the magnetic north (the horizontal component of the field).|
2575| levelIntensity  | number | Yes   | Yes   | Horizontal intensity of the magnetic field vector field.                |
2576| totalIntensity  | number | Yes   | Yes   | Total intensity of the magnetic field vector.                 |
2577
2578## LocationOptions
2579
2580Describes the geographical location.
2581
2582**System capability**: SystemCapability.Sensors.Sensor
2583
2584| Name       | Type  | Readable  | Writable  | Description   |
2585| --------- | ------ | ---- | ---- | ----- |
2586| latitude  | number | Yes   | Yes   | Latitude.  |
2587| longitude | number | Yes   | Yes   | Longitude.  |
2588| altitude  | number | Yes   | Yes   | Altitude.|
2589