1# @ohos.sensor (Sensor)
2
3The **Sensor** module provides APIs for obtaining the sensor list and subscribing to sensor data. It also provides some common sensor algorithms.
4
5> **NOTE**
6>
7> 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.
8
9
10## Modules to Import
11
12```ts
13import { sensor } from '@kit.SensorServiceKit';
14```
15## sensor.on
16
17### ACCELEROMETER<sup>9+</sup>
18
19on(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;, options?: Options): void
20
21Subscribes to data of the acceleration sensor.
22
23**Required permissions**: ohos.permission.ACCELEROMETER
24
25**Atomic service API**: This API can be used in atomic services since API version 11.
26
27**System capability**: SystemCapability.Sensors.Sensor
28
29**Parameters**
30
31| Name  | Type                                                        | Mandatory| Description                                                       |
32| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
33| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.             |
34| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerResponse** object.|
35| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
36
37**Error codes**
38
39For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
40
41| ID| Error Message                                                    |
42| -------- | ------------------------------------------------------------ |
43| 201      | Permission denied.                                           |
44| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
45| 14500101 | Service exception.                                           |
46
47**Example**
48
49```ts
50import { sensor } from '@kit.SensorServiceKit';
51import { BusinessError } from '@kit.BasicServicesKit';
52
53try {
54  sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
55    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
56    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
57    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
58  }, { interval: 100000000 });
59  setTimeout(() => {
60    sensor.off(sensor.SensorId.ACCELEROMETER);
61  }, 500);
62} catch (error) {
63  let e: BusinessError = error as BusinessError;
64  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
65}
66```
67
68### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
69
70on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
71
72Subscribes to data of the uncalibrated acceleration sensor.
73
74**Required permissions**: ohos.permission.ACCELEROMETER
75
76**System capability**: SystemCapability.Sensors.Sensor
77
78**Parameters**
79
80| Name  | Type                                                        | Mandatory| Description                                                        |
81| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
82| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
83| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.|
84| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
85
86**Error codes**
87
88For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
89
90| ID| Error Message                                                    |
91| -------- | ------------------------------------------------------------ |
92| 201      | Permission denied.                                           |
93| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
94| 14500101 | Service exception.                                           |
95
96**Example**
97
98```ts
99import { sensor } from '@kit.SensorServiceKit';
100import { BusinessError } from '@kit.BasicServicesKit';
101
102try {
103  sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
104    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
105    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
106    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
107    console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
108    console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
109    console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
110  }, { interval: 100000000 });
111  setTimeout(() => {
112    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED);
113  }, 500);
114} catch (error) {
115  let e: BusinessError = error as BusinessError;
116  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
117}
118```
119
120### AMBIENT_LIGHT<sup>9+</sup>
121
122on(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
123
124Subscribes to data of the ambient light sensor.
125
126**System capability**: SystemCapability.Sensors.Sensor
127
128**Parameters**
129
130| Name  | Type                                           | Mandatory| Description                                                       |
131| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
132| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.             |
133| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LightResponse** object.        |
134| options  | [Options](#options)                             | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
135
136**Error codes**
137
138For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
139
140| ID| Error Message                                                    |
141| -------- | ------------------------------------------------------------ |
142| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
143| 14500101 | Service exception.                                           |
144
145**Example**
146
147```ts
148import { sensor } from '@kit.SensorServiceKit';
149import { BusinessError } from '@kit.BasicServicesKit';
150
151try {
152  sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data: sensor.LightResponse) => {
153    console.info('Succeeded in getting the ambient light intensity: ' + data.intensity);
154  }, { interval: 100000000 });
155  setTimeout(() => {
156    sensor.off(sensor.SensorId.AMBIENT_LIGHT);
157  }, 500);
158} catch (error) {
159  let e: BusinessError = error as BusinessError;
160  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
161}
162```
163
164###  AMBIENT_TEMPERATURE<sup>9+</sup>
165
166on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;, options?: Options): void
167
168Subscribes to data of the ambient temperature sensor.
169
170**System capability**: SystemCapability.Sensors.Sensor
171
172**Parameters**
173
174| Name  | Type                                                        | Mandatory| Description                                                        |
175| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
176| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
177| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.|
178| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
179
180**Error codes**
181
182For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
183
184| ID| Error Message                                                    |
185| -------- | ------------------------------------------------------------ |
186| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
187| 14500101 | Service exception.                                           |
188
189**Example**
190
191```ts
192import { sensor } from '@kit.SensorServiceKit';
193import { BusinessError } from '@kit.BasicServicesKit';
194
195try {
196  sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
197    console.info('Succeeded in invoking on. Temperature: ' + data.temperature);
198  }, { interval: 100000000 });
199  setTimeout(() => {
200    sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE);
201  }, 500);
202} catch (error) {
203  let e: BusinessError = error as BusinessError;
204  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
205}
206```
207
208### BAROMETER<sup>9+</sup>
209
210on(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;, options?: Options): void
211
212Subscribes to data of the barometer sensor.
213
214**System capability**: SystemCapability.Sensors.Sensor
215
216**Parameters**
217
218| Name  | Type                                                   | Mandatory| Description                                                       |
219| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
220| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.                 |
221| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **BarometerResponse** object.    |
222| options  | [Options](#options)                                     | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
223
224**Error codes**
225
226For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
227
228| ID| Error Message                                                    |
229| -------- | ------------------------------------------------------------ |
230| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
231| 14500101 | Service exception.                                           |
232
233**Example**
234
235```ts
236import { sensor } from '@kit.SensorServiceKit';
237import { BusinessError } from '@kit.BasicServicesKit';
238
239try {
240  sensor.on(sensor.SensorId.BAROMETER, (data: sensor.BarometerResponse) => {
241    console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure);
242  }, { interval: 100000000 });
243  setTimeout(() => {
244    sensor.off(sensor.SensorId.BAROMETER);
245  }, 500);
246} catch (error) {
247  let e: BusinessError = error as BusinessError;
248  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
249}
250```
251
252###  GRAVITY<sup>9+</sup>
253
254on(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;, options?: Options): void
255
256Subscribes to data of the gravity sensor.
257
258**System capability**: SystemCapability.Sensors.Sensor
259
260**Parameters**
261
262| Name  | Type                                               | Mandatory| Description                                                       |
263| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
264| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.                   |
265| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GravityResponse** object.      |
266| options  | [Options](#options)                                 | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
267
268**Error codes**
269
270For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
271
272| ID| Error Message                                                    |
273| -------- | ------------------------------------------------------------ |
274| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
275| 14500101 | Service exception.                                           |
276
277**Example**
278
279```ts
280import { sensor } from '@kit.SensorServiceKit';
281import { BusinessError } from '@kit.BasicServicesKit';
282
283try {
284  sensor.on(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => {
285    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
286    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
287    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
288  }, { interval: 100000000 });
289  setTimeout(() => {
290    sensor.off(sensor.SensorId.GRAVITY);
291  }, 500);
292} catch (error) {
293  let e: BusinessError = error as BusinessError;
294  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
295}
296```
297
298###  GYROSCOPE<sup>9+</sup>
299
300on(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
301
302Subscribes to data of the gyroscope sensor.
303
304**Required permissions**: ohos.permission.GYROSCOPE
305
306**Atomic service API**: This API can be used in atomic services since API version 11.
307
308**System capability**: SystemCapability.Sensors.Sensor
309
310**Parameters**
311
312| Name  | Type                                                   | Mandatory| Description                                                       |
313| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
314| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.                 |
315| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeResponse** object.    |
316| options  | [Options](#options)                                     | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
317
318**Error codes**
319
320For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
321
322| ID| Error Message                                                    |
323| -------- | ------------------------------------------------------------ |
324| 201      | Permission denied.                                           |
325| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
326| 14500101 | Service exception.                                           |
327
328**Example**
329
330```ts
331import { sensor } from '@kit.SensorServiceKit';
332import { BusinessError } from '@kit.BasicServicesKit';
333
334try {
335  sensor.on(sensor.SensorId.GYROSCOPE, (data: sensor.GyroscopeResponse) => {
336    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
337    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
338    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
339  }, { interval: 100000000 });
340  setTimeout(() => {
341    sensor.off(sensor.SensorId.GYROSCOPE);
342  }, 500);
343} catch (error) {
344  let e: BusinessError = error as BusinessError;
345  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
346}
347```
348
349###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
350
351on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;,
352      options?: Options): void
353
354Subscribes to data of the uncalibrated gyroscope sensor.
355
356**Required permissions**: ohos.permission.GYROSCOPE
357
358**System capability**: SystemCapability.Sensors.Sensor
359
360**Parameters**
361
362| Name  | Type                                                        | Mandatory| Description                                                        |
363| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
364| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
365| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.|
366| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
367
368**Error codes**
369
370For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
371
372| ID| Error Message                                                    |
373| -------- | ------------------------------------------------------------ |
374| 201      | Permission denied.                                           |
375| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
376| 14500101 | Service exception.                                           |
377
378**Example**
379
380```ts
381import { sensor } from '@kit.SensorServiceKit';
382import { BusinessError } from '@kit.BasicServicesKit';
383
384try {
385  sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
386    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
387    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
388    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
389    console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
390    console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
391    console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
392  }, { interval: 100000000 });
393  setTimeout(() => {
394    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED);
395  }, 500);
396} catch (error) {
397  let e: BusinessError = error as BusinessError;
398  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
399}
400
401```
402
403###  HALL<sup>9+</sup>
404
405on(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
406
407Subscribes to data of the Hall effect sensor.
408
409**System capability**: SystemCapability.Sensors.Sensor
410
411**Parameters**
412
413| Name  | Type                                         | Mandatory| Description                                                        |
414| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
415| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.                       |
416| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HallResponse** object.          |
417| options  | [Options](#options)                           | No  | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when Hall effect events are frequently triggered.|
418
419**Error codes**
420
421For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
422
423| ID| Error Message                                                    |
424| -------- | ------------------------------------------------------------ |
425| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
426| 14500101 | Service exception.                                           |
427
428**Example**
429
430```ts
431import { sensor } from '@kit.SensorServiceKit';
432import { BusinessError } from '@kit.BasicServicesKit';
433
434try {
435  sensor.on(sensor.SensorId.HALL, (data: sensor.HallResponse) => {
436    console.info('Succeeded in invoking on. Hall status: ' + data.status);
437  }, { interval: 100000000 });
438  setTimeout(() => {
439    sensor.off(sensor.SensorId.HALL);
440  }, 500);
441} catch (error) {
442  let e: BusinessError = error as BusinessError;
443  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
444}
445
446```
447
448###   HEART_RATE<sup>9+</sup>
449
450on(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
451
452Subscribes to data of the heart rate sensor.
453
454**Required permissions**: ohos.permission.READ_HEALTH_DATA
455
456**System capability**: SystemCapability.Sensors.Sensor
457
458**Parameters**
459
460| Name  | Type                                                   | Mandatory| Description                                                       |
461| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
462| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.                |
463| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HeartRateResponse** object.    |
464| options  | [Options](#options)                                     | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
465
466**Error codes**
467
468For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
469
470| ID| Error Message                                                    |
471| -------- | ------------------------------------------------------------ |
472| 201      | Permission denied.                                           |
473| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
474| 14500101 | Service exception.                                           |
475
476**Example**
477
478```ts
479import { sensor } from '@kit.SensorServiceKit';
480import { BusinessError } from '@kit.BasicServicesKit';
481
482try {
483  sensor.on(sensor.SensorId.HEART_RATE, (data: sensor.HeartRateResponse) => {
484    console.info('Succeeded in invoking on. Heart rate: ' + data.heartRate);
485  }, { interval: 100000000 });
486  setTimeout(() => {
487    sensor.off(sensor.SensorId.HEART_RATE);
488  }, 500);
489} catch (error) {
490  let e: BusinessError = error as BusinessError;
491  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
492}
493```
494
495###  HUMIDITY<sup>9+</sup>
496
497on(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;, options?: Options): void
498
499Subscribes to data of the humidity sensor.
500
501**System capability**: SystemCapability.Sensors.Sensor
502
503**Parameters**
504
505| Name  | Type                                                 | Mandatory| Description                                                       |
506| -------- | ----------------------------------------------------- | ---- | ----------------------------------------------------------- |
507| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.                  |
508| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HumidityResponse** object.     |
509| options  | [Options](#options)                                   | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
510
511**Error codes**
512
513For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
514
515| ID| Error Message                                                    |
516| -------- | ------------------------------------------------------------ |
517| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
518| 14500101 | Service exception.                                           |
519
520**Example**
521
522```ts
523import { sensor } from '@kit.SensorServiceKit';
524import { BusinessError } from '@kit.BasicServicesKit';
525
526try {
527  sensor.on(sensor.SensorId.HUMIDITY, (data: sensor.HumidityResponse) => {
528    console.info('Succeeded in invoking on. Humidity: ' + data.humidity);
529  }, { interval: 100000000 });
530  setTimeout(() => {
531    sensor.off(sensor.SensorId.HUMIDITY);
532  }, 500);
533} catch (error) {
534  let e: BusinessError = error as BusinessError;
535  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
536}
537```
538
539###   LINEAR_ACCELEROMETER<sup>9+</sup>
540
541on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerometerResponse&gt;,
542        options?: Options): void
543
544Subscribes to data of the linear acceleration sensor.
545
546**Required permissions**: ohos.permission.ACCELEROMETER
547
548**System capability**: SystemCapability.Sensors.Sensor
549
550**Parameters**
551
552| Name  | Type                                                        | Mandatory| Description                                                        |
553| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
554| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**.       |
555| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.|
556| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
557
558**Error codes**
559
560For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
561
562| ID| Error Message                                                    |
563| -------- | ------------------------------------------------------------ |
564| 201      | Permission denied.                                           |
565| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
566| 14500101 | Service exception.                                           |
567
568**Example**
569
570```ts
571import { sensor } from '@kit.SensorServiceKit';
572import { BusinessError } from '@kit.BasicServicesKit';
573
574try {
575  sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, (data: sensor.LinearAccelerometerResponse) => {
576    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
577    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
578    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
579  }, { interval: 100000000 });
580  setTimeout(() => {
581    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER);
582  }, 500);
583} catch (error) {
584  let e: BusinessError = error as BusinessError;
585  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
586}
587```
588
589###  MAGNETIC_FIELD<sup>9+</sup>
590
591on(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;, options?: Options): void
592
593Subscribes to data of the magnetic field sensor.
594
595**System capability**: SystemCapability.Sensors.Sensor
596
597**Parameters**
598
599| Name  | Type                                                        | Mandatory| Description                                                       |
600| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
601| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.            |
602| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.|
603| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
604
605**Error codes**
606
607For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
608
609| ID| Error Message                                                    |
610| -------- | ------------------------------------------------------------ |
611| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
612| 14500101 | Service exception.                                           |
613
614**Example**
615
616```ts
617import { sensor } from '@kit.SensorServiceKit';
618import { BusinessError } from '@kit.BasicServicesKit';
619
620try {
621  sensor.on(sensor.SensorId.MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
622    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
623    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
624    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
625  }, { interval: 100000000 });
626  setTimeout(() => {
627    sensor.off(sensor.SensorId.MAGNETIC_FIELD);
628  }, 500);
629} catch (error) {
630  let e: BusinessError = error as BusinessError;
631  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
632}
633```
634
635### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
636
637on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
638
639Subscribes to data of the uncalibrated magnetic field sensor.
640
641**System capability**: SystemCapability.Sensors.Sensor
642
643**Parameters**
644
645| Name  | Type                                                        | Mandatory| Description                                                        |
646| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
647| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
648| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.|
649| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
650
651**Error codes**
652
653For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
654
655| ID| Error Message                                                    |
656| -------- | ------------------------------------------------------------ |
657| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
658| 14500101 | Service exception.                                           |
659
660**Example**
661
662```ts
663import { sensor } from '@kit.SensorServiceKit';
664import { BusinessError } from '@kit.BasicServicesKit';
665
666try {
667  sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
668    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
669    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
670    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
671    console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
672    console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
673    console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
674  }, { interval: 100000000 });
675  setTimeout(() => {
676    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED);
677  }, 500);
678} catch (error) {
679  let e: BusinessError = error as BusinessError;
680  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
681}
682```
683
684### ORIENTATION<sup>9+</sup>
685
686on(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
687
688Subscribes to data of the orientation sensor.
689
690**Atomic service API**: This API can be used in atomic services since API version 11.
691
692**System capability**: SystemCapability.Sensors.Sensor
693
694**Error codes**
695
696For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
697
698| ID| Error Message                                                    |
699| -------- | ------------------------------------------------------------ |
700| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
701| 14500101 | Service exception.                                           |
702
703**Parameters**
704
705| Name  | Type                                                       | Mandatory| Description                                                       |
706| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------------------------- |
707| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.               |
708| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **OrientationResponse** object.  |
709| options  | [Options](#options)                                         | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
710
711**Example**
712
713```ts
714import { sensor } from '@kit.SensorServiceKit';
715import { BusinessError } from '@kit.BasicServicesKit';
716
717try {
718  sensor.on(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => {
719    console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
720    console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
721    console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
722  }, { interval: 100000000 });
723  setTimeout(() => {
724    sensor.off(sensor.SensorId.ORIENTATION);
725  }, 500);
726} catch (error) {
727  let e: BusinessError = error as BusinessError;
728  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
729}
730```
731
732### PEDOMETER<sup>9+</sup>
733
734on(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
735
736Subscribes to data of the pedometer sensor.
737
738**Required permissions**: ohos.permission.ACTIVITY_MOTION
739
740**System capability**: SystemCapability.Sensors.Sensor
741
742**Error codes**
743
744For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
745
746| ID| Error Message                                                    |
747| -------- | ------------------------------------------------------------ |
748| 201      | Permission denied.                                           |
749| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
750| 14500101 | Service exception.                                           |
751
752**Parameters**
753
754| Name  | Type                                                   | Mandatory| Description                                                       |
755| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
756| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.                 |
757| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerResponse** object.    |
758| options  | [Options](#options)                                     | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
759
760**Example**
761
762```ts
763import { sensor } from '@kit.SensorServiceKit';
764import { BusinessError } from '@kit.BasicServicesKit';
765
766try {
767  sensor.on(sensor.SensorId.PEDOMETER, (data: sensor.PedometerResponse) => {
768    console.info('Succeeded in invoking on. Step count: ' + data.steps);
769  }, { interval: 100000000 });
770  setTimeout(() => {
771    sensor.off(sensor.SensorId.PEDOMETER);
772  }, 500);
773} catch (error) {
774  let e: BusinessError = error as BusinessError;
775  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
776}
777```
778
779### PEDOMETER_DETECTION<sup>9+</sup>
780
781on(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;,
782        options?: Options): void
783
784Subscribes to data of the pedometer detection sensor.
785
786**Required permissions**: ohos.permission.ACTIVITY_MOTION
787
788**System capability**: SystemCapability.Sensors.Sensor
789
790**Parameters**
791
792| Name  | Type                                                        | Mandatory| Description                                                        |
793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
794| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
795| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.|
796| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
797
798**Error codes**
799
800For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
801
802| ID| Error Message                                                    |
803| -------- | ------------------------------------------------------------ |
804| 201      | Permission denied.                                           |
805| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
806| 14500101 | Service exception.                                           |
807
808**Example**
809
810```ts
811import { sensor } from '@kit.SensorServiceKit';
812import { BusinessError } from '@kit.BasicServicesKit';
813
814try {
815  sensor.on(sensor.SensorId.PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
816    console.info('Succeeded in invoking on. Pedometer scalar: ' + data.scalar);
817  }, { interval: 100000000 });
818  setTimeout(() => {
819    sensor.off(sensor.SensorId.PEDOMETER_DETECTION);
820  }, 500);
821} catch (error) {
822  let e: BusinessError = error as BusinessError;
823  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
824}
825```
826
827### PROXIMITY<sup>9+</sup>
828
829on(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;, options?: Options): void
830
831Subscribes to data of the proximity sensor.
832
833**System capability**: SystemCapability.Sensors.Sensor
834
835**Parameters**
836
837| Name  | Type                                                   | Mandatory| Description                                                        |
838| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
839| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.                  |
840| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **ProximityResponse** object.     |
841| options  | [Options](#options)                                     | No  | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when proximity sensor events are frequently triggered.|
842
843**Error codes**
844
845For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
846
847| ID| Error Message                                                    |
848| -------- | ------------------------------------------------------------ |
849| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3.Parameter verification failed. |
850| 14500101 | Service exception.                                           |
851
852**Example**
853
854```ts
855import { sensor } from '@kit.SensorServiceKit';
856import { BusinessError } from '@kit.BasicServicesKit';
857
858try {
859  sensor.on(sensor.SensorId.PROXIMITY, (data: sensor.ProximityResponse) => {
860    console.info('Succeeded in invoking on. Distance: ' + data.distance);
861  }, { interval: 100000000 });
862  setTimeout(() => {
863    sensor.off(sensor.SensorId.PROXIMITY);
864  }, 500);
865} catch (error) {
866  let e: BusinessError = error as BusinessError;
867  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
868}
869```
870
871### ROTATION_VECTOR<sup>9+</sup>
872
873on(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;,
874        options?: Options): void
875
876Subscribes to data of the rotation vector sensor.
877
878**System capability**: SystemCapability.Sensors.Sensor
879
880**Parameters**
881
882| Name  | Type                                                        | Mandatory| Description                                                        |
883| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
884| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
885| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **RotationVectorResponse** object.|
886| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
887
888**Error codes**
889
890For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
891
892| ID| Error Message                                                    |
893| -------- | ------------------------------------------------------------ |
894| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3.Parameter verification failed. |
895| 14500101 | Service exception.                                           |
896
897**Example**
898
899```ts
900import { sensor } from '@kit.SensorServiceKit';
901import { BusinessError } from '@kit.BasicServicesKit';
902
903try {
904  sensor.on(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
905    console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
906    console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
907    console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
908    console.info('Succeeded in invoking on. Scalar quantity: ' + data.w);
909  }, { interval: 100000000 });
910  setTimeout(() => {
911    sensor.off(sensor.SensorId.ROTATION_VECTOR);
912  }, 500);
913} catch (error) {
914  let e: BusinessError = error as BusinessError;
915  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
916}
917```
918
919### SIGNIFICANT_MOTION<sup>9+</sup>
920
921on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;,
922        options?: Options): void
923
924Subscribes to data of the significant motion sensor.
925
926**System capability**: SystemCapability.Sensors.Sensor
927
928**Parameters**
929
930| Name  | Type                                                        | Mandatory| Description                                                        |
931| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
932| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
933| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.|
934| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
935
936**Error codes**
937
938For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
939
940| ID| Error Message                                                    |
941| -------- | ------------------------------------------------------------ |
942| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3.Parameter verification failed. |
943| 14500101 | Service exception.                                           |
944
945**Example**
946
947```ts
948import { sensor } from '@kit.SensorServiceKit';
949import { BusinessError } from '@kit.BasicServicesKit';
950
951try {
952  sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
953    console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
954  }, { interval: 100000000 });
955  setTimeout(() => {
956    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION);
957  }, 500);
958} catch (error) {
959  let e: BusinessError = error as BusinessError;
960  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
961}
962```
963
964###  WEAR_DETECTION<sup>9+</sup>
965
966on(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,
967        options?: Options): void
968
969Subscribes to data of the wear detection sensor.
970
971**System capability**: SystemCapability.Sensors.Sensor
972
973**Parameters**
974
975| Name  | Type                                                        | Mandatory| Description                                                       |
976| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
977| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.            |
978| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **WearDetectionResponse** object.|
979| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
980
981**Error codes**
982
983For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
984
985| ID| Error Message                                                    |
986| -------- | ------------------------------------------------------------ |
987| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3.Parameter verification failed. |
988| 14500101 | Service exception.                                           |
989
990**Example**
991
992```ts
993import { sensor } from '@kit.SensorServiceKit';
994import { BusinessError } from '@kit.BasicServicesKit';
995
996try {
997  sensor.on(sensor.SensorId.WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
998    console.info('Succeeded in invoking on. Wear status: ' + data.value);
999  }, { interval: 100000000 });
1000  setTimeout(() => {
1001    sensor.off(sensor.SensorId.WEAR_DETECTION);
1002  }, 500);
1003} catch (error) {
1004  let e: BusinessError = error as BusinessError;
1005  console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
1006}
1007```
1008
1009## sensor.once<sup>9+</sup>
1010
1011### ACCELEROMETER<sup>9+</sup>
1012
1013once(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
1014
1015Obtains data of the acceleration sensor once.
1016
1017**Required permissions**: ohos.permission.ACCELEROMETER
1018
1019**System capability**: SystemCapability.Sensors.Sensor
1020
1021**Parameters**
1022
1023| Name  | Type                                                        | Mandatory| Description                                                       |
1024| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1025| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.             |
1026| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerResponse** object.|
1027
1028**Error codes**
1029
1030For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1031
1032| ID| Error Message                                                    |
1033| -------- | ------------------------------------------------------------ |
1034| 201      | Permission denied.                                           |
1035| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1036| 14500101 | Service exception.                                           |
1037
1038**Example**
1039
1040```ts
1041import { sensor } from '@kit.SensorServiceKit';
1042import { BusinessError } from '@kit.BasicServicesKit';
1043
1044try {
1045  sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
1046    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1047    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1048    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1049  });
1050} catch (error) {
1051  let e: BusinessError = error as BusinessError;
1052  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1053}
1054```
1055
1056### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
1057
1058once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
1059
1060Obtains data of the uncalibrated acceleration sensor once.
1061
1062**Required permissions**: ohos.permission.ACCELEROMETER
1063
1064**System capability**: SystemCapability.Sensors.Sensor
1065
1066**Parameters**
1067
1068| Name  | Type                                                        | Mandatory| Description                                                        |
1069| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1070| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
1071| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.|
1072
1073**Error codes**
1074
1075For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1076
1077| ID| Error Message                                                    |
1078| -------- | ------------------------------------------------------------ |
1079| 201      | Permission denied.                                           |
1080| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1081| 14500101 | Service exception.                                           |
1082
1083**Example**
1084
1085```ts
1086import { sensor } from '@kit.SensorServiceKit';
1087import { BusinessError } from '@kit.BasicServicesKit';
1088
1089try {
1090  sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
1091    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1092    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1093    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1094    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
1095    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
1096    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
1097  });
1098} catch (error) {
1099  let e: BusinessError = error as BusinessError;
1100  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1101}
1102```
1103
1104### AMBIENT_LIGHT<sup>9+</sup>
1105
1106once(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
1107
1108Obtains data of the ambient light sensor once.
1109
1110**System capability**: SystemCapability.Sensors.Sensor
1111
1112**Parameters**
1113
1114| Name  | Type                                           | Mandatory| Description                                               |
1115| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
1116| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.     |
1117| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LightResponse** object.|
1118
1119**Error codes**
1120
1121For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1122
1123| ID| Error Message                                                    |
1124| -------- | ------------------------------------------------------------ |
1125| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1126| 14500101 | Service exception.                                           |
1127
1128**Example**
1129
1130```ts
1131import { sensor } from '@kit.SensorServiceKit';
1132import { BusinessError } from '@kit.BasicServicesKit';
1133
1134try {
1135  sensor.once(sensor.SensorId.AMBIENT_LIGHT, (data: sensor.LightResponse) => {
1136    console.info('Succeeded in invoking once. the ambient light intensity: ' + data.intensity);
1137  });
1138} catch (error) {
1139  let e: BusinessError = error as BusinessError;
1140  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1141}
1142```
1143
1144### AMBIENT_TEMPERATURE<sup>9+</sup>
1145
1146once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;): void
1147
1148Obtains data of the temperature sensor once.
1149
1150**System capability**: SystemCapability.Sensors.Sensor
1151
1152**Parameters**
1153
1154| Name  | Type                                                        | Mandatory| Description                                                        |
1155| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1156| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
1157| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.|
1158
1159**Error codes**
1160
1161For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1162
1163| ID| Error Message                                                    |
1164| -------- | ------------------------------------------------------------ |
1165| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1166| 14500101 | Service exception.                                           |
1167
1168**Example**
1169
1170```ts
1171import { sensor } from '@kit.SensorServiceKit';
1172import { BusinessError } from '@kit.BasicServicesKit';
1173
1174try {
1175  sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
1176    console.info('Succeeded in invoking once. Temperature: ' + data.temperature);
1177  });
1178} catch (error) {
1179  let e: BusinessError = error as BusinessError;
1180  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1181}
1182```
1183
1184### BAROMETER<sup>9+</sup>
1185
1186once(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
1187
1188Obtains data of the barometer sensor once.
1189
1190**System capability**: SystemCapability.Sensors.Sensor
1191
1192**Parameters**
1193
1194| Name  | Type                                                   | Mandatory| Description                                                   |
1195| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1196| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.             |
1197| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **BarometerResponse** object.|
1198
1199**Error codes**
1200
1201For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1202
1203| ID| Error Message                                                    |
1204| -------- | ------------------------------------------------------------ |
1205| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1206| 14500101 | Service exception.                                           |
1207
1208**Example**
1209
1210```ts
1211import { sensor } from '@kit.SensorServiceKit';
1212import { BusinessError } from '@kit.BasicServicesKit';
1213
1214try {
1215  sensor.once(sensor.SensorId.BAROMETER, (data: sensor.BarometerResponse) => {
1216    console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure);
1217  });
1218} catch (error) {
1219  let e: BusinessError = error as BusinessError;
1220  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1221}
1222```
1223
1224### GRAVITY<sup>9+</sup>
1225
1226once(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
1227
1228Obtains data of the gravity sensor once.
1229
1230**System capability**: SystemCapability.Sensors.Sensor
1231
1232**Parameters**
1233
1234| Name  | Type                                               | Mandatory| Description                                                 |
1235| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
1236| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.             |
1237| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GravityResponse** object.|
1238
1239**Error codes**
1240
1241For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1242
1243| ID| Error Message                                                    |
1244| -------- | ------------------------------------------------------------ |
1245| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1246| 14500101 | Service exception.                                           |
1247
1248**Example**
1249
1250```ts
1251import { sensor } from '@kit.SensorServiceKit';
1252import { BusinessError } from '@kit.BasicServicesKit';
1253
1254try {
1255  sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => {
1256    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1257    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1258    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1259  });
1260} catch (error) {
1261  let e: BusinessError = error as BusinessError;
1262  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1263}
1264```
1265
1266### GYROSCOPE<sup>9+</sup>
1267
1268once(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
1269
1270Obtains to data of the gyroscope sensor once.
1271
1272**Required permissions**: ohos.permission.GYROSCOPE
1273
1274**System capability**: SystemCapability.Sensors.Sensor
1275
1276**Parameters**
1277
1278| Name  | Type                                                   | Mandatory| Description                                                   |
1279| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1280| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.             |
1281| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeResponse** object.|
1282
1283**Error codes**
1284
1285For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1286
1287| ID| Error Message                                                    |
1288| -------- | ------------------------------------------------------------ |
1289| 201      | Permission denied.                                           |
1290| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1291| 14500101 | Service exception.                                           |
1292
1293**Example**
1294
1295```ts
1296import { sensor } from '@kit.SensorServiceKit';
1297import { BusinessError } from '@kit.BasicServicesKit';
1298
1299try {
1300  sensor.once(sensor.SensorId.GYROSCOPE, (data: sensor.GyroscopeResponse) => {
1301    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1302    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1303    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1304  });
1305} catch (error) {
1306  let e: BusinessError = error as BusinessError;
1307  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1308}
1309```
1310
1311### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
1312
1313once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
1314
1315Obtains data of the uncalibrated gyroscope sensor once.
1316
1317**Required permissions**: ohos.permission.GYROSCOPE
1318
1319**System capability**: SystemCapability.Sensors.Sensor
1320
1321**Parameters**
1322
1323| Name  | Type                                                        | Mandatory| Description                                                        |
1324| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1325| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
1326| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.|
1327
1328**Error codes**
1329
1330For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1331
1332| ID| Error Message                                                    |
1333| -------- | ------------------------------------------------------------ |
1334| 201      | Permission denied.                                           |
1335| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1336| 14500101 | Service exception.                                           |
1337
1338**Example**
1339
1340```ts
1341import { sensor } from '@kit.SensorServiceKit';
1342import { BusinessError } from '@kit.BasicServicesKit';
1343
1344try {
1345  sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
1346    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1347    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1348    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1349    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
1350    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
1351    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
1352  });
1353} catch (error) {
1354  let e: BusinessError = error as BusinessError;
1355  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1356}
1357```
1358
1359### HALL<sup>9+</sup>
1360
1361once(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;): void
1362
1363Obtains data of the Hall effect sensor once.
1364
1365**System capability**: SystemCapability.Sensors.Sensor
1366
1367**Parameters**
1368
1369| Name  | Type                                         | Mandatory| Description                                              |
1370| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
1371| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.             |
1372| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HallResponse** object.|
1373
1374**Error codes**
1375
1376For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1377
1378| ID| Error Message                                                    |
1379| -------- | ------------------------------------------------------------ |
1380| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1381| 14500101 | Service exception.                                           |
1382
1383**Example**
1384
1385```ts
1386import { sensor } from '@kit.SensorServiceKit';
1387import { BusinessError } from '@kit.BasicServicesKit';
1388
1389try {
1390  sensor.once(sensor.SensorId.HALL, (data: sensor.HallResponse) => {
1391    console.info('Succeeded in invoking once. Status: ' + data.status);
1392  });
1393} catch (error) {
1394  let e: BusinessError = error as BusinessError;
1395  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1396}
1397```
1398
1399### HEART_RATE<sup>9+</sup>
1400
1401once(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
1402
1403Obtains data of the heart rate sensor once.
1404
1405**Required permissions**: ohos.permission.READ_HEALTH_DATA
1406
1407**System capability**: SystemCapability.Sensors.Sensor
1408
1409**Parameters**
1410
1411| Name  | Type                                                   | Mandatory| Description                                                   |
1412| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1413| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.            |
1414| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HeartRateResponse** object.|
1415
1416**Error codes**
1417
1418For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1419
1420| ID| Error Message                                                    |
1421| -------- | ------------------------------------------------------------ |
1422| 201      | Permission denied.                                           |
1423| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1424| 14500101 | Service exception.                                           |
1425
1426**Example**
1427
1428```ts
1429import { sensor } from '@kit.SensorServiceKit';
1430import { BusinessError } from '@kit.BasicServicesKit';
1431
1432try {
1433  sensor.once(sensor.SensorId.HEART_RATE, (data: sensor.HeartRateResponse) => {
1434    console.info('Succeeded in invoking once. Heart rate: ' + data.heartRate);
1435  });
1436} catch (error) {
1437  let e: BusinessError = error as BusinessError;
1438  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1439}
1440```
1441
1442### HUMIDITY<sup>9+</sup>
1443
1444once(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
1445
1446Obtains data of the humidity sensor once.
1447
1448**System capability**: SystemCapability.Sensors.Sensor
1449
1450**Parameters**
1451
1452| Name  | Type                                                 | Mandatory| Description                                                  |
1453| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
1454| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.             |
1455| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HumidityResponse** object.|
1456
1457**Error codes**
1458
1459For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1460
1461| ID| Error Message                                                    |
1462| -------- | ------------------------------------------------------------ |
1463| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1464| 14500101 | Service exception.                                           |
1465
1466**Example**
1467
1468```ts
1469import { sensor } from '@kit.SensorServiceKit';
1470import { BusinessError } from '@kit.BasicServicesKit';
1471
1472try {
1473  sensor.once(sensor.SensorId.HUMIDITY, (data: sensor.HumidityResponse) => {
1474    console.info('Succeeded in invoking once. Humidity: ' + data.humidity);
1475  });
1476} catch (error) {
1477  let e: BusinessError = error as BusinessError;
1478  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1479}
1480```
1481
1482### LINEAR_ACCELEROMETER<sup>9+</sup>
1483
1484once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerometerResponse&gt;): void
1485
1486Obtains data of the linear acceleration sensor once.
1487
1488**Required permissions**: ohos.permission.ACCELEROMETER
1489
1490**System capability**: SystemCapability.Sensors.Sensor
1491
1492**Parameters**
1493
1494| Name  | Type                                                        | Mandatory| Description                                                        |
1495| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1496| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**.       |
1497| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.|
1498
1499**Error codes**
1500
1501For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1502
1503| ID| Error Message                                                    |
1504| -------- | ------------------------------------------------------------ |
1505| 201      | Permission denied.                                           |
1506| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1507| 14500101 | Service exception.                                           |
1508
1509**Example**
1510
1511```ts
1512import { sensor } from '@kit.SensorServiceKit';
1513import { BusinessError } from '@kit.BasicServicesKit';
1514
1515try {
1516  sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, (data: sensor.LinearAccelerometerResponse) => {
1517    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1518    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1519    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1520  });
1521} catch (error) {
1522  let e: BusinessError = error as BusinessError;
1523  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1524}
1525```
1526
1527### MAGNETIC_FIELD<sup>9+</sup>
1528
1529once(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
1530
1531Obtains data of the magnetic field sensor once.
1532
1533**System capability**: SystemCapability.Sensors.Sensor
1534
1535**Parameters**
1536
1537| Name  | Type                                                        | Mandatory| Description                                                       |
1538| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1539| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.            |
1540| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.|
1541
1542**Error codes**
1543
1544For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1545
1546| ID| Error Message                                                    |
1547| -------- | ------------------------------------------------------------ |
1548| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1549| 14500101 | Service exception.                                           |
1550
1551**Example**
1552
1553```ts
1554import { sensor } from '@kit.SensorServiceKit';
1555import { BusinessError } from '@kit.BasicServicesKit';
1556
1557try {
1558  sensor.once(sensor.SensorId.MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
1559    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1560    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1561    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1562  });
1563} catch (error) {
1564  let e: BusinessError = error as BusinessError;
1565  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1566}
1567```
1568
1569### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
1570
1571once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
1572
1573Obtains data of the uncalibrated magnetic field sensor once.
1574
1575**System capability**: SystemCapability.Sensors.Sensor
1576
1577**Parameters**
1578
1579| Name  | Type                                                        | Mandatory| Description                                                        |
1580| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1581| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
1582| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.|
1583
1584**Error codes**
1585
1586For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1587
1588| ID| Error Message                                                    |
1589| -------- | ------------------------------------------------------------ |
1590| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1591| 14500101 | Service exception.                                           |
1592
1593**Example**
1594
1595```ts
1596import { sensor } from '@kit.SensorServiceKit';
1597import { BusinessError } from '@kit.BasicServicesKit';
1598
1599try {
1600  sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
1601    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1602    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1603    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1604    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
1605    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
1606    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
1607  });
1608} catch (error) {
1609  let e: BusinessError = error as BusinessError;
1610  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1611}
1612```
1613
1614### ORIENTATION<sup>9+</sup>
1615
1616once(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
1617
1618Obtains data of the orientation sensor once.
1619
1620**System capability**: SystemCapability.Sensors.Sensor
1621
1622**Parameters**
1623
1624| Name  | Type                                                       | Mandatory| Description                                                     |
1625| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
1626| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.             |
1627| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **OrientationResponse** object.|
1628
1629**Error codes**
1630
1631For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1632
1633| ID| Error Message                                                    |
1634| -------- | ------------------------------------------------------------ |
1635| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1636| 14500101 | Service exception.                                           |
1637
1638**Example**
1639
1640```ts
1641import { sensor } from '@kit.SensorServiceKit';
1642import { BusinessError } from '@kit.BasicServicesKit';
1643
1644try {
1645  sensor.once(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => {
1646    console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
1647    console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
1648    console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
1649  });
1650} catch (error) {
1651  let e: BusinessError = error as BusinessError;
1652  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1653}
1654```
1655
1656### PEDOMETER<sup>9+</sup>
1657
1658once(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
1659
1660Obtains data of the pedometer sensor once.
1661
1662**Required permissions**: ohos.permission.ACTIVITY_MOTION
1663
1664**System capability**: SystemCapability.Sensors.Sensor
1665
1666**Parameters**
1667
1668| Name  | Type                                                   | Mandatory| Description                                                   |
1669| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1670| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.             |
1671| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerResponse** object.|
1672
1673**Error codes**
1674
1675For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1676
1677| ID| Error Message                                                    |
1678| -------- | ------------------------------------------------------------ |
1679| 201      | Permission denied.                                           |
1680| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1681| 14500101 | Service exception.                                           |
1682
1683**Example**
1684
1685```ts
1686import { sensor } from '@kit.SensorServiceKit';
1687import { BusinessError } from '@kit.BasicServicesKit';
1688
1689try {
1690  sensor.once(sensor.SensorId.PEDOMETER, (data: sensor.PedometerResponse) => {
1691    console.info('Succeeded in invoking once. Step count: ' + data.steps);
1692  });
1693} catch (error) {
1694  let e: BusinessError = error as BusinessError;
1695  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1696}
1697```
1698
1699### PEDOMETER_DETECTION<sup>9+</sup>
1700
1701once(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;): void
1702
1703Obtains data of the pedometer sensor once.
1704
1705**Required permissions**: ohos.permission.ACTIVITY_MOTION
1706
1707**System capability**: SystemCapability.Sensors.Sensor
1708
1709**Parameters**
1710
1711| Name  | Type                                                        | Mandatory| Description                                                        |
1712| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1713| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
1714| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.|
1715
1716**Error codes**
1717
1718For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1719
1720| ID| Error Message                                                    |
1721| -------- | ------------------------------------------------------------ |
1722| 201      | Permission denied.                                           |
1723| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1724| 14500101 | Service exception.                                           |
1725
1726**Example**
1727
1728```ts
1729import { sensor } from '@kit.SensorServiceKit';
1730import { BusinessError } from '@kit.BasicServicesKit';
1731
1732try {
1733  sensor.once(sensor.SensorId.PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
1734    console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
1735  });
1736} catch (error) {
1737  let e: BusinessError = error as BusinessError;
1738  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1739}
1740```
1741
1742### PROXIMITY<sup>9+</sup>
1743
1744once(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
1745
1746Obtains data of the proximity sensor once.
1747
1748**System capability**: SystemCapability.Sensors.Sensor
1749
1750**Parameters**
1751
1752| Name  | Type                                                   | Mandatory| Description                                                   |
1753| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1754| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.             |
1755| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **ProximityResponse** object.|
1756
1757**Error codes**
1758
1759For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1760
1761| ID| Error Message                                                    |
1762| -------- | ------------------------------------------------------------ |
1763| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1764| 14500101 | Service exception.                                           |
1765
1766**Example**
1767
1768```ts
1769import { sensor } from '@kit.SensorServiceKit';
1770import { BusinessError } from '@kit.BasicServicesKit';
1771
1772try {
1773  sensor.once(sensor.SensorId.PROXIMITY, (data: sensor.ProximityResponse) => {
1774    console.info('Succeeded in invoking once. Distance: ' + data.distance);
1775  });
1776} catch (error) {
1777  let e: BusinessError = error as BusinessError;
1778  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1779}
1780```
1781
1782### ROTATION_VECTOR<sup>9+</sup>
1783
1784once(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
1785
1786Obtains data of the rotation vector sensor once.
1787
1788**System capability**: SystemCapability.Sensors.Sensor
1789
1790**Parameters**
1791
1792| Name  | Type                                                        | Mandatory| Description                                                        |
1793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1794| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
1795| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **RotationVectorResponse** object.|
1796
1797**Error codes**
1798
1799For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1800
1801| ID| Error Message                                                    |
1802| -------- | ------------------------------------------------------------ |
1803| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1804| 14500101 | Service exception.                                           |
1805
1806**Example**
1807
1808```ts
1809import { sensor } from '@kit.SensorServiceKit';
1810import { BusinessError } from '@kit.BasicServicesKit';
1811
1812try {
1813  sensor.once(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
1814    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
1815    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
1816    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
1817    console.info('Succeeded in invoking once. Scalar quantity: ' + data.w);
1818  });
1819} catch (error) {
1820  let e: BusinessError = error as BusinessError;
1821  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1822}
1823```
1824
1825### SIGNIFICANT_MOTION<sup>9+</sup>
1826
1827once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;): void
1828
1829Obtains data of the significant motion sensor once.
1830
1831**System capability**: SystemCapability.Sensors.Sensor
1832
1833**Parameters**
1834
1835| Name  | Type                                                        | Mandatory| Description                                                        |
1836| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1837| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
1838| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.|
1839
1840**Error codes**
1841
1842For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1843
1844| ID| Error Message                                                    |
1845| -------- | ------------------------------------------------------------ |
1846| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1847| 14500101 | Service exception.                                           |
1848
1849**Example**
1850
1851```ts
1852import { sensor } from '@kit.SensorServiceKit';
1853import { BusinessError } from '@kit.BasicServicesKit';
1854
1855try {
1856  sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
1857    console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
1858  });
1859} catch (error) {
1860  let e: BusinessError = error as BusinessError;
1861  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1862}
1863```
1864
1865### WEAR_DETECTION<sup>9+</sup>
1866
1867once(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
1868
1869Obtains data of the wear detection sensor once.
1870
1871**System capability**: SystemCapability.Sensors.Sensor
1872
1873**Parameters**
1874
1875| Name  | Type                                                        | Mandatory| Description                                                       |
1876| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1877| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.            |
1878| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **WearDetectionResponse** object.|
1879
1880**Error codes**
1881
1882For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
1883
1884| ID| Error Message                                                    |
1885| -------- | ------------------------------------------------------------ |
1886| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1887| 14500101 | Service exception.                                           |
1888
1889**Example**
1890
1891```ts
1892import { sensor } from '@kit.SensorServiceKit';
1893import { BusinessError } from '@kit.BasicServicesKit';
1894
1895try {
1896  sensor.once(sensor.SensorId.WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
1897    console.info('Succeeded in invoking once. Wear status: ' + data.value);
1898  });
1899} catch (error) {
1900  let e: BusinessError = error as BusinessError;
1901  console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
1902}
1903```
1904
1905## sensor.off
1906
1907### ACCELEROMETER<sup>9+</sup>
1908
1909off(type: SensorId.ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
1910
1911Unsubscribes from data of the acceleration sensor.
1912
1913**Required permissions**: ohos.permission.ACCELEROMETER
1914
1915**Atomic service API**: This API can be used in atomic services since API version 11.
1916
1917**System capability**: SystemCapability.Sensors.Sensor
1918
1919**Parameters**
1920
1921| Name  | Type                                                        | Mandatory| Description                                                        |
1922| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1923| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.              |
1924| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
1925
1926**Error codes**
1927
1928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1929
1930| ID| Error Message                                                    |
1931| -------- | ------------------------------------------------------------ |
1932| 201      | Permission denied.                                           |
1933| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1934
1935**Example**
1936
1937```ts
1938import { sensor } from '@kit.SensorServiceKit';
1939import { BusinessError } from '@kit.BasicServicesKit';
1940
1941function callback1(data: object) {
1942  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
1943}
1944
1945function callback2(data: object) {
1946  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
1947}
1948
1949try {
1950  sensor.on(sensor.SensorId.ACCELEROMETER, callback1);
1951  sensor.on(sensor.SensorId.ACCELEROMETER, callback2);
1952  // Unsubscribe from callback1.
1953  sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
1954  // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER type.
1955  sensor.off(sensor.SensorId.ACCELEROMETER);
1956} catch (error) {
1957  let e: BusinessError = error as BusinessError;
1958  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
1959}
1960```
1961
1962### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
1963
1964off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
1965
1966Unsubscribes from data of the uncalibrated acceleration sensor.
1967
1968**Required permissions**: ohos.permission.ACCELEROMETER
1969
1970**System capability**: SystemCapability.Sensors.Sensor
1971
1972**Parameters**
1973
1974| Name  | Type                                                        | Mandatory| Description                                                        |
1975| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1976| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
1977| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
1978
1979**Error codes**
1980
1981For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1982
1983| ID| Error Message                                                    |
1984| -------- | ------------------------------------------------------------ |
1985| 201      | Permission denied.                                           |
1986| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
1987
1988**Example**
1989
1990```ts
1991import { sensor } from '@kit.SensorServiceKit';
1992import { BusinessError } from '@kit.BasicServicesKit';
1993
1994function callback1(data: object) {
1995  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
1996}
1997
1998function callback2(data: object) {
1999  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2000}
2001
2002try {
2003  sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
2004  sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2);
2005  // Unsubscribe from callback1.
2006  sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
2007  // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER_UNCALIBRATED type.
2008  sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED);
2009} catch (error) {
2010  let e: BusinessError = error as BusinessError;
2011  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2012}
2013```
2014
2015### AMBIENT_LIGHT<sup>9+</sup>
2016
2017off(type: SensorId.AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
2018
2019Unsubscribes from data of the ambient light sensor.
2020
2021**System capability**: SystemCapability.Sensors.Sensor
2022
2023**Parameters**
2024
2025| Name  | Type                                           | Mandatory| Description                                                        |
2026| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2027| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.              |
2028| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2029
2030**Error codes**
2031
2032For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2033
2034| ID| Error Message                                                    |
2035| -------- | ------------------------------------------------------------ |
2036| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2037
2038**Example**
2039
2040```ts
2041import { sensor } from '@kit.SensorServiceKit';
2042import { BusinessError } from '@kit.BasicServicesKit';
2043
2044function callback1(data: object) {
2045  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2046}
2047
2048function callback2(data: object) {
2049  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2050}
2051
2052try {
2053  sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1);
2054  sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2);
2055  // Unsubscribe from callback1.
2056  sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
2057  // Unsubscribe from all callbacks of the SensorId.AMBIENT_LIGHT type.
2058  sensor.off(sensor.SensorId.AMBIENT_LIGHT);
2059} catch (error) {
2060  let e: BusinessError = error as BusinessError;
2061  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2062}
2063```
2064
2065### AMBIENT_TEMPERATURE<sup>9+</sup>
2066
2067off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
2068
2069Unsubscribes from data of the ambient temperature sensor.
2070
2071**System capability**: SystemCapability.Sensors.Sensor
2072
2073**Parameters**
2074
2075| Name  | Type                                                        | Mandatory| Description                                                        |
2076| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2077| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
2078| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2079
2080**Error codes**
2081
2082For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2083
2084| ID| Error Message                                                    |
2085| -------- | ------------------------------------------------------------ |
2086| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2087
2088**Example**
2089
2090```ts
2091import { sensor } from '@kit.SensorServiceKit';
2092import { BusinessError } from '@kit.BasicServicesKit';
2093
2094function callback1(data: object) {
2095  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2096}
2097
2098function callback2(data: object) {
2099  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2100}
2101
2102try {
2103  sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
2104  sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2);
2105  // Unsubscribe from callback1.
2106  sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
2107  // Unsubscribe from all callbacks of the SensorId.AMBIENT_TEMPERATURE type.
2108  sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE);
2109} catch (error) {
2110  let e: BusinessError = error as BusinessError;
2111  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2112}
2113```
2114
2115### BAROMETER<sup>9+</sup>
2116
2117off(type: SensorId.BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
2118
2119Unsubscribes from data of the barometer sensor.
2120
2121**System capability**: SystemCapability.Sensors.Sensor
2122
2123**Parameters**
2124
2125| Name  | Type                                                   | Mandatory| Description                                                        |
2126| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2127| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.                  |
2128| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2129
2130**Error codes**
2131
2132For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2133
2134| ID| Error Message                                                    |
2135| -------- | ------------------------------------------------------------ |
2136| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2137
2138**Example**
2139
2140```ts
2141import { sensor } from '@kit.SensorServiceKit';
2142import { BusinessError } from '@kit.BasicServicesKit';
2143
2144function callback1(data: object) {
2145    console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2146}
2147
2148function callback2(data: object) {
2149    console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2150}
2151
2152try {
2153    sensor.on(sensor.SensorId.BAROMETER, callback1);
2154    sensor.on(sensor.SensorId.BAROMETER, callback2);
2155    // Unsubscribe from callback1.
2156    sensor.off(sensor.SensorId.BAROMETER, callback1);
2157    // Unsubscribe from all callbacks of the SensorId.BAROMETER type.
2158    sensor.off(sensor.SensorId.BAROMETER);
2159} catch (error) {
2160    let e: BusinessError = error as BusinessError;
2161    console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2162}
2163```
2164
2165### GRAVITY<sup>9+</sup>
2166
2167off(type: SensorId.GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
2168
2169Unsubscribes from data of the gravity sensor.
2170
2171**System capability**: SystemCapability.Sensors.Sensor
2172
2173**Parameters**
2174
2175| Name  | Type                                               | Mandatory| Description                                                        |
2176| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
2177| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.                    |
2178| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2179
2180**Error codes**
2181
2182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2183
2184| ID| Error Message                                                    |
2185| -------- | ------------------------------------------------------------ |
2186| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2187
2188**Example**
2189
2190```ts
2191import { sensor } from '@kit.SensorServiceKit';
2192import { BusinessError } from '@kit.BasicServicesKit';
2193
2194function callback1(data: object) {
2195  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2196}
2197
2198function callback2(data: object) {
2199  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2200}
2201
2202try {
2203  sensor.on(sensor.SensorId.GRAVITY, callback1);
2204  sensor.on(sensor.SensorId.GRAVITY, callback2);
2205  // Unsubscribe from callback1.
2206  sensor.off(sensor.SensorId.GRAVITY, callback1);
2207  // Unsubscribe from all callbacks of the SensorId.GRAVITY type.
2208  sensor.off(sensor.SensorId.GRAVITY);
2209} catch (error) {
2210  let e: BusinessError = error as BusinessError;
2211  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2212}
2213
2214```
2215
2216### GYROSCOPE<sup>9+</sup>
2217
2218off(type: SensorId.GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
2219
2220Unsubscribes from data of the gyroscope sensor.
2221
2222**Required permissions**: ohos.permission.GYROSCOPE
2223
2224**Atomic service API**: This API can be used in atomic services since API version 11.
2225
2226**System capability**: SystemCapability.Sensors.Sensor
2227
2228**Parameters**
2229
2230| Name  | Type                                                   | Mandatory| Description                                                        |
2231| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2232| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.                  |
2233| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2234
2235**Error codes**
2236
2237For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2238
2239| ID| Error Message                                                    |
2240| -------- | ------------------------------------------------------------ |
2241| 201      | Permission denied.                                           |
2242| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2243
2244**Example**
2245
2246```ts
2247import { sensor } from '@kit.SensorServiceKit';
2248import { BusinessError } from '@kit.BasicServicesKit';
2249
2250function callback1(data: object) {
2251  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2252}
2253
2254function callback2(data: object) {
2255  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2256}
2257
2258try {
2259  sensor.on(sensor.SensorId.GYROSCOPE, callback1);
2260  sensor.on(sensor.SensorId.GYROSCOPE, callback2);
2261  // Unsubscribe from callback1.
2262  sensor.off(sensor.SensorId.GYROSCOPE, callback1);
2263  // Unsubscribe from all callbacks of the SensorId.GYROSCOPE type.
2264  sensor.off(sensor.SensorId.GYROSCOPE);
2265} catch (error) {
2266  let e: BusinessError = error as BusinessError;
2267  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2268}
2269```
2270
2271### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
2272
2273off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
2274
2275 Unsubscribes from data of the uncalibrated gyroscope sensor.
2276
2277**Required permissions**: ohos.permission.GYROSCOPE
2278
2279**System capability**: SystemCapability.Sensors.Sensor
2280
2281**Parameters**
2282
2283| Name  | Type                                                        | Mandatory| Description                                                        |
2284| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2285| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
2286| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2287
2288**Error codes**
2289
2290For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2291
2292| ID| Error Message                                                    |
2293| -------- | ------------------------------------------------------------ |
2294| 201      | Permission denied.                                           |
2295| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2296
2297**Example**
2298
2299```ts
2300import { sensor } from '@kit.SensorServiceKit';
2301import { BusinessError } from '@kit.BasicServicesKit';
2302
2303function callback1(data: object) {
2304  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2305}
2306
2307function callback2(data: object) {
2308  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2309}
2310
2311try {
2312  sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
2313  sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2);
2314  // Unsubscribe from callback1.
2315  sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
2316  // Unsubscribe from all callbacks of the SensorId.GYROSCOPE_UNCALIBRATED type.
2317  sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED);
2318} catch (error) {
2319  let e: BusinessError = error as BusinessError;
2320  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2321}
2322```
2323
2324### HALL<sup>9+</sup>
2325
2326off(type: SensorId.HALL, callback?: Callback&lt;HallResponse&gt;): void
2327
2328Unsubscribes from data of the Hall effect sensor.
2329
2330**System capability**: SystemCapability.Sensors.Sensor
2331
2332**Parameters**
2333
2334| Name  | Type                                         | Mandatory| Description                                                        |
2335| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
2336| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.                       |
2337| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2338
2339**Error codes**
2340
2341For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2342
2343| ID| Error Message                                                    |
2344| -------- | ------------------------------------------------------------ |
2345| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2346
2347**Example**
2348
2349```ts
2350import { sensor } from '@kit.SensorServiceKit';
2351import { BusinessError } from '@kit.BasicServicesKit';
2352
2353function callback1(data: object) {
2354  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2355}
2356
2357function callback2(data: object) {
2358  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2359}
2360
2361try {
2362  sensor.on(sensor.SensorId.HALL, callback1);
2363  sensor.on(sensor.SensorId.HALL, callback2);
2364  // Unsubscribe from callback1.
2365  sensor.off(sensor.SensorId.HALL, callback1);
2366  // Unsubscribe from all callbacks of the SensorId.HALL type.
2367  sensor.off(sensor.SensorId.HALL);
2368} catch (error) {
2369  let e: BusinessError = error as BusinessError;
2370  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2371}
2372```
2373
2374### HEART_RATE<sup>9+</sup>
2375
2376off(type: SensorId.HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
2377
2378Unsubscribes from data of the heart rate sensor.
2379
2380**Required permissions**: ohos.permission.READ_HEALTH_DATA
2381
2382**System capability**: SystemCapability.Sensors.Sensor
2383
2384**Parameters**
2385
2386| Name  | Type                                                   | Mandatory| Description                                                        |
2387| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2388| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.                 |
2389| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2390
2391**Error codes**
2392
2393For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2394
2395| ID| Error Message                                                    |
2396| -------- | ------------------------------------------------------------ |
2397| 201      | Permission denied.                                           |
2398| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2399
2400**Example**
2401
2402```ts
2403import { sensor } from '@kit.SensorServiceKit';
2404import { BusinessError } from '@kit.BasicServicesKit';
2405
2406function callback1(data: object) {
2407  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2408}
2409
2410function callback2(data: object) {
2411  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2412}
2413
2414try {
2415  sensor.on(sensor.SensorId.HEART_RATE, callback1);
2416  sensor.on(sensor.SensorId.HEART_RATE, callback2);
2417  // Unsubscribe from callback1.
2418  sensor.off(sensor.SensorId.HEART_RATE, callback1);
2419  // Unsubscribe from all callbacks of the SensorId.HEART_RATE type.
2420  sensor.off(sensor.SensorId.HEART_RATE);
2421} catch (error) {
2422  let e: BusinessError = error as BusinessError;
2423  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2424}
2425```
2426
2427### HUMIDITY<sup>9+</sup>
2428
2429off(type: SensorId.HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
2430
2431Unsubscribes from data of the humidity sensor.
2432
2433**System capability**: SystemCapability.Sensors.Sensor
2434
2435**Parameters**
2436
2437| Name  | Type                                                 | Mandatory| Description                                                        |
2438| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2439| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.                   |
2440| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2441
2442**Error codes**
2443
2444For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2445
2446| ID| Error Message                                                    |
2447| -------- | ------------------------------------------------------------ |
2448| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2449
2450**Example**
2451
2452```ts
2453import { sensor } from '@kit.SensorServiceKit';
2454import { BusinessError } from '@kit.BasicServicesKit';
2455
2456function callback1(data: object) {
2457  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2458}
2459
2460function callback2(data: object) {
2461  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2462}
2463
2464try {
2465  sensor.on(sensor.SensorId.HUMIDITY, callback1);
2466  sensor.on(sensor.SensorId.HUMIDITY, callback2);
2467  // Unsubscribe from callback1.
2468  sensor.off(sensor.SensorId.HUMIDITY, callback1);
2469  // Unsubscribe from all callbacks of the SensorId.HUMIDITY type.
2470  sensor.off(sensor.SensorId.HUMIDITY);
2471} catch (error) {
2472  let e: BusinessError = error as BusinessError;
2473  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2474}
2475```
2476
2477### LINEAR_ACCELEROMETER<sup>9+</sup>
2478
2479off(type: SensorId.LINEAR_ACCELEROMETER, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
2480
2481Unsubscribes from data of the linear acceleration sensor.
2482
2483**Required permissions**: ohos.permission.ACCELEROMETER
2484
2485**System capability**: SystemCapability.Sensors.Sensor
2486
2487**Parameters**
2488
2489| Name  | Type                                                        | Mandatory| Description                                                        |
2490| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2491| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELERATION**.        |
2492| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2493
2494**Error codes**
2495
2496For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2497
2498| ID| Error Message                                                    |
2499| -------- | ------------------------------------------------------------ |
2500| 201      | Permission denied.                                           |
2501| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2502
2503**Example**
2504
2505```ts
2506import { sensor } from '@kit.SensorServiceKit';
2507import { BusinessError } from '@kit.BasicServicesKit';
2508
2509function callback1(data: object) {
2510  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2511}
2512
2513function callback2(data: object) {
2514  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2515}
2516
2517try {
2518  sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
2519  sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2);
2520  // Unsubscribe from callback1.
2521  sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
2522  // Unsubscribe from all callbacks of the SensorId.LINEAR_ACCELEROMETER type.
2523  sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER);
2524} catch (error) {
2525  let e: BusinessError = error as BusinessError;
2526  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2527}
2528```
2529
2530### MAGNETIC_FIELD<sup>9+</sup>
2531
2532off(type: SensorId.MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
2533
2534Unsubscribes from data of the magnetic field sensor.
2535
2536**System capability**: SystemCapability.Sensors.Sensor
2537
2538**Parameters**
2539
2540| Name  | Type                                                        | Mandatory| Description                                                        |
2541| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2542| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.             |
2543| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2544
2545**Error codes**
2546
2547For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2548
2549| ID| Error Message                                                    |
2550| -------- | ------------------------------------------------------------ |
2551| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2552
2553**Example**
2554
2555```ts
2556import { sensor } from '@kit.SensorServiceKit';
2557import { BusinessError } from '@kit.BasicServicesKit';
2558
2559function callback1(data: object) {
2560  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2561}
2562
2563function callback2(data: object) {
2564  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2565}
2566
2567try {
2568  sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1);
2569  sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2);
2570  // Unsubscribe from callback1.
2571  sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
2572  // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD type.
2573  sensor.off(sensor.SensorId.MAGNETIC_FIELD);
2574} catch (error) {
2575  let e: BusinessError = error as BusinessError;
2576  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2577}
2578```
2579
2580### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
2581
2582off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
2583
2584Unsubscribes from data of the uncalibrated magnetic field sensor.
2585
2586**System capability**: SystemCapability.Sensors.Sensor
2587
2588**Parameters**
2589
2590| Name  | Type                                                        | Mandatory| Description                                                        |
2591| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2592| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
2593| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2594
2595**Error codes**
2596
2597For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2598
2599| ID| Error Message                                                    |
2600| -------- | ------------------------------------------------------------ |
2601| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2602
2603**Example**
2604
2605```ts
2606import { sensor } from '@kit.SensorServiceKit';
2607import { BusinessError } from '@kit.BasicServicesKit';
2608
2609function callback1(data: object) {
2610  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2611}
2612
2613function callback2(data: object) {
2614  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2615}
2616
2617try {
2618  sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
2619  sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2);
2620  // Unsubscribe from callback1.
2621  sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
2622  // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD_UNCALIBRATED type.
2623  sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED);
2624} catch (error) {
2625  let e: BusinessError = error as BusinessError;
2626  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2627}
2628```
2629
2630### ORIENTATION<sup>9+</sup>
2631
2632off(type: SensorId.ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
2633
2634Unsubscribes from data of the orientation sensor.
2635
2636**Atomic service API**: This API can be used in atomic services since API version 11.
2637
2638**System capability**: SystemCapability.Sensors.Sensor
2639
2640**Parameters**
2641
2642| Name  | Type                                                       | Mandatory| Description                                                        |
2643| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2644| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.                |
2645| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2646
2647**Error codes**
2648
2649For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2650
2651| ID| Error Message                                                    |
2652| -------- | ------------------------------------------------------------ |
2653| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2654
2655**Example**
2656
2657```ts
2658import { sensor } from '@kit.SensorServiceKit';
2659import { BusinessError } from '@kit.BasicServicesKit';
2660
2661function callback1(data: object) {
2662  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2663}
2664
2665function callback2(data: object) {
2666  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2667}
2668
2669try {
2670  sensor.on(sensor.SensorId.ORIENTATION, callback1);
2671  sensor.on(sensor.SensorId.ORIENTATION, callback2);
2672  // Unsubscribe from callback1.
2673  sensor.off(sensor.SensorId.ORIENTATION, callback1);
2674  // Unsubscribe from all callbacks of the SensorId.ORIENTATION type.
2675  sensor.off(sensor.SensorId.ORIENTATION);
2676} catch (error) {
2677  let e: BusinessError = error as BusinessError;
2678  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2679}
2680```
2681
2682### PEDOMETER<sup>9+</sup>
2683
2684off(type: SensorId.PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
2685
2686Unsubscribes from data of the pedometer sensor.
2687
2688**Required permissions**: ohos.permission.ACTIVITY_MOTION
2689
2690**System capability**: SystemCapability.Sensors.Sensor
2691
2692**Parameters**
2693
2694| Name  | Type                                                   | Mandatory| Description                                                        |
2695| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2696| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.                  |
2697| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2698
2699**Error codes**
2700
2701For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2702
2703| ID| Error Message                                                    |
2704| -------- | ------------------------------------------------------------ |
2705| 201      | Permission denied.                                           |
2706| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2707
2708**Example**
2709
2710```ts
2711import { sensor } from '@kit.SensorServiceKit';
2712import { BusinessError } from '@kit.BasicServicesKit';
2713
2714function callback1(data: object) {
2715  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2716}
2717
2718function callback2(data: object) {
2719  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2720}
2721
2722try {
2723  sensor.on(sensor.SensorId.PEDOMETER, callback1);
2724  sensor.on(sensor.SensorId.PEDOMETER, callback2);
2725  // Unsubscribe from callback1.
2726  sensor.off(sensor.SensorId.PEDOMETER, callback1);
2727  // Unsubscribe from all callbacks of the SensorId.ORIENTATION type.
2728  sensor.off(sensor.SensorId.PEDOMETER);
2729} catch (error) {
2730  let e: BusinessError = error as BusinessError;
2731  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2732}
2733```
2734
2735### PEDOMETER_DETECTION<sup>9+</sup>
2736
2737off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
2738
2739Unsubscribes from data of the pedometer detection sensor.
2740
2741**Required permissions**: ohos.permission.ACTIVITY_MOTION
2742
2743**System capability**: SystemCapability.Sensors.Sensor
2744
2745**Parameters**
2746
2747| Name  | Type                                                        | Mandatory| Description                                                        |
2748| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2749| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
2750| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2751
2752**Error codes**
2753
2754For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2755
2756| ID| Error Message                                                    |
2757| -------- | ------------------------------------------------------------ |
2758| 201      | Permission denied.                                           |
2759| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2760
2761**Example**
2762
2763```ts
2764import { sensor } from '@kit.SensorServiceKit';
2765import { BusinessError } from '@kit.BasicServicesKit';
2766
2767function callback1(data: object) {
2768  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2769}
2770
2771function callback2(data: object) {
2772  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2773}
2774
2775try {
2776  sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1);
2777  sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2);
2778  // Unsubscribe from callback1.
2779  sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
2780  // Unsubscribe from all callbacks of the SensorId.PEDOMETER_DETECTION type.
2781  sensor.off(sensor.SensorId.PEDOMETER_DETECTION);
2782} catch (error) {
2783  let e: BusinessError = error as BusinessError;
2784  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2785}
2786```
2787
2788### PROXIMITY<sup>9+</sup>
2789
2790off(type: SensorId.PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
2791
2792Unsubscribes from data of the proximity sensor.
2793
2794**System capability**: SystemCapability.Sensors.Sensor
2795
2796**Parameters**
2797
2798| Name  | Type                                                   | Mandatory| Description                                                        |
2799| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2800| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.                  |
2801| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2802
2803**Error codes**
2804
2805For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2806
2807| ID| Error Message                                                    |
2808| -------- | ------------------------------------------------------------ |
2809| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2810
2811**Example**
2812
2813```ts
2814import { sensor } from '@kit.SensorServiceKit';
2815import { BusinessError } from '@kit.BasicServicesKit';
2816
2817function callback1(data: object) {
2818  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2819}
2820
2821function callback2(data: object) {
2822  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2823}
2824
2825try {
2826  sensor.on(sensor.SensorId.PROXIMITY, callback1);
2827  sensor.on(sensor.SensorId.PROXIMITY, callback2);
2828  // Unsubscribe from callback1.
2829  sensor.off(sensor.SensorId.PROXIMITY, callback1);
2830  // Unsubscribe from all callbacks of the SensorId.PROXIMITY type.
2831  sensor.off(sensor.SensorId.PROXIMITY);
2832} catch (error) {
2833  let e: BusinessError = error as BusinessError;
2834  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2835}
2836```
2837
2838### ROTATION_VECTOR<sup>9+</sup>
2839
2840off(type: SensorId.ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
2841
2842Unsubscribes from data of the rotation vector sensor.
2843
2844**System capability**: SystemCapability.Sensors.Sensor
2845
2846**Parameters**
2847
2848| Name  | Type                                                        | Mandatory| Description                                                        |
2849| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2850| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
2851| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2852
2853**Error codes**
2854
2855For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2856
2857| ID| Error Message                                                    |
2858| -------- | ------------------------------------------------------------ |
2859| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2860
2861**Example**
2862
2863```ts
2864import { sensor } from '@kit.SensorServiceKit';
2865import { BusinessError } from '@kit.BasicServicesKit';
2866
2867function callback1(data: object) {
2868  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2869}
2870
2871function callback2(data: object) {
2872  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2873}
2874
2875try {
2876  sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1);
2877  sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2);
2878  // Unsubscribe from callback1.
2879  sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
2880  // Unsubscribe from all callbacks of the SensorId.ROTATION_VECTOR type.
2881  sensor.off(sensor.SensorId.ROTATION_VECTOR);
2882} catch (error) {
2883  let e: BusinessError = error as BusinessError;
2884  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2885}
2886```
2887
2888### SIGNIFICANT_MOTION<sup>9+</sup>
2889
2890off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
2891
2892Unsubscribes from data of the significant motion sensor.
2893
2894**System capability**: SystemCapability.Sensors.Sensor
2895
2896**Parameters**
2897
2898| Name  | Type                                                        | Mandatory| Description                                                        |
2899| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2900| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
2901| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2902
2903**Error codes**
2904
2905For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2906
2907| ID| Error Message                                                    |
2908| -------- | ------------------------------------------------------------ |
2909| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2910
2911**Example**
2912
2913```ts
2914import { sensor } from '@kit.SensorServiceKit';
2915import { BusinessError } from '@kit.BasicServicesKit';
2916
2917function callback1(data: object) {
2918  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2919}
2920
2921function callback2(data: object) {
2922  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2923}
2924
2925try {
2926  sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
2927  sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2);
2928  // Unsubscribe from callback1.
2929  sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
2930  // Unsubscribe from all callbacks of the SensorId.SIGNIFICANT_MOTION type.
2931  sensor.off(sensor.SensorId.SIGNIFICANT_MOTION);
2932} catch (error) {
2933  let e: BusinessError = error as BusinessError;
2934  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2935}
2936```
2937
2938### WEAR_DETECTION<sup>9+</sup>
2939
2940off(type: SensorId.WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
2941
2942Unsubscribes from data of the wear detection sensor.
2943
2944**System capability**: SystemCapability.Sensors.Sensor
2945
2946**Parameters**
2947
2948| Name  | Type                                                        | Mandatory| Description                                                        |
2949| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2950| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.             |
2951| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
2952
2953**Error codes**
2954
2955For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2956
2957| ID| Error Message                                                    |
2958| -------- | ------------------------------------------------------------ |
2959| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2960
2961**Example**
2962
2963```ts
2964import { sensor } from '@kit.SensorServiceKit';
2965import { BusinessError } from '@kit.BasicServicesKit';
2966
2967function callback1(data: object) {
2968  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data));
2969}
2970
2971function callback2(data: object) {
2972  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data));
2973}
2974
2975try {
2976  sensor.on(sensor.SensorId.WEAR_DETECTION, callback1);
2977  sensor.on(sensor.SensorId.WEAR_DETECTION, callback2);
2978  // Unsubscribe from callback1.
2979  sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
2980  // Unsubscribe from all callbacks of the SensorId.WEAR_DETECTION type.
2981  sensor.off(sensor.SensorId.WEAR_DETECTION);
2982} catch (error) {
2983  let e: BusinessError = error as BusinessError;
2984  console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`);
2985}
2986```
2987
2988## sensor.getGeomagneticInfo<sup>9+</sup>
2989
2990getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
2991
2992Obtains the geomagnetic field of a geographic location at a certain time. This API uses an asynchronous callback to return the result.
2993
2994**System capability**: SystemCapability.Sensors.Sensor
2995
2996**Parameters**
2997
2998| Name         | Type                                                        | Mandatory| Description                              |
2999| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
3000| locationOptions | [LocationOptions](#locationoptions)                          | Yes  | Geographic location, including the longitude, latitude, and altitude.                        |
3001| timeMillis      | number                                                       | Yes  | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.|
3002| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes  | Callback used to return the geomagnetic field.                |
3003
3004**Error codes**
3005
3006For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3007
3008| ID| Error Message                                                    |
3009| -------- | ------------------------------------------------------------ |
3010| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3011| 14500101 | Service exception.                                           |
3012
3013**Example**
3014
3015```ts
3016import { sensor } from '@kit.SensorServiceKit';
3017import { BusinessError } from '@kit.BasicServicesKit';
3018
3019try {
3020  sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000,
3021      (err: BusinessError, data: sensor.GeomagneticResponse) => {
3022    if (err) {
3023      console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`);
3024      return;
3025    }
3026    console.info("Succeeded in getting geomagneticInfo x" + data.x);
3027    console.info("Succeeded in getting geomagneticInfo y" + data.y);
3028    console.info("Succeeded in getting geomagneticInfo z" + data.z);
3029    console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip);
3030    console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle);
3031    console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity);
3032    console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity);
3033  });
3034} catch (error) {
3035  let e: BusinessError = error as BusinessError;
3036  console.error(`Failed to get geomagneticInfo. Code: ${e.code}, message: ${e.message}`);
3037}
3038```
3039
3040## sensor.getGeomagneticInfo<sup>9+</sup>
3041
3042getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
3043
3044Obtains the geomagnetic field of a geographic location at a certain time. This API uses a promise to return the result.
3045
3046**System capability**: SystemCapability.Sensors.Sensor
3047
3048**Parameters**
3049
3050| Name         | Type                               | Mandatory| Description                              |
3051| --------------- | ----------------------------------- | ---- | ---------------------------------- |
3052| locationOptions | [LocationOptions](#locationoptions) | Yes  | Geographic location, including the longitude, latitude, and altitude.                        |
3053| timeMillis      | number                              | Yes  | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.|
3054
3055**Return value**
3056
3057| Type                                                      | Description          |
3058| ---------------------------------------------------------- | -------------- |
3059| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|
3060
3061**Error codes**
3062
3063For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3064
3065| ID| Error Message                                                    |
3066| -------- | ------------------------------------------------------------ |
3067| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3068| 14500101 | Service exception.                                           |
3069
3070**Example**
3071
3072```ts
3073import { sensor } from '@kit.SensorServiceKit';
3074import { BusinessError } from '@kit.BasicServicesKit';
3075
3076try {
3077  const promise = sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000);
3078  promise.then((data: sensor.GeomagneticResponse) => {
3079    console.info("Succeeded in getting geomagneticInfo x" + data.x);
3080    console.info("Succeeded in getting geomagneticInfo y" + data.y);
3081    console.info("Succeeded in getting geomagneticInfo z" + data.z);
3082    console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip);
3083    console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle);
3084    console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity);
3085    console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity);
3086  }, (err: BusinessError) => {
3087    console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`);
3088  });
3089} catch (error) {
3090  let e: BusinessError = error as BusinessError;
3091  console.error(`Failed to get geomagneticInfo. Code: ${e.code}, message: ${e.message}`);
3092}
3093```
3094
3095## sensor.getDeviceAltitude<sup>9+</sup>
3096
3097getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
3098
3099Obtains the altitude based on the atmospheric pressure. This API uses an asynchronous callback to return the result.
3100
3101**System capability**: SystemCapability.Sensors.Sensor
3102
3103**Parameters**
3104
3105| Name         | Type                       | Mandatory| Description                                 |
3106| --------------- | --------------------------- | ---- | ------------------------------------- |
3107| seaPressure     | number                      | Yes  | Sea-level atmospheric pressure, in hPa.        |
3108| currentPressure | number                      | Yes  | Specified atmospheric pressure, in hPa.|
3109| callback        | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the altitude, in meters. |
3110
3111**Error codes**
3112
3113For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3114
3115| ID| Error Message                                                    |
3116| -------- | ------------------------------------------------------------ |
3117| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3118| 14500101 | Service exception.                                           |
3119
3120**Example**
3121
3122```ts
3123import { sensor } from '@kit.SensorServiceKit';
3124import { BusinessError } from '@kit.BasicServicesKit';
3125
3126try {
3127  let seaPressure = 1013.2;
3128  let currentPressure = 1500.0;
3129  sensor.getDeviceAltitude(seaPressure, currentPressure, (err: BusinessError, data: number) => {
3130    if (err) {
3131      console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`);
3132      return;
3133    }
3134    console.info('Succeeded in getting altitude: ' + data);
3135  });
3136} catch (error) {
3137  let e: BusinessError = error as BusinessError;
3138  console.error(`Failed to get altitude. Code: ${e.code}, message: ${e.message}`);
3139}
3140```
3141
3142## sensor.getDeviceAltitude<sup>9+</sup>
3143
3144getDeviceAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
3145
3146Obtains the altitude based on the atmospheric pressure. This API uses a promise to return the result.
3147
3148**System capability**: SystemCapability.Sensors.Sensor
3149
3150**Parameters**
3151
3152| Name         | Type  | Mandatory| Description                                 |
3153| --------------- | ------ | ---- | ------------------------------------- |
3154| seaPressure     | number | Yes  | Sea-level atmospheric pressure, in hPa.        |
3155| currentPressure | number | Yes  | Specified atmospheric pressure, in hPa.|
3156
3157**Return value**
3158
3159| Type                 | Description                                |
3160| --------------------- | ------------------------------------ |
3161| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|
3162
3163**Error codes**
3164
3165For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3166
3167| ID| Error Message                                                    |
3168| -------- | ------------------------------------------------------------ |
3169| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3170| 14500101 | Service exception.                                           |
3171
3172**Example**
3173
3174```ts
3175import { sensor } from '@kit.SensorServiceKit';
3176import { BusinessError } from '@kit.BasicServicesKit';
3177
3178try {
3179  let seaPressure = 1013.2;
3180  let currentPressure = 1500.0;
3181  const promise = sensor.getDeviceAltitude(seaPressure, currentPressure);
3182  promise.then((data: number) => {
3183    console.info('Succeeded in getting sensor_getDeviceAltitude_Promise', data);
3184  }, (err: BusinessError) => {
3185    console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`);
3186  });
3187} catch (error) {
3188  let e: BusinessError = error as BusinessError;
3189  console.error(`Failed to get altitude. Code: ${e.code}, message: ${e.message}`);
3190}
3191```
3192
3193## sensor.getInclination<sup>9+</sup>
3194
3195getInclination(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
3196
3197Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result.
3198
3199**System capability**: SystemCapability.Sensors.Sensor
3200
3201**Parameters**
3202
3203| Name           | Type                       | Mandatory| Description                        |
3204| ----------------- | --------------------------- | ---- | ---------------------------- |
3205| inclinationMatrix | Array&lt;number&gt;         | Yes  | Inclination matrix.              |
3206| callback          | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the magnetic dip, in radians.|
3207
3208**Error codes**
3209
3210For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3211
3212| ID| Error Message                                                    |
3213| -------- | ------------------------------------------------------------ |
3214| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3215| 14500101 | Service exception.                                           |
3216
3217**Example**
3218
3219```ts
3220import { sensor } from '@kit.SensorServiceKit';
3221import { BusinessError } from '@kit.BasicServicesKit';
3222
3223try {
3224  // inclinationMatrix can be 3*3 or 4*4.
3225  let inclinationMatrix = [
3226    1, 0, 0,
3227    0, 1, 0,
3228    0, 0, 1
3229  ]
3230  sensor.getInclination(inclinationMatrix, (err: BusinessError, data: number) => {
3231    if (err) {
3232      console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`);
3233      return;
3234    }
3235    console.info('Succeeded in getting inclination: ' + data);
3236  })
3237} catch (error) {
3238  let e: BusinessError = error as BusinessError;
3239  console.error(`Failed to get inclination. Code: ${e.code}, message: ${e.message}`);
3240}
3241```
3242
3243## sensor.getInclination<sup>9+</sup>
3244
3245 getInclination(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
3246
3247Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.
3248
3249**System capability**: SystemCapability.Sensors.Sensor
3250
3251**Parameters**
3252
3253| Name           | Type               | Mandatory| Description          |
3254| ----------------- | ------------------- | ---- | -------------- |
3255| inclinationMatrix | Array&lt;number&gt; | Yes  | Inclination matrix.|
3256
3257**Return value**
3258
3259| Type                 | Description                        |
3260| --------------------- | ---------------------------- |
3261| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|
3262
3263**Error codes**
3264
3265For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3266
3267| ID| Error Message                                                    |
3268| -------- | ------------------------------------------------------------ |
3269| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3270| 14500101 | Service exception.                                           |
3271
3272**Example**
3273
3274```ts
3275import { sensor } from '@kit.SensorServiceKit';
3276import { BusinessError } from '@kit.BasicServicesKit';
3277
3278try {
3279  // inclinationMatrix can be 3*3 or 4*4.
3280  let inclinationMatrix = [
3281    1, 0, 0,
3282    0, 1, 0,
3283    0, 0, 1
3284  ]
3285  const promise = sensor.getInclination(inclinationMatrix);
3286  promise.then((data: number) => {
3287    console.info('Succeeded in getting inclination: ' + data);
3288  }, (err: BusinessError) => {
3289    console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`);
3290  });
3291} catch (error) {
3292  let e: BusinessError = error as BusinessError;
3293  console.error(`Failed to get inclination. Code: ${e.code}, message: ${e.message}`);
3294}
3295```
3296
3297## sensor.getAngleVariation<sup>9+</sup>
3298
3299 getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;,
3300        callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
3301
3302Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result.
3303
3304**System capability**: SystemCapability.Sensors.Sensor
3305
3306**Parameters**
3307
3308| Name               | Type                                    | Mandatory| Description                             |
3309| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
3310| currentRotationMatrix | Array&lt;number&gt;                      | Yes  | Current rotation matrix.               |
3311| preRotationMatrix     | Array&lt;number&gt;                      | Yes  | The other rotation matrix.                   |
3312| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the angle change around the z, x, and y axes.|
3313
3314**Error codes**
3315
3316For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3317
3318| ID| Error Message                                                    |
3319| -------- | ------------------------------------------------------------ |
3320| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3321| 14500101 | Service exception.                                           |
3322
3323**Example**
3324
3325```ts
3326import { sensor } from '@kit.SensorServiceKit';
3327import { BusinessError } from '@kit.BasicServicesKit';
3328
3329try {
3330  // The rotation matrix can be 3*3 or 4*4.
3331  let currentRotationMatrix = [
3332    1, 0, 0,
3333    0, 1, 0,
3334    0, 0, 1
3335  ];
3336  let preRotationMatrix = [
3337    1, 0, 0,
3338    0, 0.87, -0.50,
3339    0, 0.50, 0.87
3340  ];
3341  sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, (err: BusinessError, data: Array<number>) => {
3342    if (err) {
3343      console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`);
3344      return;
3345    }
3346    if (data.length < 3) {
3347      console.error("Failed to get angle variation, length" + data.length);
3348    }
3349    console.info("Z: " + data[0]);
3350    console.info("X: " + data[1]);
3351    console.info("Y  : " + data[2]);
3352  })
3353} catch (error) {
3354  let e: BusinessError = error as BusinessError;
3355  console.error(`Failed to get angle variation. Code: ${e.code}, message: ${e.message}`);
3356}
3357```
3358
3359## sensor.getAngleVariation<sup>9+</sup>
3360
3361getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
3362
3363Obtains the angle change between two rotation matrices. This API uses a promise to return the result.
3364
3365**System capability**: SystemCapability.Sensors.Sensor
3366
3367**Parameters**
3368
3369| Name               | Type               | Mandatory| Description              |
3370| --------------------- | ------------------- | ---- | ------------------ |
3371| currentRotationMatrix | Array&lt;number&gt; | Yes  | Current rotation matrix.|
3372| preRotationMatrix     | Array&lt;number&gt; | Yes  | The other rotation matrix.                 |
3373
3374**Return value**
3375
3376| Type                              | Description                             |
3377| ---------------------------------- | --------------------------------- |
3378| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes.|
3379
3380**Error codes**
3381
3382For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3383
3384| ID| Error Message                                                    |
3385| -------- | ------------------------------------------------------------ |
3386| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3387| 14500101 | Service exception.                                           |
3388
3389**Example**
3390
3391```ts
3392import { sensor } from '@kit.SensorServiceKit';
3393import { BusinessError } from '@kit.BasicServicesKit';
3394
3395try {
3396  // The rotation matrix can be 3*3 or 4*4.
3397  let currentRotationMatrix = [
3398    1, 0, 0,
3399    0, 1, 0,
3400    0, 0, 1
3401  ];
3402  let preRotationMatrix = [
3403    1, 0, 0,
3404    0, 0.87, -0.50,
3405    0, 0.50, 0.87
3406  ];
3407  const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix);
3408  promise.then((data: Array<number>) => {
3409    if (data.length < 3) {
3410      console.error("Failed to get angle variation, length" + data.length);
3411    }
3412    console.info("Z: " + data[0]);
3413    console.info("X: " + data[1]);
3414    console.info("Y  : " + data[2]);
3415  }, (err: BusinessError) => {
3416    console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`);
3417  });
3418} catch (error) {
3419  let e: BusinessError = error as BusinessError;
3420  console.error(`Failed to get angle variation. Code: ${e.code}, message: ${e.message}`);
3421}
3422```
3423
3424## sensor.getRotationMatrix<sup>9+</sup>
3425
3426getRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
3427
3428Obtains the rotation matrix from a rotation vector. This API uses an asynchronous callback to return the result.
3429
3430**System capability**: SystemCapability.Sensors.Sensor
3431
3432**Parameters**
3433
3434| Name        | Type                                    | Mandatory| Description          |
3435| -------------- | ---------------------------------------- | ---- | -------------- |
3436| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector.|
3437| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation matrix.|
3438
3439**Error codes**
3440
3441For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3442
3443| ID| Error Message                                                    |
3444| -------- | ------------------------------------------------------------ |
3445| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3446| 14500101 | Service exception.                                           |
3447
3448**Example**
3449
3450```ts
3451import { sensor } from '@kit.SensorServiceKit';
3452import { BusinessError } from '@kit.BasicServicesKit';
3453
3454try {
3455  let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
3456  sensor.getRotationMatrix(rotationVector, (err: BusinessError, data: Array<number>) => {
3457    if (err) {
3458      console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3459      return;
3460    }
3461    for (let i = 0; i < data.length; i++) {
3462      console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3463    }
3464  })
3465} catch (error) {
3466  let e: BusinessError = error as BusinessError;
3467  console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3468}
3469```
3470
3471## sensor.getRotationMatrix<sup>9+</sup>
3472
3473getRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
3474
3475Obtains the rotation matrix from a rotation vector. This API uses a promise to return the result.
3476
3477**System capability**: SystemCapability.Sensors.Sensor
3478
3479**Parameters**
3480
3481| Name        | Type               | Mandatory| Description          |
3482| -------------- | ------------------- | ---- | -------------- |
3483| rotationVector | Array&lt;number&gt; | Yes  | Rotation vector.|
3484
3485**Return value**
3486
3487| Type                              | Description          |
3488| ---------------------------------- | -------------- |
3489| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|
3490
3491**Error codes**
3492
3493For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3494
3495| ID| Error Message                                                    |
3496| -------- | ------------------------------------------------------------ |
3497| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3498| 14500101 | Service exception.                                           |
3499
3500**Example**
3501
3502```ts
3503import { sensor } from '@kit.SensorServiceKit';
3504import { BusinessError } from '@kit.BasicServicesKit';
3505
3506try {
3507  let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
3508  const promise = sensor.getRotationMatrix(rotationVector);
3509  promise.then((data: Array<number>) => {
3510    for (let i = 0; i < data.length; i++) {
3511      console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3512    }
3513  }, (err: BusinessError) => {
3514    console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3515  });
3516} catch (error) {
3517  let e: BusinessError = error as BusinessError;
3518  console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3519}
3520```
3521
3522## sensor.transformRotationMatrix<sup>9+</sup>
3523
3524transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions,
3525        callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
3526
3527Transforms a rotation vector based on the coordinate system. This API uses an asynchronous callback to return the result.
3528
3529**System capability**: SystemCapability.Sensors.Sensor
3530
3531**Parameters**
3532
3533| Name          | Type                                     | Mandatory| Description                  |
3534| ---------------- | ----------------------------------------- | ---- | ---------------------- |
3535| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector.        |
3536| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Rotation vector to transform.      |
3537| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes  | Callback used to return the rotation vector after being transformed.|
3538
3539**Error codes**
3540
3541For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3542
3543| ID| Error Message                                                    |
3544| -------- | ------------------------------------------------------------ |
3545| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3546| 14500101 | Service exception.                                           |
3547
3548**Example**
3549
3550```ts
3551import { sensor } from '@kit.SensorServiceKit';
3552import { BusinessError } from '@kit.BasicServicesKit';
3553
3554try {
3555  let rotationMatrix = [
3556    1, 0, 0,
3557    0, 0.87, -0.50,
3558    0, 0.50, 0.87
3559  ];
3560  sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, (err: BusinessError, data: Array<number>) => {
3561    if (err) {
3562      console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3563      return;
3564    }
3565    for (let i = 0; i < data.length; i++) {
3566      console.info('Succeeded in getting data[' + i + '] = ' + data[i]);
3567    }
3568  })
3569} catch (error) {
3570  let e: BusinessError = error as BusinessError;
3571  console.error(`Failed to transform rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3572}
3573```
3574
3575## sensor.transformRotationMatrix<sup>9+</sup>
3576
3577transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
3578
3579Transforms a rotation vector based on the coordinate system. This API uses a promise to return the result.
3580
3581**System capability**: SystemCapability.Sensors.Sensor
3582
3583**Parameters**
3584
3585| Name          | Type                                     | Mandatory| Description            |
3586| ---------------- | ----------------------------------------- | ---- | ---------------- |
3587| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector.  |
3588| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Rotation vector to transform.|
3589
3590**Return value**
3591
3592| Type                              | Description                  |
3593| ---------------------------------- | ---------------------- |
3594| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being transformed.|
3595
3596**Error codes**
3597
3598For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3599
3600| ID| Error Message                                                    |
3601| -------- | ------------------------------------------------------------ |
3602| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3603| 14500101 | Service exception.                                           |
3604
3605**Example**
3606
3607```ts
3608import { sensor } from '@kit.SensorServiceKit';
3609import { BusinessError } from '@kit.BasicServicesKit';
3610
3611try {
3612  let rotationMatrix = [
3613    1, 0, 0,
3614    0, 0.87, -0.50,
3615    0, 0.50, 0.87
3616  ];
3617  const promise = sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 });
3618  promise.then((data: Array<number>) => {
3619    for (let i = 0; i < data.length; i++) {
3620      console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3621    }
3622  }, (err: BusinessError) => {
3623    console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3624  });
3625} catch (error) {
3626  let e: BusinessError = error as BusinessError;
3627  console.error(`Failed to transform rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3628}
3629```
3630
3631## sensor.getQuaternion<sup>9+</sup>
3632
3633getQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
3634
3635Obtains the quaternion from a rotation vector. This API uses an asynchronous callback to return the result.
3636
3637**System capability**: SystemCapability.Sensors.Sensor
3638
3639**Parameters**
3640
3641| Name        | Type                                    | Mandatory| Description          |
3642| -------------- | ---------------------------------------- | ---- | -------------- |
3643| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector.|
3644| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the quaternion.|
3645
3646**Error codes**
3647
3648For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3649
3650| ID| Error Message                                                    |
3651| -------- | ------------------------------------------------------------ |
3652| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3653| 14500101 | Service exception.                                           |
3654
3655**Example**
3656
3657```ts
3658import { sensor } from '@kit.SensorServiceKit';
3659import { BusinessError } from '@kit.BasicServicesKit';
3660
3661try {
3662  let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
3663  sensor.getQuaternion(rotationVector, (err: BusinessError, data: Array<number>) => {
3664    if (err) {
3665      console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`);
3666      return;
3667    }
3668    for (let i = 0; i < data.length; i++) {
3669      console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3670    }
3671  })
3672} catch (error) {
3673  let e: BusinessError = error as BusinessError;
3674  console.error(`Failed to get quaternion. Code: ${e.code}, message: ${e.message}`);
3675}
3676```
3677
3678## sensor.getQuaternion<sup>9+</sup>
3679
3680getQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
3681
3682Obtains the quaternion from a rotation vector. This API uses a promise to return the result.
3683
3684**System capability**: SystemCapability.Sensors.Sensor
3685
3686**Parameters**
3687
3688| Name        | Type               | Mandatory| Description          |
3689| -------------- | ------------------- | ---- | -------------- |
3690| rotationVector | Array&lt;number&gt; | Yes  | Rotation vector.|
3691
3692**Return value**
3693
3694| Type                              | Description        |
3695| ---------------------------------- | ------------ |
3696| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
3697
3698**Error codes**
3699
3700For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3701
3702| ID| Error Message                                                    |
3703| -------- | ------------------------------------------------------------ |
3704| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3705| 14500101 | Service exception.                                           |
3706
3707**Example**
3708
3709```ts
3710import { sensor } from '@kit.SensorServiceKit';
3711import { BusinessError } from '@kit.BasicServicesKit';
3712
3713try {
3714    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
3715    const promise = sensor.getQuaternion(rotationVector);
3716    promise.then((data: Array<number>) => {
3717        for (let i = 0; i < data.length; i++) {
3718            console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3719        }
3720    }, (err: BusinessError) => {
3721        console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`);
3722    });
3723} catch (error) {
3724    let e: BusinessError = error as BusinessError;
3725    console.error(`Failed to get quaternion. Code: ${e.code}, message: ${e.message}`);
3726}
3727```
3728
3729## sensor.getOrientation<sup>9+</sup>
3730
3731getOrientation(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
3732
3733Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result.
3734
3735**System capability**: SystemCapability.Sensors.Sensor
3736
3737**Parameters**
3738
3739| Name        | Type                                    | Mandatory| Description                             |
3740| -------------- | ---------------------------------------- | ---- | --------------------------------- |
3741| rotationMatrix | Array&lt;number&gt;                      | Yes  | Rotation matrix.                   |
3742| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation angle around the z, x, and y axes.|
3743
3744**Error codes**
3745
3746For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3747
3748| ID| Error Message                                                    |
3749| -------- | ------------------------------------------------------------ |
3750| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3751| 14500101 | Service exception.                                           |
3752
3753**Example**
3754
3755```ts
3756import { sensor } from '@kit.SensorServiceKit';
3757import { BusinessError } from '@kit.BasicServicesKit';
3758
3759try {
3760  let preRotationMatrix = [
3761    1, 0, 0,
3762    0, 0.87, -0.50,
3763    0, 0.50, 0.87
3764  ];
3765  sensor.getOrientation(preRotationMatrix, (err: BusinessError, data: Array<number>) => {
3766    if (err) {
3767      console.error(`Failed to get orientation. Code: ${err.code}, message: ${err.message}`);
3768      return;
3769    }
3770    if (data.length < 3) {
3771      console.error("Failed to get orientation, length" + data.length);
3772    }
3773    console.info("Succeeded in getting data. Z: " + data[0]);
3774    console.info("Succeeded in getting data. X: " + data[1]);
3775    console.info("Succeeded in getting data. Y: " + data[2]);
3776  })
3777} catch (error) {
3778  let e: BusinessError = error as BusinessError;
3779  console.error(`Failed to get orientation. Code: ${e.code}, message: ${e.message}`);
3780}
3781```
3782
3783## sensor.getOrientation<sup>9+</sup>
3784
3785getOrientation(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
3786
3787Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.
3788
3789**System capability**: SystemCapability.Sensors.Sensor
3790
3791**Parameters**
3792
3793| Name        | Type               | Mandatory| Description          |
3794| -------------- | ------------------- | ---- | -------------- |
3795| rotationMatrix | Array&lt;number&gt; | Yes  | Rotation vector.|
3796
3797**Return value**
3798
3799| Type                              | Description                             |
3800| ---------------------------------- | --------------------------------- |
3801| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes.|
3802
3803**Error codes**
3804
3805For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3806
3807| ID| Error Message                                                    |
3808| -------- | ------------------------------------------------------------ |
3809| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3810| 14500101 | Service exception.                                           |
3811
3812**Example**
3813
3814```ts
3815import { sensor } from '@kit.SensorServiceKit';
3816import { BusinessError } from '@kit.BasicServicesKit';
3817
3818try {
3819  let preRotationMatrix = [
3820    1, 0, 0,
3821    0, 0.87, -0.50,
3822    0, 0.50, 0.87
3823  ];
3824  const promise = sensor.getOrientation(preRotationMatrix);
3825  promise.then((data: Array<number>) => {
3826    for (let i = 0; i < data.length; i++) {
3827      console.info('Succeeded in getting data[' + i + ']: ' + data[i]);
3828    }
3829  }, (err: BusinessError) => {
3830    console.error(`Failed to getOrientatin. Code: ${err.code}, message: ${err.message}`);
3831  });
3832} catch (error) {
3833  let e: BusinessError = error as BusinessError;
3834  console.error(`Failed to getOrientatin Code: ${e.code}, message: ${e.message}`);
3835}
3836```
3837
3838## sensor.getRotationMatrix<sup>9+</sup>
3839
3840getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
3841
3842Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result.
3843
3844**System capability**: SystemCapability.Sensors.Sensor
3845
3846**Parameters**
3847
3848| Name     | Type                                                        | Mandatory| Description          |
3849| ----------- | ------------------------------------------------------------ | ---- | -------------- |
3850| gravity     | Array&lt;number&gt;                                          | Yes  | Gravity vector.|
3851| geomagnetic | Array&lt;number&gt;                                          | Yes  | Geomagnetic vector.|
3852| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes  | Callback used to return the rotation matrix.|
3853
3854**Error codes**
3855
3856For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3857
3858| ID| Error Message                                                    |
3859| -------- | ------------------------------------------------------------ |
3860| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3861| 14500101 | Service exception.                                           |
3862
3863**Example**
3864
3865```ts
3866import { sensor } from '@kit.SensorServiceKit';
3867import { BusinessError } from '@kit.BasicServicesKit';
3868
3869try {
3870  let gravity = [-0.27775216, 0.5351276, 9.788099];
3871  let geomagnetic = [210.87253, -78.6096, -111.44444];
3872  sensor.getRotationMatrix(gravity, geomagnetic, (err: BusinessError, data: sensor.RotationMatrixResponse) => {
3873    if (err) {
3874      console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3875      return;
3876    }
3877    console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data));
3878  })
3879} catch (error) {
3880  let e: BusinessError = error as BusinessError;
3881  console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3882}
3883```
3884
3885## sensor.getRotationMatrix<sup>9+</sup>
3886
3887getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;): Promise&lt;RotationMatrixResponse&gt;
3888
3889Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses a promise to return the result.
3890
3891**System capability**: SystemCapability.Sensors.Sensor
3892
3893**Parameters**
3894
3895| Name     | Type               | Mandatory| Description          |
3896| ----------- | ------------------- | ---- | -------------- |
3897| gravity     | Array&lt;number&gt; | Yes  | Gravity vector.|
3898| geomagnetic | Array&lt;number&gt; | Yes  | Geomagnetic vector.|
3899
3900**Return value**
3901
3902| Type                                                        | Description          |
3903| ------------------------------------------------------------ | -------------- |
3904| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
3905
3906**Error codes**
3907
3908For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3909
3910| ID| Error Message                                                    |
3911| -------- | ------------------------------------------------------------ |
3912| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3913| 14500101 | Service exception.                                           |
3914
3915**Example**
3916
3917```ts
3918import { sensor } from '@kit.SensorServiceKit';
3919import { BusinessError } from '@kit.BasicServicesKit';
3920
3921try {
3922  let gravity = [-0.27775216, 0.5351276, 9.788099];
3923  let geomagnetic = [210.87253, -78.6096, -111.44444];
3924  const promise = sensor.getRotationMatrix(gravity, geomagnetic);
3925  promise.then((data: sensor.RotationMatrixResponse) => {
3926    console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data));
3927  }, (err: BusinessError) => {
3928    console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`);
3929  });
3930} catch (error) {
3931  let e: BusinessError = error as BusinessError;
3932  console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`);
3933}
3934```
3935
3936## sensor.getSensorList<sup>9+</sup>
3937
3938getSensorList(callback: AsyncCallback&lt;Array&lt;Sensor&gt;&gt;): void
3939
3940Obtains information about all sensors on the device. This API uses an asynchronous callback to return the result.
3941
3942**System capability**: SystemCapability.Sensors.Sensor
3943
3944**Parameters**
3945
3946| Name  | Type                                          | Mandatory| Description            |
3947| -------- | ---------------------------------------------- | ---- | ---------------- |
3948| callback | AsyncCallback&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | Yes  | Callback used to return the sensor list.|
3949
3950**Error codes**
3951
3952For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3953
3954| ID| Error Message                                                    |
3955| -------- | ------------------------------------------------------------ |
3956| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
3957| 14500101 | Service exception.                                           |
3958
3959**Example**
3960
3961```ts
3962import { sensor } from '@kit.SensorServiceKit';
3963import { BusinessError } from '@kit.BasicServicesKit';
3964
3965try {
3966  sensor.getSensorList((err: BusinessError, data: Array<sensor.Sensor>) => {
3967    if (err) {
3968      console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`);
3969      return;
3970    }
3971    for (let i = 0; i < data.length; i++) {
3972      console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i]));
3973    }
3974  });
3975} catch (error) {
3976  let e: BusinessError = error as BusinessError;
3977  console.error(`Failed to get sensorList. Code: ${e.code}, message: ${e.message}`);
3978}
3979```
3980
3981## sensor.getSensorList<sup>9+</sup>
3982
3983 getSensorList(): Promise&lt;Array&lt;Sensor&gt;&gt;
3984
3985Obtains information about all sensors on the device. This API uses a promise to return the result.
3986
3987**System capability**: SystemCapability.Sensors.Sensor
3988
3989**Return value**
3990
3991| Name | Type                                    | Mandatory| Description            |
3992| ------- | ---------------------------------------- | ---- | ---------------- |
3993| promise | Promise&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | Yes  | Promise used to return the sensor list.|
3994
3995**Error codes**
3996
3997For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
3998
3999| ID| Error Message                                                    |
4000| -------- | ------------------------------------------------------------ |
4001| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
4002| 14500101 | Service exception.                                           |
4003
4004**Example**
4005
4006```ts
4007import { sensor } from '@kit.SensorServiceKit';
4008import { BusinessError } from '@kit.BasicServicesKit';
4009
4010try {
4011  sensor.getSensorList().then((data: Array<sensor.Sensor>) => {
4012    for (let i = 0; i < data.length; i++) {
4013      console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i]));
4014    }
4015  }, (err: BusinessError) => {
4016    console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`);
4017  });
4018} catch (error) {
4019  let e: BusinessError = error as BusinessError;
4020  console.error(`Failed to get sensorList. Code: ${e.code}, message: ${e.message}`);
4021}
4022```
4023
4024## sensor.getSensorListSync<sup>12+</sup>
4025
4026getSensorListSync(): Array&lt;Sensor&gt;
4027
4028Obtains information about all sensors on the device. This API returns the result synchronously.
4029
4030**System capability**: SystemCapability.Sensors.Sensor
4031
4032**Return value**
4033
4034| Type                                   | Mandatory| Description                            |
4035| --------------------------------------- | ---- | -------------------------------- |
4036| &lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | Yes  | List of sensor attributes.|
4037
4038**Error codes**
4039
4040For details about the following error codes, see [Sensor Error Codes](errorcode-sensor.md).
4041
4042| ID| Error Message          |
4043| -------- | ------------------ |
4044| 14500101 | Service exception. |
4045
4046**Example**
4047
4048```ts
4049import { sensor } from '@kit.SensorServiceKit';
4050import { BusinessError } from '@kit.BasicServicesKit';
4051
4052try {
4053  let ret = sensor.getSensorListSync()
4054  for (let i = 0; i < ret.length; i++) {
4055    console.info('Succeeded in getting sensor: ' + JSON.stringify(ret[i]));
4056  }
4057} catch(error) {
4058    let e: BusinessError = error as BusinessError;
4059    console.error(`Failed to get singleSensor . Code: ${e.code}, message: ${e.message}`);
4060}
4061```
4062
4063##  sensor.getSingleSensor<sup>9+</sup>
4064
4065getSingleSensor(type: SensorId, callback: AsyncCallback&lt;Sensor&gt;): void
4066
4067Obtains information about the sensor of a specific type. This API uses an asynchronous callback to return the result.
4068
4069**System capability**: SystemCapability.Sensors.Sensor
4070
4071**Parameters**
4072
4073| Name  | Type                                   | Mandatory| Description            |
4074| -------- | --------------------------------------- | ---- | ---------------- |
4075| type     | [SensorId](#sensorid9)                  | Yes  | Sensor type.    |
4076| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | Yes  | Callback used to return the sensor information.|
4077
4078**Error codes**
4079
4080For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
4081
4082| ID| Error Message                                                    |
4083| -------- | ------------------------------------------------------------ |
4084| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
4085| 14500101 | Service exception.                                           |
4086| 14500102 | The sensor is not supported by the device.                   |
4087
4088**Example**
4089
4090```ts
4091import { sensor } from '@kit.SensorServiceKit';
4092import { BusinessError } from '@kit.BasicServicesKit';
4093
4094try {
4095  sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err: BusinessError, data: sensor.Sensor) => {
4096    if (err) {
4097      console.error(`Failed to get singleSensor. Code: ${err.code}, message: ${err.message}`);
4098      return;
4099    }
4100    console.info('Succeeded in getting sensor: ' + JSON.stringify(data));
4101  });
4102} catch (error) {
4103  let e: BusinessError = error as BusinessError;
4104  console.error(`Failed to get singleSensor. Code: ${e.code}, message: ${e.message}`);
4105}
4106```
4107
4108##  sensor.getSingleSensor<sup>9+</sup>
4109
4110 getSingleSensor(type: SensorId): Promise&lt;Sensor&gt;
4111
4112Obtains information about the sensor of a specific type. This API uses a promise to return the result.
4113
4114**System capability**: SystemCapability.Sensors.Sensor
4115
4116**Parameters**
4117
4118| Name| Type                  | Mandatory| Description        |
4119| ------ | ---------------------- | ---- | ------------ |
4120| type   | [SensorId](#sensorid9) | Yes  | Sensor type.|
4121
4122**Return value**
4123
4124| Name | Type                             | Mandatory| Description                        |
4125| ------- | --------------------------------- | ---- | ---------------------------- |
4126| promise | Promise&lt;[Sensor](#sensor9)&gt; | Yes  | Promise used to return the sensor information.|
4127
4128**Error codes**
4129
4130For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
4131
4132| ID| Error Message                                                    |
4133| -------- | ------------------------------------------------------------ |
4134| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
4135| 14500101 | Service exception.                                           |
4136| 14500102 | The sensor is not supported by the device.                   |
4137
4138**Example**
4139
4140```ts
4141import { sensor } from '@kit.SensorServiceKit';
4142import { BusinessError } from '@kit.BasicServicesKit';
4143
4144try {
4145  sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data: sensor.Sensor) => {
4146    console.info('Succeeded in getting sensor: ' + JSON.stringify(data));
4147  }, (err: BusinessError) => {
4148    console.error(`Failed to get singleSensor . Code: ${err.code}, message: ${err.message}`);
4149  });
4150} catch (error) {
4151  let e: BusinessError = error as BusinessError;
4152  console.error(`Failed to get singleSensor . Code: ${e.code}, message: ${e.message}`);
4153}
4154```
4155
4156## sensor.getSingleSensorSync<sup>12+</sup>
4157
4158getSingleSensorSync(type: SensorId): Sensor
4159
4160Obtains information about the sensor of a specific type. This API returns the result synchronously.
4161
4162**System capability**: SystemCapability.Sensors.Sensor
4163
4164**Parameters**
4165
4166| Name| Type                  | Mandatory| Description        |
4167| ------ | ---------------------- | ---- | ------------ |
4168| type   | [SensorId](#sensorid9) | Yes  | Sensor type.|
4169
4170**Return value**
4171
4172| Type  | Mandatory| Description                        |
4173| ------ | ---- | ---------------------------- |
4174| Sensor | Yes  | Sensor information.|
4175
4176**Error codes**
4177
4178For details about the error codes, see [Sensor Error Codes](errorcode-sensor.md) and [Universal Error Codes](../errorcode-universal.md).
4179
4180| ID| Error Message                                                    |
4181| -------- | ------------------------------------------------------------ |
4182| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
4183| 14500101 | Service exception.                                           |
4184| 14500102 | The sensor is not supported by the device.                   |
4185
4186**Example**
4187
4188```ts
4189import { sensor } from '@kit.SensorServiceKit';
4190import { BusinessError } from '@kit.BasicServicesKit';
4191
4192try {
4193  let ret = sensor.getSingleSensorSync(sensor.SensorId.ACCELEROMETER);
4194  console.info('Succeeded in getting sensor: ' + JSON.stringify(ret));
4195} catch (error) {
4196  let e: BusinessError = error as BusinessError;
4197  console.error(`Failed to get singleSensor . Code: ${e.code}, message: ${e.message}`);
4198}
4199```
4200
4201## SensorId<sup>9+</sup>
4202
4203Enumerates the sensor types.
4204
4205**System capability**: SystemCapability.Sensors.Sensor
4206
4207| Name                       | Value  | Description                                                        |
4208| --------------------------- | ---- | ------------------------------------------------------------ |
4209| ACCELEROMETER               | 1    | Acceleration sensor.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
4210| GYROSCOPE                   | 2    | Gyroscope sensor.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
4211| AMBIENT_LIGHT               | 5    | Ambient light sensor.                                              |
4212| MAGNETIC_FIELD              | 6    | Magnetic field sensor.                                                |
4213| BAROMETER                   | 8    | Barometer sensor.                                              |
4214| HALL                        | 10   | Hall effect sensor.                                                |
4215| PROXIMITY                   | 12   | Proximity sensor.                                              |
4216| HUMIDITY                    | 13   | Humidity sensor.                                                |
4217| ORIENTATION                 | 256  | Orientation sensor.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
4218| GRAVITY                     | 257  | Gravity sensor.                                                |
4219| LINEAR_ACCELEROMETER        | 258  | Linear acceleration sensor.                                          |
4220| ROTATION_VECTOR             | 259  | Rotation vector sensor.                                            |
4221| AMBIENT_TEMPERATURE         | 260  | Ambient temperature sensor.                                            |
4222| MAGNETIC_FIELD_UNCALIBRATED | 261  | Uncalibrated magnetic field sensor.                                          |
4223| GYROSCOPE_UNCALIBRATED      | 263  | Uncalibrated gyroscope sensor.                                        |
4224| SIGNIFICANT_MOTION          | 264  | Significant motion sensor.                                            |
4225| PEDOMETER_DETECTION         | 265  | Pedometer detection sensor.                                            |
4226| PEDOMETER                   | 266  | Pedometer sensor.                                                |
4227| HEART_RATE                  | 278  | Heart rate sensor.                                                |
4228| WEAR_DETECTION              | 280  | Wear detection sensor.                                            |
4229| ACCELEROMETER_UNCALIBRATED  | 281  | Uncalibrated acceleration sensor.                                      |
4230
4231## SensorType<sup>(deprecated)</sup>
4232
4233Enumerates the sensor types.
4234
4235**System capability**: SystemCapability.Sensors.Sensor
4236
4237
4238| Name                                      | Value  | Description                  |
4239| ------------------------------------------ | ---- | ---------------------- |
4240| SENSOR_TYPE_ID_ACCELEROMETER               | 1    | Acceleration sensor.        |
4241| SENSOR_TYPE_ID_GYROSCOPE                   | 2    | Gyroscope sensor.        |
4242| SENSOR_TYPE_ID_AMBIENT_LIGHT               | 5    | Ambient light sensor.        |
4243| SENSOR_TYPE_ID_MAGNETIC_FIELD              | 6    | Magnetic field sensor.          |
4244| SENSOR_TYPE_ID_BAROMETER                   | 8    | Barometer sensor.        |
4245| SENSOR_TYPE_ID_HALL                        | 10   | Hall effect sensor.          |
4246| SENSOR_TYPE_ID_PROXIMITY                   | 12   | Proximity sensor.        |
4247| SENSOR_TYPE_ID_HUMIDITY                    | 13   | Humidity sensor.          |
4248| SENSOR_TYPE_ID_ORIENTATION                 | 256  | Orientation sensor.          |
4249| SENSOR_TYPE_ID_GRAVITY                     | 257  | Gravity sensor.          |
4250| SENSOR_TYPE_ID_LINEAR_ACCELERATION         | 258  | Linear acceleration sensor.    |
4251| SENSOR_TYPE_ID_ROTATION_VECTOR             | 259  | Rotation vector sensor.      |
4252| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE         | 260  | Ambient temperature sensor.      |
4253| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | Uncalibrated magnetic field sensor.    |
4254| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED      | 263  | Uncalibrated gyroscope sensor.  |
4255| SENSOR_TYPE_ID_SIGNIFICANT_MOTION          | 264  | Significant motion sensor.      |
4256| SENSOR_TYPE_ID_PEDOMETER_DETECTION         | 265  | Pedometer detection sensor.      |
4257| SENSOR_TYPE_ID_PEDOMETER                   | 266  | Pedometer sensor.          |
4258| SENSOR_TYPE_ID_HEART_RATE                  | 278  | Heart rate sensor.          |
4259| SENSOR_TYPE_ID_WEAR_DETECTION              | 280  | Wear detection sensor.      |
4260| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED  | 281  | Uncalibrated acceleration sensor.|
4261
4262## SensorAccuracy<sup>11+</sup>
4263
4264Enumerates the accuracy levels of sensor data.
4265
4266**Atomic service API**: This API can be used in atomic services since API version 11.
4267
4268**System capability**: SystemCapability.Sensors.Sensor
4269
4270| Name   | Value| Description                    |
4271| --------- | ---- | ------------------------ |
4272| ACCURACY_UNRELIABLE | 0   | The sensor data is unreliable.|
4273| ACCURACY_LOW | 1   | The sensor data is at a low accuracy level.|
4274| ACCURACY_MEDIUM | 2   | The sensor data is at a medium accuracy level.|
4275| ACCURACY_HIGH | 3   | The sensor data is at a high accuracy level.|
4276
4277## Response
4278
4279Describes the timestamp of the sensor data.
4280
4281**Atomic service API**: This API can be used in atomic services since API version 11.
4282
4283**System capability**: SystemCapability.Sensors.Sensor
4284
4285| Name     | Type  | Readable| Writable| Description                    |
4286| --------- | ------ | ---- | ---- | ------------------------ |
4287| timestamp | number | Yes  | Yes  | Timestamp when the sensor reports data.|
4288| accuracy<sup>11+</sup> | [SensorAccuracy](#sensoraccuracy11)<sup>11+</sup> | Yes  | No  | Accuracy of the sensor data.|
4289
4290## Sensor<sup>9+</sup>
4291
4292Describes the sensor information.
4293
4294**System capability**: SystemCapability.Sensors.Sensor
4295
4296| Name           | Type| Readable| Writable| Description                  |
4297| --------------- | -------- | ---------------------- | ---------------------- | ---------------------- |
4298| sensorName      | string   | Yes | No | Sensor name.           |
4299| vendorName      | string   | Yes | No | Vendor of the sensor.        |
4300| firmwareVersion | string   | Yes | No | Firmware version of the sensor.      |
4301| hardwareVersion | string   | Yes | No | Hardware version of the sensor.      |
4302| sensorId        | number   | Yes | No | Sensor type ID.        |
4303| maxRange        | number   | Yes | No | Maximum measurement range of the sensor.|
4304| minSamplePeriod | number   | Yes | No | Minimum sampling period.  |
4305| maxSamplePeriod | number   | Yes | No | Maximum sampling period.  |
4306| precision       | number   | Yes | No | Precision of the sensor.          |
4307| power           | number   | Yes | No | Estimated sensor power, in mA. |
4308
4309## AccelerometerResponse
4310
4311Describes the acceleration sensor data. It extends from [Response](#response).
4312
4313**Atomic service API**: This API can be used in atomic services since API version 11.
4314
4315**System capability**: SystemCapability.Sensors.Sensor
4316
4317
4318| Name| Type  | Readable| Writable| Description                                                      |
4319| ---- | ------ | ---- | ---- | ---------------------------------------------------------- |
4320| x    | number | Yes  | Yes  | Acceleration along the x-axis of the device, in m/s². The value is equal to the reported physical quantity.|
4321| y    | number | Yes  | Yes  | Acceleration along the y-axis of the device, in m/s². The value is equal to the reported physical quantity.|
4322| z    | number | Yes  | Yes  | Acceleration along the z-axis of the device, in m/s². The value is equal to the reported physical quantity.|
4323
4324
4325## LinearAccelerometerResponse
4326
4327Describes the linear acceleration sensor data. It extends from [Response](#response).
4328
4329**System capability**: SystemCapability.Sensors.Sensor
4330
4331
4332| Name| Type  | Readable| Writable| Description                                    |
4333| ---- | ------ | ---- | ---- | ---------------------------------------- |
4334| x    | number | Yes  | Yes  | Linear acceleration along the x-axis of the device, in m/s².|
4335| y    | number | Yes  | Yes  | Linear acceleration along the y-axis of the device, in m/s².|
4336| z    | number | Yes  | Yes  | Linear acceleration along the z-axis of the device, in m/s².|
4337
4338
4339## AccelerometerUncalibratedResponse
4340
4341Describes the uncalibrated acceleration sensor data. It extends from [Response](#response).
4342
4343**System capability**: SystemCapability.Sensors.Sensor
4344
4345
4346| Name | Type  | Readable| Writable| Description                                          |
4347| ----- | ------ | ---- | ---- | ---------------------------------------------- |
4348| x     | number | Yes  | Yes  | Uncalibrated acceleration along the x-axis of the device, in m/s².    |
4349| y     | number | Yes  | Yes  | Uncalibrated acceleration along the y-axis of the device, in m/s².    |
4350| z     | number | Yes  | Yes  | Uncalibrated acceleration along the z-axis of the device, in m/s².    |
4351| biasX | number | Yes  | Yes  | Uncalibrated acceleration bias along the x-axis of the device, in m/s².|
4352| biasY | number | Yes  | Yes  | Uncalibrated acceleration bias along the y-axis of the device, in m/s².|
4353| biasZ | number | Yes  | Yes  | Uncalibrated acceleration bias along the z-axis of the device, in m/s².|
4354
4355
4356## GravityResponse
4357
4358Describes the gravity sensor data. It extends from [Response](#response).
4359
4360**System capability**: SystemCapability.Sensors.Sensor
4361
4362
4363| Name| Type  | Readable| Writable| Description                                    |
4364| ---- | ------ | ---- | ---- | ---------------------------------------- |
4365| x    | number | Yes  | Yes  | Gravitational acceleration along the x-axis of the device, in m/s².|
4366| y    | number | Yes  | Yes  | Gravitational acceleration along the y-axis of the device, in m/s².|
4367| z    | number | Yes  | Yes  | Gravitational acceleration along the z-axis of the device, in m/s².|
4368
4369
4370## OrientationResponse
4371
4372Describes the orientation sensor data. It extends from [Response](#response).
4373
4374**Atomic service API**: This API can be used in atomic services since API version 11.
4375
4376**System capability**: SystemCapability.Sensors.Sensor
4377
4378
4379| Name | Type  | Readable| Writable| Description                                                 |
4380| ----- | ------ | ---- | ---- | ----------------------------------------------------- |
4381| alpha | number | Yes  | Yes  | Rotation angle of the device around the z-axis, in degrees. The value ranges from 0 to 360. |
4382| beta  | number | Yes  | Yes  | Rotation angle of the device around the x-axis, in degrees. The value ranges from 0 to ±180.|
4383| gamma | number | Yes  | Yes  | Rotation angle of the device around the y-axis, in degrees. The value ranges from 0 to ±90. |
4384
4385
4386## RotationVectorResponse
4387
4388Describes the rotation vector sensor data. It extends from [Response](#response).
4389
4390**System capability**: SystemCapability.Sensors.Sensor
4391
4392
4393| Name| Type  | Readable| Writable| Description             |
4394| ---- | ------ | ---- | ---- | ----------------- |
4395| x    | number | Yes  | Yes  | X-component of the rotation vector.|
4396| y    | number | Yes  | Yes  | Y-component of the rotation vector.|
4397| z    | number | Yes  | Yes  | Z-component of the rotation vector.|
4398| w    | number | Yes  | Yes  | Scalar.           |
4399
4400
4401## GyroscopeResponse
4402
4403Describes the gyroscope sensor data. It extends from [Response](#response).
4404
4405**Atomic service API**: This API can be used in atomic services since API version 11.
4406
4407**System capability**: SystemCapability.Sensors.Sensor
4408
4409
4410| Name| Type  | Readable| Writable| Description                                                  |
4411| ---- | ------ | ---- | ---- | ------------------------------------------------------ |
4412| x    | number | Yes  | Yes  | Angular velocity of rotation around the x-axis of the device, in rad/s. The value is equal to the reported physical quantity.|
4413| y    | number | Yes  | Yes  | Angular velocity of rotation around the y-axis of the device, in rad/s. The value is equal to the reported physical quantity.|
4414| z    | number | Yes  | Yes  | Angular velocity of rotation around the z-axis of the device, in rad/s. The value is equal to the reported physical quantity.|
4415
4416
4417## GyroscopeUncalibratedResponse
4418
4419Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response).
4420
4421**System capability**: SystemCapability.Sensors.Sensor
4422
4423
4424| Name | Type  | Readable| Writable| Description                                      |
4425| ----- | ------ | ---- | ---- | ------------------------------------------ |
4426| x     | number | Yes  | Yes  | Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.    |
4427| y     | number | Yes  | Yes  | Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.    |
4428| z     | number | Yes  | Yes  | Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.    |
4429| biasX | number | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.|
4430| biasY | number | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.|
4431| biasZ | number | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.|
4432
4433
4434## SignificantMotionResponse
4435
4436Describes the significant motion sensor data. It extends from [Response](#response).
4437
4438**System capability**: SystemCapability.Sensors.Sensor
4439
4440
4441| Name  | Type  | Readable| Writable| Description                                                        |
4442| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4443| 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 **1** is reported when the device has a significant motion.|
4444
4445
4446## ProximityResponse
4447
4448Describes the proximity sensor data. It extends from [Response](#response).
4449
4450**System capability**: SystemCapability.Sensors.Sensor
4451
4452
4453| Name    | Type  | Readable| Writable| Description                                                      |
4454| -------- | ------ | ---- | ---- | ---------------------------------------------------------- |
4455| 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 a value greater than 0 means that they are far away from each other.|
4456
4457
4458## LightResponse
4459
4460Describes the ambient light sensor data. It extends from [Response](#response).
4461
4462**System capability**: SystemCapability.Sensors.Sensor
4463
4464
4465| Name                           | Type  | Readable| Writable| Description                                                        |
4466| ------------------------------- | ------ | ---- | ---- | ------------------------------------------------------------ |
4467| intensity                       | number | Yes  | Yes  | Illumination, in lux.                                      |
4468| colorTemperature<sup>12+</sup>  | number | Yes  | Yes  | Color temperature, in Kelvin. This parameter is optional. If this parameter is not supported, **undefined** is returned. If this parameter is supported, a normal value is returned.|
4469| infraredLuminance<sup>12+</sup> | number | Yes  | Yes  | IR luminance, in cd/m2. This parameter is optional. If this parameter is not supported, **undefined** is returned. If this parameter is supported, a normal value is returned.|
4470
4471
4472## HallResponse
4473
4474Describes the Hall effect sensor data. It extends from [Response](#response).
4475
4476**System capability**: SystemCapability.Sensors.Sensor
4477
4478
4479| Name  | Type  | Readable| Writable| Description                                                        |
4480| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4481| 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.|
4482
4483
4484## MagneticFieldResponse
4485
4486Describes the magnetic field sensor data. It extends from [Response](#response).
4487
4488**System capability**: SystemCapability.Sensors.Sensor
4489
4490
4491| Name| Type  | Readable| Writable| Description                        |
4492| ---- | ------ | ---- | ---- | ---------------------------- |
4493| x    | number | Yes  | Yes  | Magnetic field strength on the x-axis, in μT.|
4494| y    | number | Yes  | Yes  | Magnetic field strength on the y-axis, in μT.|
4495| z    | number | Yes  | Yes  | Magnetic field strength on the z-axis, in μT.|
4496
4497
4498## MagneticFieldUncalibratedResponse
4499
4500Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response).
4501
4502**System capability**: SystemCapability.Sensors.Sensor
4503
4504
4505| Name | Type  | Readable| Writable| Description                                  |
4506| ----- | ------ | ---- | ---- | -------------------------------------- |
4507| x     | number | Yes  | Yes  | Uncalibrated magnetic field strength on the x-axis, in μT.    |
4508| y     | number | Yes  | Yes  | Uncalibrated magnetic field strength on the y-axis, in μT.    |
4509| z     | number | Yes  | Yes  | Uncalibrated magnetic field strength on the z-axis, in μT.    |
4510| biasX | number | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the x-axis, in μT.|
4511| biasY | number | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the y-axis, in μT.|
4512| biasZ | number | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the z-axis, in μT.|
4513
4514
4515## PedometerResponse
4516
4517Describes the pedometer sensor data. It extends from [Response](#response).
4518
4519**System capability**: SystemCapability.Sensors.Sensor
4520
4521
4522| Name | Type  | Readable| Writable| Description            |
4523| ----- | ------ | ---- | ---- | ---------------- |
4524| steps | number | Yes  | Yes  | Number of steps a user has walked.|
4525
4526
4527## HumidityResponse
4528
4529Describes the humidity sensor data. It extends from [Response](#response).
4530
4531**System capability**: SystemCapability.Sensors.Sensor
4532
4533
4534| Name    | Type  | Readable| Writable| Description                                                     |
4535| -------- | ------ | ---- | ---- | --------------------------------------------------------- |
4536| humidity | number | Yes  | Yes  | Ambient relative humidity, in a percentage (%).|
4537
4538
4539## PedometerDetectionResponse
4540
4541Describes the pedometer detection sensor data. It extends from [Response](#response).
4542
4543**System capability**: SystemCapability.Sensors.Sensor
4544
4545
4546| Name  | Type  | Readable| Writable| Description                                                        |
4547| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4548| 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.|
4549
4550
4551## AmbientTemperatureResponse
4552
4553Describes the ambient temperature sensor data. It extends from [Response](#response).
4554
4555**System capability**: SystemCapability.Sensors.Sensor
4556
4557
4558| Name       | Type  | Readable| Writable| Description                      |
4559| ----------- | ------ | ---- | ---- | -------------------------- |
4560| temperature | number | Yes  | Yes  | Ambient temperature, in degree Celsius.|
4561
4562
4563## BarometerResponse
4564
4565Describes the barometer sensor data. It extends from [Response](#response).
4566
4567**System capability**: SystemCapability.Sensors.Sensor
4568
4569
4570| Name    | Type  | Readable| Writable| Description                  |
4571| -------- | ------ | ---- | ---- | ---------------------- |
4572| pressure | number | Yes  | Yes  | Atmospheric pressure, in units of hPa.|
4573
4574
4575## HeartRateResponse
4576
4577Describes the heart rate sensor data. It extends from [Response](#response).
4578
4579**System capability**: SystemCapability.Sensors.Sensor
4580
4581
4582| Name     | Type  | Readable| Writable| Description                                   |
4583| --------- | ------ | ---- | ---- | --------------------------------------- |
4584| heartRate | number | Yes  | Yes  | Heart rate, in beats per minute (bpm).|
4585
4586
4587## WearDetectionResponse
4588
4589Describes the wear detection sensor data. It extends from [Response](#response).
4590
4591**System capability**: SystemCapability.Sensors.Sensor
4592
4593
4594| Name | Type  | Readable| Writable| Description                                            |
4595| ----- | ------ | ---- | ---- | ------------------------------------------------ |
4596| 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.|
4597
4598
4599## Options
4600
4601Describes the sensor data reporting frequency.
4602
4603**Atomic service API**: This API can be used in atomic services since API version 11.
4604
4605**System capability**: SystemCapability.Sensors.Sensor
4606
4607| Name    | Type                                                       | Readable| Writable| Description                                                        |
4608| -------- | ----------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
4609| interval | number\|[SensorFrequency](#sensorfrequency11)<sup>11+</sup> | Yes  | Yes  | Frequency at which a sensor reports data. The default value is 200,000,000 ns. The maximum and minimum values of this parameter are determined by the reporting frequency supported by the hardware. If the configured frequency is greater than the maximum value, the maximum value is used for data reporting. If the configured frequency is less than the minimum value, the minimum value is used for data reporting.|
4610
4611## SensorFrequency<sup>11+</sup>
4612
4613type SensorFrequency = 'game' | 'ui' | 'normal'
4614
4615Defines the reporting frequency mode of the sensor.
4616
4617**Atomic service API**: This API can be used in atomic services since API version 11.
4618
4619**System capability**: SystemCapability.Sensors.Sensor
4620
4621| Type    | Description                                                        |
4622| -------- | ------------------------------------------------------------ |
4623| 'game'   | Game mode, which specifies a sensor data reporting frequency of 20,000,000 ns. This parameter takes effect only when the frequency is within the frequency range supported by the hardware.|
4624| 'ui'     | UI mode, which specifies a sensor data reporting frequency of 60,000,000 ns. This parameter takes effect only when the frequency is within the frequency range supported by the hardware.|
4625| 'normal' | Normal mode, which specifies a sensor data reporting frequency of 200,000,000 ns. This parameter takes effect only when the frequency is within the frequency range supported by the hardware.|
4626
4627## RotationMatrixResponse
4628
4629Describes the response for setting the rotation matrix.
4630
4631**System capability**: SystemCapability.Sensors.Sensor
4632
4633| Name       | Type               | Readable| Writable| Description      |
4634| ----------- | ------------------- | ---- | ---- | ---------- |
4635| rotation    | Array&lt;number&gt; | Yes  | Yes  | Rotation matrix.|
4636| inclination | Array&lt;number&gt; | Yes  | Yes  | Inclination matrix.|
4637
4638
4639## CoordinatesOptions
4640
4641Describes the coordinate options.
4642
4643**System capability**: SystemCapability.Sensors.Sensor
4644
4645| Name| Type  | Readable| Writable| Description       |
4646| ---- | ------ | ---- | ---- | ----------- |
4647| x    | number | Yes  | Yes  | X coordinate direction.|
4648| y    | number | Yes  | Yes  | Y coordinate direction.|
4649
4650
4651## GeomagneticResponse
4652
4653Describes a geomagnetic response object.
4654
4655**System capability**: SystemCapability.Sensors.Sensor
4656
4657| Name           | Type  | Readable| Writable| Description                                              |
4658| --------------- | ------ | ---- | ---- | -------------------------------------------------- |
4659| x               | number | Yes  | Yes  | North component of the geomagnetic field.                                  |
4660| y               | number | Yes  | Yes  | East component of the geomagnetic field.                                  |
4661| z               | number | Yes  | Yes  | Vertical component of the geomagnetic field.                                |
4662| geomagneticDip  | number | Yes  | Yes  | Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.            |
4663| 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).|
4664| levelIntensity  | number | Yes  | Yes  | Horizontal intensity of the magnetic field vector field.                                |
4665| totalIntensity  | number | Yes  | Yes  | Total intensity of the magnetic field vector.                                  |
4666
4667## LocationOptions
4668
4669Describes the geographical location.
4670
4671**System capability**: SystemCapability.Sensors.Sensor
4672
4673| Name     | Type  | Readable| Writable| Description      |
4674| --------- | ------ | ---- | ---- | ---------- |
4675| latitude  | number | Yes  | Yes  | Latitude.    |
4676| longitude | number | Yes  | Yes  | Longitude.    |
4677| altitude  | number | Yes  | Yes  | Altitude.|
4678
4679## sensor.on<sup>(deprecated)</sup>
4680
4681### ACCELEROMETER<sup>(deprecated)</sup>
4682
4683on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
4684
4685Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4686
4687> **NOTE**
4688>
4689> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER](#accelerometer9)<sup>9+</sup> instead.
4690
4691**Required permissions**: ohos.permission.ACCELEROMETER
4692
4693**System capability**: SystemCapability.Sensors.Sensor
4694
4695**Parameters**
4696
4697| Name  | Type                                                        | Mandatory| Description                                                        |
4698| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4699| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.    |
4700| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
4701| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4702
4703**Example**
4704
4705```ts
4706import { sensor } from '@kit.SensorServiceKit';
4707
4708sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
4709  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4710  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4711  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4712},
4713  { interval: 100000000 }
4714);
4715```
4716
4717### LINEAR_ACCELERATION<sup>(deprecated)</sup>
4718
4719on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void
4720
4721Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4722
4723> **NOTE**
4724>
4725> This API is deprecated since API version 9. You are advised to use [sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)<sup>9+</sup> instead.
4726
4727**Required permissions**: ohos.permission.ACCELEROMETER
4728
4729**System capability**: SystemCapability.Sensors.Sensor
4730
4731**Parameters**
4732
4733| Name  | Type                                                        | Mandatory| Description                                                        |
4734| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4735| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
4736| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
4737| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4738
4739### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
4740
4741on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
4742
4743Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4744
4745> **NOTE**
4746>
4747> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)<sup>9+</sup> instead.
4748
4749**Required permissions**: ohos.permission.ACCELEROMETER
4750
4751**System capability**: SystemCapability.Sensors.Sensor
4752
4753**Parameters**
4754
4755| Name  | Type                                                        | Mandatory| Description                                                        |
4756| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4757| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
4758| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
4759| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4760
4761**Example**
4762
4763```ts
4764import { sensor } from '@kit.SensorServiceKit';
4765
4766sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
4767  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4768  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4769  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4770  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4771  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4772  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4773},
4774  { interval: 100000000 }
4775);
4776
4777```
4778
4779### GRAVITY<sup>(deprecated)</sup>
4780
4781on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void
4782
4783Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect.
4784
4785> **NOTE**
4786>
4787> This API is deprecated since API version 9. You are advised to use [sensor.on.GRAVITY](#gravity9)<sup>9+</sup> instead.
4788
4789**System capability**: SystemCapability.Sensors.Sensor
4790
4791**Parameters**
4792
4793| Name  | Type                                                      | Mandatory| Description                                                       |
4794| -------- | ---------------------------------------------------------- | ---- | ----------------------------------------------------------- |
4795| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.           |
4796| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | Yes  | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
4797| options  | [Options](#options)                                        | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
4798
4799**Example**
4800
4801```ts
4802import { sensor } from '@kit.SensorServiceKit';
4803
4804sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
4805  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4806  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4807  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4808},
4809  { interval: 100000000 }
4810);
4811```
4812
4813### GYROSCOPE<sup>(deprecated)</sup>
4814
4815on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
4816
4817Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
4818
4819> **NOTE**
4820>
4821> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE](#gyroscope9)<sup>9+</sup> instead.
4822
4823**Required permissions**: ohos.permission.GYROSCOPE
4824
4825**System capability**: SystemCapability.Sensors.Sensor
4826
4827**Parameters**
4828
4829| Name  | Type                                                        | Mandatory| Description                                                        |
4830| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4831| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.        |
4832| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | Yes  | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
4833| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4834
4835**Example**
4836
4837```ts
4838import { sensor } from '@kit.SensorServiceKit';
4839
4840sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
4841  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4842  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4843  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4844},
4845  { interval: 100000000 }
4846);
4847```
4848
4849### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
4850
4851on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;, options?: Options): void
4852
4853Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
4854
4855> **NOTE**
4856>
4857> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)<sup>9+</sup> instead.
4858
4859**Required permissions**: ohos.permission.GYROSCOPE
4860
4861**System capability**: SystemCapability.Sensors.Sensor
4862
4863**Parameters**
4864
4865| Name  | Type                                                        | Mandatory| Description                                                        |
4866| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4867| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
4868| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
4869| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4870
4871**Example**
4872
4873```ts
4874import { sensor } from '@kit.SensorServiceKit';
4875
4876sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
4877  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4878  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4879  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4880  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4881  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4882  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4883},
4884  { interval: 100000000 }
4885);
4886```
4887
4888### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
4889
4890on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;, options?: Options): void
4891
4892Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect.
4893
4894> **NOTE**
4895>
4896> This API is deprecated since API version 9. You are advised to use [sensor.on.SIGNIFICANT_MOTION](#significant_motion9)<sup>9+</sup> instead.
4897
4898**System capability**: SystemCapability.Sensors.Sensor
4899
4900**Parameters**
4901
4902| Name  | Type                                                        | Mandatory| Description                                                        |
4903| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4904| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
4905| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
4906| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4907
4908**Example**
4909
4910```ts
4911import { sensor } from '@kit.SensorServiceKit';
4912
4913sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
4914  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4915},
4916  { interval: 100000000 }
4917);
4918```
4919
4920### PEDOMETER_DETECTION<sup>(deprecated)</sup>
4921
4922on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;, options?: Options): void
4923
4924Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect.
4925
4926> **NOTE**
4927>
4928> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)<sup>9+</sup> instead.
4929
4930**Required permissions**: ohos.permission.ACTIVITY_MOTION
4931
4932**System capability**: SystemCapability.Sensors.Sensor
4933
4934**Parameters**
4935
4936| Name  | Type                                                        | Mandatory| Description                                                        |
4937| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4938| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
4939| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
4940| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4941
4942**Example**
4943
4944```ts
4945import { sensor } from '@kit.SensorServiceKit';
4946
4947sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
4948  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4949},
4950  { interval: 100000000 }
4951);
4952```
4953
4954### PEDOMETER<sup>(deprecated)</sup>
4955
4956on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
4957
4958Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect.
4959
4960> **NOTE**
4961>
4962> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER](#pedometer9)<sup>9+</sup> instead.
4963
4964**Required permissions**: ohos.permission.ACTIVITY_MOTION
4965
4966**System capability**: SystemCapability.Sensors.Sensor
4967
4968**Parameters**
4969
4970| Name  | Type                                                        | Mandatory| Description                                                        |
4971| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4972| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.          |
4973| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | Yes  | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
4974| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
4975
4976**Example**
4977
4978```ts
4979import { sensor } from '@kit.SensorServiceKit';
4980
4981sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
4982  console.info('Succeeded in invoking on. Steps: ' + data.steps);
4983},
4984  { interval: 100000000 }
4985);
4986```
4987
4988### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
4989
4990on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;AmbientTemperatureResponse&gt;,  options?: Options): void
4991
4992Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect.
4993
4994> **NOTE**
4995>
4996> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)<sup>9+</sup> instead.
4997
4998**System capability**: SystemCapability.Sensors.Sensor
4999
5000**Parameters**
5001
5002| Name  | Type                                                        | Mandatory| Description                                                        |
5003| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5004| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
5005| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
5006| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5007
5008**Example**
5009
5010```ts
5011import { sensor } from '@kit.SensorServiceKit';
5012
5013sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5014  console.info('Succeeded in invoking on. Temperature: ' + data.temperature);
5015},
5016  { interval: 100000000 }
5017);
5018```
5019
5020### MAGNETIC_FIELD<sup>(deprecated)</sup>
5021
5022on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
5023
5024Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.
5025
5026> **NOTE**
5027>
5028> This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD](#magnetic_field9)<sup>9+</sup> instead.
5029
5030**System capability**: SystemCapability.Sensors.Sensor
5031
5032**Parameters**
5033
5034| Name  | Type                                                        | Mandatory| Description                                                        |
5035| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5036| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.     |
5037| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
5038| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5039
5040**Example**
5041
5042```ts
5043import { sensor } from '@kit.SensorServiceKit';
5044
5045sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5046  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5047  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5048  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5049},
5050  { interval: 100000000 }
5051);
5052```
5053
5054### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5055
5056on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
5057
5058Subscribes 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.
5059
5060> **NOTE**
5061>
5062> This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)<sup>9+</sup> instead.
5063
5064**System capability**: SystemCapability.Sensors.Sensor
5065
5066**Parameters**
5067
5068| Name  | Type                                                        | Mandatory| Description                                                        |
5069| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5070| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
5071| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
5072| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5073
5074**Example**
5075
5076```ts
5077import { sensor } from '@kit.SensorServiceKit';
5078
5079sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5080  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5081  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5082  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5083  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
5084  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
5085  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
5086},
5087  { interval: 100000000 }
5088);
5089```
5090
5091### PROXIMITY<sup>(deprecated)</sup>
5092
5093on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;,options?: Options): void
5094
5095Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.
5096
5097> **NOTE**
5098>
5099> This API is deprecated since API version 9. You are advised to use [sensor.on.PROXIMITY](#proximity9)<sup>9+</sup> instead.
5100
5101**System capability**: SystemCapability.Sensors.Sensor
5102
5103**Parameters**
5104
5105| Name  | Type                                                        | Mandatory| Description                                                        |
5106| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5107| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.        |
5108| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | Yes  | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
5109| options  | [Options](#options)                                          | No  | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when proximity sensor events are frequently triggered.|
5110
5111**Example**
5112
5113```ts
5114import { sensor } from '@kit.SensorServiceKit';
5115
5116sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5117  console.info('Succeeded in invoking on. Distance: ' + data.distance);
5118},
5119  { interval: 100000000 }
5120);
5121```
5122
5123### HUMIDITY<sup>(deprecated)</sup>
5124
5125on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
5126
5127Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect.
5128
5129> **NOTE**
5130>
5131> This API is deprecated since API version 9. You are advised to use [sensor.on.HUMIDITY](#humidity9)<sup>9+</sup> instead.
5132
5133**System capability**: SystemCapability.Sensors.Sensor
5134
5135**Parameters**
5136
5137| Name  | Type                                                       | Mandatory| Description                                                        |
5138| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5139| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.           |
5140| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | Yes  | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
5141| options  | [Options](#options)                                         | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5142
5143**Example**
5144
5145```ts
5146import { sensor } from '@kit.SensorServiceKit';
5147
5148sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5149  console.info('Succeeded in invoking on. Humidity: ' + data.humidity);
5150},
5151  { interval: 100000000 }
5152);
5153```
5154
5155### BAROMETER<sup>(deprecated)</sup>
5156
5157on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;,options?: Options): void
5158
5159Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
5160
5161> **NOTE**
5162>
5163> This API is deprecated since API version 9. You are advised to use [sensor.on.BAROMETER](#barometer9)<sup>9+</sup> instead.
5164
5165**System capability**: SystemCapability.Sensors.Sensor
5166
5167**Parameters**
5168
5169| Name  | Type                                                        | Mandatory| Description                                                        |
5170| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5171| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.        |
5172| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | Yes  | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
5173| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5174
5175**Example**
5176
5177```ts
5178import { sensor } from '@kit.SensorServiceKit';
5179
5180sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5181  console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure);
5182},
5183  { interval: 100000000 }
5184);
5185```
5186
5187### HALL<sup>(deprecated)</sup>
5188
5189on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
5190
5191Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect.
5192
5193> **NOTE**
5194>
5195> This API is deprecated since API version 9. You are advised to use [sensor.on.HALL](#hall9)<sup>9+</sup> instead.
5196
5197**System capability**: SystemCapability.Sensors.Sensor
5198
5199**Parameters**
5200
5201| Name  | Type                                                   | Mandatory| Description                                                        |
5202| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5203| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.               |
5204| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | Yes  | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
5205| options  | [Options](#options)                                     | No  | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when Hall effect events are frequently triggered.|
5206
5207**Example**
5208
5209```ts
5210import { sensor } from '@kit.SensorServiceKit';
5211
5212sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5213  console.info('Succeeded in invoking on. Status: ' + data.status);
5214},
5215  { interval: 100000000 }
5216);
5217```
5218
5219### AMBIENT_LIGHT<sup>(deprecated)</sup>
5220
5221on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
5222
5223Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect.
5224
5225> **NOTE**
5226>
5227> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_LIGHT](#ambient_light9)<sup>9+</sup> instead.
5228
5229**System capability**: SystemCapability.Sensors.Sensor
5230
5231**Parameters**
5232
5233| Name  | Type                                                        | Mandatory| Description                                                       |
5234| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
5235| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.   |
5236| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | Yes  | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
5237| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.|
5238
5239**Example**
5240
5241```ts
5242import { sensor } from '@kit.SensorServiceKit';
5243
5244sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5245  console.info('Succeeded in invoking on. Illumination: ' + data.intensity);
5246},
5247  { interval: 100000000 }
5248);
5249```
5250
5251### ORIENTATION<sup>(deprecated)</sup>
5252
5253on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
5254
5255Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect.
5256
5257> **NOTE**
5258>
5259> This API is deprecated since API version 9. You are advised to use [sensor.on.ORIENTATION](#orientation9)<sup>9+</sup> instead.
5260
5261**System capability**: SystemCapability.Sensors.Sensor
5262
5263**Parameters**
5264
5265| Name  | Type                                                        | Mandatory| Description                                                        |
5266| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5267| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.        |
5268| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | Yes  | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
5269| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5270
5271**Example**
5272
5273```ts
5274import { sensor } from '@kit.SensorServiceKit';
5275
5276sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5277  console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
5278  console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
5279  console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
5280},
5281  { interval: 100000000 }
5282);
5283```
5284
5285### HEART_RATE<sup>(deprecated)</sup>
5286
5287on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
5288
5289Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect.
5290
5291> **NOTE**
5292>
5293> This API is deprecated since API version 9. You are advised to use [sensor.on.HEART_RATE](#heart_rate9)<sup>9+</sup> instead.
5294
5295**Required permissions**: ohos.permission.HEALTH_DATA
5296
5297**System capability**: SystemCapability.Sensors.Sensor
5298
5299**Parameters**
5300
5301| Name  | Type                                                        | Mandatory| Description                                                        |
5302| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5303| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.         |
5304| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | Yes  | Callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
5305| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5306
5307### ROTATION_VECTOR<sup>(deprecated)</sup>
5308
5309on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;RotationVectorResponse&gt;,options?: Options): void
5310
5311Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect.
5312
5313> **NOTE**
5314>
5315> This API is deprecated since API version 9. You are advised to use [sensor.on.ROTATION_VECTOR](#rotation_vector9)<sup>9+</sup> instead.
5316
5317**System capability**: SystemCapability.Sensors.Sensor
5318
5319**Parameters**
5320
5321| Name  | Type                                                        | Mandatory| Description                                                        |
5322| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5323| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
5324| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
5325| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5326
5327**Example**
5328
5329```ts
5330import { sensor } from '@kit.SensorServiceKit';
5331
5332sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5333  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5334  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5335  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5336  console.info('Succeeded in invoking on. Scalar quantity: ' + data.w);
5337},
5338  { interval: 100000000 }
5339);
5340```
5341
5342### WEAR_DETECTION<sup>(deprecated)</sup>
5343
5344on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,options?: Options): void
5345
5346Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect.
5347
5348> **NOTE**
5349>
5350> This API is deprecated since API version 9. You are advised to use [sensor.on.WEAR_DETECTION](#wear_detection9)<sup>9+</sup> instead.
5351
5352**System capability**: SystemCapability.Sensors.Sensor
5353
5354**Parameters**
5355
5356| Name  | Type                                                        | Mandatory| Description                                                        |
5357| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5358| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
5359| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
5360| options  | [Options](#options)                                          | No  | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. |
5361
5362**Example**
5363
5364```ts
5365import { sensor } from '@kit.SensorServiceKit';
5366
5367sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
5368  console.info('Succeeded in invoking on. Wear status: ' + data.value);
5369},
5370  { interval: 100000000 }
5371);
5372```
5373
5374## sensor.once<sup>(deprecated)</sup>
5375
5376### ACCELEROMETER<sup>(deprecated)</sup>
5377
5378once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
5379
5380Subscribes to only one data change of the acceleration sensor.
5381
5382> **NOTE**
5383>
5384> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER](#accelerometer9-1)<sup>9+</sup> instead.
5385
5386**Required permissions**: ohos.permission.ACCELEROMETER
5387
5388**System capability**: SystemCapability.Sensors.Sensor
5389
5390**Parameters**
5391
5392| Name  | Type                                                        | Mandatory| Description                                                        |
5393| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5394| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.            |
5395| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
5396
5397**Example**
5398
5399```ts
5400import { sensor } from '@kit.SensorServiceKit';
5401
5402sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
5403  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5404  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5405  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5406});
5407```
5408
5409### LINEAR_ACCELERATION<sup>(deprecated)</sup>
5410
5411once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;): void
5412
5413Subscribes to only one data change of the linear acceleration sensor.
5414
5415> **NOTE**
5416>
5417> This API is deprecated since API version 9. You are advised to use [sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)<sup>9+</sup> instead.
5418
5419**Required permissions**: ohos.permission.ACCELERATION
5420
5421**System capability**: SystemCapability.Sensors.Sensor
5422
5423**Parameters**
5424
5425| Name  | Type                                                        | Mandatory| Description                                                        |
5426| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5427| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.  |
5428| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
5429
5430### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
5431
5432once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
5433
5434Subscribes to only one data change of the uncalibrated acceleration sensor.
5435
5436> **NOTE**
5437>
5438> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)<sup>9+</sup> instead.
5439
5440**Required permissions**: ohos.permission.ACCELEROMETER
5441
5442**System capability**: SystemCapability.Sensors.Sensor
5443
5444**Parameters**
5445
5446| Name  | Type                                                        | Mandatory| Description                                                        |
5447| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5448| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
5449| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
5450
5451**Example**
5452
5453```ts
5454import { sensor } from '@kit.SensorServiceKit';
5455
5456sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
5457  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5458  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5459  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5460  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5461  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5462  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5463});
5464```
5465
5466### GRAVITY<sup>(deprecated)</sup>
5467
5468once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
5469
5470Subscribes to only one data change of the gravity sensor.
5471
5472> **NOTE**
5473>
5474> This API is deprecated since API version 9. You are advised to use [sensor.once.GRAVITY](#gravity9-1)<sup>9+</sup> instead.
5475
5476**System capability**: SystemCapability.Sensors.Sensor
5477
5478**Parameters**
5479
5480| Name  | Type                                                      | Mandatory| Description                                                        |
5481| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5482| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.                    |
5483| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | Yes  | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
5484
5485**Example**
5486
5487```ts
5488import { sensor } from '@kit.SensorServiceKit';
5489
5490sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
5491  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5492  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5493  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5494  });
5495```
5496
5497### GYROSCOPE<sup>(deprecated)</sup>
5498
5499once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
5500
5501Subscribes to only one data change of the gyroscope sensor.
5502
5503> **NOTE**
5504>
5505> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE](#gyroscope9-1)<sup>9+</sup> instead.
5506
5507**Required permissions**: ohos.permission.GYROSCOPE
5508
5509**System capability**: SystemCapability.Sensors.Sensor
5510
5511**Parameters**
5512
5513| Name  | Type                                                        | Mandatory| Description                                                        |
5514| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5515| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.                |
5516| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | Yes  | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
5517
5518**Example**
5519
5520```ts
5521import { sensor } from '@kit.SensorServiceKit';
5522
5523sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
5524  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5525  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5526  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5527});
5528```
5529
5530### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
5531
5532once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
5533
5534Subscribes to only one data change of the uncalibrated gyroscope sensor.
5535
5536> **NOTE**
5537>
5538> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)<sup>9+</sup> instead.
5539
5540**Required permissions**: ohos.permission.GYROSCOPE
5541
5542**System capability**: SystemCapability.Sensors.Sensor
5543
5544**Parameters**
5545
5546| Name  | Type                                                        | Mandatory| Description                                                        |
5547| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5548| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
5549| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
5550
5551**Example**
5552
5553
5554```ts
5555import { sensor } from '@kit.SensorServiceKit';
5556
5557sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
5558    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5559    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5560    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5561    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5562    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5563    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5564});
5565```
5566
5567### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
5568
5569once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void
5570
5571Subscribes to only one data change of the significant motion sensor.
5572
5573> **NOTE**
5574>
5575> This API is deprecated since API version 9. You are advised to use [sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)<sup>9+</sup> instead.
5576
5577**System capability**: SystemCapability.Sensors.Sensor
5578
5579**Parameters**
5580
5581| Name  | Type                                                        | Mandatory| Description                                                        |
5582| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5583| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.     |
5584| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
5585
5586**Example**
5587
5588```ts
5589import { sensor } from '@kit.SensorServiceKit';
5590
5591sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
5592  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5593});
5594```
5595
5596### PEDOMETER_DETECTION<sup>(deprecated)</sup>
5597
5598once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void
5599
5600Subscribes to only one data change of the pedometer detection sensor.
5601
5602> **NOTE**
5603>
5604> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)<sup>9+</sup> instead.
5605
5606**Required permissions**: ohos.permission.ACTIVITY_MOTION
5607
5608**System capability**: SystemCapability.Sensors.Sensor
5609
5610**Parameters**
5611
5612| Name  | Type                                                        | Mandatory| Description                                                        |
5613| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5614| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.    |
5615| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
5616
5617**Example**
5618
5619```ts
5620import { sensor } from '@kit.SensorServiceKit';
5621
5622sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
5623  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5624});
5625```
5626
5627### PEDOMETER<sup>(deprecated)</sup>
5628
5629once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
5630
5631Subscribes to only one data change of the pedometer sensor.
5632
5633> **NOTE**
5634>
5635> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER](#pedometer9-1)<sup>9+</sup> instead.
5636
5637**Required permissions**: ohos.permission.ACTIVITY_MOTION
5638
5639**System capability**: SystemCapability.Sensors.Sensor
5640
5641**Parameters**
5642
5643| Name  | Type                                                        | Mandatory| Description                                                        |
5644| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5645| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.                  |
5646| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | Yes  | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
5647
5648**Example**
5649
5650```ts
5651import { sensor } from '@kit.SensorServiceKit';
5652
5653sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
5654  console.info('Succeeded in invoking once. Steps: ' + data.steps);
5655});
5656```
5657
5658### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
5659
5660once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void
5661
5662Subscribes to only one data change of the ambient temperature sensor.
5663
5664> **NOTE**
5665>
5666> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)<sup>9+</sup> instead.
5667
5668**System capability**: SystemCapability.Sensors.Sensor
5669
5670**Parameters**
5671
5672| Name  | Type                                                        | Mandatory| Description                                                        |
5673| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5674| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.    |
5675| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
5676
5677**Example**
5678
5679```ts
5680import { sensor } from '@kit.SensorServiceKit';
5681
5682sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5683  console.info('Succeeded in invoking once. Temperature: ' + data.temperature);
5684});
5685```
5686
5687### MAGNETIC_FIELD<sup>(deprecated)</sup>
5688
5689once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
5690
5691Subscribes to only one data change of the magnetic field sensor.
5692
5693> **NOTE**
5694>
5695> This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)<sup>9+</sup> instead.
5696
5697**System capability**: SystemCapability.Sensors.Sensor
5698
5699**Parameters**
5700
5701| Name  | Type                                                        | Mandatory| Description                                                        |
5702| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5703| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.             |
5704| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
5705
5706**Example**
5707
5708```ts
5709import { sensor } from '@kit.SensorServiceKit';
5710
5711sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5712  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5713  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5714  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5715});
5716```
5717
5718### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5719
5720once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
5721
5722Subscribes to only one data change of the uncalibrated magnetic field sensor.
5723
5724> **NOTE**
5725>
5726> This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)<sup>9+</sup> instead.
5727
5728**System capability**: SystemCapability.Sensors.Sensor
5729
5730**Parameters**
5731
5732| Name  | Type                                                        | Mandatory| Description                                                        |
5733| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5734| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
5735| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
5736
5737**Example**
5738
5739```ts
5740import { sensor } from '@kit.SensorServiceKit';
5741
5742sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5743  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5744  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5745  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5746  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5747  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5748  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5749});
5750```
5751
5752### PROXIMITY<sup>(deprecated)</sup>
5753
5754once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
5755
5756Subscribes to only one data change of the proximity sensor.
5757
5758> **NOTE**
5759>
5760> This API is deprecated since API version 9. You are advised to use [sensor.once.PROXIMITY](#proximity9-1)<sup>9+</sup> instead.
5761
5762**System capability**: SystemCapability.Sensors.Sensor
5763
5764**Parameters**
5765
5766| Name  | Type                                                        | Mandatory| Description                                                        |
5767| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5768| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.                |
5769| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | Yes  | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
5770
5771**Example**
5772
5773```ts
5774import { sensor } from '@kit.SensorServiceKit';
5775
5776sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5777  console.info('Succeeded in invoking once. Distance: ' + data.distance);
5778}
5779);
5780```
5781
5782### HUMIDITY<sup>(deprecated)</sup>
5783
5784once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
5785
5786Subscribes to only one data change of the humidity sensor.
5787
5788> **NOTE**
5789>
5790> This API is deprecated since API version 9. You are advised to use [sensor.once.HUMIDITY](#humidity9-1)<sup>9+</sup> instead.
5791
5792**System capability**: SystemCapability.Sensors.Sensor
5793
5794**Parameters**
5795
5796| Name  | Type                                                       | Mandatory| Description                                                        |
5797| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5798| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.                   |
5799| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | Yes  | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
5800
5801**Example**
5802
5803```ts
5804import { sensor } from '@kit.SensorServiceKit';
5805
5806sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5807  console.info('Succeeded in invoking once. Humidity: ' + data.humidity);
5808});
5809```
5810
5811### BAROMETER<sup>(deprecated)</sup>
5812
5813once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
5814
5815Subscribes to only one data change of the barometer sensor.
5816
5817> **NOTE**
5818>
5819> This API is deprecated since API version 9. You are advised to use [sensor.once.BAROMETER](#barometer9-1)<sup>9+</sup> instead.
5820
5821**System capability**: SystemCapability.Sensors.Sensor
5822
5823**Parameters**
5824
5825| Name  | Type                                                        | Mandatory| Description                                                        |
5826| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5827| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.                |
5828| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | Yes  | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
5829
5830**Example**
5831
5832```ts
5833import { sensor } from '@kit.SensorServiceKit';
5834
5835sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5836  console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure);
5837});
5838```
5839
5840### HALL<sup>(deprecated)</sup>
5841
5842once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
5843
5844Subscribes to only one data change of the Hall effect sensor.
5845
5846> **NOTE**
5847>
5848> This API is deprecated since API version 9. You are advised to use [sensor.once.HALL](#hall9-1)<sup>9+</sup> instead.
5849
5850**System capability**: SystemCapability.Sensors.Sensor
5851
5852**Parameters**
5853
5854| Name  | Type                                                   | Mandatory| Description                                                        |
5855| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5856| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.                       |
5857| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | Yes  | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
5858
5859**Example**
5860
5861```ts
5862import { sensor } from '@kit.SensorServiceKit';
5863
5864sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5865  console.info('Succeeded in invoking once. Status: ' + data.status);
5866});
5867```
5868
5869### AMBIENT_LIGHT<sup>(deprecated)</sup>
5870
5871once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
5872
5873Subscribes to only one data change of the ambient light sensor.
5874
5875> **NOTE**
5876>
5877> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_LIGHT](#ambient_light9-1)<sup>9+</sup> instead.
5878
5879**System capability**: SystemCapability.Sensors.Sensor
5880
5881**Parameters**
5882
5883| Name  | Type                                                        | Mandatory| Description                                                        |
5884| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5885| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.            |
5886| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | Yes  | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
5887
5888**Example**
5889
5890```ts
5891import { sensor } from '@kit.SensorServiceKit';
5892
5893sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5894  console.info('Succeeded in invoking once. invoking once. Illumination: ' + data.intensity);
5895});
5896```
5897
5898### ORIENTATION<sup>(deprecated)</sup>
5899
5900once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
5901
5902Subscribes to only one data change of the orientation sensor.
5903
5904> **NOTE**
5905>
5906> This API is deprecated since API version 9. You are advised to use [sensor.once.ORIENTATION](#orientation9-1)<sup>9+</sup> instead.
5907
5908**System capability**: SystemCapability.Sensors.Sensor
5909
5910**Parameters**
5911
5912| Name  | Type                                                        | Mandatory| Description                                                        |
5913| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5914| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.                |
5915| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | Yes  | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
5916
5917**Example**
5918
5919```ts
5920import { sensor } from '@kit.SensorServiceKit';
5921
5922sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5923  console.info('Succeeded in invoking the device rotateing at an angle around the X axis: ' + data.beta);
5924  console.info('Succeeded in invoking the device rotateing at an angle around the Y axis: ' + data.gamma);
5925  console.info('Succeeded in invoking the device rotateing at an angle around the Z axis: ' + data.alpha);
5926});
5927```
5928
5929### ROTATION_VECTOR<sup>(deprecated)</sup>
5930
5931once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
5932
5933Subscribes to only one data change of the rotation vector sensor.
5934
5935> **NOTE**
5936>
5937> This API is deprecated since API version 9. You are advised to use [sensor.once.ROTATION_VECTOR](#rotation_vector9-1)<sup>9+</sup> instead.
5938
5939**System capability**: SystemCapability.Sensors.Sensor
5940
5941**Parameters**
5942
5943| Name  | Type                                                        | Mandatory| Description                                                        |
5944| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5945| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.        |
5946| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
5947
5948**Example**
5949
5950```ts
5951import { sensor } from '@kit.SensorServiceKit';
5952
5953sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5954  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5955  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5956  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5957  console.info('Succeeded in invoking once. Scalar quantity: ' + data.w);
5958});
5959```
5960
5961### HEART_RATE<sup>(deprecated)</sup>
5962
5963once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
5964
5965Subscribes to only one data change of the heart rate sensor.
5966
5967> **NOTE**
5968>
5969> This API is deprecated since API version 9. You are advised to use [sensor.once.HEART_RATE](#heart_rate9-1)<sup>9+</sup> instead.
5970
5971**Required permissions**: ohos.permission.HEART_RATE
5972
5973**System capability**: SystemCapability.Sensors.Sensor
5974
5975**Parameters**
5976
5977| Name  | Type                                                        | Mandatory| Description                                                        |
5978| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5979| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.                 |
5980| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | Yes  | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
5981
5982**Example**
5983
5984
5985```ts
5986import { sensor } from '@kit.SensorServiceKit';
5987
5988sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, (data: sensor.HeartRateResponse) => {
5989  console.info("Succeeded in invoking once. Heart rate: " + data.heartRate);
5990});
5991```
5992
5993### WEAR_DETECTION<sup>(deprecated)</sup>
5994
5995once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
5996
5997Subscribes to only one data change of the wear detection sensor.
5998
5999> **NOTE**
6000>
6001> This API is deprecated since API version 9. You are advised to use [sensor.once.WEAR_DETECTION](#wear_detection9-1)<sup>9+</sup> instead.
6002
6003**System capability**: SystemCapability.Sensors.Sensor
6004
6005**Parameters**
6006
6007| Name  | Type                                                        | Mandatory| Description                                                        |
6008| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6009| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.         |
6010| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
6011
6012**Example**
6013
6014
6015```ts
6016import { sensor } from '@kit.SensorServiceKit';
6017
6018sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
6019  console.info("Succeeded in invoking once. Wear status: " + data.value);
6020});
6021```
6022
6023## sensor.off<sup>(deprecated)</sup>
6024
6025### ACCELEROMETER<sup>(deprecated)</sup>
6026
6027off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
6028
6029Unsubscribes from sensor data changes.
6030
6031> **NOTE**
6032>
6033> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER<sup>9+</sup>](#accelerometer9-2) instead.
6034
6035**Required permissions**: ohos.permission.ACCELEROMETER
6036
6037**System capability**: SystemCapability.Sensors.Sensor
6038
6039**Parameters**
6040
6041| Name  | Type                                                        | Mandatory| Description                                                        |
6042| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6043| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
6044| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6045
6046**Example**
6047
6048```ts
6049import { sensor } from '@kit.SensorServiceKit';
6050
6051function callback(data: sensor.AccelerometerResponse) {
6052  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6053  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6054  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6055}
6056
6057sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
6058```
6059
6060### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
6061
6062off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
6063
6064Unsubscribes from sensor data changes.
6065
6066> **NOTE**
6067>
6068> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)<sup>9+</sup> instead.
6069
6070**Required permissions**: ohos.permission.ACCELEROMETER
6071
6072**System capability**: SystemCapability.Sensors.Sensor
6073
6074**Parameters**
6075
6076| Name  | Type                                                        | Mandatory| Description                                                        |
6077| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6078| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
6079| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6080
6081**Example**
6082
6083```ts
6084import { sensor } from '@kit.SensorServiceKit';
6085
6086function callback(data: sensor.AccelerometerUncalibratedResponse) {
6087  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6088  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6089  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6090  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6091  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6092  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6093}
6094
6095sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
6096```
6097
6098### AMBIENT_LIGHT<sup>(deprecated)</sup>
6099
6100off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
6101
6102Unsubscribes from sensor data changes.
6103
6104> **NOTE**
6105>
6106> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_LIGHT](#ambient_light9-2)<sup>9+</sup> instead.
6107
6108**System capability**: SystemCapability.Sensors.Sensor
6109
6110**Parameters**
6111
6112| Name  | Type                                                        | Mandatory| Description                                                        |
6113| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6114| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
6115| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6116
6117**Example**
6118
6119```ts
6120import { sensor } from '@kit.SensorServiceKit';
6121
6122function callback(data: sensor.LightResponse) {
6123  console.info('Succeeded in invoking off. Illumination: ' + data.intensity);
6124}
6125
6126sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
6127```
6128
6129### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
6130
6131off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
6132
6133Unsubscribes from sensor data changes.
6134
6135> **NOTE**
6136>
6137> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)<sup>9+</sup> instead.
6138
6139**System capability**: SystemCapability.Sensors.Sensor
6140
6141**Parameters**
6142
6143| Name  | Type                                                        | Mandatory| Description                                                        |
6144| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6145| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
6146| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6147
6148**Example**
6149
6150```ts
6151import { sensor } from '@kit.SensorServiceKit';
6152
6153function callback(data: sensor.AmbientTemperatureResponse) {
6154  console.info('Succeeded in invoking off. Temperature: ' + data.temperature);
6155}
6156
6157sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
6158```
6159
6160### BAROMETER<sup>(deprecated)</sup>
6161
6162off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
6163
6164Unsubscribes from sensor data changes.
6165
6166> **NOTE**
6167>
6168> This API is deprecated since API version 9. You are advised to use [sensor.off.BAROMETER](#barometer9-2)<sup>9+</sup> instead.
6169
6170**System capability**: SystemCapability.Sensors.Sensor
6171
6172**Parameters**
6173
6174| Name  | Type                                                        | Mandatory| Description                                                        |
6175| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6176| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**.    |
6177| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6178
6179**Example**
6180
6181```ts
6182import { sensor } from '@kit.SensorServiceKit';
6183
6184function callback(data: sensor.BarometerResponse) {
6185  console.info('Succeeded in invoking off. Atmospheric pressure: ' + data.pressure);
6186}
6187
6188sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
6189```
6190
6191### GRAVITY<sup>(deprecated)</sup>
6192
6193off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
6194
6195Unsubscribes from sensor data changes.
6196
6197> **NOTE**
6198>
6199> This API is deprecated since API version 9. You are advised to use [sensor.off.GRAVITY](#gravity9-2)<sup>9+</sup> instead.
6200
6201**System capability**: SystemCapability.Sensors.Sensor
6202
6203**Parameters**
6204
6205| Name  | Type                                                      | Mandatory| Description                                                        |
6206| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6207| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**.        |
6208| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6209
6210**Example**
6211
6212```ts
6213import { sensor } from '@kit.SensorServiceKit';
6214
6215function callback(data: sensor.GravityResponse) {
6216  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6217  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6218  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6219}
6220
6221sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
6222```
6223
6224### GYROSCOPE<sup>(deprecated)</sup>
6225
6226off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
6227
6228Unsubscribes from sensor data changes.
6229
6230> **NOTE**
6231>
6232> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE](#gyroscope9-2)<sup>9+</sup> instead.
6233
6234**Required permissions**: ohos.permission.GYROSCOPE
6235
6236**System capability**: SystemCapability.Sensors.Sensor
6237
6238**Parameters**
6239
6240| Name  | Type                                                        | Mandatory| Description                                                        |
6241| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6242| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**.    |
6243| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6244
6245**Example**
6246
6247```ts
6248import { sensor } from '@kit.SensorServiceKit';
6249
6250function callback(data: sensor.GyroscopeResponse) {
6251  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6252  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6253  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6254}
6255
6256sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
6257```
6258
6259### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
6260
6261off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
6262
6263Unsubscribes from sensor data changes.
6264
6265> **NOTE**
6266>
6267> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)<sup>9+</sup> instead.
6268
6269**Required permissions**: ohos.permission.GYROSCOPE
6270
6271**System capability**: SystemCapability.Sensors.Sensor
6272
6273**Parameters**
6274
6275| Name  | Type                                                        | Mandatory| Description                                                        |
6276| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6277| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
6278| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6279
6280**Example**
6281
6282```ts
6283import { sensor } from '@kit.SensorServiceKit';
6284
6285function callback(data: sensor.GyroscopeUncalibratedResponse) {
6286  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6287  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6288  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6289}
6290
6291sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
6292```
6293
6294### HALL<sup>(deprecated)</sup>
6295
6296off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
6297
6298Unsubscribes from sensor data changes.
6299
6300> **NOTE**
6301>
6302> This API is deprecated since API version 9. You are advised to use [sensor.off.HALL](#hall9-2)<sup>9+</sup> instead.
6303
6304**System capability**: SystemCapability.Sensors.Sensor
6305
6306**Parameters**
6307
6308| Name  | Type                                                   | Mandatory| Description                                                        |
6309| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6310| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**.           |
6311| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6312
6313**Example**
6314
6315```ts
6316import { sensor } from '@kit.SensorServiceKit';
6317
6318function callback(data: sensor.HallResponse) {
6319  console.info('Succeeded in invoking off. Status: ' + data.status);
6320}
6321
6322sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
6323```
6324
6325### HEART_RATE<sup>(deprecated)</sup>
6326
6327off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
6328
6329Unsubscribes from sensor data changes.
6330
6331> **NOTE**
6332>
6333> This API is deprecated since API version 9. You are advised to use [sensor.off.HEART_RATE](#heart_rate9-2)<sup>9+</sup> instead.
6334
6335**Required permissions**: ohos.permission.HEALTH_DATA
6336
6337**System capability**: SystemCapability.Sensors.Sensor
6338
6339**Parameters**
6340
6341| Name  | Type                                                        | Mandatory| Description                                                        |
6342| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6343| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**.     |
6344| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6345
6346**Example**
6347
6348```ts
6349import { sensor } from '@kit.SensorServiceKit';
6350
6351function callback(data: sensor.HeartRateResponse) {
6352  console.info('Succeeded in invoking off. Humidity: ' + data.heartRate);
6353}
6354
6355sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
6356```
6357
6358### HUMIDITY<sup>(deprecated)</sup>
6359
6360off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
6361
6362Unsubscribes from sensor data changes.
6363
6364> **NOTE**
6365>
6366> This API is deprecated since API version 9. You are advised to use [sensor.off.HUMIDITY](#humidity9-2)<sup>9+</sup> instead.
6367
6368**System capability**: SystemCapability.Sensors.Sensor
6369
6370**Parameters**
6371
6372| Name  | Type                                                       | Mandatory| Description                                                        |
6373| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6374| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**.       |
6375| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6376
6377**Example**
6378
6379```ts
6380import { sensor } from '@kit.SensorServiceKit';
6381
6382function callback(data: sensor.HumidityResponse) {
6383  console.info('Succeeded in invoking off. Humidity: ' + data.humidity);
6384}
6385
6386sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
6387```
6388
6389### LINEAR_ACCELERATION<sup>(deprecated)</sup>
6390
6391off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
6392
6393Unsubscribes from sensor data changes.
6394
6395> **NOTE**
6396>
6397> This API is deprecated since API version 9. You are advised to use [sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)<sup>9+</sup> instead.
6398
6399**Required permissions**: ohos.permission.ACCELEROMETER
6400
6401**System capability**: SystemCapability.Sensors.Sensor
6402
6403**Parameters**
6404
6405| Name  | Type                                                        | Mandatory| Description                                                        |
6406| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6407| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
6408| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6409
6410**Example**
6411
6412```ts
6413import { sensor } from '@kit.SensorServiceKit';
6414
6415function callback(data: sensor.LinearAccelerometerResponse) {
6416  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6417  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6418  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6419}
6420
6421sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
6422```
6423
6424### MAGNETIC_FIELD<sup>(deprecated)</sup>
6425
6426 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
6427
6428Unsubscribes from sensor data changes.
6429
6430> **NOTE**
6431>
6432> This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)<sup>9+</sup> instead.
6433
6434**System capability**: SystemCapability.Sensors.Sensor
6435
6436**Parameters**
6437
6438| Name  | Type                                                        | Mandatory| Description                                                        |
6439| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6440| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
6441| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6442
6443**Example**
6444
6445```ts
6446import { sensor } from '@kit.SensorServiceKit';
6447
6448function callback(data: sensor.MagneticFieldResponse) {
6449  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6450  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6451  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6452}
6453
6454sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
6455```
6456
6457### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
6458
6459 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
6460
6461Unsubscribes from sensor data changes.
6462
6463> **NOTE**
6464>
6465> This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)<sup>9+</sup> instead.
6466
6467**System capability**: SystemCapability.Sensors.Sensor
6468
6469**Parameters**
6470
6471| Name  | Type                                                        | Mandatory| Description                                                        |
6472| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6473| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
6474| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6475
6476**Example**
6477
6478```ts
6479import { sensor } from '@kit.SensorServiceKit';
6480
6481function callback(data: sensor.MagneticFieldUncalibratedResponse) {
6482  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6483  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6484  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6485  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6486  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6487  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6488}
6489
6490sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
6491```
6492
6493### ORIENTATION<sup>(deprecated)</sup>
6494
6495 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
6496
6497Unsubscribes from sensor data changes.
6498
6499> **NOTE**
6500>
6501> This API is deprecated since API version 9. You are advised to use [sensor.off.ORIENTATION](#orientation9-2)<sup>9+</sup> instead.
6502
6503**System capability**: SystemCapability.Sensors.Sensor
6504
6505**Parameters**
6506
6507| Name  | Type                                                        | Mandatory| Description                                                        |
6508| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6509| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**.    |
6510| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6511
6512**Example**
6513
6514```ts
6515import { sensor } from '@kit.SensorServiceKit';
6516
6517function callback(data: sensor.OrientationResponse) {
6518  console.info('Succeeded in invoking off. The device rotates at an angle around the X axis: ' + data.beta);
6519  console.info('Succeeded in invoking off. The device rotates at an angle around the Y axis: ' + data.gamma);
6520  console.info('Succeeded in invoking off. The device rotates at an angle around the Z axis: ' + data.alpha);
6521}
6522
6523sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
6524```
6525
6526### PEDOMETER<sup>(deprecated)</sup>
6527
6528off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
6529
6530Unsubscribes from sensor data changes.
6531
6532> **NOTE**
6533>
6534> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER](#pedometer9-2)<sup>9+</sup> instead.
6535
6536**Required permissions**: ohos.permission.ACTIVITY_MOTION
6537
6538**System capability**: SystemCapability.Sensors.Sensor
6539
6540**Parameters**
6541
6542| Name  | Type                                                        | Mandatory| Description                                                        |
6543| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6544| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**.      |
6545| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6546
6547**Example**
6548
6549```ts
6550import { sensor } from '@kit.SensorServiceKit';
6551
6552function callback(data: sensor.PedometerResponse) {
6553  console.info('Succeeded in invoking off. Steps: ' + data.steps);
6554}
6555
6556sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
6557```
6558
6559### PEDOMETER_DETECTION<sup>(deprecated)</sup>
6560
6561off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
6562
6563Unsubscribes from sensor data changes.
6564
6565> **NOTE**
6566>
6567> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)<sup>9+</sup> instead.
6568
6569**Required permissions**: ohos.permission.ACTIVITY_MOTION
6570
6571**System capability**: SystemCapability.Sensors.Sensor
6572
6573**Parameters**
6574
6575| Name  | Type                                                        | Mandatory| Description                                                        |
6576| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6577| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
6578| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6579
6580**Example**
6581
6582```ts
6583import { sensor } from '@kit.SensorServiceKit';
6584
6585function callback(data: sensor.PedometerDetectionResponse) {
6586  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6587}
6588
6589sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
6590```
6591
6592### PROXIMITY<sup>(deprecated)</sup>
6593
6594off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
6595
6596Unsubscribes from sensor data changes.
6597
6598> **NOTE**
6599>
6600> This API is deprecated since API version 9. You are advised to use [sensor.off.PROXIMITY](#proximity9-2)<sup>9+</sup> instead.
6601
6602**System capability**: SystemCapability.Sensors.Sensor
6603
6604**Parameters**
6605
6606| Name  | Type                                                        | Mandatory| Description                                                        |
6607| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6608| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**.    |
6609| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6610
6611**Example**
6612
6613```ts
6614import { sensor } from '@kit.SensorServiceKit';
6615
6616function callback(data: sensor.ProximityResponse) {
6617  console.info('Succeeded in invoking off. Distance: ' + data.distance);
6618}
6619
6620sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
6621```
6622
6623### ROTATION_VECTOR<sup>(deprecated)</sup>
6624
6625off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
6626
6627Unsubscribes from sensor data changes.
6628
6629> **NOTE**
6630>
6631> This API is deprecated since API version 9. You are advised to use [sensor.off.ROTATION_VECTOR](#rotation_vector9-2)<sup>9+</sup> instead.
6632
6633**System capability**: SystemCapability.Sensors.Sensor
6634
6635**Parameters**
6636
6637| Name  | Type                                                        | Mandatory| Description                                                        |
6638| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6639| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
6640| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6641
6642**Example**
6643
6644```ts
6645import { sensor } from '@kit.SensorServiceKit';
6646
6647function callback(data: sensor.RotationVectorResponse) {
6648  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6649  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6650  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6651  console.info('Succeeded in invoking off. Scalar quantity: ' + data.w);
6652}
6653
6654sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
6655```
6656
6657### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
6658
6659off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
6660
6661Unsubscribes from sensor data changes.
6662
6663> **NOTE**
6664>
6665> This API is deprecated since API version 9. You are advised to use [sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)<sup>9+</sup> instead.
6666
6667**System capability**: SystemCapability.Sensors.Sensor
6668
6669**Parameters**
6670
6671| Name  | Type                                                        | Mandatory| Description                                                        |
6672| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6673| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
6674| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6675
6676**Example**
6677
6678```ts
6679import { sensor } from '@kit.SensorServiceKit';
6680
6681function callback(data: sensor.SignificantMotionResponse) {
6682  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6683}
6684
6685sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
6686```
6687
6688### WEAR_DETECTION<sup>(deprecated)</sup>
6689
6690off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
6691
6692Unsubscribes from sensor data changes.
6693
6694> **NOTE**
6695>
6696> This API is deprecated since API version 9. You are advised to use [sensor.off.WEAR_DETECTION](#wear_detection9-2)<sup>9+</sup> instead.
6697
6698**System capability**: SystemCapability.Sensors.Sensor
6699
6700**Parameters**
6701
6702| Name  | Type                                                        | Mandatory| Description                                                        |
6703| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6704| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
6705| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
6706
6707**Example**
6708
6709```ts
6710import { sensor } from '@kit.SensorServiceKit';
6711
6712function accCallback(data: sensor.WearDetectionResponse) {
6713  console.info('Succeeded in invoking off. Wear status: ' + data.value);
6714}
6715
6716sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
6717```
6718
6719## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6720
6721transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
6722
6723Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses an asynchronous callback to return the result.
6724
6725> **NOTE**
6726>
6727> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9)<sup>9+</sup> instead.
6728
6729**System capability**: SystemCapability.Sensors.Sensor
6730
6731**Parameters**
6732
6733| Name          | Type                                     | Mandatory| Description                      |
6734| ---------------- | ----------------------------------------- | ---- | -------------------------- |
6735| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector to rotate.            |
6736| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Direction of the coordinate system.          |
6737| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes  | Callback used to return the rotation vector after being rotated.|
6738
6739**Example**
6740
6741```ts
6742import { sensor } from '@kit.SensorServiceKit';
6743import { BusinessError } from '@kit.BasicServicesKit';
6744
6745sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 },
6746                                 (err: BusinessError, data: Array<number>) => {
6747  if (err) {
6748    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6749    return;
6750  }
6751  console.info("Succeeded in starting Operation. Data obtained: " + data);
6752  for (let i = 0; i < data.length; i++) {
6753    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6754  }
6755})
6756```
6757## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6758
6759transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
6760
6761Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.
6762
6763> **NOTE**
6764>
6765> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)<sup>9+</sup> instead.
6766
6767**System capability**: SystemCapability.Sensors.Sensor
6768
6769**Parameters**
6770
6771| Name             | Type                                      | Mandatory  | Description      |
6772| ---------------- | ---------------------------------------- | ---- | -------- |
6773| inRotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to rotate. |
6774| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.|
6775
6776**Return value**
6777
6778| Type                              | Description                              |
6779| ---------------------------------- | ---------------------------------- |
6780| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|
6781
6782**Example**
6783
6784```ts
6785import { sensor } from '@kit.SensorServiceKit';
6786import { BusinessError } from '@kit.BasicServicesKit';
6787
6788const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 });
6789promise.then((data: Array<number>) => {
6790  console.info("Succeeded in starting Operation");
6791  for (let i = 0; i < data.length; i++) {
6792    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6793  }
6794}).catch((err: BusinessError) => {
6795  console.error(`Failed to operate.`);
6796})
6797```
6798
6799## sensor.getGeomagneticField<sup>(deprecated)</sup>
6800
6801getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
6802
6803Obtains the geomagnetic field of a geographic location. This API uses an asynchronous callback to return the result.
6804
6805> **NOTE**
6806>
6807> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)<sup>9+</sup> instead.
6808
6809**System capability**: SystemCapability.Sensors.Sensor
6810
6811**Parameters**
6812
6813| Name         | Type                                                        | Mandatory| Description                              |
6814| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
6815| locationOptions | [LocationOptions](#locationoptions)                          | Yes  | Geographic location.                        |
6816| timeMillis      | number                                                       | Yes  | Time for obtaining the magnetic declination, in milliseconds.|
6817| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes  | Callback used to return the geomagnetic field.                |
6818
6819**Example**
6820
6821```ts
6822import { sensor } from '@kit.SensorServiceKit';
6823import { BusinessError } from '@kit.BasicServicesKit';
6824
6825sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000,
6826                           (err: BusinessError, data: sensor.GeomagneticResponse) => {
6827  if (err) {
6828    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6829    return;
6830  }
6831  console.info('Succeeded in getting sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
6832  data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
6833  ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
6834});
6835```
6836## sensor.getGeomagneticField<sup>(deprecated)</sup>
6837
6838getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
6839
6840Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.
6841
6842> **NOTE**
6843>
6844> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)<sup>9+</sup> instead.
6845
6846**System capability**: SystemCapability.Sensors.Sensor
6847
6848**Parameters**
6849
6850| Name            | Type                                 | Mandatory  | Description               |
6851| --------------- | ----------------------------------- | ---- | ----------------- |
6852| locationOptions | [LocationOptions](#locationoptions) | Yes   | Geographic location.            |
6853| timeMillis      | number                              | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
6854
6855**Return value**
6856
6857| Type                                                      | Description                      |
6858| ---------------------------------------------------------- | -------------------------- |
6859| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|
6860
6861**Example**
6862
6863```ts
6864import { sensor } from '@kit.SensorServiceKit';
6865import { BusinessError } from '@kit.BasicServicesKit';
6866
6867const promise = sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000);
6868promise.then((data: sensor.GeomagneticResponse) => {
6869  console.info('Succeeded in getting sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
6870  data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
6871  ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
6872}).catch((reason: BusinessError) => {
6873  console.error(`Failed to operate.`);
6874})
6875```
6876
6877## sensor.getAltitude<sup>(deprecated)</sup>
6878
6879getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
6880
6881Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses an asynchronous callback to return the result.
6882
6883> **NOTE**
6884>
6885> This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9)<sup>9+</sup> instead.
6886
6887**System capability**: SystemCapability.Sensors.Sensor
6888
6889**Parameters**
6890
6891| Name         | Type                       | Mandatory| Description                                  |
6892| --------------- | --------------------------- | ---- | -------------------------------------- |
6893| seaPressure     | number                      | Yes  | Sea-level atmospheric pressure, in hPa.         |
6894| currentPressure | number                      | Yes  | Atmospheric pressure at the altitude where the device is located, in hPa. |
6895| callback        | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the altitude, in meters.|
6896
6897**Example**
6898
6899```ts
6900import { sensor } from '@kit.SensorServiceKit';
6901import { BusinessError } from '@kit.BasicServicesKit';
6902
6903sensor.getAltitude(0, 200, (err: BusinessError, data: number) => {
6904  if (err) {
6905    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6906    return;
6907  }
6908  console.info("Succeeded in getting getAltitude interface get data: " + data);
6909});
6910```
6911
6912## sensor.getAltitude<sup>(deprecated)</sup>
6913
6914getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
6915
6916Obtains 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.
6917
6918> **NOTE**
6919>
6920> This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)<sup>9+</sup> instead.
6921
6922**System capability**: SystemCapability.Sensors.Sensor
6923
6924**Parameters**
6925
6926| Name            | Type    | Mandatory  | Description                  |
6927| --------------- | ------ | ---- | -------------------- |
6928| seaPressure     | number | Yes   | Sea-level atmospheric pressure, in hPa.    |
6929| currentPressure | number | Yes   | Atmospheric pressure at the altitude where the device is located, in hPa.|
6930
6931**Return value**
6932
6933| Type                 | Description                                            |
6934| --------------------- | ------------------------------------------------ |
6935| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|
6936
6937**Example**
6938
6939```ts
6940import { sensor } from '@kit.SensorServiceKit';
6941import { BusinessError } from '@kit.BasicServicesKit';
6942
6943const promise = sensor.getAltitude(0, 200);
6944promise.then((data: number) => {
6945  console.info('Succeeded in getting sensor_getAltitude_Promise success', data);
6946}).catch((err: BusinessError) => {
6947  console.error(`Failed to operate.`);
6948})
6949```
6950
6951
6952## sensor.getGeomagneticDip<sup>(deprecated)</sup>
6953
6954getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
6955
6956Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result.
6957
6958> **NOTE**
6959>
6960> This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9)<sup>9+</sup> instead.
6961
6962**System capability**: SystemCapability.Sensors.Sensor
6963
6964**Parameters**
6965
6966| Name           | Type                       | Mandatory| Description                            |
6967| ----------------- | --------------------------- | ---- | -------------------------------- |
6968| inclinationMatrix | Array&lt;number&gt;         | Yes  | Inclination matrix.                  |
6969| callback          | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the magnetic dip, in radians.|
6970
6971**Example**
6972
6973```ts
6974import { sensor } from '@kit.SensorServiceKit';
6975import { BusinessError } from '@kit.BasicServicesKit';
6976
6977sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], (err: BusinessError, data: number) => {
6978  if (err) {
6979    console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`);
6980    return;
6981  }
6982  console.info("Succeeded in getting getGeomagneticDip interface get data: " + data);
6983})
6984```
6985
6986## sensor.getGeomagneticDip<sup>(deprecated)</sup>
6987
6988getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
6989
6990Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.
6991
6992> **NOTE**
6993>
6994> This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9-1)<sup>9+</sup> instead.
6995
6996**System capability**: SystemCapability.Sensors.Sensor
6997
6998**Parameters**
6999
7000| Name              | Type                 | Mandatory  | Description     |
7001| ----------------- | ------------------- | ---- | ------- |
7002| inclinationMatrix | Array&lt;number&gt; | Yes   | Inclination matrix.|
7003
7004**Return value**
7005
7006| Type                 | Description                                    |
7007| --------------------- | ---------------------------------------- |
7008| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|
7009
7010**Example**
7011
7012```ts
7013import { sensor } from '@kit.SensorServiceKit';
7014import { BusinessError } from '@kit.BasicServicesKit';
7015
7016const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
7017promise.then((data: number) => {
7018  console.info('Succeeded in get GeomagneticDip_promise', data);
7019}).catch((err: BusinessError) => {
7020  console.error(`Failed to operate.`);
7021})
7022```
7023
7024## sensor. getAngleModify<sup>(deprecated)</sup>
7025
7026getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
7027
7028Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result.
7029
7030> **NOTE**
7031>
7032> This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9)<sup>9+</sup> instead.
7033
7034**System capability**: SystemCapability.Sensors.Sensor
7035
7036**Parameters**
7037
7038| Name               | Type                                    | Mandatory| Description                                 |
7039| --------------------- | ---------------------------------------- | ---- | ------------------------------------- |
7040| currentRotationMatrix | Array&lt;number&gt;                      | Yes  | Current rotation matrix.                   |
7041| preRotationMatrix     | Array&lt;number&gt;                      | Yes  | Peer rotation matrix.                       |
7042| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the angle change around the z, x, and y axes.|
7043
7044**Example**
7045
7046```ts
7047import { sensor } from '@kit.SensorServiceKit';
7048import { BusinessError } from '@kit.BasicServicesKit';
7049
7050sensor.getAngleModify([1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87],
7051                      (err: BusinessError, data: Array<number>) => {
7052  if (err) {
7053    console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`);
7054    return;
7055  }
7056  for (let i = 0; i < data.length; i++) {
7057    console.info("data[" + i + "]: " + data[i]);
7058  }
7059})
7060```
7061
7062## sensor. getAngleModify<sup>(deprecated)</sup>
7063
7064getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
7065
7066Obtains the angle change between two rotation matrices. This API uses a promise to return the result.
7067
7068> **NOTE**
7069>
7070> This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9-1)<sup>9+</sup> instead.
7071
7072**System capability**: SystemCapability.Sensors.Sensor
7073
7074**Parameters**
7075
7076| Name                  | Type                 | Mandatory  | Description       |
7077| --------------------- | ------------------- | ---- | --------- |
7078| currentRotationMatrix | Array&lt;number&gt; | Yes   | Current rotation matrix.|
7079| preRotationMatrix     | Array&lt;number&gt; | Yes   | Rotation vector to rotate.  |
7080
7081**Return value**
7082
7083| Type                              | Description                                         |
7084| ---------------------------------- | --------------------------------------------- |
7085| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes.|
7086
7087**Example**
7088
7089```ts
7090import { sensor } from '@kit.SensorServiceKit';
7091import { BusinessError } from '@kit.BasicServicesKit';
7092
7093const 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]);
7094promise.then((data: Array<number>) => {
7095  console.info('Succeeded in getting AngleModify_promise.');
7096  for (let i = 0; i < data.length; i++) {
7097    console.info("Succeeded in getting data[" + i + "]: " + data[i]);
7098  }
7099}).catch((reason: BusinessError) => {
7100  let e: BusinessError = reason as BusinessError;
7101  console.info("Succeeded in getting promise::catch", e);
7102})
7103```
7104
7105## sensor.createRotationMatrix<sup>(deprecated)</sup>
7106
7107createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
7108
7109Converts a rotation vector into a rotation matrix. This API uses an asynchronous callback to return the result.
7110
7111> **NOTE**
7112>
7113> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9)<sup>9+</sup> instead.
7114
7115**System capability**: SystemCapability.Sensors.Sensor
7116
7117**Parameters**
7118
7119| Name        | Type                                    | Mandatory| Description              |
7120| -------------- | ---------------------------------------- | ---- | ------------------ |
7121| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector to convert.    |
7122| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation matrix.|
7123
7124**Example**
7125
7126```ts
7127import { sensor } from '@kit.SensorServiceKit';
7128import { BusinessError } from '@kit.BasicServicesKit';
7129
7130sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877],
7131                            (err: BusinessError, data: Array<number>) => {
7132  if (err) {
7133    console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`);
7134    return;
7135  }
7136  for (let i = 0; i < data.length; i++) {
7137    console.info("Succeeded in getting data[" + i + "]: " + data[i]);
7138  }
7139})
7140```
7141
7142## sensor.createRotationMatrix<sup>(deprecated)</sup>
7143
7144createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
7145
7146Converts a rotation vector into a rotation matrix. This API uses a promise to return the result.
7147
7148> **NOTE**
7149>
7150> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)<sup>9+</sup> instead.
7151
7152**System capability**: SystemCapability.Sensors.Sensor
7153
7154**Parameters**
7155
7156| Name           | Type                 | Mandatory  | Description     |
7157| -------------- | ------------------- | ---- | ------- |
7158| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
7159
7160**Return value**
7161
7162| Type                              | Description                      |
7163| ---------------------------------- | -------------------------- |
7164| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|
7165
7166**Example**
7167
7168 ```ts
7169import { sensor } from '@kit.SensorServiceKit';
7170import { BusinessError } from '@kit.BasicServicesKit';
7171
7172const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
7173promise.then((data: Array<number>) => {
7174  console.info('Succeeded in getting createRotationMatrix_promise');
7175  for (let i = 0; i < data.length; i++) {
7176    console.info("data[" + i + "]: " + data[i]);
7177  }
7178}).catch((reason: BusinessError) => {
7179  console.info("Succeeded in getting promise::catch", reason);
7180})
7181 ```
7182
7183## sensor.createQuaternion<sup>(deprecated)</sup>
7184
7185createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
7186
7187Converts a rotation vector into a quaternion. This API uses an asynchronous callback to return the result.
7188
7189> **NOTE**
7190>
7191> This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9)<sup>9+</sup> instead.
7192
7193**System capability**: SystemCapability.Sensors.Sensor
7194
7195**Parameters**
7196
7197| Name        | Type                                    | Mandatory| Description            |
7198| -------------- | ---------------------------------------- | ---- | ---------------- |
7199| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector to convert.  |
7200| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the quaternion.|
7201
7202**Example**
7203
7204```ts
7205import { sensor } from '@kit.SensorServiceKit';
7206import { BusinessError } from '@kit.BasicServicesKit';
7207
7208sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877],
7209                        (err: BusinessError, data: Array<number>) => {
7210  if (err) {
7211    console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`);
7212    return;
7213  }
7214  for (let i = 0; i < data.length; i++) {
7215    console.info("Succeeded in getting data[" + i + "]: " + data[i]);
7216  }
7217})
7218```
7219
7220## sensor.createQuaternion<sup>(deprecated)</sup>
7221
7222createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
7223
7224Converts a rotation vector into a quaternion. This API uses a promise to return the result.
7225
7226> **NOTE**
7227>
7228> This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9-1)<sup>9+</sup> instead.
7229
7230**System capability**: SystemCapability.Sensors.Sensor
7231
7232**Parameters**
7233
7234| Name           | Type                 | Mandatory  | Description     |
7235| -------------- | ------------------- | ---- | ------- |
7236| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
7237
7238**Return value**
7239
7240| Type                              | Description                    |
7241| ---------------------------------- | ------------------------ |
7242| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
7243
7244**Example**
7245
7246```ts
7247import { sensor } from '@kit.SensorServiceKit';
7248import { BusinessError } from '@kit.BasicServicesKit';
7249
7250const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
7251promise.then((data: Array<number>) => {
7252  console.info('Succeeded in getting createQuaternion_promise');
7253  for (let i = 0; i < data.length; i++) {
7254    console.info("data[" + i + "]: " + data[i]);
7255  }
7256}).catch((err: BusinessError) => {
7257  console.info(`Failed to get promise.`);
7258})
7259```
7260
7261## sensor.getDirection<sup>(deprecated)</sup>
7262
7263getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
7264
7265Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result.
7266
7267> **NOTE**
7268>
7269> This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9)<sup>9+</sup> instead.
7270
7271**System capability**: SystemCapability.Sensors.Sensor
7272
7273**Parameters**
7274
7275| Name        | Type                                    | Mandatory| Description                                 |
7276| -------------- | ---------------------------------------- | ---- | ------------------------------------- |
7277| rotationMatrix | Array&lt;number&gt;                      | Yes  | Peer rotation matrix.                       |
7278| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation angle around the z, x, and y axes.|
7279
7280**Example**
7281
7282```ts
7283import { sensor } from '@kit.SensorServiceKit';
7284import { BusinessError } from '@kit.BasicServicesKit';
7285
7286sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], (err: BusinessError, data: Array<number>) => {
7287  if (err) {
7288    console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`);
7289    return;
7290  }
7291  console.info("Succeeded in getting getDirection interface get data: " + data);
7292  for (let i = 1; i < data.length; i++) {
7293    console.info("Succeeded in getting sensor_getDirection_callback" + data[i]);
7294  }
7295})
7296```
7297
7298## sensor.getDirection<sup>(deprecated)</sup>
7299
7300getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
7301
7302Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.
7303
7304> **NOTE**
7305>
7306> This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9-1)<sup>9+</sup> instead.
7307
7308**System capability**: SystemCapability.Sensors.Sensor
7309
7310**Parameters**
7311
7312| Name           | Type                 | Mandatory  | Description     |
7313| -------------- | ------------------- | ---- | ------- |
7314| rotationMatrix | Array&lt;number&gt; | Yes   | Rotation vector to rotate.|
7315
7316**Return value**
7317
7318| Type                              | Description                                         |
7319| ---------------------------------- | --------------------------------------------- |
7320| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes.|
7321
7322**Example**
7323
7324```ts
7325import { sensor } from '@kit.SensorServiceKit';
7326import { BusinessError } from '@kit.BasicServicesKit';
7327
7328const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
7329promise.then((data: Array<number>) => {
7330  console.info('Succeeded in getting sensor_getAltitude_Promise', data);
7331  for (let i = 1; i < data.length; i++) {
7332    console.info("Succeeded in getting sensor_getDirection_promise" + data[i]);
7333  }
7334}).catch((err: BusinessError) => {
7335  console.info(`Failed to get promise.`);
7336})
7337```
7338
7339## sensor.createRotationMatrix<sup>(deprecated)</sup>
7340
7341createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
7342
7343Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result.
7344
7345> **NOTE**
7346>
7347> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)<sup>9+</sup> instead.
7348
7349**System capability**: SystemCapability.Sensors.Sensor
7350
7351**Parameters**
7352
7353| Name     | Type                                                        | Mandatory| Description              |
7354| ----------- | ------------------------------------------------------------ | ---- | ------------------ |
7355| gravity     | Array&lt;number&gt;                                          | Yes  | Gravity vector.    |
7356| geomagnetic | Array&lt;number&gt;                                          | Yes  | Geomagnetic vector.    |
7357| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes  | Callback used to return the rotation matrix.|
7358
7359**Example**
7360
7361```ts
7362import { sensor } from '@kit.SensorServiceKit';
7363import { BusinessError } from '@kit.BasicServicesKit';
7364
7365sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444],
7366                            (err: BusinessError, data: sensor.RotationMatrixResponse) => {
7367  if (err) {
7368    console.error(`Failed to get create rotationMatrix. Code: ${err.code}, message: ${err.message}`);
7369    return;
7370  }
7371  console.info(JSON.stringify(data));
7372})
7373```
7374
7375## sensor.createRotationMatrix<sup>(deprecated)</sup>
7376
7377createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;): Promise&lt;RotationMatrixResponse&gt;
7378
7379Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result.
7380
7381> **NOTE**
7382>
7383> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)<sup>9+</sup> instead.
7384
7385**System capability**: SystemCapability.Sensors.Sensor
7386
7387**Parameters**
7388
7389| Name        | Type                 | Mandatory  | Description     |
7390| ----------- | ------------------- | ---- | ------- |
7391| gravity     | Array&lt;number&gt; | Yes   | Gravity vector.|
7392| geomagnetic | Array&lt;number&gt; | Yes   | Geomagnetic vector.|
7393
7394**Return value**
7395
7396| Type                                                        | Description                      |
7397| ------------------------------------------------------------ | -------------------------- |
7398| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
7399
7400**Example**
7401
7402```ts
7403import { sensor } from '@kit.SensorServiceKit';
7404import { BusinessError } from '@kit.BasicServicesKit';
7405
7406const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
7407promise.then((data: sensor.RotationMatrixResponse) => {
7408  console.info(JSON.stringify(data));
7409}).catch((err: BusinessError) => {
7410  console.info(`Failed to get promise.`);
7411})
7412```
7413