• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 matrix.|
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².|
4321| y    | number | Yes  | Yes  | Acceleration along the y-axis of the device, in m/s².|
4322| z    | number | Yes  | Yes  | Acceleration along the z-axis of the device, in m/s².|
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.|
4382| beta  | number | Yes  | Yes  | Rotation angle of the device around the x-axis, in degrees.|
4383| gamma | number | Yes  | Yes  | Rotation angle of the device around the y-axis, in degrees.|
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.|
4413| y    | number | Yes  | Yes  | Angular velocity of rotation around the y-axis of the device, in rad/s.|
4414| z    | number | Yes  | Yes  | Angular velocity of rotation around the z-axis of the device, in rad/s.|
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
4668## LocationOptions
4669
4670Describes the geographical location.
4671
4672**System capability**: SystemCapability.Sensors.Sensor
4673
4674| Name     | Type  | Readable| Writable| Description      |
4675| --------- | ------ | ---- | ---- | ---------- |
4676| latitude  | number | Yes  | Yes  | Latitude.    |
4677| longitude | number | Yes  | Yes  | Longitude.    |
4678| altitude  | number | Yes  | Yes  | Altitude.|
4679
4680## sensor.on<sup>(deprecated)</sup>
4681
4682### ACCELEROMETER<sup>(deprecated)</sup>
4683
4684on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
4685
4686Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4687
4688> **NOTE**
4689>
4690> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER](#accelerometer9)<sup>9+</sup> instead.
4691
4692**Required permissions**: ohos.permission.ACCELEROMETER
4693
4694**System capability**: SystemCapability.Sensors.Sensor
4695
4696**Parameters**
4697
4698| Name  | Type                                                        | Mandatory| Description                                                        |
4699| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4700| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.    |
4701| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
4702| 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. |
4703
4704**Example**
4705
4706```ts
4707import { sensor } from '@kit.SensorServiceKit';
4708
4709sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
4710  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4711  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4712  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4713},
4714  { interval: 100000000 }
4715);
4716```
4717
4718### LINEAR_ACCELERATION<sup>(deprecated)</sup>
4719
4720on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void
4721
4722Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4723
4724> **NOTE**
4725>
4726> This API is deprecated since API version 9. You are advised to use [sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)<sup>9+</sup> instead.
4727
4728**Required permissions**: ohos.permission.ACCELEROMETER
4729
4730**System capability**: SystemCapability.Sensors.Sensor
4731
4732**Parameters**
4733
4734| Name  | Type                                                        | Mandatory| Description                                                        |
4735| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4736| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
4737| 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**.|
4738| 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. |
4739
4740### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
4741
4742on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
4743
4744Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
4745
4746> **NOTE**
4747>
4748> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)<sup>9+</sup> instead.
4749
4750**Required permissions**: ohos.permission.ACCELEROMETER
4751
4752**System capability**: SystemCapability.Sensors.Sensor
4753
4754**Parameters**
4755
4756| Name  | Type                                                        | Mandatory| Description                                                        |
4757| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4758| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
4759| 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**.|
4760| 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. |
4761
4762**Example**
4763
4764```ts
4765import { sensor } from '@kit.SensorServiceKit';
4766
4767sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
4768  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4769  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4770  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4771  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4772  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4773  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4774},
4775  { interval: 100000000 }
4776);
4777
4778```
4779
4780### GRAVITY<sup>(deprecated)</sup>
4781
4782on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void
4783
4784Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect.
4785
4786> **NOTE**
4787>
4788> This API is deprecated since API version 9. You are advised to use [sensor.on.GRAVITY](#gravity9)<sup>9+</sup> instead.
4789
4790**System capability**: SystemCapability.Sensors.Sensor
4791
4792**Parameters**
4793
4794| Name  | Type                                                      | Mandatory| Description                                                       |
4795| -------- | ---------------------------------------------------------- | ---- | ----------------------------------------------------------- |
4796| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.           |
4797| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | Yes  | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
4798| 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.|
4799
4800**Example**
4801
4802```ts
4803import { sensor } from '@kit.SensorServiceKit';
4804
4805sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
4806  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4807  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4808  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4809},
4810  { interval: 100000000 }
4811);
4812```
4813
4814### GYROSCOPE<sup>(deprecated)</sup>
4815
4816on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
4817
4818Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
4819
4820> **NOTE**
4821>
4822> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE](#gyroscope9)<sup>9+</sup> instead.
4823
4824**Required permissions**: ohos.permission.GYROSCOPE
4825
4826**System capability**: SystemCapability.Sensors.Sensor
4827
4828**Parameters**
4829
4830| Name  | Type                                                        | Mandatory| Description                                                        |
4831| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4832| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.        |
4833| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | Yes  | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
4834| 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. |
4835
4836**Example**
4837
4838```ts
4839import { sensor } from '@kit.SensorServiceKit';
4840
4841sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
4842  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4843  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4844  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4845},
4846  { interval: 100000000 }
4847);
4848```
4849
4850### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
4851
4852on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;, options?: Options): void
4853
4854Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
4855
4856> **NOTE**
4857>
4858> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)<sup>9+</sup> instead.
4859
4860**Required permissions**: ohos.permission.GYROSCOPE
4861
4862**System capability**: SystemCapability.Sensors.Sensor
4863
4864**Parameters**
4865
4866| Name  | Type                                                        | Mandatory| Description                                                        |
4867| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4868| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
4869| 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**.|
4870| 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. |
4871
4872**Example**
4873
4874```ts
4875import { sensor } from '@kit.SensorServiceKit';
4876
4877sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
4878  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4879  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4880  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4881  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4882  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4883  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4884},
4885  { interval: 100000000 }
4886);
4887```
4888
4889### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
4890
4891on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;, options?: Options): void
4892
4893Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect.
4894
4895> **NOTE**
4896>
4897> This API is deprecated since API version 9. You are advised to use [sensor.on.SIGNIFICANT_MOTION](#significant_motion9)<sup>9+</sup> instead.
4898
4899**System capability**: SystemCapability.Sensors.Sensor
4900
4901**Parameters**
4902
4903| Name  | Type                                                        | Mandatory| Description                                                        |
4904| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4905| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
4906| 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**.|
4907| 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. |
4908
4909**Example**
4910
4911```ts
4912import { sensor } from '@kit.SensorServiceKit';
4913
4914sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
4915  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4916},
4917  { interval: 100000000 }
4918);
4919```
4920
4921### PEDOMETER_DETECTION<sup>(deprecated)</sup>
4922
4923on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;, options?: Options): void
4924
4925Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect.
4926
4927> **NOTE**
4928>
4929> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)<sup>9+</sup> instead.
4930
4931**Required permissions**: ohos.permission.ACTIVITY_MOTION
4932
4933**System capability**: SystemCapability.Sensors.Sensor
4934
4935**Parameters**
4936
4937| Name  | Type                                                        | Mandatory| Description                                                        |
4938| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4939| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
4940| 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**.|
4941| 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. |
4942
4943**Example**
4944
4945```ts
4946import { sensor } from '@kit.SensorServiceKit';
4947
4948sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
4949  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4950},
4951  { interval: 100000000 }
4952);
4953```
4954
4955### PEDOMETER<sup>(deprecated)</sup>
4956
4957on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
4958
4959Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect.
4960
4961> **NOTE**
4962>
4963> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER](#pedometer9)<sup>9+</sup> instead.
4964
4965**Required permissions**: ohos.permission.ACTIVITY_MOTION
4966
4967**System capability**: SystemCapability.Sensors.Sensor
4968
4969**Parameters**
4970
4971| Name  | Type                                                        | Mandatory| Description                                                        |
4972| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4973| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.          |
4974| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | Yes  | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
4975| 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. |
4976
4977**Example**
4978
4979```ts
4980import { sensor } from '@kit.SensorServiceKit';
4981
4982sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
4983  console.info('Succeeded in invoking on. Steps: ' + data.steps);
4984},
4985  { interval: 100000000 }
4986);
4987```
4988
4989### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
4990
4991on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;AmbientTemperatureResponse&gt;,  options?: Options): void
4992
4993Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect.
4994
4995> **NOTE**
4996>
4997> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)<sup>9+</sup> instead.
4998
4999**System capability**: SystemCapability.Sensors.Sensor
5000
5001**Parameters**
5002
5003| Name  | Type                                                        | Mandatory| Description                                                        |
5004| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5005| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
5006| 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**.|
5007| 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. |
5008
5009**Example**
5010
5011```ts
5012import { sensor } from '@kit.SensorServiceKit';
5013
5014sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5015  console.info('Succeeded in invoking on. Temperature: ' + data.temperature);
5016},
5017  { interval: 100000000 }
5018);
5019```
5020
5021### MAGNETIC_FIELD<sup>(deprecated)</sup>
5022
5023on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
5024
5025Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.
5026
5027> **NOTE**
5028>
5029> This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD](#magnetic_field9)<sup>9+</sup> instead.
5030
5031**System capability**: SystemCapability.Sensors.Sensor
5032
5033**Parameters**
5034
5035| Name  | Type                                                        | Mandatory| Description                                                        |
5036| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5037| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.     |
5038| 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**.|
5039| 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. |
5040
5041**Example**
5042
5043```ts
5044import { sensor } from '@kit.SensorServiceKit';
5045
5046sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5047  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5048  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5049  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5050},
5051  { interval: 100000000 }
5052);
5053```
5054
5055### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5056
5057on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
5058
5059Subscribes 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.
5060
5061> **NOTE**
5062>
5063> 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.
5064
5065**System capability**: SystemCapability.Sensors.Sensor
5066
5067**Parameters**
5068
5069| Name  | Type                                                        | Mandatory| Description                                                        |
5070| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5071| 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**.|
5072| 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**.|
5073| 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. |
5074
5075**Example**
5076
5077```ts
5078import { sensor } from '@kit.SensorServiceKit';
5079
5080sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5081  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5082  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5083  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5084  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
5085  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
5086  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
5087},
5088  { interval: 100000000 }
5089);
5090```
5091
5092### PROXIMITY<sup>(deprecated)</sup>
5093
5094on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;,options?: Options): void
5095
5096Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.
5097
5098> **NOTE**
5099>
5100> This API is deprecated since API version 9. You are advised to use [sensor.on.PROXIMITY](#proximity9)<sup>9+</sup> instead.
5101
5102**System capability**: SystemCapability.Sensors.Sensor
5103
5104**Parameters**
5105
5106| Name  | Type                                                        | Mandatory| Description                                                        |
5107| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5108| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.        |
5109| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | Yes  | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
5110| 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.|
5111
5112**Example**
5113
5114```ts
5115import { sensor } from '@kit.SensorServiceKit';
5116
5117sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5118  console.info('Succeeded in invoking on. Distance: ' + data.distance);
5119},
5120  { interval: 100000000 }
5121);
5122```
5123
5124### HUMIDITY<sup>(deprecated)</sup>
5125
5126on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
5127
5128Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect.
5129
5130> **NOTE**
5131>
5132> This API is deprecated since API version 9. You are advised to use [sensor.on.HUMIDITY](#humidity9)<sup>9+</sup> instead.
5133
5134**System capability**: SystemCapability.Sensors.Sensor
5135
5136**Parameters**
5137
5138| Name  | Type                                                       | Mandatory| Description                                                        |
5139| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5140| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.           |
5141| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | Yes  | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
5142| 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. |
5143
5144**Example**
5145
5146```ts
5147import { sensor } from '@kit.SensorServiceKit';
5148
5149sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5150  console.info('Succeeded in invoking on. Humidity: ' + data.humidity);
5151},
5152  { interval: 100000000 }
5153);
5154```
5155
5156### BAROMETER<sup>(deprecated)</sup>
5157
5158on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;,options?: Options): void
5159
5160Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
5161
5162> **NOTE**
5163>
5164> This API is deprecated since API version 9. You are advised to use [sensor.on.BAROMETER](#barometer9)<sup>9+</sup> instead.
5165
5166**System capability**: SystemCapability.Sensors.Sensor
5167
5168**Parameters**
5169
5170| Name  | Type                                                        | Mandatory| Description                                                        |
5171| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5172| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.        |
5173| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | Yes  | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
5174| 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. |
5175
5176**Example**
5177
5178```ts
5179import { sensor } from '@kit.SensorServiceKit';
5180
5181sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5182  console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure);
5183},
5184  { interval: 100000000 }
5185);
5186```
5187
5188### HALL<sup>(deprecated)</sup>
5189
5190on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
5191
5192Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect.
5193
5194> **NOTE**
5195>
5196> This API is deprecated since API version 9. You are advised to use [sensor.on.HALL](#hall9)<sup>9+</sup> instead.
5197
5198**System capability**: SystemCapability.Sensors.Sensor
5199
5200**Parameters**
5201
5202| Name  | Type                                                   | Mandatory| Description                                                        |
5203| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5204| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.               |
5205| 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**.|
5206| 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.|
5207
5208**Example**
5209
5210```ts
5211import { sensor } from '@kit.SensorServiceKit';
5212
5213sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5214  console.info('Succeeded in invoking on. Status: ' + data.status);
5215},
5216  { interval: 100000000 }
5217);
5218```
5219
5220### AMBIENT_LIGHT<sup>(deprecated)</sup>
5221
5222on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
5223
5224Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect.
5225
5226> **NOTE**
5227>
5228> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_LIGHT](#ambient_light9)<sup>9+</sup> instead.
5229
5230**System capability**: SystemCapability.Sensors.Sensor
5231
5232**Parameters**
5233
5234| Name  | Type                                                        | Mandatory| Description                                                       |
5235| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
5236| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.   |
5237| 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**.|
5238| 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.|
5239
5240**Example**
5241
5242```ts
5243import { sensor } from '@kit.SensorServiceKit';
5244
5245sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5246  console.info('Succeeded in invoking on. Illumination: ' + data.intensity);
5247},
5248  { interval: 100000000 }
5249);
5250```
5251
5252### ORIENTATION<sup>(deprecated)</sup>
5253
5254on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
5255
5256Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect.
5257
5258> **NOTE**
5259>
5260> This API is deprecated since API version 9. You are advised to use [sensor.on.ORIENTATION](#orientation9)<sup>9+</sup> instead.
5261
5262**System capability**: SystemCapability.Sensors.Sensor
5263
5264**Parameters**
5265
5266| Name  | Type                                                        | Mandatory| Description                                                        |
5267| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5268| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.        |
5269| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | Yes  | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
5270| 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. |
5271
5272**Example**
5273
5274```ts
5275import { sensor } from '@kit.SensorServiceKit';
5276
5277sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5278  console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
5279  console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
5280  console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
5281},
5282  { interval: 100000000 }
5283);
5284```
5285
5286### HEART_RATE<sup>(deprecated)</sup>
5287
5288on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
5289
5290Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect.
5291
5292> **NOTE**
5293>
5294> This API is deprecated since API version 9. You are advised to use [sensor.on.HEART_RATE](#heart_rate9)<sup>9+</sup> instead.
5295
5296**Required permissions**: ohos.permission.HEALTH_DATA
5297
5298**System capability**: SystemCapability.Sensors.Sensor
5299
5300**Parameters**
5301
5302| Name  | Type                                                        | Mandatory| Description                                                        |
5303| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5304| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.         |
5305| 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**.|
5306| 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. |
5307
5308### ROTATION_VECTOR<sup>(deprecated)</sup>
5309
5310on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;RotationVectorResponse&gt;,options?: Options): void
5311
5312Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect.
5313
5314> **NOTE**
5315>
5316> This API is deprecated since API version 9. You are advised to use [sensor.on.ROTATION_VECTOR](#rotation_vector9)<sup>9+</sup> instead.
5317
5318**System capability**: SystemCapability.Sensors.Sensor
5319
5320**Parameters**
5321
5322| Name  | Type                                                        | Mandatory| Description                                                        |
5323| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5324| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
5325| 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**.|
5326| 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. |
5327
5328**Example**
5329
5330```ts
5331import { sensor } from '@kit.SensorServiceKit';
5332
5333sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5334  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5335  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5336  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5337  console.info('Succeeded in invoking on. Scalar quantity: ' + data.w);
5338},
5339  { interval: 100000000 }
5340);
5341```
5342
5343### WEAR_DETECTION<sup>(deprecated)</sup>
5344
5345on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,options?: Options): void
5346
5347Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect.
5348
5349> **NOTE**
5350>
5351> This API is deprecated since API version 9. You are advised to use [sensor.on.WEAR_DETECTION](#wear_detection9)<sup>9+</sup> instead.
5352
5353**System capability**: SystemCapability.Sensors.Sensor
5354
5355**Parameters**
5356
5357| Name  | Type                                                        | Mandatory| Description                                                        |
5358| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5359| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
5360| 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**.|
5361| 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. |
5362
5363**Example**
5364
5365```ts
5366import { sensor } from '@kit.SensorServiceKit';
5367
5368sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
5369  console.info('Succeeded in invoking on. Wear status: ' + data.value);
5370},
5371  { interval: 100000000 }
5372);
5373```
5374
5375## sensor.once<sup>(deprecated)</sup>
5376
5377### ACCELEROMETER<sup>(deprecated)</sup>
5378
5379once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
5380
5381Subscribes to only one data change of the acceleration sensor.
5382
5383> **NOTE**
5384>
5385> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER](#accelerometer9-1)<sup>9+</sup> instead.
5386
5387**Required permissions**: ohos.permission.ACCELEROMETER
5388
5389**System capability**: SystemCapability.Sensors.Sensor
5390
5391**Parameters**
5392
5393| Name  | Type                                                        | Mandatory| Description                                                        |
5394| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5395| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.            |
5396| 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**.|
5397
5398**Example**
5399
5400```ts
5401import { sensor } from '@kit.SensorServiceKit';
5402
5403sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
5404  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5405  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5406  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5407});
5408```
5409
5410### LINEAR_ACCELERATION<sup>(deprecated)</sup>
5411
5412once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;): void
5413
5414Subscribes to only one data change of the linear acceleration sensor.
5415
5416> **NOTE**
5417>
5418> This API is deprecated since API version 9. You are advised to use [sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)<sup>9+</sup> instead.
5419
5420**Required permissions**: ohos.permission.ACCELERATION
5421
5422**System capability**: SystemCapability.Sensors.Sensor
5423
5424**Parameters**
5425
5426| Name  | Type                                                        | Mandatory| Description                                                        |
5427| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5428| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.  |
5429| 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**.|
5430
5431### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
5432
5433once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
5434
5435Subscribes to only one data change of the uncalibrated acceleration sensor.
5436
5437> **NOTE**
5438>
5439> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)<sup>9+</sup> instead.
5440
5441**Required permissions**: ohos.permission.ACCELEROMETER
5442
5443**System capability**: SystemCapability.Sensors.Sensor
5444
5445**Parameters**
5446
5447| Name  | Type                                                        | Mandatory| Description                                                        |
5448| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5449| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
5450| 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**.|
5451
5452**Example**
5453
5454```ts
5455import { sensor } from '@kit.SensorServiceKit';
5456
5457sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
5458  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5459  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5460  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5461  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5462  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5463  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5464});
5465```
5466
5467### GRAVITY<sup>(deprecated)</sup>
5468
5469once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
5470
5471Subscribes to only one data change of the gravity sensor.
5472
5473> **NOTE**
5474>
5475> This API is deprecated since API version 9. You are advised to use [sensor.once.GRAVITY](#gravity9-1)<sup>9+</sup> instead.
5476
5477**System capability**: SystemCapability.Sensors.Sensor
5478
5479**Parameters**
5480
5481| Name  | Type                                                      | Mandatory| Description                                                        |
5482| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5483| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.                    |
5484| 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**.|
5485
5486**Example**
5487
5488```ts
5489import { sensor } from '@kit.SensorServiceKit';
5490
5491sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
5492  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5493  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5494  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5495  });
5496```
5497
5498### GYROSCOPE<sup>(deprecated)</sup>
5499
5500once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
5501
5502Subscribes to only one data change of the gyroscope sensor.
5503
5504> **NOTE**
5505>
5506> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE](#gyroscope9-1)<sup>9+</sup> instead.
5507
5508**Required permissions**: ohos.permission.GYROSCOPE
5509
5510**System capability**: SystemCapability.Sensors.Sensor
5511
5512**Parameters**
5513
5514| Name  | Type                                                        | Mandatory| Description                                                        |
5515| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5516| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.                |
5517| 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**.|
5518
5519**Example**
5520
5521```ts
5522import { sensor } from '@kit.SensorServiceKit';
5523
5524sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
5525  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5526  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5527  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5528});
5529```
5530
5531### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
5532
5533once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
5534
5535Subscribes to only one data change of the uncalibrated gyroscope sensor.
5536
5537> **NOTE**
5538>
5539> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)<sup>9+</sup> instead.
5540
5541**Required permissions**: ohos.permission.GYROSCOPE
5542
5543**System capability**: SystemCapability.Sensors.Sensor
5544
5545**Parameters**
5546
5547| Name  | Type                                                        | Mandatory| Description                                                        |
5548| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5549| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
5550| 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**.|
5551
5552**Example**
5553
5554
5555```ts
5556import { sensor } from '@kit.SensorServiceKit';
5557
5558sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
5559    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5560    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5561    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5562    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5563    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5564    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5565});
5566```
5567
5568### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
5569
5570once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void
5571
5572Subscribes to only one data change of the significant motion sensor.
5573
5574> **NOTE**
5575>
5576> This API is deprecated since API version 9. You are advised to use [sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)<sup>9+</sup> instead.
5577
5578**System capability**: SystemCapability.Sensors.Sensor
5579
5580**Parameters**
5581
5582| Name  | Type                                                        | Mandatory| Description                                                        |
5583| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5584| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.     |
5585| 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**.|
5586
5587**Example**
5588
5589```ts
5590import { sensor } from '@kit.SensorServiceKit';
5591
5592sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
5593  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5594});
5595```
5596
5597### PEDOMETER_DETECTION<sup>(deprecated)</sup>
5598
5599once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void
5600
5601Subscribes to only one data change of the pedometer detection sensor.
5602
5603> **NOTE**
5604>
5605> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)<sup>9+</sup> instead.
5606
5607**Required permissions**: ohos.permission.ACTIVITY_MOTION
5608
5609**System capability**: SystemCapability.Sensors.Sensor
5610
5611**Parameters**
5612
5613| Name  | Type                                                        | Mandatory| Description                                                        |
5614| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5615| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.    |
5616| 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**.|
5617
5618**Example**
5619
5620```ts
5621import { sensor } from '@kit.SensorServiceKit';
5622
5623sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
5624  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5625});
5626```
5627
5628### PEDOMETER<sup>(deprecated)</sup>
5629
5630once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
5631
5632Subscribes to only one data change of the pedometer sensor.
5633
5634> **NOTE**
5635>
5636> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER](#pedometer9-1)<sup>9+</sup> instead.
5637
5638**Required permissions**: ohos.permission.ACTIVITY_MOTION
5639
5640**System capability**: SystemCapability.Sensors.Sensor
5641
5642**Parameters**
5643
5644| Name  | Type                                                        | Mandatory| Description                                                        |
5645| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5646| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.                  |
5647| 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**.|
5648
5649**Example**
5650
5651```ts
5652import { sensor } from '@kit.SensorServiceKit';
5653
5654sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
5655  console.info('Succeeded in invoking once. Steps: ' + data.steps);
5656});
5657```
5658
5659### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
5660
5661once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void
5662
5663Subscribes to only one data change of the ambient temperature sensor.
5664
5665> **NOTE**
5666>
5667> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)<sup>9+</sup> instead.
5668
5669**System capability**: SystemCapability.Sensors.Sensor
5670
5671**Parameters**
5672
5673| Name  | Type                                                        | Mandatory| Description                                                        |
5674| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5675| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.    |
5676| 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**.|
5677
5678**Example**
5679
5680```ts
5681import { sensor } from '@kit.SensorServiceKit';
5682
5683sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5684  console.info('Succeeded in invoking once. Temperature: ' + data.temperature);
5685});
5686```
5687
5688### MAGNETIC_FIELD<sup>(deprecated)</sup>
5689
5690once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
5691
5692Subscribes to only one data change of the magnetic field sensor.
5693
5694> **NOTE**
5695>
5696> This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)<sup>9+</sup> instead.
5697
5698**System capability**: SystemCapability.Sensors.Sensor
5699
5700**Parameters**
5701
5702| Name  | Type                                                        | Mandatory| Description                                                        |
5703| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5704| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.             |
5705| 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**.|
5706
5707**Example**
5708
5709```ts
5710import { sensor } from '@kit.SensorServiceKit';
5711
5712sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5713  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5714  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5715  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5716});
5717```
5718
5719### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5720
5721once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
5722
5723Subscribes to only one data change of the uncalibrated magnetic field sensor.
5724
5725> **NOTE**
5726>
5727> 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.
5728
5729**System capability**: SystemCapability.Sensors.Sensor
5730
5731**Parameters**
5732
5733| Name  | Type                                                        | Mandatory| Description                                                        |
5734| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5735| 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**.|
5736| 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**.|
5737
5738**Example**
5739
5740```ts
5741import { sensor } from '@kit.SensorServiceKit';
5742
5743sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5744  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5745  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5746  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5747  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5748  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5749  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5750});
5751```
5752
5753### PROXIMITY<sup>(deprecated)</sup>
5754
5755once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
5756
5757Subscribes to only one data change of the proximity sensor.
5758
5759> **NOTE**
5760>
5761> This API is deprecated since API version 9. You are advised to use [sensor.once.PROXIMITY](#proximity9-1)<sup>9+</sup> instead.
5762
5763**System capability**: SystemCapability.Sensors.Sensor
5764
5765**Parameters**
5766
5767| Name  | Type                                                        | Mandatory| Description                                                        |
5768| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5769| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.                |
5770| 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**.|
5771
5772**Example**
5773
5774```ts
5775import { sensor } from '@kit.SensorServiceKit';
5776
5777sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5778  console.info('Succeeded in invoking once. Distance: ' + data.distance);
5779}
5780);
5781```
5782
5783### HUMIDITY<sup>(deprecated)</sup>
5784
5785once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
5786
5787Subscribes to only one data change of the humidity sensor.
5788
5789> **NOTE**
5790>
5791> This API is deprecated since API version 9. You are advised to use [sensor.once.HUMIDITY](#humidity9-1)<sup>9+</sup> instead.
5792
5793**System capability**: SystemCapability.Sensors.Sensor
5794
5795**Parameters**
5796
5797| Name  | Type                                                       | Mandatory| Description                                                        |
5798| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5799| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.                   |
5800| 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**.|
5801
5802**Example**
5803
5804```ts
5805import { sensor } from '@kit.SensorServiceKit';
5806
5807sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5808  console.info('Succeeded in invoking once. Humidity: ' + data.humidity);
5809});
5810```
5811
5812### BAROMETER<sup>(deprecated)</sup>
5813
5814once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
5815
5816Subscribes to only one data change of the barometer sensor.
5817
5818> **NOTE**
5819>
5820> This API is deprecated since API version 9. You are advised to use [sensor.once.BAROMETER](#barometer9-1)<sup>9+</sup> instead.
5821
5822**System capability**: SystemCapability.Sensors.Sensor
5823
5824**Parameters**
5825
5826| Name  | Type                                                        | Mandatory| Description                                                        |
5827| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5828| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.                |
5829| 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**.|
5830
5831**Example**
5832
5833```ts
5834import { sensor } from '@kit.SensorServiceKit';
5835
5836sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5837  console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure);
5838});
5839```
5840
5841### HALL<sup>(deprecated)</sup>
5842
5843once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
5844
5845Subscribes to only one data change of the Hall effect sensor.
5846
5847> **NOTE**
5848>
5849> This API is deprecated since API version 9. You are advised to use [sensor.once.HALL](#hall9-1)<sup>9+</sup> instead.
5850
5851**System capability**: SystemCapability.Sensors.Sensor
5852
5853**Parameters**
5854
5855| Name  | Type                                                   | Mandatory| Description                                                        |
5856| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5857| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.                       |
5858| 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**.|
5859
5860**Example**
5861
5862```ts
5863import { sensor } from '@kit.SensorServiceKit';
5864
5865sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5866  console.info('Succeeded in invoking once. Status: ' + data.status);
5867});
5868```
5869
5870### AMBIENT_LIGHT<sup>(deprecated)</sup>
5871
5872once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
5873
5874Subscribes to only one data change of the ambient light sensor.
5875
5876> **NOTE**
5877>
5878> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_LIGHT](#ambient_light9-1)<sup>9+</sup> instead.
5879
5880**System capability**: SystemCapability.Sensors.Sensor
5881
5882**Parameters**
5883
5884| Name  | Type                                                        | Mandatory| Description                                                        |
5885| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5886| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.            |
5887| 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**.|
5888
5889**Example**
5890
5891```ts
5892import { sensor } from '@kit.SensorServiceKit';
5893
5894sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5895  console.info('Succeeded in invoking once. invoking once. Illumination: ' + data.intensity);
5896});
5897```
5898
5899### ORIENTATION<sup>(deprecated)</sup>
5900
5901once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
5902
5903Subscribes to only one data change of the orientation sensor.
5904
5905> **NOTE**
5906>
5907> This API is deprecated since API version 9. You are advised to use [sensor.once.ORIENTATION](#orientation9-1)<sup>9+</sup> instead.
5908
5909**System capability**: SystemCapability.Sensors.Sensor
5910
5911**Parameters**
5912
5913| Name  | Type                                                        | Mandatory| Description                                                        |
5914| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5915| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.                |
5916| 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**.|
5917
5918**Example**
5919
5920```ts
5921import { sensor } from '@kit.SensorServiceKit';
5922
5923sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5924  console.info('Succeeded in invoking the device rotateing at an angle around the X axis: ' + data.beta);
5925  console.info('Succeeded in invoking the device rotateing at an angle around the Y axis: ' + data.gamma);
5926  console.info('Succeeded in invoking the device rotateing at an angle around the Z axis: ' + data.alpha);
5927});
5928```
5929
5930### ROTATION_VECTOR<sup>(deprecated)</sup>
5931
5932once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
5933
5934Subscribes to only one data change of the rotation vector sensor.
5935
5936> **NOTE**
5937>
5938> This API is deprecated since API version 9. You are advised to use [sensor.once.ROTATION_VECTOR](#rotation_vector9-1)<sup>9+</sup> instead.
5939
5940**System capability**: SystemCapability.Sensors.Sensor
5941
5942**Parameters**
5943
5944| Name  | Type                                                        | Mandatory| Description                                                        |
5945| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5946| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.        |
5947| 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**.|
5948
5949**Example**
5950
5951```ts
5952import { sensor } from '@kit.SensorServiceKit';
5953
5954sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5955  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5956  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5957  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5958  console.info('Succeeded in invoking once. Scalar quantity: ' + data.w);
5959});
5960```
5961
5962### HEART_RATE<sup>(deprecated)</sup>
5963
5964once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
5965
5966Subscribes to only one data change of the heart rate sensor.
5967
5968> **NOTE**
5969>
5970> This API is deprecated since API version 9. You are advised to use [sensor.once.HEART_RATE](#heart_rate9-1)<sup>9+</sup> instead.
5971
5972**Required permissions**: ohos.permission.HEART_RATE
5973
5974**System capability**: SystemCapability.Sensors.Sensor
5975
5976**Parameters**
5977
5978| Name  | Type                                                        | Mandatory| Description                                                        |
5979| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5980| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.                 |
5981| 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**.|
5982
5983**Example**
5984
5985
5986```ts
5987import { sensor } from '@kit.SensorServiceKit';
5988
5989sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, (data: sensor.HeartRateResponse) => {
5990  console.info("Succeeded in invoking once. Heart rate: " + data.heartRate);
5991});
5992```
5993
5994### WEAR_DETECTION<sup>(deprecated)</sup>
5995
5996once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
5997
5998Subscribes to only one data change of the wear detection sensor.
5999
6000> **NOTE**
6001>
6002> This API is deprecated since API version 9. You are advised to use [sensor.once.WEAR_DETECTION](#wear_detection9-1)<sup>9+</sup> instead.
6003
6004**System capability**: SystemCapability.Sensors.Sensor
6005
6006**Parameters**
6007
6008| Name  | Type                                                        | Mandatory| Description                                                        |
6009| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6010| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.         |
6011| 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**.|
6012
6013**Example**
6014
6015
6016```ts
6017import { sensor } from '@kit.SensorServiceKit';
6018
6019sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
6020  console.info("Succeeded in invoking once. Wear status: " + data.value);
6021});
6022```
6023
6024## sensor.off<sup>(deprecated)</sup>
6025
6026### ACCELEROMETER<sup>(deprecated)</sup>
6027
6028off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
6029
6030Unsubscribes from sensor data changes.
6031
6032> **NOTE**
6033>
6034> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER<sup>9+</sup>](#accelerometer9-2) instead.
6035
6036**Required permissions**: ohos.permission.ACCELEROMETER
6037
6038**System capability**: SystemCapability.Sensors.Sensor
6039
6040**Parameters**
6041
6042| Name  | Type                                                        | Mandatory| Description                                                        |
6043| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6044| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
6045| 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.|
6046
6047**Example**
6048
6049```ts
6050import { sensor } from '@kit.SensorServiceKit';
6051
6052function callback(data: sensor.AccelerometerResponse) {
6053  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6054  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6055  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6056}
6057
6058sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
6059```
6060
6061### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
6062
6063off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
6064
6065Unsubscribes from sensor data changes.
6066
6067> **NOTE**
6068>
6069> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)<sup>9+</sup> instead.
6070
6071**Required permissions**: ohos.permission.ACCELEROMETER
6072
6073**System capability**: SystemCapability.Sensors.Sensor
6074
6075**Parameters**
6076
6077| Name  | Type                                                        | Mandatory| Description                                                        |
6078| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6079| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
6080| 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.|
6081
6082**Example**
6083
6084```ts
6085import { sensor } from '@kit.SensorServiceKit';
6086
6087function callback(data: sensor.AccelerometerUncalibratedResponse) {
6088  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6089  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6090  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6091  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6092  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6093  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6094}
6095
6096sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
6097```
6098
6099### AMBIENT_LIGHT<sup>(deprecated)</sup>
6100
6101off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
6102
6103Unsubscribes from sensor data changes.
6104
6105> **NOTE**
6106>
6107> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_LIGHT](#ambient_light9-2)<sup>9+</sup> instead.
6108
6109**System capability**: SystemCapability.Sensors.Sensor
6110
6111**Parameters**
6112
6113| Name  | Type                                                        | Mandatory| Description                                                        |
6114| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6115| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
6116| 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.|
6117
6118**Example**
6119
6120```ts
6121import { sensor } from '@kit.SensorServiceKit';
6122
6123function callback(data: sensor.LightResponse) {
6124  console.info('Succeeded in invoking off. Illumination: ' + data.intensity);
6125}
6126
6127sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
6128```
6129
6130### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
6131
6132off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
6133
6134Unsubscribes from sensor data changes.
6135
6136> **NOTE**
6137>
6138> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)<sup>9+</sup> instead.
6139
6140**System capability**: SystemCapability.Sensors.Sensor
6141
6142**Parameters**
6143
6144| Name  | Type                                                        | Mandatory| Description                                                        |
6145| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6146| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
6147| 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.|
6148
6149**Example**
6150
6151```ts
6152import { sensor } from '@kit.SensorServiceKit';
6153
6154function callback(data: sensor.AmbientTemperatureResponse) {
6155  console.info('Succeeded in invoking off. Temperature: ' + data.temperature);
6156}
6157
6158sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
6159```
6160
6161### BAROMETER<sup>(deprecated)</sup>
6162
6163off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
6164
6165Unsubscribes from sensor data changes.
6166
6167> **NOTE**
6168>
6169> This API is deprecated since API version 9. You are advised to use [sensor.off.BAROMETER](#barometer9-2)<sup>9+</sup> instead.
6170
6171**System capability**: SystemCapability.Sensors.Sensor
6172
6173**Parameters**
6174
6175| Name  | Type                                                        | Mandatory| Description                                                        |
6176| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6177| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**.    |
6178| 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.|
6179
6180**Example**
6181
6182```ts
6183import { sensor } from '@kit.SensorServiceKit';
6184
6185function callback(data: sensor.BarometerResponse) {
6186  console.info('Succeeded in invoking off. Atmospheric pressure: ' + data.pressure);
6187}
6188
6189sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
6190```
6191
6192### GRAVITY<sup>(deprecated)</sup>
6193
6194off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
6195
6196Unsubscribes from sensor data changes.
6197
6198> **NOTE**
6199>
6200> This API is deprecated since API version 9. You are advised to use [sensor.off.GRAVITY](#gravity9-2)<sup>9+</sup> instead.
6201
6202**System capability**: SystemCapability.Sensors.Sensor
6203
6204**Parameters**
6205
6206| Name  | Type                                                      | Mandatory| Description                                                        |
6207| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6208| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**.        |
6209| 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.|
6210
6211**Example**
6212
6213```ts
6214import { sensor } from '@kit.SensorServiceKit';
6215
6216function callback(data: sensor.GravityResponse) {
6217  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6218  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6219  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6220}
6221
6222sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
6223```
6224
6225### GYROSCOPE<sup>(deprecated)</sup>
6226
6227off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
6228
6229Unsubscribes from sensor data changes.
6230
6231> **NOTE**
6232>
6233> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE](#gyroscope9-2)<sup>9+</sup> instead.
6234
6235**Required permissions**: ohos.permission.GYROSCOPE
6236
6237**System capability**: SystemCapability.Sensors.Sensor
6238
6239**Parameters**
6240
6241| Name  | Type                                                        | Mandatory| Description                                                        |
6242| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6243| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**.    |
6244| 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.|
6245
6246**Example**
6247
6248```ts
6249import { sensor } from '@kit.SensorServiceKit';
6250
6251function callback(data: sensor.GyroscopeResponse) {
6252  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6253  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6254  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6255}
6256
6257sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
6258```
6259
6260### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
6261
6262off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
6263
6264Unsubscribes from sensor data changes.
6265
6266> **NOTE**
6267>
6268> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)<sup>9+</sup> instead.
6269
6270**Required permissions**: ohos.permission.GYROSCOPE
6271
6272**System capability**: SystemCapability.Sensors.Sensor
6273
6274**Parameters**
6275
6276| Name  | Type                                                        | Mandatory| Description                                                        |
6277| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6278| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
6279| 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.|
6280
6281**Example**
6282
6283```ts
6284import { sensor } from '@kit.SensorServiceKit';
6285
6286function callback(data: sensor.GyroscopeUncalibratedResponse) {
6287  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6288  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6289  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6290}
6291
6292sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
6293```
6294
6295### HALL<sup>(deprecated)</sup>
6296
6297off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
6298
6299Unsubscribes from sensor data changes.
6300
6301> **NOTE**
6302>
6303> This API is deprecated since API version 9. You are advised to use [sensor.off.HALL](#hall9-2)<sup>9+</sup> instead.
6304
6305**System capability**: SystemCapability.Sensors.Sensor
6306
6307**Parameters**
6308
6309| Name  | Type                                                   | Mandatory| Description                                                        |
6310| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6311| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**.           |
6312| 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.|
6313
6314**Example**
6315
6316```ts
6317import { sensor } from '@kit.SensorServiceKit';
6318
6319function callback(data: sensor.HallResponse) {
6320  console.info('Succeeded in invoking off. Status: ' + data.status);
6321}
6322
6323sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
6324```
6325
6326### HEART_RATE<sup>(deprecated)</sup>
6327
6328off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
6329
6330Unsubscribes from sensor data changes.
6331
6332> **NOTE**
6333>
6334> This API is deprecated since API version 9. You are advised to use [sensor.off.HEART_RATE](#heart_rate9-2)<sup>9+</sup> instead.
6335
6336**Required permissions**: ohos.permission.HEALTH_DATA
6337
6338**System capability**: SystemCapability.Sensors.Sensor
6339
6340**Parameters**
6341
6342| Name  | Type                                                        | Mandatory| Description                                                        |
6343| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6344| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**.     |
6345| 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.|
6346
6347**Example**
6348
6349```ts
6350import { sensor } from '@kit.SensorServiceKit';
6351
6352function callback(data: sensor.HeartRateResponse) {
6353  console.info('Succeeded in invoking off. Humidity: ' + data.heartRate);
6354}
6355
6356sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
6357```
6358
6359### HUMIDITY<sup>(deprecated)</sup>
6360
6361off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
6362
6363Unsubscribes from sensor data changes.
6364
6365> **NOTE**
6366>
6367> This API is deprecated since API version 9. You are advised to use [sensor.off.HUMIDITY](#humidity9-2)<sup>9+</sup> instead.
6368
6369**System capability**: SystemCapability.Sensors.Sensor
6370
6371**Parameters**
6372
6373| Name  | Type                                                       | Mandatory| Description                                                        |
6374| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6375| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**.       |
6376| 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.|
6377
6378**Example**
6379
6380```ts
6381import { sensor } from '@kit.SensorServiceKit';
6382
6383function callback(data: sensor.HumidityResponse) {
6384  console.info('Succeeded in invoking off. Humidity: ' + data.humidity);
6385}
6386
6387sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
6388```
6389
6390### LINEAR_ACCELERATION<sup>(deprecated)</sup>
6391
6392off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
6393
6394Unsubscribes from sensor data changes.
6395
6396> **NOTE**
6397>
6398> This API is deprecated since API version 9. You are advised to use [sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)<sup>9+</sup> instead.
6399
6400**Required permissions**: ohos.permission.ACCELEROMETER
6401
6402**System capability**: SystemCapability.Sensors.Sensor
6403
6404**Parameters**
6405
6406| Name  | Type                                                        | Mandatory| Description                                                        |
6407| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6408| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
6409| 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.|
6410
6411**Example**
6412
6413```ts
6414import { sensor } from '@kit.SensorServiceKit';
6415
6416function callback(data: sensor.LinearAccelerometerResponse) {
6417  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6418  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6419  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6420}
6421
6422sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
6423```
6424
6425### MAGNETIC_FIELD<sup>(deprecated)</sup>
6426
6427 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
6428
6429Unsubscribes from sensor data changes.
6430
6431> **NOTE**
6432>
6433> This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)<sup>9+</sup> instead.
6434
6435**System capability**: SystemCapability.Sensors.Sensor
6436
6437**Parameters**
6438
6439| Name  | Type                                                        | Mandatory| Description                                                        |
6440| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6441| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
6442| 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.|
6443
6444**Example**
6445
6446```ts
6447import { sensor } from '@kit.SensorServiceKit';
6448
6449function callback(data: sensor.MagneticFieldResponse) {
6450  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6451  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6452  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6453}
6454
6455sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
6456```
6457
6458### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
6459
6460 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
6461
6462Unsubscribes from sensor data changes.
6463
6464> **NOTE**
6465>
6466> 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.
6467
6468**System capability**: SystemCapability.Sensors.Sensor
6469
6470**Parameters**
6471
6472| Name  | Type                                                        | Mandatory| Description                                                        |
6473| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6474| 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**.|
6475| 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.|
6476
6477**Example**
6478
6479```ts
6480import { sensor } from '@kit.SensorServiceKit';
6481
6482function callback(data: sensor.MagneticFieldUncalibratedResponse) {
6483  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6484  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6485  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6486  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6487  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6488  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6489}
6490
6491sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
6492```
6493
6494### ORIENTATION<sup>(deprecated)</sup>
6495
6496 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
6497
6498Unsubscribes from sensor data changes.
6499
6500> **NOTE**
6501>
6502> This API is deprecated since API version 9. You are advised to use [sensor.off.ORIENTATION](#orientation9-2)<sup>9+</sup> instead.
6503
6504**System capability**: SystemCapability.Sensors.Sensor
6505
6506**Parameters**
6507
6508| Name  | Type                                                        | Mandatory| Description                                                        |
6509| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6510| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**.    |
6511| 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.|
6512
6513**Example**
6514
6515```ts
6516import { sensor } from '@kit.SensorServiceKit';
6517
6518function callback(data: sensor.OrientationResponse) {
6519  console.info('Succeeded in invoking off. The device rotates at an angle around the X axis: ' + data.beta);
6520  console.info('Succeeded in invoking off. The device rotates at an angle around the Y axis: ' + data.gamma);
6521  console.info('Succeeded in invoking off. The device rotates at an angle around the Z axis: ' + data.alpha);
6522}
6523
6524sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
6525```
6526
6527### PEDOMETER<sup>(deprecated)</sup>
6528
6529off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
6530
6531Unsubscribes from sensor data changes.
6532
6533> **NOTE**
6534>
6535> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER](#pedometer9-2)<sup>9+</sup> instead.
6536
6537**Required permissions**: ohos.permission.ACTIVITY_MOTION
6538
6539**System capability**: SystemCapability.Sensors.Sensor
6540
6541**Parameters**
6542
6543| Name  | Type                                                        | Mandatory| Description                                                        |
6544| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6545| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**.      |
6546| 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.|
6547
6548**Example**
6549
6550```ts
6551import { sensor } from '@kit.SensorServiceKit';
6552
6553function callback(data: sensor.PedometerResponse) {
6554  console.info('Succeeded in invoking off. Steps: ' + data.steps);
6555}
6556
6557sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
6558```
6559
6560### PEDOMETER_DETECTION<sup>(deprecated)</sup>
6561
6562off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
6563
6564Unsubscribes from sensor data changes.
6565
6566> **NOTE**
6567>
6568> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)<sup>9+</sup> instead.
6569
6570**Required permissions**: ohos.permission.ACTIVITY_MOTION
6571
6572**System capability**: SystemCapability.Sensors.Sensor
6573
6574**Parameters**
6575
6576| Name  | Type                                                        | Mandatory| Description                                                        |
6577| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6578| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
6579| 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.|
6580
6581**Example**
6582
6583```ts
6584import { sensor } from '@kit.SensorServiceKit';
6585
6586function callback(data: sensor.PedometerDetectionResponse) {
6587  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6588}
6589
6590sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
6591```
6592
6593### PROXIMITY<sup>(deprecated)</sup>
6594
6595off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
6596
6597Unsubscribes from sensor data changes.
6598
6599> **NOTE**
6600>
6601> This API is deprecated since API version 9. You are advised to use [sensor.off.PROXIMITY](#proximity9-2)<sup>9+</sup> instead.
6602
6603**System capability**: SystemCapability.Sensors.Sensor
6604
6605**Parameters**
6606
6607| Name  | Type                                                        | Mandatory| Description                                                        |
6608| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6609| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**.    |
6610| 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.|
6611
6612**Example**
6613
6614```ts
6615import { sensor } from '@kit.SensorServiceKit';
6616
6617function callback(data: sensor.ProximityResponse) {
6618  console.info('Succeeded in invoking off. Distance: ' + data.distance);
6619}
6620
6621sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
6622```
6623
6624### ROTATION_VECTOR<sup>(deprecated)</sup>
6625
6626off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
6627
6628Unsubscribes from sensor data changes.
6629
6630> **NOTE**
6631>
6632> This API is deprecated since API version 9. You are advised to use [sensor.off.ROTATION_VECTOR](#rotation_vector9-2)<sup>9+</sup> instead.
6633
6634**System capability**: SystemCapability.Sensors.Sensor
6635
6636**Parameters**
6637
6638| Name  | Type                                                        | Mandatory| Description                                                        |
6639| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6640| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
6641| 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.|
6642
6643**Example**
6644
6645```ts
6646import { sensor } from '@kit.SensorServiceKit';
6647
6648function callback(data: sensor.RotationVectorResponse) {
6649  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6650  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6651  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6652  console.info('Succeeded in invoking off. Scalar quantity: ' + data.w);
6653}
6654
6655sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
6656```
6657
6658### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
6659
6660off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
6661
6662Unsubscribes from sensor data changes.
6663
6664> **NOTE**
6665>
6666> This API is deprecated since API version 9. You are advised to use [sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)<sup>9+</sup> instead.
6667
6668**System capability**: SystemCapability.Sensors.Sensor
6669
6670**Parameters**
6671
6672| Name  | Type                                                        | Mandatory| Description                                                        |
6673| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6674| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
6675| 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.|
6676
6677**Example**
6678
6679```ts
6680import { sensor } from '@kit.SensorServiceKit';
6681
6682function callback(data: sensor.SignificantMotionResponse) {
6683  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6684}
6685
6686sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
6687```
6688
6689### WEAR_DETECTION<sup>(deprecated)</sup>
6690
6691off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
6692
6693Unsubscribes from sensor data changes.
6694
6695> **NOTE**
6696>
6697> This API is deprecated since API version 9. You are advised to use [sensor.off.WEAR_DETECTION](#wear_detection9-2)<sup>9+</sup> instead.
6698
6699**System capability**: SystemCapability.Sensors.Sensor
6700
6701**Parameters**
6702
6703| Name  | Type                                                        | Mandatory| Description                                                        |
6704| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6705| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes  | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
6706| 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.|
6707
6708**Example**
6709
6710```ts
6711import { sensor } from '@kit.SensorServiceKit';
6712
6713function accCallback(data: sensor.WearDetectionResponse) {
6714  console.info('Succeeded in invoking off. Wear status: ' + data.value);
6715}
6716
6717sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
6718```
6719
6720## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6721
6722transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
6723
6724Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses an asynchronous callback to return the result.
6725
6726> **NOTE**
6727>
6728> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9)<sup>9+</sup> instead.
6729
6730**System capability**: SystemCapability.Sensors.Sensor
6731
6732**Parameters**
6733
6734| Name          | Type                                     | Mandatory| Description                      |
6735| ---------------- | ----------------------------------------- | ---- | -------------------------- |
6736| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector to rotate.            |
6737| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Direction of the coordinate system.          |
6738| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes  | Callback used to return the rotation vector after being rotated.|
6739
6740**Example**
6741
6742```ts
6743import { sensor } from '@kit.SensorServiceKit';
6744import { BusinessError } from '@kit.BasicServicesKit';
6745
6746sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 },
6747                                 (err: BusinessError, data: Array<number>) => {
6748  if (err) {
6749    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6750    return;
6751  }
6752  console.info("Succeeded in starting Operation. Data obtained: " + data);
6753  for (let i = 0; i < data.length; i++) {
6754    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6755  }
6756})
6757```
6758## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6759
6760transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
6761
6762Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.
6763
6764> **NOTE**
6765>
6766> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)<sup>9+</sup> instead.
6767
6768**System capability**: SystemCapability.Sensors.Sensor
6769
6770**Parameters**
6771
6772| Name             | Type                                      | Mandatory  | Description      |
6773| ---------------- | ---------------------------------------- | ---- | -------- |
6774| inRotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to rotate. |
6775| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.|
6776
6777**Return value**
6778
6779| Type                              | Description                              |
6780| ---------------------------------- | ---------------------------------- |
6781| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|
6782
6783**Example**
6784
6785```ts
6786import { sensor } from '@kit.SensorServiceKit';
6787import { BusinessError } from '@kit.BasicServicesKit';
6788
6789const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 });
6790promise.then((data: Array<number>) => {
6791  console.info("Succeeded in starting Operation");
6792  for (let i = 0; i < data.length; i++) {
6793    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6794  }
6795}).catch((err: BusinessError) => {
6796  console.error(`Failed to operate.`);
6797})
6798```
6799
6800## sensor.getGeomagneticField<sup>(deprecated)</sup>
6801
6802getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
6803
6804Obtains the geomagnetic field of a geographic location. This API uses an asynchronous callback to return the result.
6805
6806> **NOTE**
6807>
6808> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)<sup>9+</sup> instead.
6809
6810**System capability**: SystemCapability.Sensors.Sensor
6811
6812**Parameters**
6813
6814| Name         | Type                                                        | Mandatory| Description                              |
6815| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
6816| locationOptions | [LocationOptions](#locationoptions)                          | Yes  | Geographic location.                        |
6817| timeMillis      | number                                                       | Yes  | Time for obtaining the magnetic declination, in milliseconds.|
6818| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes  | Callback used to return the geomagnetic field.                |
6819
6820**Example**
6821
6822```ts
6823import { sensor } from '@kit.SensorServiceKit';
6824import { BusinessError } from '@kit.BasicServicesKit';
6825
6826sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000,
6827                           (err: BusinessError, data: sensor.GeomagneticResponse) => {
6828  if (err) {
6829    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6830    return;
6831  }
6832  console.info('Succeeded in getting sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
6833  data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
6834  ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
6835});
6836```
6837## sensor.getGeomagneticField<sup>(deprecated)</sup>
6838
6839getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
6840
6841Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.
6842
6843> **NOTE**
6844>
6845> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)<sup>9+</sup> instead.
6846
6847**System capability**: SystemCapability.Sensors.Sensor
6848
6849**Parameters**
6850
6851| Name            | Type                                 | Mandatory  | Description               |
6852| --------------- | ----------------------------------- | ---- | ----------------- |
6853| locationOptions | [LocationOptions](#locationoptions) | Yes   | Geographic location.            |
6854| timeMillis      | number                              | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
6855
6856**Return value**
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   | Peer rotation matrix.  |
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   | Peer rotation matrix.|
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