1# @ohos.sensor (传感器)
2
3sensor模块提供了获取传感器数据的能力,包括获取传感器属性列表,订阅传感器数据,以及一些通用的传感器算法。
4
5> **说明:**
6>
7> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
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
21订阅加速度传感器数据。
22
23**需要权限**:ohos.permission.ACCELEROMETER
24
25**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
26
27**系统能力**:SystemCapability.Sensors.Sensor
28
29**参数**:
30
31| 参数名   | 类型                                                         | 必填 | 说明                                                        |
32| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
33| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。              |
34| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerResponse。 |
35| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
36
37**错误码**:
38
39以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
40
41| 错误码ID | 错误信息                                                     |
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**示例**:
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
72订阅未校准加速度传感器数据。
73
74**需要权限**:ohos.permission.ACCELEROMETER
75
76**系统能力**:SystemCapability.Sensors.Sensor
77
78**参数**:
79
80| 参数名   | 类型                                                         | 必填 | 说明                                                         |
81| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
82| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
83| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerUncalibratedResponse。 |
84| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
85
86**错误码**:
87
88以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
89
90| 错误码ID | 错误信息                                                     |
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**示例**:
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
124订阅环境光传感器数据。
125
126**系统能力**:SystemCapability.Sensors.Sensor
127
128**参数**:
129
130| 参数名   | 类型                                            | 必填 | 说明                                                        |
131| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
132| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。              |
133| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LightResponse。         |
134| options  | [Options](#options)                             | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
135
136**错误码**:
137
138以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
139
140| 错误码ID | 错误信息                                                     |
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**示例**:
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
168订阅温度传感器数据。
169
170**系统能力**:SystemCapability.Sensors.Sensor
171
172**参数**:
173
174| 参数名   | 类型                                                         | 必填 | 说明                                                         |
175| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
176| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
177| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AmbientTemperatureResponse。 |
178| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
179
180**错误码**:
181
182以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
183
184| 错误码ID | 错误信息                                                     |
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**示例**:
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
212订阅气压计传感器数据。
213
214**系统能力**:SystemCapability.Sensors.Sensor
215
216**参数**:
217
218| 参数名   | 类型                                                    | 必填 | 说明                                                        |
219| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
220| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。                  |
221| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为BarometerResponse。     |
222| options  | [Options](#options)                                     | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
223
224**错误码**:
225
226以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
227
228| 错误码ID | 错误信息                                                     |
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**示例**:
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
256订阅重力传感器数据。
257
258**系统能力**:SystemCapability.Sensors.Sensor
259
260**参数**:
261
262| 参数名   | 类型                                                | 必填 | 说明                                                        |
263| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
264| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。                    |
265| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GravityResponse。       |
266| options  | [Options](#options)                                 | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
267
268**错误码**:
269
270以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
271
272| 错误码ID | 错误信息                                                     |
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**示例**:
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
302订阅校准的陀螺仪传感器数据。
303
304**需要权限**:ohos.permission.GYROSCOPE
305
306**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
307
308**系统能力**:SystemCapability.Sensors.Sensor
309
310**参数**:
311
312| 参数名   | 类型                                                    | 必填 | 说明                                                        |
313| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
314| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。                  |
315| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeResponse。     |
316| options  | [Options](#options)                                     | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
317
318**错误码**:
319
320以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
321
322| 错误码ID | 错误信息                                                     |
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**示例**:
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
354订阅未校准陀螺仪传感器数据。
355
356**需要权限**:ohos.permission.GYROSCOPE
357
358**系统能力**:SystemCapability.Sensors.Sensor
359
360**参数**:
361
362| 参数名   | 类型                                                         | 必填 | 说明                                                         |
363| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
364| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
365| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeUncalibratedResponse。 |
366| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
367
368**错误码**:
369
370以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
371
372| 错误码ID | 错误信息                                                     |
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**示例**:
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
407订阅霍尔传感器数据。
408
409**系统能力**:SystemCapability.Sensors.Sensor
410
411**参数**:
412
413| 参数名   | 类型                                          | 必填 | 说明                                                         |
414| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
415| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。                        |
416| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HallResponse。           |
417| options  | [Options](#options)                           | 否   | 可选参数列表,默认值为200000000ns。当霍尔事件被触发的很频繁时,该参数用于限定事件上报的频率。 |
418
419**错误码**:
420
421以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
422
423| 错误码ID | 错误信息                                                     |
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**示例**:
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
452订阅心率传感器数据。
453
454**需要权限**:ohos.permission.READ_HEALTH_DATA
455
456**系统能力**:SystemCapability.Sensors.Sensor
457
458**参数**:
459
460| 参数名   | 类型                                                    | 必填 | 说明                                                        |
461| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
462| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。                 |
463| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HeartRateResponse。     |
464| options  | [Options](#options)                                     | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
465
466**错误码**:
467
468以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
469
470| 错误码ID | 错误信息                                                     |
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**示例**:
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
499订阅湿度传感器数据。
500
501**系统能力**:SystemCapability.Sensors.Sensor
502
503**参数**:
504
505| 参数名   | 类型                                                  | 必填 | 说明                                                        |
506| -------- | ----------------------------------------------------- | ---- | ----------------------------------------------------------- |
507| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。                   |
508| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HumidityResponse。      |
509| options  | [Options](#options)                                   | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
510
511**错误码**:
512
513以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
514
515| 错误码ID | 错误信息                                                     |
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**示例**:
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
544订阅线性加速度传感器数据。
545
546**需要权限**:ohos.permission.ACCELEROMETER
547
548**系统能力**:SystemCapability.Sensors.Sensor
549
550**参数**:
551
552| 参数名   | 类型                                                         | 必填 | 说明                                                         |
553| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
554| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。        |
555| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LinearAccelerometerResponse。 |
556| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
557
558**错误码**:
559
560以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
561
562| 错误码ID | 错误信息                                                     |
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**示例**:
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
593订阅地磁传感器数据。
594
595**系统能力**:SystemCapability.Sensors.Sensor
596
597**参数**:
598
599| 参数名   | 类型                                                         | 必填 | 说明                                                        |
600| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
601| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。             |
602| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldResponse。 |
603| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
604
605**错误码**:
606
607以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
608
609| 错误码ID | 错误信息                                                     |
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**示例**:
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
639订阅未校准地磁传感器数据。
640
641**系统能力:** SystemCapability.Sensors.Sensor
642
643**参数**:
644
645| 参数名   | 类型                                                         | 必填 | 说明                                                         |
646| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
647| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
648| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldUncalibratedResponse。 |
649| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
650
651**错误码**:
652
653以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
654
655| 错误码ID | 错误信息                                                     |
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**示例**:
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
688订阅方向传感器数据。
689
690**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
691
692**系统能力**:SystemCapability.Sensors.Sensor
693
694**错误码**:
695
696以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
697
698| 错误码ID | 错误信息                                                     |
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**参数**:
704
705| 参数名   | 类型                                                        | 必填 | 说明                                                        |
706| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------------------------- |
707| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。                |
708| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为OrientationResponse。   |
709| options  | [Options](#options)                                         | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
710
711**示例**:
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
736订阅计步器传感器数据。
737
738**需要权限**:ohos.permission.ACTIVITY_MOTION
739
740**系统能力**:SystemCapability.Sensors.Sensor
741
742**错误码**:
743
744以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
745
746| 错误码ID | 错误信息                                                     |
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**参数**:
753
754| 参数名   | 类型                                                    | 必填 | 说明                                                        |
755| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- |
756| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。                  |
757| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerResponse。     |
758| options  | [Options](#options)                                     | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
759
760**示例**:
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
784订阅计步检测器传感器数据。
785
786**需要权限**:ohos.permission.ACTIVITY_MOTION
787
788**系统能力**:SystemCapability.Sensors.Sensor
789
790**参数**:
791
792| 参数名   | 类型                                                         | 必填 | 说明                                                         |
793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
794| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
795| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerDetectionResponse。 |
796| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
797
798**错误码**:
799
800以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
801
802| 错误码ID | 错误信息                                                     |
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**示例**:
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
831订阅接近光传感器数据。
832
833**系统能力**:SystemCapability.Sensors.Sensor
834
835**参数**:
836
837| 参数名   | 类型                                                    | 必填 | 说明                                                         |
838| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
839| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。                   |
840| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为ProximityResponse。      |
841| options  | [Options](#options)                                     | 否   | 可选参数列表,默认值为200000000ns。当接近光事件被触发的很频繁时,该参数用于限定事件上报的频率。 |
842
843**错误码**:
844
845以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
846
847| 错误码ID | 错误信息                                                     |
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**示例**:
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
876订阅旋转矢量传感器数据。
877
878**系统能力**:SystemCapability.Sensors.Sensor
879
880**参数**:
881
882| 参数名   | 类型                                                         | 必填 | 说明                                                         |
883| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
884| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
885| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为RotationVectorResponse。 |
886| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
887
888**错误码**:
889
890以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
891
892| 错误码ID | 错误信息                                                     |
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**示例**:
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
924订阅有效运动传感器数据。
925
926**系统能力**:SystemCapability.Sensors.Sensor
927
928**参数**:
929
930| 参数名   | 类型                                                         | 必填 | 说明                                                         |
931| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
932| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
933| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为SignificantMotionResponse。 |
934| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
935
936**错误码**:
937
938以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
939
940| 错误码ID | 错误信息                                                     |
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**示例**:
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
969订阅佩戴检测传感器数据。
970
971**系统能力**:SystemCapability.Sensors.Sensor
972
973**参数**:
974
975| 参数名   | 类型                                                         | 必填 | 说明                                                        |
976| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
977| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。             |
978| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为WearDetectionResponse。 |
979| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
980
981**错误码**:
982
983以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
984
985| 错误码ID | 错误信息                                                     |
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**示例**:
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
1015获取一次加速度传感器数据。
1016
1017**需要权限**:ohos.permission.ACCELEROMETER
1018
1019**系统能力**:SystemCapability.Sensors.Sensor
1020
1021**参数**:
1022
1023| 参数名   | 类型                                                         | 必填 | 说明                                                        |
1024| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1025| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。              |
1026| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerResponse。 |
1027
1028**错误码**:
1029
1030以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1031
1032| 错误码ID | 错误信息                                                     |
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**示例**:
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
1060获取一次未校准加速度传感器数据。
1061
1062**需要权限**:ohos.permission.ACCELEROMETER
1063
1064**系统能力**:SystemCapability.Sensors.Sensor
1065
1066**参数**:
1067
1068| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1069| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1070| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
1071| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerUncalibratedResponse。 |
1072
1073**错误码**:
1074
1075以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1076
1077| 错误码ID | 错误信息                                                     |
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**示例**:
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
1108获取一次环境光传感器数据。
1109
1110**系统能力**:SystemCapability.Sensors.Sensor
1111
1112**参数**:
1113
1114| 参数名   | 类型                                            | 必填 | 说明                                                |
1115| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
1116| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。      |
1117| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LightResponse。 |
1118
1119**错误码**:
1120
1121以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1122
1123| 错误码ID | 错误信息                                                     |
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**示例**:
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
1148获取一次温度传感器数据。
1149
1150**系统能力**:SystemCapability.Sensors.Sensor
1151
1152**参数**:
1153
1154| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1155| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1156| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
1157| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AmbientTemperatureResponse。 |
1158
1159**错误码**:
1160
1161以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1162
1163| 错误码ID | 错误信息                                                     |
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**示例**:
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
1188获取一次气压计传感器数据。
1189
1190**系统能力:** SystemCapability.Sensors.Sensor
1191
1192**参数**:
1193
1194| 参数名   | 类型                                                    | 必填 | 说明                                                    |
1195| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1196| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。              |
1197| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为BarometerResponse。 |
1198
1199**错误码**:
1200
1201以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1202
1203| 错误码ID | 错误信息                                                     |
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**示例**:
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
1228获取一次重力传感器数据。
1229
1230**系统能力**:SystemCapability.Sensors.Sensor
1231
1232**参数**:
1233
1234| 参数名   | 类型                                                | 必填 | 说明                                                  |
1235| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
1236| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。              |
1237| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GravityResponse。 |
1238
1239**错误码**:
1240
1241以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1242
1243| 错误码ID | 错误信息                                                     |
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**示例**:
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
1270获取一次陀螺仪传感器数据。
1271
1272**需要权限**:ohos.permission.GYROSCOPE
1273
1274**系统能力**:SystemCapability.Sensors.Sensor
1275
1276**参数**:
1277
1278| 参数名   | 类型                                                    | 必填 | 说明                                                    |
1279| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1280| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。              |
1281| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeResponse。 |
1282
1283**错误码**:
1284
1285以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1286
1287| 错误码ID | 错误信息                                                     |
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**示例**:
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
1315获取一次未校准陀螺仪传感器数据。
1316
1317**需要权限**:ohos.permission.GYROSCOPE
1318
1319**系统能力**:SystemCapability.Sensors.Sensor
1320
1321**参数**:
1322
1323| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1324| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1325| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
1326| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeUncalibratedResponse。 |
1327
1328**错误码**:
1329
1330以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1331
1332| 错误码ID | 错误信息                                                     |
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**示例**:
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
1363获取一次霍尔传感器数据。
1364
1365**系统能力**:SystemCapability.Sensors.Sensor
1366
1367**参数**:
1368
1369| 参数名   | 类型                                          | 必填 | 说明                                               |
1370| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
1371| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。              |
1372| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HallResponse。 |
1373
1374**错误码**:
1375
1376以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1377
1378| 错误码ID | 错误信息                                                     |
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**示例**:
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
1403获取一次心率传感器数据。
1404
1405**需要权限**:ohos.permission.READ_HEALTH_DATA
1406
1407**系统能力**:SystemCapability.Sensors.Sensor
1408
1409**参数**:
1410
1411| 参数名   | 类型                                                    | 必填 | 说明                                                    |
1412| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1413| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。             |
1414| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HeartRateResponse。 |
1415
1416**错误码**:
1417
1418以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1419
1420| 错误码ID | 错误信息                                                     |
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**示例**:
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
1446获取一次湿度传感器数据。
1447
1448**系统能力**:SystemCapability.Sensors.Sensor
1449
1450**参数**:
1451
1452| 参数名   | 类型                                                  | 必填 | 说明                                                   |
1453| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
1454| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。              |
1455| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HumidityResponse。 |
1456
1457**错误码**:
1458
1459以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1460
1461| 错误码ID | 错误信息                                                     |
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**示例**:
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
1486获取一次线性加速度传感器数据。
1487
1488**需要权限**:ohos.permission.ACCELEROMETER
1489
1490**系统能力**:SystemCapability.Sensors.Sensor
1491
1492**参数**:
1493
1494| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1495| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1496| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。        |
1497| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LinearAccelerometerResponse。 |
1498
1499**错误码**:
1500
1501以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1502
1503| 错误码ID | 错误信息                                                     |
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**示例**:
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
1531获取一次磁场传感器数据。
1532
1533**系统能力**:SystemCapability.Sensors.Sensor
1534
1535**参数**:
1536
1537| 参数名   | 类型                                                         | 必填 | 说明                                                        |
1538| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1539| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。             |
1540| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldResponse。 |
1541
1542**错误码**:
1543
1544以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1545
1546| 错误码ID | 错误信息                                                     |
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**示例**:
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
1573获取一次未经校准的磁场传感器数据。
1574
1575**系统能力**:SystemCapability.Sensors.Sensor
1576
1577**参数**:
1578
1579| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1580| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1581| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
1582| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldUncalibratedResponse。 |
1583
1584**错误码**:
1585
1586以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1587
1588| 错误码ID | 错误信息                                                     |
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**示例**:
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
1618获取一次方向传感器数据。
1619
1620**系统能力**:SystemCapability.Sensors.Sensor
1621
1622**参数**:
1623
1624| 参数名   | 类型                                                        | 必填 | 说明                                                      |
1625| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
1626| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。              |
1627| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为OrientationResponse。 |
1628
1629**错误码**:
1630
1631以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1632
1633| 错误码ID | 错误信息                                                     |
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**示例**:
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
1660获取一次计步器传感器数据。
1661
1662**需要权限**:ohos.permission.ACTIVITY_MOTION
1663
1664**系统能力**:SystemCapability.Sensors.Sensor
1665
1666**参数**:
1667
1668| 参数名   | 类型                                                    | 必填 | 说明                                                    |
1669| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1670| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。              |
1671| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerResponse。 |
1672
1673**错误码**:
1674
1675以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1676
1677| 错误码ID | 错误信息                                                     |
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**示例**:
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
1703获取一次计步检测器传感器数据。
1704
1705**系需要权限**:ohos.permission.ACTIVITY_MOTION
1706
1707**系统能力**:SystemCapability.Sensors.Sensor
1708
1709**参数**:
1710
1711| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1712| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1713| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
1714| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerDetectionResponse。 |
1715
1716**错误码**:
1717
1718以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1719
1720| 错误码ID | 错误信息                                                     |
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**示例**:
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
1746获取一次接近光传感器数据。
1747
1748**系统能力**:SystemCapability.Sensors.Sensor
1749
1750**参数**:
1751
1752| 参数名   | 类型                                                    | 必填 | 说明                                                    |
1753| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
1754| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。              |
1755| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为ProximityResponse。 |
1756
1757**错误码**:
1758
1759以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1760
1761| 错误码ID | 错误信息                                                     |
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**示例**:
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
1786获取一次旋转矢量传感器数据。
1787
1788**系统能力**:SystemCapability.Sensors.Sensor
1789
1790**参数**:
1791
1792| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1794| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
1795| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为RotationVectorResponse。 |
1796
1797**错误码**:
1798
1799以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1800
1801| 错误码ID | 错误信息                                                     |
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**示例**:
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
1829获取一次有效运动传感器数据。
1830
1831**系统能力**:SystemCapability.Sensors.Sensor
1832
1833**参数**:
1834
1835| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1836| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1837| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
1838| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为SignificantMotionResponse。 |
1839
1840**错误码**:
1841
1842以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1843
1844| 错误码ID | 错误信息                                                     |
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**示例**:
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
1869获取一次佩戴检测传感器数据。
1870
1871**系统能力**:SystemCapability.Sensors.Sensor
1872
1873**参数**:
1874
1875| 参数名   | 类型                                                         | 必填 | 说明                                                        |
1876| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
1877| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。             |
1878| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为WearDetectionResponse。 |
1879
1880**错误码**:
1881
1882以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
1883
1884| 错误码ID | 错误信息                                                     |
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**示例**:
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
1911取消订阅加速度传感器数据。
1912
1913**需要权限**:ohos.permission.ACCELEROMETER
1914
1915**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
1916
1917**系统能力**:SystemCapability.Sensors.Sensor
1918
1919**参数**:
1920
1921| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1922| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1923| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。               |
1924| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
1925
1926**错误码**:
1927
1928以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1929
1930| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
1953  sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
1954  // 取消SensorId.ACCELEROMETER类型的所有回调
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
1966取消订阅未校准加速度传感器数据。
1967
1968**需要权限**:ohos.permission.ACCELEROMETER
1969
1970**系统能力**:SystemCapability.Sensors.Sensor
1971
1972**参数**:
1973
1974| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1975| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1976| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
1977| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
1978
1979**错误码**:
1980
1981以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1982
1983| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2006  sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
2007  // 取消注册SensorId.ACCELEROMETER_UNCALIBRATED类型的所有回调
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
2019取消订阅环境光传感器数据。
2020
2021**系统能力**:SystemCapability.Sensors.Sensor
2022
2023**参数**:
2024
2025| 参数名   | 类型                                            | 必填 | 说明                                                         |
2026| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
2027| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。               |
2028| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2029
2030**错误码**:
2031
2032以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2033
2034| 错误码ID | 错误信息                                                     |
2035| -------- | ------------------------------------------------------------ |
2036| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2037
2038**示例**:
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  // 仅取消callback1的注册
2056  sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
2057  // 取消注册SensorId.AMBIENT_LIGHT
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
2069取消订阅温度传感器数据。
2070
2071**系统能力**:SystemCapability.Sensors.Sensor
2072
2073**参数**:
2074
2075| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2076| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2077| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
2078| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2079
2080**错误码**:
2081
2082以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2083
2084| 错误码ID | 错误信息                                                     |
2085| -------- | ------------------------------------------------------------ |
2086| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2087
2088**示例**:
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  // 仅取消callback1的注册
2106  sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
2107  // 取消注册SensorId.AMBIENT_TEMPERATURE的所有回调
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
2119取消订阅气压计传感器数据。
2120
2121**系统能力**:SystemCapability.Sensors.Sensor
2122
2123**参数**:
2124
2125| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2126| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2127| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。                   |
2128| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2129
2130**错误码**:
2131
2132以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2133
2134| 错误码ID | 错误信息                                                     |
2135| -------- | ------------------------------------------------------------ |
2136| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2137
2138**示例**:
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    // 仅取消callback1的注册
2156    sensor.off(sensor.SensorId.BAROMETER, callback1);
2157    // 取消注册SensorId.BAROMETER的所有回调
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
2169取消订阅重力传感器数据。
2170
2171**系统能力**:SystemCapability.Sensors.Sensor
2172
2173**参数**:
2174
2175| 参数名   | 类型                                                | 必填 | 说明                                                         |
2176| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
2177| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。                     |
2178| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2179
2180**错误码**:
2181
2182以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2183
2184| 错误码ID | 错误信息                                                     |
2185| -------- | ------------------------------------------------------------ |
2186| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2187
2188**示例**:
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  // 仅取消callback1的注册
2206  sensor.off(sensor.SensorId.GRAVITY, callback1);
2207  // 取消注册SensorId.GRAVITY的所有回调
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
2220取消订阅陀螺仪传感器数据。
2221
2222**需要权限**:ohos.permission.GYROSCOPE
2223
2224**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
2225
2226**系统能力**:SystemCapability.Sensors.Sensor
2227
2228**参数**:
2229
2230| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2231| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2232| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。                   |
2233| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2234
2235**错误码**:
2236
2237以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2238
2239| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2262  sensor.off(sensor.SensorId.GYROSCOPE, callback1);
2263  // 取消注册SensorId.GYROSCOPE的所有回调
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 取消订阅未校准陀螺仪传感器数据。
2276
2277**需要权限**:ohos.permission.GYROSCOPE
2278
2279**系统能力**:SystemCapability.Sensors.Sensor
2280
2281**参数**:
2282
2283| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2284| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2285| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
2286| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2287
2288**错误码**:
2289
2290以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2291
2292| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2315  sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
2316  // 取消注册SensorId.GYROSCOPE_UNCALIBRATED的所有回调
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
2328取消订阅霍尔传感器数据。
2329
2330**系统能力**:SystemCapability.Sensors.Sensor
2331
2332**参数**:
2333
2334| 参数名   | 类型                                          | 必填 | 说明                                                         |
2335| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
2336| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。                        |
2337| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2338
2339**错误码**:
2340
2341以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2342
2343| 错误码ID | 错误信息                                                     |
2344| -------- | ------------------------------------------------------------ |
2345| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2346
2347**示例**:
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  // 仅取消callback1的注册
2365  sensor.off(sensor.SensorId.HALL, callback1);
2366  // 取消注册SensorId.HALL的所有回调
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
2378取消订阅心率传感器数据。
2379
2380**需要权限**:ohos.permission.READ_HEALTH_DATA
2381
2382**系统能力**:SystemCapability.Sensors.Sensor
2383
2384**参数**:
2385
2386| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2387| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2388| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。                  |
2389| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2390
2391**错误码**:
2392
2393以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2394
2395| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2418  sensor.off(sensor.SensorId.HEART_RATE, callback1);
2419  // 取消注册SensorId.HEART_RATE的所有回调
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
2431取消订阅湿度传感器数据。
2432
2433**系统能力**:SystemCapability.Sensors.Sensor
2434
2435**参数**:
2436
2437| 参数名   | 类型                                                  | 必填 | 说明                                                         |
2438| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2439| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。                    |
2440| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2441
2442**错误码**:
2443
2444以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2445
2446| 错误码ID | 错误信息                                                     |
2447| -------- | ------------------------------------------------------------ |
2448| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2449
2450**示例**:
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  // 仅取消callback1的注册
2468  sensor.off(sensor.SensorId.HUMIDITY, callback1);
2469  // 取消注册SensorId.HUMIDITY的所有回调
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
2481取消订阅线性加速度传感器数据。
2482
2483**需要权限**:ohos.permission.ACCELEROMETER
2484
2485**系统能力**:SystemCapability.Sensors.Sensor
2486
2487**参数**:
2488
2489| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2490| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2491| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELERATION。         |
2492| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2493
2494**错误码**:
2495
2496以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2497
2498| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2521  sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
2522  // 取消注册SensorId.LINEAR_ACCELEROMETER的所有回调
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
2534取消订阅磁场传感器数据。
2535
2536**系统能力**:SystemCapability.Sensors.Sensor
2537
2538**参数**:
2539
2540| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2541| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2542| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。              |
2543| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2544
2545**错误码**:
2546
2547以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2548
2549| 错误码ID | 错误信息                                                     |
2550| -------- | ------------------------------------------------------------ |
2551| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2552
2553**示例**:
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  // 仅取消callback1的注册
2571  sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
2572  // 取消注册SensorId.MAGNETIC_FIELD的所有回调
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
2584取消订阅未校准的磁场传感器数据。
2585
2586**系统能力**:SystemCapability.Sensors.Sensor
2587
2588**参数**:
2589
2590| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2591| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2592| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
2593| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2594
2595**错误码**:
2596
2597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2598
2599| 错误码ID | 错误信息                                                     |
2600| -------- | ------------------------------------------------------------ |
2601| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2602
2603**示例**:
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  // 仅取消callback1的注册
2621  sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
2622  // 取消注册SensorId.MAGNETIC_FIELD_UNCALIBRATED的所有回调
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
2634取消订阅方向传感器数据。
2635
2636**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
2637
2638**系统能力**:SystemCapability.Sensors.Sensor
2639
2640**参数**:
2641
2642| 参数名   | 类型                                                        | 必填 | 说明                                                         |
2643| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2644| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。                 |
2645| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2646
2647**错误码**:
2648
2649以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2650
2651| 错误码ID | 错误信息                                                     |
2652| -------- | ------------------------------------------------------------ |
2653| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2654
2655**示例**:
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  // 仅取消callback1的注册
2673  sensor.off(sensor.SensorId.ORIENTATION, callback1);
2674  // 取消注册SensorId.ORIENTATION的所有回调
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
2686取消订阅计步器传感器数据。
2687
2688**需要权限**:ohos.permission.ACTIVITY_MOTION
2689
2690**系统能力**:SystemCapability.Sensors.Sensor
2691
2692**参数**:
2693
2694| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2695| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2696| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。                   |
2697| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2698
2699**错误码**:
2700
2701以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2702
2703| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2726  sensor.off(sensor.SensorId.PEDOMETER, callback1);
2727  // 取消注册SensorId.ORIENTATION的所有回调
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
2739取消订阅计步检测器传感器数据。
2740
2741**需要权限**:ohos.permission.ACTIVITY_MOTION
2742
2743**系统能力**:SystemCapability.Sensors.Sensor
2744
2745**参数**:
2746
2747| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2748| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2749| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
2750| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2751
2752**错误码**:
2753
2754以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2755
2756| 错误码ID | 错误信息                                                     |
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**示例**:
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  // 仅取消callback1的注册
2779  sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
2780  // 取消注册SensorId.PEDOMETER_DETECTION的所有回调
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
2792取消订阅接近光传感器数据。
2793
2794**系统能力**:SystemCapability.Sensors.Sensor
2795
2796**参数**:
2797
2798| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2799| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2800| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。                   |
2801| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2802
2803**错误码**:
2804
2805以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2806
2807| 错误码ID | 错误信息                                                     |
2808| -------- | ------------------------------------------------------------ |
2809| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2810
2811**示例**:
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  // 仅取消callback1的注册
2829  sensor.off(sensor.SensorId.PROXIMITY, callback1);
2830  // 取消注册SensorId.PROXIMITY的所有回调
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
2842取消订阅旋转矢量传感器数据。
2843
2844**系统能力**:SystemCapability.Sensors.Sensor
2845
2846**参数**:
2847
2848| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2849| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2850| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
2851| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2852
2853**错误码**:
2854
2855以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2856
2857| 错误码ID | 错误信息                                                     |
2858| -------- | ------------------------------------------------------------ |
2859| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2860
2861**示例**:
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  // 仅取消callback1的注册
2879  sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
2880  // 取消注册SensorId.ROTATION_VECTOR的所有回调
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
2892取消订阅有效运动传感器数据。
2893
2894**系统能力**:SystemCapability.Sensors.Sensor
2895
2896**参数**:
2897
2898| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2899| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2900| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
2901| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2902
2903**错误码**:
2904
2905以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2906
2907| 错误码ID | 错误信息                                                     |
2908| -------- | ------------------------------------------------------------ |
2909| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2910
2911**示例**:
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  // 仅取消callback1的注册
2929  sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
2930  // 取消注册SensorId.SIGNIFICANT_MOTION的所有回调
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
2942取消订阅佩戴检测传感器数据。
2943
2944**系统能力**:SystemCapability.Sensors.Sensor
2945
2946**参数**:
2947
2948| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2949| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2950| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。              |
2951| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
2952
2953**错误码**:
2954
2955以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2956
2957| 错误码ID | 错误信息                                                     |
2958| -------- | ------------------------------------------------------------ |
2959| 401      | Parameter error.Possible causes:1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed. |
2960
2961**示例**:
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  // 仅取消callback1的注册
2979  sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
2980  // 取消注册SensorId.WEAR_DETECTION的所有回调
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
2992获取某时刻地球上特定位置的地磁场信息,使用Callback异步方式返回结果。
2993
2994**系统能力**:SystemCapability.Sensors.Sensor
2995
2996**参数**:
2997
2998| 参数名          | 类型                                                         | 必填 | 说明                               |
2999| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
3000| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置,包括经度、纬度和海拔高度。                         |
3001| timeMillis      | number                                                       | 是   | 获取磁偏角的时间,unix时间戳,单位毫秒。 |
3002| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 回调函数,异步返回地磁场信息。                 |
3003
3004**错误码**:
3005
3006以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3007
3008| 错误码ID | 错误信息                                                     |
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**示例**:
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
3044获取某时刻地球上特定位置的地磁场信息,使用Promise异步方式返回结果。
3045
3046**系统能力**:SystemCapability.Sensors.Sensor
3047
3048**参数**:
3049
3050| 参数名          | 类型                                | 必填 | 说明                               |
3051| --------------- | ----------------------------------- | ---- | ---------------------------------- |
3052| locationOptions | [LocationOptions](#locationoptions) | 是   | 地理位置,包括经度、纬度和海拔高度。                         |
3053| timeMillis      | number                              | 是   | 获取磁偏角的时间,unix时间戳,单位毫秒。 |
3054
3055**返回值**:
3056
3057| 类型                                                       | 说明           |
3058| ---------------------------------------------------------- | -------------- |
3059| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise对象,使用异步方式返回地磁场信息。 |
3060
3061**错误码**:
3062
3063以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3064
3065| 错误码ID | 错误信息                                                     |
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**示例**:
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
3099根据气压值获取海拔高度,使用Callback异步方式返回结果。
3100
3101**系统能力**:SystemCapability.Sensors.Sensor
3102
3103**参数**:
3104
3105| 参数名          | 类型                        | 必填 | 说明                                  |
3106| --------------- | --------------------------- | ---- | ------------------------------------- |
3107| seaPressure     | number                      | 是   | 海平面气压值,单位为hPa。         |
3108| currentPressure | number                      | 是   | 指定的气压值,单位为hPa。 |
3109| callback        | AsyncCallback&lt;number&gt; | 是   | 回调函数,异步返回指定的气压值对应的海拔高度,单位为米。  |
3110
3111**错误码**:
3112
3113以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3114
3115| 错误码ID | 错误信息                                                     |
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**示例**:
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
3146根据气压值获取海拔高度,使用Promise异步方式返回结果。
3147
3148**系统能力**:SystemCapability.Sensors.Sensor
3149
3150**参数**:
3151
3152| 参数名          | 类型   | 必填 | 说明                                  |
3153| --------------- | ------ | ---- | ------------------------------------- |
3154| seaPressure     | number | 是   | 海平面气压值,单位为hPa。         |
3155| currentPressure | number | 是   | 指定的气压值,单位为hPa。 |
3156
3157**返回值**:
3158
3159| 类型                  | 说明                                 |
3160| --------------------- | ------------------------------------ |
3161| Promise&lt;number&gt; | Promise对象,使用异步方式返回指定的气压值对应的海拔高度,单位为米。 |
3162
3163**错误码**:
3164
3165以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3166
3167| 错误码ID | 错误信息                                                     |
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**示例**:
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
3197根据倾斜矩阵计算地磁倾角,使用Callback异步方式返回结果。
3198
3199**系统能力**:SystemCapability.Sensors.Sensor
3200
3201**参数**:
3202
3203| 参数名            | 类型                        | 必填 | 说明                         |
3204| ----------------- | --------------------------- | ---- | ---------------------------- |
3205| inclinationMatrix | Array&lt;number&gt;         | 是   | 倾斜矩阵。               |
3206| callback          | AsyncCallback&lt;number&gt; | 是   | 回调函数,异步返回地磁倾角,单位为弧度。 |
3207
3208**错误码**:
3209
3210以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3211
3212| 错误码ID | 错误信息                                                     |
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**示例**:
3218
3219```ts
3220import { sensor } from '@kit.SensorServiceKit';
3221import { BusinessError } from '@kit.BasicServicesKit';
3222
3223try {
3224  // inclinationMatrix可以为3*3,或者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
3247根据倾斜矩阵计算地磁倾角,使用Promise异步方式返回结果。
3248
3249**系统能力**:SystemCapability.Sensors.Sensor
3250
3251**参数**:
3252
3253| 参数名            | 类型                | 必填 | 说明           |
3254| ----------------- | ------------------- | ---- | -------------- |
3255| inclinationMatrix | Array&lt;number&gt; | 是   | 倾斜矩阵。 |
3256
3257**返回值**:
3258
3259| 类型                  | 说明                         |
3260| --------------------- | ---------------------------- |
3261| Promise&lt;number&gt; | Promise对象,使用异步方式返回地磁倾斜角,单位为弧度。 |
3262
3263**错误码**:
3264
3265以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3266
3267| 错误码ID | 错误信息                                                     |
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**示例**:
3273
3274```ts
3275import { sensor } from '@kit.SensorServiceKit';
3276import { BusinessError } from '@kit.BasicServicesKit';
3277
3278try {
3279  // inclinationMatrix可以为3*3,或者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
3302计算两个旋转矩阵之间的角度变化,使用Callback异步方式返回结果。
3303
3304**系统能力**:SystemCapability.Sensors.Sensor
3305
3306**参数**:
3307
3308| 参数名                | 类型                                     | 必填 | 说明                              |
3309| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
3310| currentRotationMatrix | Array&lt;number&gt;                      | 是   | 当前旋转矩阵。                |
3311| preRotationMatrix     | Array&lt;number&gt;                      | 是   | 相对旋转矩阵。                    |
3312| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,异步返回绕z、x、y轴方向的旋转角度。 |
3313
3314**错误码**:
3315
3316以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3317
3318| 错误码ID | 错误信息                                                     |
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**示例**:
3324
3325```ts
3326import { sensor } from '@kit.SensorServiceKit';
3327import { BusinessError } from '@kit.BasicServicesKit';
3328
3329try {
3330  // 旋转矩阵可以为3*3,或者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
3363得到两个旋转矩阵之间的角度变化,使用Promise异步方式返回结果。
3364
3365**系统能力**:SystemCapability.Sensors.Sensor
3366
3367**参数**:
3368
3369| 参数名                | 类型                | 必填 | 说明               |
3370| --------------------- | ------------------- | ---- | ------------------ |
3371| currentRotationMatrix | Array&lt;number&gt; | 是   | 当前旋转矩阵。 |
3372| preRotationMatrix     | Array&lt;number&gt; | 是   | 相对旋转矩阵。                  |
3373
3374**返回值**:
3375
3376| 类型                               | 说明                              |
3377| ---------------------------------- | --------------------------------- |
3378| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,使用异步方式返回绕z、x、y轴方向的旋转角度。 |
3379
3380**错误码**:
3381
3382以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3383
3384| 错误码ID | 错误信息                                                     |
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**示例**:
3390
3391```ts
3392import { sensor } from '@kit.SensorServiceKit';
3393import { BusinessError } from '@kit.BasicServicesKit';
3394
3395try {
3396  // 旋转矩阵可以为3*3,或者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
3428根据旋转矢量获取旋转矩阵,使用Callback异步方式返回结果。
3429
3430**系统能力**:SystemCapability.Sensors.Sensor
3431
3432**参数**:
3433
3434| 参数名         | 类型                                     | 必填 | 说明           |
3435| -------------- | ---------------------------------------- | ---- | -------------- |
3436| rotationVector | Array&lt;number&gt;                      | 是   | 旋转矢量。 |
3437| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,异步返回3*3旋转矩阵。 |
3438
3439**错误码**:
3440
3441以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3442
3443| 错误码ID | 错误信息                                                     |
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**示例**:
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
3475根据旋转矢量获取旋转矩阵,使用Promise异步方式返回结果。
3476
3477**系统能力**:SystemCapability.Sensors.Sensor
3478
3479**参数**:
3480
3481| 参数名         | 类型                | 必填 | 说明           |
3482| -------------- | ------------------- | ---- | -------------- |
3483| rotationVector | Array&lt;number&gt; | 是   | 旋转矢量。 |
3484
3485**返回值**:
3486
3487| 类型                               | 说明           |
3488| ---------------------------------- | -------------- |
3489| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,使用异步方式返回旋转矩阵。 |
3490
3491**错误码**:
3492
3493以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3494
3495| 错误码ID | 错误信息                                                     |
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**示例**:
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
3527根据指定坐标系映射旋转矩阵,使用Callback异步方式返回结果。
3528
3529**系统能力**:SystemCapability.Sensors.Sensor
3530
3531**参数**:
3532
3533| 参数名           | 类型                                      | 必填 | 说明                   |
3534| ---------------- | ----------------------------------------- | ---- | ---------------------- |
3535| inRotationVector | Array&lt;number&gt;                       | 是   | 旋转矩阵。         |
3536| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 指定坐标系方向。       |
3537| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | 是   | 回调函数,异步返回映射后的旋转矩阵。 |
3538
3539**错误码**:
3540
3541以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3542
3543| 错误码ID | 错误信息                                                     |
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**示例**:
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
3579根据指定坐标系映射旋转矩阵,使用Promise异步方式返回结果。
3580
3581**系统能力**:SystemCapability.Sensors.Sensor
3582
3583**参数**:
3584
3585| 参数名           | 类型                                      | 必填 | 说明             |
3586| ---------------- | ----------------------------------------- | ---- | ---------------- |
3587| inRotationVector | Array&lt;number&gt;                       | 是   | 旋转矩阵。   |
3588| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 指定坐标系方向。 |
3589
3590**返回值**:
3591
3592| 类型                               | 说明                   |
3593| ---------------------------------- | ---------------------- |
3594| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,使用异步方式返回转换后的旋转矩阵。 |
3595
3596**错误码**:
3597
3598以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3599
3600| 错误码ID | 错误信息                                                     |
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**示例** :
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
3635根据旋转向量计算归一化四元数,使用Callback异步方式返回结果。
3636
3637**系统能力**:SystemCapability.Sensors.Sensor
3638
3639**参数**:
3640
3641| 参数名         | 类型                                     | 必填 | 说明           |
3642| -------------- | ---------------------------------------- | ---- | -------------- |
3643| rotationVector | Array&lt;number&gt;                      | 是   | 旋转矢量。 |
3644| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,异步返回归一化四元数。 |
3645
3646**错误码**:
3647
3648以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3649
3650| 错误码ID | 错误信息                                                     |
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**示例**:
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
3682根据旋转向量计算归一化四元数,使用Promise异步方式返回结果。
3683
3684**系统能力**:SystemCapability.Sensors.Sensor
3685
3686**参数**:
3687
3688| 参数名         | 类型                | 必填 | 说明           |
3689| -------------- | ------------------- | ---- | -------------- |
3690| rotationVector | Array&lt;number&gt; | 是   | 旋转矢量。 |
3691
3692**返回值**:
3693
3694| 类型                               | 说明         |
3695| ---------------------------------- | ------------ |
3696| Promise&lt;Array&lt;number&gt;&gt; | Promise,使用异步方式对象返归一化回四元数。 |
3697
3698**错误码**:
3699
3700以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3701
3702| 错误码ID | 错误信息                                                     |
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**示例**:
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
3733根据旋转矩阵计算设备方向,使用Callback异步方式返回结果。
3734
3735**系统能力**:SystemCapability.Sensors.Sensor
3736
3737**参数**:
3738
3739| 参数名         | 类型                                     | 必填 | 说明                              |
3740| -------------- | ---------------------------------------- | ---- | --------------------------------- |
3741| rotationMatrix | Array&lt;number&gt;                      | 是   | 旋转矩阵。                    |
3742| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,异步返回围绕z、x、y轴方向的旋转角度。 |
3743
3744**错误码**:
3745
3746以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3747
3748| 错误码ID | 错误信息                                                     |
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**示例**:
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
3787根据旋转矩阵计算设备的方向,使用Promise异步方式返回结果。
3788
3789**系统能力**:SystemCapability.Sensors.Sensor
3790
3791**参数**:
3792
3793| 参数名         | 类型                | 必填 | 说明           |
3794| -------------- | ------------------- | ---- | -------------- |
3795| rotationMatrix | Array&lt;number&gt; | 是   | 旋转矩阵。 |
3796
3797**返回值**:
3798
3799| 类型                               | 说明                              |
3800| ---------------------------------- | --------------------------------- |
3801| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,使用异步方式返回围绕z、x、y轴方向的旋转角度。 |
3802
3803**错误码**:
3804
3805以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3806
3807| 错误码ID | 错误信息                                                     |
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**示例**:
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
3842根据重力矢量和地磁矢量计算旋转矩阵,使用Callback异步方式返回结果。
3843
3844**系统能力**:SystemCapability.Sensors.Sensor
3845
3846**参数**:
3847
3848| 参数名      | 类型                                                         | 必填 | 说明           |
3849| ----------- | ------------------------------------------------------------ | ---- | -------------- |
3850| gravity     | Array&lt;number&gt;                                          | 是   | 重力矢量。 |
3851| geomagnetic | Array&lt;number&gt;                                          | 是   | 地磁矢量。 |
3852| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是   | 回调函数,异步返回旋转矩阵。 |
3853
3854**错误码**:
3855
3856以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3857
3858| 错误码ID | 错误信息                                                     |
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**示例**:
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
3889根据重力矢量和地磁矢量计算旋转矩阵,使用Promise异步方式返回结果。
3890
3891**系统能力**:SystemCapability.Sensors.Sensor
3892
3893**参数**:
3894
3895| 参数名      | 类型                | 必填 | 说明           |
3896| ----------- | ------------------- | ---- | -------------- |
3897| gravity     | Array&lt;number&gt; | 是   | 重力向量。 |
3898| geomagnetic | Array&lt;number&gt; | 是   | 地磁矢量。 |
3899
3900**返回值**:
3901
3902| 类型                                                         | 说明           |
3903| ------------------------------------------------------------ | -------------- |
3904| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise对象,使用异步方式返回旋转矩阵。 |
3905
3906**错误码**:
3907
3908以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3909
3910| 错误码ID | 错误信息                                                     |
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**示例**:
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
3940获取设备上的所有传感器信息,使用Callback异步方式返回结果。
3941
3942**系统能力**:SystemCapability.Sensors.Sensor
3943
3944**参数**:
3945
3946| 参数名   | 类型                                           | 必填 | 说明             |
3947| -------- | ---------------------------------------------- | ---- | ---------------- |
3948| callback | AsyncCallback&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | 是   | 回调函数,异步返回传感器属性列表。 |
3949
3950**错误码**:
3951
3952以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3953
3954| 错误码ID | 错误信息                                                     |
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**示例**:
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
3985获取设备上的所有传感器信息,使用Promise异步方式返回结果。
3986
3987**系统能力**:SystemCapability.Sensors.Sensor
3988
3989**返回值**:
3990
3991| 参数名  | 类型                                     | 必填 | 说明             |
3992| ------- | ---------------------------------------- | ---- | ---------------- |
3993| promise | Promise&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | 是   | Promise对象,使用异步方式返回传感器属性列表。 |
3994
3995**错误码**:
3996
3997以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
3998
3999| 错误码ID | 错误信息                                                     |
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**示例**:
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
4028获取设备上的所有传感器信息,使用同步方式返回结果。
4029
4030**系统能力**:SystemCapability.Sensors.Sensor
4031
4032**返回值**:
4033
4034| 类型                                    | 必填 | 说明                             |
4035| --------------------------------------- | ---- | -------------------------------- |
4036| &lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | 是   | 使用同步方式返回传感器属性列表。 |
4037
4038**错误码**:
4039
4040以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)。
4041
4042| 错误码ID | 错误信息           |
4043| -------- | ------------------ |
4044| 14500101 | Service exception. |
4045
4046**示例**:
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
4067获取指定传感器类型的属性信息,使用Callback异步方式返回结果。
4068
4069**系统能力**:SystemCapability.Sensors.Sensor
4070
4071**参数**:
4072
4073| 参数名   | 类型                                    | 必填 | 说明             |
4074| -------- | --------------------------------------- | ---- | ---------------- |
4075| type     | [SensorId](#sensorid9)                  | 是   | 指定传感器类型。     |
4076| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | 是   | 回调函数,异步返回指定传感器的属性信息。 |
4077
4078**错误码**:
4079
4080以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
4081
4082| 错误码ID | 错误信息                                                     |
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**示例**:
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
4112获取指定类型的传感器信息,使用Promise异步方式返回结果。
4113
4114**系统能力**:SystemCapability.Sensors.Sensor
4115
4116**参数**:
4117
4118| 参数名 | 类型                   | 必填 | 说明         |
4119| ------ | ---------------------- | ---- | ------------ |
4120| type   | [SensorId](#sensorid9) | 是   | 传感器类型。 |
4121
4122**返回值**:
4123
4124| 参数名  | 类型                              | 必填 | 说明                         |
4125| ------- | --------------------------------- | ---- | ---------------------------- |
4126| promise | Promise&lt;[Sensor](#sensor9)&gt; | 是   | 使用异步方式返回传感器信息。 |
4127
4128**错误码**:
4129
4130以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
4131
4132| 错误码ID | 错误信息                                                     |
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**示例**:
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
4160获取指定类型的传感器信息,使用同步方式返回结果。
4161
4162**系统能力**:SystemCapability.Sensors.Sensor
4163
4164**参数**:
4165
4166| 参数名 | 类型                   | 必填 | 说明         |
4167| ------ | ---------------------- | ---- | ------------ |
4168| type   | [SensorId](#sensorid9) | 是   | 传感器类型。 |
4169
4170**返回值**:
4171
4172| 类型   | 必填 | 说明                         |
4173| ------ | ---- | ---------------------------- |
4174| Sensor | 是   | 使用同步方式返回传感器信息。 |
4175
4176**错误码**:
4177
4178以下错误码的详细介绍请参见[传感器错误码](errorcode-sensor.md)和[通用错误码](../errorcode-universal.md)。
4179
4180| 错误码ID | 错误信息                                                     |
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**示例**:
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
4203表示当前支持订阅或取消订阅的传感器类型。
4204
4205**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4206
4207| 名称                        | 值   | 说明                                                         |
4208| --------------------------- | ---- | ------------------------------------------------------------ |
4209| ACCELEROMETER               | 1    | 加速度传感器。<br/>**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。 |
4210| GYROSCOPE                   | 2    | 陀螺仪传感器。<br/>**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。 |
4211| AMBIENT_LIGHT               | 5    | 环境光传感器。                                               |
4212| MAGNETIC_FIELD              | 6    | 磁场传感器。                                                 |
4213| BAROMETER                   | 8    | 气压计传感器。                                               |
4214| HALL                        | 10   | 霍尔传感器。                                                 |
4215| PROXIMITY                   | 12   | 接近光传感器。                                               |
4216| HUMIDITY                    | 13   | 湿度传感器。                                                 |
4217| ORIENTATION                 | 256  | 方向传感器。<br/>**原子化服务API**:从API Version 11开始,该接口在支持原子化服务中使用。 |
4218| GRAVITY                     | 257  | 重力传感器。                                                 |
4219| LINEAR_ACCELEROMETER        | 258  | 线性加速度传感器。                                           |
4220| ROTATION_VECTOR             | 259  | 旋转矢量传感器。                                             |
4221| AMBIENT_TEMPERATURE         | 260  | 环境温度传感器。                                             |
4222| MAGNETIC_FIELD_UNCALIBRATED | 261  | 未校准磁场传感器。                                           |
4223| GYROSCOPE_UNCALIBRATED      | 263  | 未校准陀螺仪传感器。                                         |
4224| SIGNIFICANT_MOTION          | 264  | 有效运动传感器。                                             |
4225| PEDOMETER_DETECTION         | 265  | 计步检测传感器。                                             |
4226| PEDOMETER                   | 266  | 计步传感器。                                                 |
4227| HEART_RATE                  | 278  | 心率传感器。                                                 |
4228| WEAR_DETECTION              | 280  | 佩戴检测传感器。                                             |
4229| ACCELEROMETER_UNCALIBRATED  | 281  | 未校准加速度计传感器。                                       |
4230
4231## SensorType<sup>(deprecated)</sup>
4232
4233表示要订阅或取消订阅的传感器类型。
4234
4235**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4236
4237
4238| 名称                                       | 值   | 说明                   |
4239| ------------------------------------------ | ---- | ---------------------- |
4240| SENSOR_TYPE_ID_ACCELEROMETER               | 1    | 加速度传感器。         |
4241| SENSOR_TYPE_ID_GYROSCOPE                   | 2    | 陀螺仪传感器。         |
4242| SENSOR_TYPE_ID_AMBIENT_LIGHT               | 5    | 环境光传感器。         |
4243| SENSOR_TYPE_ID_MAGNETIC_FIELD              | 6    | 磁场传感器。           |
4244| SENSOR_TYPE_ID_BAROMETER                   | 8    | 气压计传感器。         |
4245| SENSOR_TYPE_ID_HALL                        | 10   | 霍尔传感器。           |
4246| SENSOR_TYPE_ID_PROXIMITY                   | 12   | 接近光传感器。         |
4247| SENSOR_TYPE_ID_HUMIDITY                    | 13   | 湿度传感器。           |
4248| SENSOR_TYPE_ID_ORIENTATION                 | 256  | 方向传感器。           |
4249| SENSOR_TYPE_ID_GRAVITY                     | 257  | 重力传感器。           |
4250| SENSOR_TYPE_ID_LINEAR_ACCELERATION         | 258  | 线性加速度传感器。     |
4251| SENSOR_TYPE_ID_ROTATION_VECTOR             | 259  | 旋转矢量传感器。       |
4252| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE         | 260  | 环境温度传感器。       |
4253| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | 未校准磁场传感器。     |
4254| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED      | 263  | 未校准陀螺仪传感器。   |
4255| SENSOR_TYPE_ID_SIGNIFICANT_MOTION          | 264  | 有效运动传感器。       |
4256| SENSOR_TYPE_ID_PEDOMETER_DETECTION         | 265  | 计步检测传感器。       |
4257| SENSOR_TYPE_ID_PEDOMETER                   | 266  | 计步传感器。           |
4258| SENSOR_TYPE_ID_HEART_RATE                  | 278  | 心率传感器。           |
4259| SENSOR_TYPE_ID_WEAR_DETECTION              | 280  | 佩戴检测传感器。       |
4260| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED  | 281  | 未校准加速度计传感器。 |
4261
4262## SensorAccuracy<sup>11+</sup>
4263
4264传感器数据的精度。
4265
4266**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4267
4268**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4269
4270| 名称    | 值 | 说明                     |
4271| --------- | ---- | ------------------------ |
4272| ACCURACY_UNRELIABLE | 0   | 传感器数据不可信。 |
4273| ACCURACY_LOW | 1   | 传感器低挡位精度。 |
4274| ACCURACY_MEDIUM | 2   | 传感器中挡位精度。 |
4275| ACCURACY_HIGH | 3   | 传感器高挡位精度。 |
4276
4277## Response
4278
4279传感器数据的时间戳。
4280
4281**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4282
4283**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4284
4285| 名称      | 类型   | 可读 | 可写 | 说明                     |
4286| --------- | ------ | ---- | ---- | ------------------------ |
4287| timestamp | number | 是   | 是   | 传感器数据上报的时间戳。 |
4288| accuracy<sup>11+</sup> | [SensorAccuracy](#sensoraccuracy11)<sup>11+</sup> | 是   | 否   | 传感器数据上报的精度挡位值。 |
4289
4290## Sensor<sup>9+</sup>
4291
4292指示传感器信息。
4293
4294**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4295
4296| 名称            | 类型 | 可读 | 可写 | 说明                   |
4297| --------------- | -------- | ---------------------- | ---------------------- | ---------------------- |
4298| sensorName      | string   | 是  | 否  | 传感器名称。            |
4299| vendorName      | string   | 是  | 否  | 传感器供应商。         |
4300| firmwareVersion | string   | 是  | 否  | 传感器固件版本。       |
4301| hardwareVersion | string   | 是  | 否  | 传感器硬件版本。       |
4302| sensorId        | number   | 是  | 否  | 传感器类型id。         |
4303| maxRange        | number   | 是  | 否  | 传感器测量范围的最大值。 |
4304| minSamplePeriod | number   | 是  | 否  | 允许的最小采样周期。   |
4305| maxSamplePeriod | number   | 是  | 否  | 允许的最大采样周期。   |
4306| precision       | number   | 是  | 否  | 传感器精度。           |
4307| power           | number   | 是  | 否  | 传感器功率的估计值,单位:mA。  |
4308
4309## AccelerometerResponse
4310
4311加速度传感器数据,继承于[Response](#response)。
4312
4313**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4314
4315**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4316
4317
4318| 名称 | 类型   | 可读 | 可写 | 说明                                                       |
4319| ---- | ------ | ---- | ---- | ---------------------------------------------------------- |
4320| x    | number | 是   | 是   | 施加在设备x轴的加速度,单位 : m/s²;取值为实际上报物理量。 |
4321| y    | number | 是   | 是   | 施加在设备y轴的加速度,单位 : m/s²;取值为实际上报物理量。 |
4322| z    | number | 是   | 是   | 施加在设备z轴的加速度,单位 : m/s²;取值为实际上报物理量。 |
4323
4324
4325## LinearAccelerometerResponse
4326
4327线性加速度传感器数据,继承于[Response](#response)。
4328
4329**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4330
4331
4332| 名称 | 类型   | 可读 | 可写 | 说明                                     |
4333| ---- | ------ | ---- | ---- | ---------------------------------------- |
4334| x    | number | 是   | 是   | 施加在设备x轴的线性加速度,单位 : m/s²。 |
4335| y    | number | 是   | 是   | 施加在设备y轴的线性加速度,单位 : m/s²。 |
4336| z    | number | 是   | 是   | 施加在设备z轴的线性加速度,单位 : m/s²。 |
4337
4338
4339## AccelerometerUncalibratedResponse
4340
4341未校准加速度计传感器数据,继承于[Response](#response)。
4342
4343**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4344
4345
4346| 名称  | 类型   | 可读 | 可写 | 说明                                           |
4347| ----- | ------ | ---- | ---- | ---------------------------------------------- |
4348| x     | number | 是   | 是   | 施加在设备x轴未校准的加速度,单位 : m/s²。     |
4349| y     | number | 是   | 是   | 施加在设备y轴未校准的加速度,单位 : m/s²。     |
4350| z     | number | 是   | 是   | 施加在设备z轴未校准的加速度,单位 : m/s²。     |
4351| biasX | number | 是   | 是   | 施加在设备x轴未校准的加速度偏量,单位 : m/s²。 |
4352| biasY | number | 是   | 是   | 施加在设备y轴未校准的加速度偏量,单位 : m/s²。 |
4353| biasZ | number | 是   | 是   | 施加在设备z轴未校准的加速度偏量,单位 : m/s²。 |
4354
4355
4356## GravityResponse
4357
4358重力传感器数据,继承于[Response](#response)。
4359
4360**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4361
4362
4363| 名称 | 类型   | 可读 | 可写 | 说明                                     |
4364| ---- | ------ | ---- | ---- | ---------------------------------------- |
4365| x    | number | 是   | 是   | 施加在设备x轴的重力加速度,单位 : m/s²。 |
4366| y    | number | 是   | 是   | 施加在设备y轴的重力加速度,单位 : m/s²。 |
4367| z    | number | 是   | 是   | 施加在设备z轴的重力加速度,单位 : m/s²。 |
4368
4369
4370## OrientationResponse
4371
4372方向传感器数据,继承于[Response](#response)。
4373
4374**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4375
4376**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4377
4378
4379| 名称  | 类型   | 可读 | 可写 | 说明                                                  |
4380| ----- | ------ | ---- | ---- | ----------------------------------------------------- |
4381| alpha | number | 是   | 是   | 设备围绕Z轴的旋转角度,单位:度;取值范围为0-360度。  |
4382| beta  | number | 是   | 是   | 设备围绕X轴的旋转角度,单位:度;取值范围为0-±180度。 |
4383| gamma | number | 是   | 是   | 设备围绕Y轴的旋转角度,单位:度;取值范围为0-±90度。  |
4384
4385
4386## RotationVectorResponse
4387
4388旋转矢量传感器数据,继承于[Response](#response)。
4389
4390**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4391
4392
4393| 名称 | 类型   | 可读 | 可写 | 说明              |
4394| ---- | ------ | ---- | ---- | ----------------- |
4395| x    | number | 是   | 是   | 旋转矢量x轴分量。 |
4396| y    | number | 是   | 是   | 旋转矢量y轴分量。 |
4397| z    | number | 是   | 是   | 旋转矢量z轴分量。 |
4398| w    | number | 是   | 是   | 标量。            |
4399
4400
4401## GyroscopeResponse
4402
4403陀螺仪传感器数据,继承于[Response](#response)。
4404
4405**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4406
4407**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4408
4409
4410| 名称 | 类型   | 可读 | 可写 | 说明                                                   |
4411| ---- | ------ | ---- | ---- | ------------------------------------------------------ |
4412| x    | number | 是   | 是   | 设备x轴的旋转角速度,单位rad/s;取值为实际上报物理量。 |
4413| y    | number | 是   | 是   | 设备y轴的旋转角速度,单位rad/s;取值为实际上报物理量。 |
4414| z    | number | 是   | 是   | 设备z轴的旋转角速度,单位rad/s;取值为实际上报物理量。 |
4415
4416
4417## GyroscopeUncalibratedResponse
4418
4419未校准陀螺仪传感器数据,继承于[Response](#response)。
4420
4421**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4422
4423
4424| 名称  | 类型   | 可读 | 可写 | 说明                                       |
4425| ----- | ------ | ---- | ---- | ------------------------------------------ |
4426| x     | number | 是   | 是   | 设备x轴未校准的旋转角速度,单位rad/s。     |
4427| y     | number | 是   | 是   | 设备y轴未校准的旋转角速度,单位rad/s。     |
4428| z     | number | 是   | 是   | 设备z轴未校准的旋转角速度,单位rad/s。     |
4429| biasX | number | 是   | 是   | 设备x轴未校准的旋转角速度偏量,单位rad/s。 |
4430| biasY | number | 是   | 是   | 设备y轴未校准的旋转角速度偏量,单位rad/s。 |
4431| biasZ | number | 是   | 是   | 设备z轴未校准的旋转角速度偏量,单位rad/s。 |
4432
4433
4434## SignificantMotionResponse
4435
4436有效运动传感器数据,继承于[Response](#response)。
4437
4438**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4439
4440
4441| 名称   | 类型   | 可读 | 可写 | 说明                                                         |
4442| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4443| scalar | number | 是   | 是   | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;和&nbsp;z)上,设备是否存在大幅度运动;若存在大幅度运动则数据上报为1。 |
4444
4445
4446## ProximityResponse
4447
4448接近光传感器数据,继承于[Response](#response)。
4449
4450**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4451
4452
4453| 名称     | 类型   | 可读 | 可写 | 说明                                                       |
4454| -------- | ------ | ---- | ---- | ---------------------------------------------------------- |
4455| distance | number | 是   | 是   | 可见物体与设备显示器的接近程度。0表示接近,大于0表示远离。 |
4456
4457
4458## LightResponse
4459
4460环境光传感器数据,继承于[Response](#response)。
4461
4462**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4463
4464
4465| 名称                            | 类型   | 可读 | 可写 | 说明                                                         |
4466| ------------------------------- | ------ | ---- | ---- | ------------------------------------------------------------ |
4467| intensity                       | number | 是   | 是   | 光强(单位:勒克斯)。                                       |
4468| colorTemperature<sup>12+</sup>  | number | 是   | 是   | 色温(单位:开尔文),可选参数,如果该参数不支持在js层返回未定义,支持则返回正常数值。 |
4469| infraredLuminance<sup>12+</sup> | number | 是   | 是   | 红外亮度(单位:cd/m²),可选参数,如果该参数不支持在js层返回未定义,支持则返回正常数值。 |
4470
4471
4472## HallResponse
4473
4474霍尔传感器数据,继承于[Response](#response)。
4475
4476**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4477
4478
4479| 名称   | 类型   | 可读 | 可写 | 说明                                                         |
4480| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4481| status | number | 是   | 是   | 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示没有,大于0表示有。 |
4482
4483
4484## MagneticFieldResponse
4485
4486磁场传感器数据,继承于[Response](#response)。
4487
4488**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4489
4490
4491| 名称 | 类型   | 可读 | 可写 | 说明                         |
4492| ---- | ------ | ---- | ---- | ---------------------------- |
4493| x    | number | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
4494| y    | number | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
4495| z    | number | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
4496
4497
4498## MagneticFieldUncalibratedResponse
4499
4500未校准磁场传感器数据,继承于[Response](#response)。
4501
4502**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4503
4504
4505| 名称  | 类型   | 可读 | 可写 | 说明                                   |
4506| ----- | ------ | ---- | ---- | -------------------------------------- |
4507| x     | number | 是   | 是   | x轴未校准环境磁场强度,单位 : μT。     |
4508| y     | number | 是   | 是   | y轴未校准环境磁场强度,单位 : μT。     |
4509| z     | number | 是   | 是   | z轴未校准环境磁场强度,单位 : μT。     |
4510| biasX | number | 是   | 是   | x轴未校准环境磁场强度偏量,单位 : μT。 |
4511| biasY | number | 是   | 是   | y轴未校准环境磁场强度偏量,单位 : μT。 |
4512| biasZ | number | 是   | 是   | z轴未校准环境磁场强度偏量,单位 : μT。 |
4513
4514
4515## PedometerResponse
4516
4517计步传感器数据,继承于[Response](#response)。
4518
4519**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4520
4521
4522| 名称  | 类型   | 可读 | 可写 | 说明             |
4523| ----- | ------ | ---- | ---- | ---------------- |
4524| steps | number | 是   | 是   | 用户的行走步数。 |
4525
4526
4527## HumidityResponse
4528
4529湿度传感器数据,继承于[Response](#response)。
4530
4531**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4532
4533
4534| 名称     | 类型   | 可读 | 可写 | 说明                                                      |
4535| -------- | ------ | ---- | ---- | --------------------------------------------------------- |
4536| humidity | number | 是   | 是   | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |
4537
4538
4539## PedometerDetectionResponse
4540
4541计步检测传感器数据,继承于[Response](#response)。
4542
4543**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4544
4545
4546| 名称   | 类型   | 可读 | 可写 | 说明                                                         |
4547| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4548| scalar | number | 是   | 是   | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |
4549
4550
4551## AmbientTemperatureResponse
4552
4553温度传感器数据,继承于[Response](#response)。
4554
4555**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4556
4557
4558| 名称        | 类型   | 可读 | 可写 | 说明                       |
4559| ----------- | ------ | ---- | ---- | -------------------------- |
4560| temperature | number | 是   | 是   | 环境温度(单位:摄氏度)。 |
4561
4562
4563## BarometerResponse
4564
4565气压计传感器数据,继承于[Response](#response)。
4566
4567**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4568
4569
4570| 名称     | 类型   | 可读 | 可写 | 说明                   |
4571| -------- | ------ | ---- | ---- | ---------------------- |
4572| pressure | number | 是   | 是   | 压力值(单位:百帕)。 |
4573
4574
4575## HeartRateResponse
4576
4577心率传感器数据,继承于[Response](#response)。
4578
4579**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4580
4581
4582| 名称      | 类型   | 可读 | 可写 | 说明                                    |
4583| --------- | ------ | ---- | ---- | --------------------------------------- |
4584| heartRate | number | 是   | 是   | 心率值。测量用户的心率数值,单位:bpm。 |
4585
4586
4587## WearDetectionResponse
4588
4589佩戴检测传感器数据,继承于[Response](#response)。
4590
4591**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4592
4593
4594| 名称  | 类型   | 可读 | 可写 | 说明                                             |
4595| ----- | ------ | ---- | ---- | ------------------------------------------------ |
4596| value | number | 是   | 是   | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
4597
4598
4599## Options
4600
4601设置传感器上报频率。
4602
4603**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4604
4605**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4606
4607| 名称     | 类型                                                        | 可读 | 可写 | 说明                                                         |
4608| -------- | ----------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
4609| interval | number\|[SensorFrequency](#sensorfrequency11)<sup>11+</sup> | 是   | 是   | 表示传感器的上报频率,默认值为200000000ns。该属性有最小值和最大值的限制,由硬件支持的上报频率决定,当设置频率大于最大值时以最大值上报数据,小于最小值时以最小值上报数据。 |
4610
4611## SensorFrequency<sup>11+</sup>
4612
4613type SensorFrequency = 'game' | 'ui' | 'normal'
4614
4615传感器上报频率模式。
4616
4617**原子化服务API**:从API Version 11开始,该接口支持在原子化服务中使用。
4618
4619**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4620
4621| 类型     | 说明                                                         |
4622| -------- | ------------------------------------------------------------ |
4623| 'game'   | 用于指定传感器上报频率,频率值为20000000ns,该频率被设置在硬件支持的频率范围内时会生效,值固定为'game'字符串。 |
4624| 'ui'     | 用于指定传感器上报频率,频率值为60000000ns,该频率被设置在硬件支持的频率范围内时会生效,值固定为'ui'字符串。 |
4625| 'normal' | 用于指定传感器上报频率,频率值为200000000ns,该频率被设置在硬件支持的频率范围内时会生效,值固定为'normal'字符串。 |
4626
4627## RotationMatrixResponse
4628
4629设置旋转矩阵响应对象。
4630
4631**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4632
4633| 名称        | 类型                | 可读 | 可写 | 说明       |
4634| ----------- | ------------------- | ---- | ---- | ---------- |
4635| rotation    | Array&lt;number&gt; | 是   | 是   | 旋转矩阵。 |
4636| inclination | Array&lt;number&gt; | 是   | 是   | 倾斜矩阵。 |
4637
4638
4639## CoordinatesOptions
4640
4641设置坐标选项对象。
4642
4643**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4644
4645| 名称 | 类型   | 可读 | 可写 | 说明        |
4646| ---- | ------ | ---- | ---- | ----------- |
4647| x    | number | 是   | 是   | x坐标方向。 |
4648| y    | number | 是   | 是   | y坐标方向。 |
4649
4650
4651## GeomagneticResponse
4652
4653设置地磁响应对象。
4654
4655**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4656
4657| 名称            | 类型   | 可读 | 可写 | 说明                                               |
4658| --------------- | ------ | ---- | ---- | -------------------------------------------------- |
4659| x               | number | 是   | 是   | 地磁场的北分量。                                   |
4660| y               | number | 是   | 是   | 地磁场的东分量。                                   |
4661| z               | number | 是   | 是   | 地磁场的垂直分量。                                 |
4662| geomagneticDip  | number | 是   | 是   | 地磁倾角,即地球磁场线与水平面的夹角。             |
4663| deflectionAngle | number | 是   | 是   | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
4664| levelIntensity  | number | 是   | 是   | 地磁场的水平强度。                                 |
4665| totalIntensity  | number | 是   | 是   | 地磁场的总强度。                                   |
4666
4667## LocationOptions
4668
4669指示地理位置。
4670
4671**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
4672
4673| 名称      | 类型   | 可读 | 可写 | 说明       |
4674| --------- | ------ | ---- | ---- | ---------- |
4675| latitude  | number | 是   | 是   | 纬度。     |
4676| longitude | number | 是   | 是   | 经度。     |
4677| altitude  | number | 是   | 是   | 海拔高度。 |
4678
4679## sensor.on<sup>(deprecated)</sup>
4680
4681### ACCELEROMETER<sup>(deprecated)</sup>
4682
4683on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
4684
4685监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4686
4687> **说明**:
4688>
4689> 从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER](#accelerometer9)<sup>9+</sup>代替。
4690
4691**需要权限**:ohos.permission.ACCELEROMETER
4692
4693**系统能力**:SystemCapability.Sensors.Sensor
4694
4695**参数**:
4696
4697| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4698| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4699| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | 是   | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。     |
4700| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
4701| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4702
4703**示例**:
4704
4705```ts
4706import { sensor } from '@kit.SensorServiceKit';
4707
4708sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
4709  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4710  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4711  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4712},
4713  { interval: 100000000 }
4714);
4715```
4716
4717### LINEAR_ACCELERATION<sup>(deprecated)</sup>
4718
4719on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void
4720
4721监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4722
4723> **说明**:
4724>
4725> 从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)<sup>9+</sup>代替。
4726
4727**需要权限**:ohos.permission.ACCELEROMETER
4728
4729**系统能力**:SystemCapability.Sensors.Sensor
4730
4731**参数**:
4732
4733| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4734| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4735| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
4736| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
4737| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4738
4739### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
4740
4741on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
4742
4743监听未校准加速度计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4744
4745> **说明**:
4746>
4747> 从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)<sup>9+</sup>代替。
4748
4749**需要权限**:ohos.permission.ACCELEROMETER
4750
4751**系统能力**:SystemCapability.Sensors.Sensor
4752
4753**参数**:
4754
4755| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4756| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4757| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 是   | 要订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
4758| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
4759| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4760
4761**示例**:
4762
4763```ts
4764import { sensor } from '@kit.SensorServiceKit';
4765
4766sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
4767  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4768  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4769  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4770  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4771  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4772  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4773},
4774  { interval: 100000000 }
4775);
4776
4777```
4778
4779### GRAVITY<sup>(deprecated)</sup>
4780
4781on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void
4782
4783监听重力传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4784
4785> **说明**:
4786>
4787> 从API version 9 开始不再维护,建议使用[sensor.on.GRAVITY](#gravity9)<sup>9+</sup>代替。
4788
4789**系统能力**:SystemCapability.Sensors.Sensor
4790
4791**参数**:
4792
4793| 参数名   | 类型                                                       | 必填 | 说明                                                        |
4794| -------- | ---------------------------------------------------------- | ---- | ----------------------------------------------------------- |
4795| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | 是   | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。            |
4796| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | 是   | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
4797| options  | [Options](#options)                                        | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
4798
4799**示例**:
4800
4801```ts
4802import { sensor } from '@kit.SensorServiceKit';
4803
4804sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
4805  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4806  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4807  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4808},
4809  { interval: 100000000 }
4810);
4811```
4812
4813### GYROSCOPE<sup>(deprecated)</sup>
4814
4815on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
4816
4817监听陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4818
4819> **说明**:
4820>
4821> 从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE](#gyroscope9)<sup>9+</sup>代替。
4822
4823**需要权限**:ohos.permission.GYROSCOPE
4824
4825**系统能力**:SystemCapability.Sensors.Sensor
4826
4827**参数**:
4828
4829| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4830| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4831| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | 是   | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。         |
4832| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | 是   | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
4833| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4834
4835**示例**:
4836
4837```ts
4838import { sensor } from '@kit.SensorServiceKit';
4839
4840sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
4841  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4842  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4843  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4844},
4845  { interval: 100000000 }
4846);
4847```
4848
4849### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
4850
4851on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;, options?: Options): void
4852
4853监听未校准陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4854
4855> **说明**:
4856>
4857> 从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)<sup>9+</sup>代替。
4858
4859**需要权限**:ohos.permission.GYROSCOPE
4860
4861**系统能力**:SystemCapability.Sensors.Sensor
4862
4863**参数**:
4864
4865| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4866| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4867| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
4868| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
4869| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4870
4871**示例**:
4872
4873```ts
4874import { sensor } from '@kit.SensorServiceKit';
4875
4876sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
4877  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
4878  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
4879  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
4880  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
4881  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
4882  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
4883},
4884  { interval: 100000000 }
4885);
4886```
4887
4888### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
4889
4890on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;, options?: Options): void
4891
4892监听有效运动传感器数据变化。如果多次调用该接口,仅最后一次调用生效。
4893
4894> **说明**:
4895>
4896> 从API version 9 开始不再维护,建议使用[sensor.on.SIGNIFICANT_MOTION](#significant_motion9)<sup>9+</sup>代替。
4897
4898**系统能力**:SystemCapability.Sensors.Sensor
4899
4900**参数**:
4901
4902| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4903| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4904| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 是   | 要订阅的有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
4905| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
4906| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4907
4908**示例**:
4909
4910```ts
4911import { sensor } from '@kit.SensorServiceKit';
4912
4913sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
4914  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4915},
4916  { interval: 100000000 }
4917);
4918```
4919
4920### PEDOMETER_DETECTION<sup>(deprecated)</sup>
4921
4922on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;, options?: Options): void
4923
4924监听计步检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4925
4926> **说明**:
4927>
4928> 从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)<sup>9+</sup>代替。
4929
4930**需要权限**:ohos.permission.ACTIVITY_MOTION
4931
4932**系统能力**:SystemCapability.Sensors.Sensor
4933
4934**参数**:
4935
4936| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4937| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4938| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
4939| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
4940| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4941
4942**示例**:
4943
4944```ts
4945import { sensor } from '@kit.SensorServiceKit';
4946
4947sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
4948  console.info('Succeeded in invoking on. Scalar data: ' + data.scalar);
4949},
4950  { interval: 100000000 }
4951);
4952```
4953
4954### PEDOMETER<sup>(deprecated)</sup>
4955
4956on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
4957
4958监听计步传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4959
4960> **说明**:
4961>
4962> 从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER](#pedometer9)<sup>9+</sup>代替。
4963
4964**需要权限**:ohos.permission.ACTIVITY_MOTION
4965
4966**系统能力**:SystemCapability.Sensors.Sensor
4967
4968**参数**:
4969
4970| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4971| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4972| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | 是   | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。           |
4973| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | 是   | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
4974| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
4975
4976**示例**:
4977
4978```ts
4979import { sensor } from '@kit.SensorServiceKit';
4980
4981sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
4982  console.info('Succeeded in invoking on. Steps: ' + data.steps);
4983},
4984  { interval: 100000000 }
4985);
4986```
4987
4988### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
4989
4990on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;AmbientTemperatureResponse&gt;,  options?: Options): void
4991
4992监听环境温度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
4993
4994> **说明**:
4995>
4996> 从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)<sup>9+</sup>代替。
4997
4998**系统能力**:SystemCapability.Sensors.Sensor
4999
5000**参数**:
5001
5002| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5003| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5004| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 是   | 要订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
5005| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
5006| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5007
5008**示例**:
5009
5010```ts
5011import { sensor } from '@kit.SensorServiceKit';
5012
5013sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5014  console.info('Succeeded in invoking on. Temperature: ' + data.temperature);
5015},
5016  { interval: 100000000 }
5017);
5018```
5019
5020### MAGNETIC_FIELD<sup>(deprecated)</sup>
5021
5022on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
5023
5024监听磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5025
5026> **说明**:
5027>
5028> 从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD](#magnetic_field9)<sup>9+</sup>代替。
5029
5030**系统能力**:SystemCapability.Sensors.Sensor
5031
5032**参数**:
5033
5034| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5035| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5036| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | 是   | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。      |
5037| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
5038| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5039
5040**示例**:
5041
5042```ts
5043import { sensor } from '@kit.SensorServiceKit';
5044
5045sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5046  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5047  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5048  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5049},
5050  { interval: 100000000 }
5051);
5052```
5053
5054### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5055
5056on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
5057
5058监听未校准磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5059
5060> **说明**:
5061>
5062> 从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)<sup>9+</sup>代替。
5063
5064**系统能力**:SystemCapability.Sensors.Sensor
5065
5066**参数**:
5067
5068| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5069| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5070| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 是   | 要订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
5071| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
5072| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5073
5074**示例**:
5075
5076```ts
5077import { sensor } from '@kit.SensorServiceKit';
5078
5079sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5080  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5081  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5082  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5083  console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX);
5084  console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY);
5085  console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ);
5086},
5087  { interval: 100000000 }
5088);
5089```
5090
5091### PROXIMITY<sup>(deprecated)</sup>
5092
5093on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;,options?: Options): void
5094
5095监听接近光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5096
5097> **说明**:
5098>
5099> 从API version 9 开始不再维护,建议使用[sensor.on.PROXIMITY](#proximity9)<sup>9+</sup>代替。
5100
5101**系统能力**:SystemCapability.Sensors.Sensor
5102
5103**参数**:
5104
5105| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5106| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5107| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | 是   | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。         |
5108| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | 是   | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
5109| options  | [Options](#options)                                          | 否   | 可选参数列表,默认值为200000000ns。当接近光事件被触发的很频繁时,该参数用于限定事件上报的频率。 |
5110
5111**示例**:
5112
5113```ts
5114import { sensor } from '@kit.SensorServiceKit';
5115
5116sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5117  console.info('Succeeded in invoking on. Distance: ' + data.distance);
5118},
5119  { interval: 100000000 }
5120);
5121```
5122
5123### HUMIDITY<sup>(deprecated)</sup>
5124
5125on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
5126
5127监听湿度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5128
5129> **说明**:
5130>
5131> 从API version 9 开始不再维护,建议使用[sensor.on.HUMIDITY](#humidity9)<sup>9+</sup>代替。
5132
5133**系统能力**:SystemCapability.Sensors.Sensor
5134
5135**参数**:
5136
5137| 参数名   | 类型                                                        | 必填 | 说明                                                         |
5138| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5139| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | 是   | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。            |
5140| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | 是   | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
5141| options  | [Options](#options)                                         | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5142
5143**示例**:
5144
5145```ts
5146import { sensor } from '@kit.SensorServiceKit';
5147
5148sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5149  console.info('Succeeded in invoking on. Humidity: ' + data.humidity);
5150},
5151  { interval: 100000000 }
5152);
5153```
5154
5155### BAROMETER<sup>(deprecated)</sup>
5156
5157on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;,options?: Options): void
5158
5159监听气压计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5160
5161> **说明**:
5162>
5163> 从API version 9 开始不再维护,建议使用[sensor.on.BAROMETER](#barometer9)<sup>9+</sup>代替。
5164
5165**系统能力**:SystemCapability.Sensors.Sensor
5166
5167**参数**:
5168
5169| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5170| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5171| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | 是   | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。         |
5172| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | 是   | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
5173| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5174
5175**示例**:
5176
5177```ts
5178import { sensor } from '@kit.SensorServiceKit';
5179
5180sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5181  console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure);
5182},
5183  { interval: 100000000 }
5184);
5185```
5186
5187### HALL<sup>(deprecated)</sup>
5188
5189on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
5190
5191监听霍尔传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5192
5193> **说明**:
5194>
5195> 从API version 9 开始不再维护,建议使用[sensor.on.HALL](#hall9)<sup>9+</sup>代替。
5196
5197**系统能力**:SystemCapability.Sensors.Sensor
5198
5199**参数**:
5200
5201| 参数名   | 类型                                                    | 必填 | 说明                                                         |
5202| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5203| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | 是   | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。                |
5204| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | 是   | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
5205| options  | [Options](#options)                                     | 否   | 可选参数列表,默认值为200000000ns。当霍尔事件被触发的很频繁时,该参数用于限定事件上报的频率。 |
5206
5207**示例**:
5208
5209```ts
5210import { sensor } from '@kit.SensorServiceKit';
5211
5212sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5213  console.info('Succeeded in invoking on. Status: ' + data.status);
5214},
5215  { interval: 100000000 }
5216);
5217```
5218
5219### AMBIENT_LIGHT<sup>(deprecated)</sup>
5220
5221on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
5222
5223监听环境光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5224
5225> **说明**:
5226>
5227> 从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_LIGHT](#ambient_light9)<sup>9+</sup>代替。
5228
5229**系统能力**:SystemCapability.Sensors.Sensor
5230
5231**参数**:
5232
5233| 参数名   | 类型                                                         | 必填 | 说明                                                        |
5234| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
5235| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | 是   | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。    |
5236| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | 是   | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
5237| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。 |
5238
5239**示例**:
5240
5241```ts
5242import { sensor } from '@kit.SensorServiceKit';
5243
5244sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5245  console.info('Succeeded in invoking on. Illumination: ' + data.intensity);
5246},
5247  { interval: 100000000 }
5248);
5249```
5250
5251### ORIENTATION<sup>(deprecated)</sup>
5252
5253on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
5254
5255监听方向传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5256
5257> **说明**:
5258>
5259> 从API version 9 开始不再维护,建议使用[sensor.on.ORIENTATION](#orientation9)<sup>9+</sup>代替。
5260
5261**系统能力**:SystemCapability.Sensors.Sensor
5262
5263**参数**:
5264
5265| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5266| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5267| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | 是   | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。         |
5268| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | 是   | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
5269| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5270
5271**示例**:
5272
5273```ts
5274import { sensor } from '@kit.SensorServiceKit';
5275
5276sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5277  console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
5278  console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
5279  console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
5280},
5281  { interval: 100000000 }
5282);
5283```
5284
5285### HEART_RATE<sup>(deprecated)</sup>
5286
5287on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
5288
5289监听心率传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5290
5291> **说明**:
5292>
5293> 从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9)<sup>9+</sup>代替。
5294
5295**需要权限**:ohos.permission.HEALTH_DATA
5296
5297**系统能力**:SystemCapability.Sensors.Sensor
5298
5299**参数**:
5300
5301| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5302| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5303| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | 是   | 要订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。          |
5304| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | 是   | 注册心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
5305| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5306
5307### ROTATION_VECTOR<sup>(deprecated)</sup>
5308
5309on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;RotationVectorResponse&gt;,options?: Options): void
5310
5311监听旋转矢量传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5312
5313> **说明**:
5314>
5315> 从API version 9 开始不再维护,建议使用[sensor.on.ROTATION_VECTOR](#rotation_vector9)<sup>9+</sup>代替。
5316
5317**系统能力**:SystemCapability.Sensors.Sensor
5318
5319**参数**:
5320
5321| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5322| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5323| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | 是   | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
5324| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
5325| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5326
5327**示例**:
5328
5329```ts
5330import { sensor } from '@kit.SensorServiceKit';
5331
5332sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5333  console.info('Succeeded in invoking on. X-coordinate component: ' + data.x);
5334  console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y);
5335  console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z);
5336  console.info('Succeeded in invoking on. Scalar quantity: ' + data.w);
5337},
5338  { interval: 100000000 }
5339);
5340```
5341
5342### WEAR_DETECTION<sup>(deprecated)</sup>
5343
5344on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,options?: Options): void
5345
5346监听所佩戴的检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
5347
5348> **说明**:
5349>
5350> 从API version 9 开始不再维护,建议使用[sensor.on.WEAR_DETECTION](#wear_detection9)<sup>9+</sup>代替。
5351
5352**系统能力**:SystemCapability.Sensors.Sensor
5353
5354**参数**:
5355
5356| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5357| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5358| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | 是   | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。  |
5359| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
5360| options  | [Options](#options)                                          | 否   | 可选参数列表,用于设置传感器上报频率,默认值为200000000ns。  |
5361
5362**示例**:
5363
5364```ts
5365import { sensor } from '@kit.SensorServiceKit';
5366
5367sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
5368  console.info('Succeeded in invoking on. Wear status: ' + data.value);
5369},
5370  { interval: 100000000 }
5371);
5372```
5373
5374## sensor.once<sup>(deprecated)</sup>
5375
5376### ACCELEROMETER<sup>(deprecated)</sup>
5377
5378once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
5379
5380监听加速度传感器的数据变化一次。
5381
5382> **说明**:
5383>
5384> 从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER](#accelerometer9-1)<sup>9+</sup>代替。
5385
5386**需要权限**:ohos.permission.ACCELEROMETER
5387
5388**系统能力**:SystemCapability.Sensors.Sensor
5389
5390**参数**:
5391
5392| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5393| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5394| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | 是   | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。             |
5395| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
5396
5397**示例**:
5398
5399```ts
5400import { sensor } from '@kit.SensorServiceKit';
5401
5402sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
5403  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5404  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5405  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5406});
5407```
5408
5409### LINEAR_ACCELERATION<sup>(deprecated)</sup>
5410
5411once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;): void
5412
5413监听线性加速度传感器数据变化一次。
5414
5415> **说明**:
5416>
5417> 从API version 9 开始不再维护,建议使用[sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)<sup>9+</sup>代替。
5418
5419**需要权限**:ohos.permission.ACCELERATION
5420
5421**系统能力**:SystemCapability.Sensors.Sensor
5422
5423**参数**:
5424
5425| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5426| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5427| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。   |
5428| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
5429
5430### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
5431
5432once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
5433
5434监听未校准加速度传感器的数据变化一次。
5435
5436> **说明**:
5437>
5438> 从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)<sup>9+</sup>代替。
5439
5440**需要权限**:ohos.permission.ACCELEROMETER
5441
5442**系统能力**:SystemCapability.Sensors.Sensor
5443
5444**参数**:
5445
5446| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5447| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5448| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 是   | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
5449| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
5450
5451**示例**:
5452
5453```ts
5454import { sensor } from '@kit.SensorServiceKit';
5455
5456sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => {
5457  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5458  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5459  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5460  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5461  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5462  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5463});
5464```
5465
5466### GRAVITY<sup>(deprecated)</sup>
5467
5468once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
5469
5470监听重力传感器的数据变化一次。
5471
5472> **说明**:
5473>
5474> 从API version 9 开始不再维护,建议使用[sensor.once.GRAVITY](#gravity9-1)<sup>9+</sup>代替。
5475
5476**系统能力**:SystemCapability.Sensors.Sensor
5477
5478**参数**:
5479
5480| 参数名   | 类型                                                       | 必填 | 说明                                                         |
5481| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5482| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | 是   | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。                     |
5483| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | 是   | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
5484
5485**示例**:
5486
5487```ts
5488import { sensor } from '@kit.SensorServiceKit';
5489
5490sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => {
5491  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5492  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5493  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5494  });
5495```
5496
5497### GYROSCOPE<sup>(deprecated)</sup>
5498
5499once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
5500
5501监听陀螺仪传感器的数据变化一次。
5502
5503> **说明**:
5504>
5505> 从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE](#gyroscope9-1)<sup>9+</sup>代替。
5506
5507**需要权限**:ohos.permission.GYROSCOPE
5508
5509**系统能力**:SystemCapability.Sensors.Sensor
5510
5511**参数**:
5512
5513| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5514| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5515| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | 是   | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。                 |
5516| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | 是   | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
5517
5518**示例**:
5519
5520```ts
5521import { sensor } from '@kit.SensorServiceKit';
5522
5523sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => {
5524  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5525  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5526  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5527});
5528```
5529
5530### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
5531
5532once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
5533
5534监听未校准陀螺仪传感器的数据变化一次。
5535
5536> **说明**:
5537>
5538> 从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)<sup>9+</sup>代替。
5539
5540**需要权限**:ohos.permission.GYROSCOPE
5541
5542**系统能力**:SystemCapability.Sensors.Sensor
5543
5544**参数**:
5545
5546| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5547| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5548| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
5549| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
5550
5551**示例**:
5552
5553
5554```ts
5555import { sensor } from '@kit.SensorServiceKit';
5556
5557sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => {
5558    console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5559    console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5560    console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5561    console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5562    console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5563    console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5564});
5565```
5566
5567### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
5568
5569once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void
5570
5571监听有效运动传感器的数据变化一次。
5572
5573> **说明**:
5574>
5575> 从API version 9 开始不再维护,建议使用[sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)<sup>9+</sup>代替。
5576
5577**系统能力**:SystemCapability.Sensors.Sensor
5578
5579**参数**:
5580
5581| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5582| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5583| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 是   | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。      |
5584| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
5585
5586**示例**:
5587
5588```ts
5589import { sensor } from '@kit.SensorServiceKit';
5590
5591sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => {
5592  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5593});
5594```
5595
5596### PEDOMETER_DETECTION<sup>(deprecated)</sup>
5597
5598once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void
5599
5600监听计步检测传感器数据变化一次。
5601
5602> **说明**:
5603>
5604> 从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)<sup>9+</sup>代替。
5605
5606**需要权限**:ohos.permission.ACTIVITY_MOTION
5607
5608**系统能力**:SystemCapability.Sensors.Sensor
5609
5610**参数**:
5611
5612| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5613| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5614| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。     |
5615| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
5616
5617**示例**:
5618
5619```ts
5620import { sensor } from '@kit.SensorServiceKit';
5621
5622sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => {
5623  console.info('Succeeded in invoking once. Scalar data: ' + data.scalar);
5624});
5625```
5626
5627### PEDOMETER<sup>(deprecated)</sup>
5628
5629once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
5630
5631监听计步器传感器数据变化一次。
5632
5633> **说明**:
5634>
5635> 从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER](#pedometer9-1)<sup>9+</sup>代替。
5636
5637**需要权限**:ohos.permission.ACTIVITY_MOTION
5638
5639**系统能力**:SystemCapability.Sensors.Sensor
5640
5641**参数**:
5642
5643| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5644| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5645| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | 是   | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。                   |
5646| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | 是   | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
5647
5648**示例**:
5649
5650```ts
5651import { sensor } from '@kit.SensorServiceKit';
5652
5653sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => {
5654  console.info('Succeeded in invoking once. Steps: ' + data.steps);
5655});
5656```
5657
5658### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
5659
5660once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void
5661
5662监听环境温度传感器数据变化一次。
5663
5664> **说明**:
5665>
5666> 从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)<sup>9+</sup>代替。
5667
5668**系统能力**:SystemCapability.Sensors.Sensor
5669
5670**参数**:
5671
5672| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5673| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5674| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 是   | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。     |
5675| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
5676
5677**示例**:
5678
5679```ts
5680import { sensor } from '@kit.SensorServiceKit';
5681
5682sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => {
5683  console.info('Succeeded in invoking once. Temperature: ' + data.temperature);
5684});
5685```
5686
5687### MAGNETIC_FIELD<sup>(deprecated)</sup>
5688
5689once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
5690
5691监听磁场传感器数据变化一次。
5692
5693> **说明**:
5694>
5695> 从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)<sup>9+</sup>代替。
5696
5697**系统能力**:SystemCapability.Sensors.Sensor
5698
5699**参数**:
5700
5701| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5702| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5703| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | 是   | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。              |
5704| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
5705
5706**示例**:
5707
5708```ts
5709import { sensor } from '@kit.SensorServiceKit';
5710
5711sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => {
5712  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5713  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5714  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5715});
5716```
5717
5718### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
5719
5720once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
5721
5722监听未校准磁场传感器数据变化一次。
5723
5724> **说明**:
5725>
5726> 从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)<sup>9+</sup>代替。
5727
5728**系统能力**:SystemCapability.Sensors.Sensor
5729
5730**参数**:
5731
5732| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5733| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5734| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 是   | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
5735| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
5736
5737**示例**:
5738
5739```ts
5740import { sensor } from '@kit.SensorServiceKit';
5741
5742sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => {
5743  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5744  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5745  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5746  console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX);
5747  console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY);
5748  console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ);
5749});
5750```
5751
5752### PROXIMITY<sup>(deprecated)</sup>
5753
5754once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
5755
5756监听接近光传感器数据变化一次。
5757
5758> **说明**:
5759>
5760> 从API version 9 开始不再维护,建议使用[sensor.once.PROXIMITY](#proximity9-1)<sup>9+</sup>代替。
5761
5762**系统能力**:SystemCapability.Sensors.Sensor
5763
5764**参数**:
5765
5766| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5767| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5768| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | 是   | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。                 |
5769| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | 是   | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
5770
5771**示例**:
5772
5773```ts
5774import { sensor } from '@kit.SensorServiceKit';
5775
5776sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => {
5777  console.info('Succeeded in invoking once. Distance: ' + data.distance);
5778}
5779);
5780```
5781
5782### HUMIDITY<sup>(deprecated)</sup>
5783
5784once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
5785
5786监听湿度传感器数据变化一次。
5787
5788> **说明**:
5789>
5790> 从API version 9 开始不再维护,建议使用[sensor.once.HUMIDITY](#humidity9-1)<sup>9+</sup>代替。
5791
5792**系统能力**:SystemCapability.Sensors.Sensor
5793
5794**参数**:
5795
5796| 参数名   | 类型                                                        | 必填 | 说明                                                         |
5797| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5798| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | 是   | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。                    |
5799| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | 是   | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
5800
5801**示例**:
5802
5803```ts
5804import { sensor } from '@kit.SensorServiceKit';
5805
5806sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => {
5807  console.info('Succeeded in invoking once. Humidity: ' + data.humidity);
5808});
5809```
5810
5811### BAROMETER<sup>(deprecated)</sup>
5812
5813once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
5814
5815监听气压计传感器数据变化一次。
5816
5817> **说明**:
5818>
5819> 从API version 9 开始不再维护,建议使用[sensor.once.BAROMETER](#barometer9-1)<sup>9+</sup>代替。
5820
5821**系统能力**:SystemCapability.Sensors.Sensor
5822
5823**参数**:
5824
5825| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5826| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5827| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | 是   | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。                 |
5828| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | 是   | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
5829
5830**示例**:
5831
5832```ts
5833import { sensor } from '@kit.SensorServiceKit';
5834
5835sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => {
5836  console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure);
5837});
5838```
5839
5840### HALL<sup>(deprecated)</sup>
5841
5842once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
5843
5844监听霍尔传感器数据变化一次。
5845
5846> **说明**:
5847>
5848> 从API version 9 开始不再维护,建议使用[sensor.once.HALL](#hall9-1)<sup>9+</sup>代替。
5849
5850**系统能力**:SystemCapability.Sensors.Sensor
5851
5852**参数**:
5853
5854| 参数名   | 类型                                                    | 必填 | 说明                                                         |
5855| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5856| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | 是   | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。                        |
5857| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | 是   | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
5858
5859**示例**:
5860
5861```ts
5862import { sensor } from '@kit.SensorServiceKit';
5863
5864sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => {
5865  console.info('Succeeded in invoking once. Status: ' + data.status);
5866});
5867```
5868
5869### AMBIENT_LIGHT<sup>(deprecated)</sup>
5870
5871once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
5872
5873监听环境光传感器数据变化一次。
5874
5875> **说明**:
5876>
5877> 从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_LIGHT](#ambient_light9-1)<sup>9+</sup>代替。
5878
5879**系统能力**:SystemCapability.Sensors.Sensor
5880
5881**参数**:
5882
5883| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5884| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5885| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | 是   | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。             |
5886| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | 是   | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
5887
5888**示例**:
5889
5890```ts
5891import { sensor } from '@kit.SensorServiceKit';
5892
5893sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => {
5894  console.info('Succeeded in invoking once. invoking once. Illumination: ' + data.intensity);
5895});
5896```
5897
5898### ORIENTATION<sup>(deprecated)</sup>
5899
5900once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
5901
5902监听方向传感器数据变化一次。
5903
5904> **说明**:
5905>
5906> 从API version 9 开始不再维护,建议使用[sensor.once.ORIENTATION](#orientation9-1)<sup>9+</sup>代替。
5907
5908**系统能力**:SystemCapability.Sensors.Sensor
5909
5910**参数**:
5911
5912| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5913| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5914| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | 是   | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。                 |
5915| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | 是   | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
5916
5917**示例**:
5918
5919```ts
5920import { sensor } from '@kit.SensorServiceKit';
5921
5922sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => {
5923  console.info('Succeeded in invoking the device rotateing at an angle around the X axis: ' + data.beta);
5924  console.info('Succeeded in invoking the device rotateing at an angle around the Y axis: ' + data.gamma);
5925  console.info('Succeeded in invoking the device rotateing at an angle around the Z axis: ' + data.alpha);
5926});
5927```
5928
5929### ROTATION_VECTOR<sup>(deprecated)</sup>
5930
5931once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
5932
5933监听旋转矢量传感器数据变化一次。
5934
5935> **说明**:
5936>
5937> 从API version 9 开始不再维护,建议使用[sensor.once.ROTATION_VECTOR](#rotation_vector9-1)<sup>9+</sup>代替。
5938
5939**系统能力**:SystemCapability.Sensors.Sensor
5940
5941**参数**:
5942
5943| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5944| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5945| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | 是   | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。         |
5946| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
5947
5948**示例**:
5949
5950```ts
5951import { sensor } from '@kit.SensorServiceKit';
5952
5953sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => {
5954  console.info('Succeeded in invoking once. X-coordinate component: ' + data.x);
5955  console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y);
5956  console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z);
5957  console.info('Succeeded in invoking once. Scalar quantity: ' + data.w);
5958});
5959```
5960
5961### HEART_RATE<sup>(deprecated)</sup>
5962
5963once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
5964
5965监听心率传感器数据变化一次。
5966
5967> **说明**:
5968>
5969> 从API version 9 开始不再维护,建议使用[sensor.once.HEART_RATE](#heart_rate9-1)<sup>9+</sup>代替。
5970
5971**需要权限**:ohos.permission.HEART_RATE
5972
5973**系统能力**:SystemCapability.Sensors.Sensor
5974
5975**参数**:
5976
5977| 参数名   | 类型                                                         | 必填 | 说明                                                         |
5978| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5979| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | 是   | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。                  |
5980| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | 是   | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
5981
5982**示例**:
5983
5984
5985```ts
5986import { sensor } from '@kit.SensorServiceKit';
5987
5988sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, (data: sensor.HeartRateResponse) => {
5989  console.info("Succeeded in invoking once. Heart rate: " + data.heartRate);
5990});
5991```
5992
5993### WEAR_DETECTION<sup>(deprecated)</sup>
5994
5995once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
5996
5997监听所佩戴的检测传感器的数据变化一次。
5998
5999> **说明**:
6000>
6001> 从API version 9 开始不再维护,建议使用[sensor.once.WEAR_DETECTION](#wear_detection9-1)<sup>9+</sup>代替。
6002
6003**系统能力**:SystemCapability.Sensors.Sensor
6004
6005**参数**:
6006
6007| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6008| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6009| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | 是   | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。          |
6010| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
6011
6012**示例**:
6013
6014
6015```ts
6016import { sensor } from '@kit.SensorServiceKit';
6017
6018sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => {
6019  console.info("Succeeded in invoking once. Wear status: " + data.value);
6020});
6021```
6022
6023## sensor.off<sup>(deprecated)</sup>
6024
6025### ACCELEROMETER<sup>(deprecated)</sup>
6026
6027off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
6028
6029取消订阅传感器数据。
6030
6031> **说明**:
6032>
6033> 从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER<sup>9+</sup>](#accelerometer9-2)代替。
6034
6035**需要权限**:ohos.permission.ACCELEROMETER
6036
6037**系统能力**:SystemCapability.Sensors.Sensor
6038
6039**参数**:
6040
6041| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6042| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6043| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | 是   | 要取消订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
6044| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6045
6046**示例**:
6047
6048```ts
6049import { sensor } from '@kit.SensorServiceKit';
6050
6051function callback(data: sensor.AccelerometerResponse) {
6052  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6053  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6054  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6055}
6056
6057sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
6058```
6059
6060### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
6061
6062off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
6063
6064取消订阅传感器数据。
6065
6066> **说明**:
6067>
6068> 从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)<sup>9+</sup>代替。
6069
6070**需要权限**:ohos.permission.ACCELEROMETER
6071
6072**系统能力**:SystemCapability.Sensors.Sensor
6073
6074**参数**:
6075
6076| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6077| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6078| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 是   | 要取消订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
6079| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6080
6081**示例**:
6082
6083```ts
6084import { sensor } from '@kit.SensorServiceKit';
6085
6086function callback(data: sensor.AccelerometerUncalibratedResponse) {
6087  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6088  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6089  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6090  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6091  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6092  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6093}
6094
6095sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
6096```
6097
6098### AMBIENT_LIGHT<sup>(deprecated)</sup>
6099
6100off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
6101
6102取消订阅传感器数据。
6103
6104> **说明**:
6105>
6106> 从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_LIGHT](#ambient_light9-2)<sup>9+</sup>代替。
6107
6108**系统能力**:SystemCapability.Sensors.Sensor
6109
6110**参数**:
6111
6112| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6113| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6114| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | 是   | 要取消订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
6115| callback | Callback&lt;[LightResponse](#lightresponse)&gt;              | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6116
6117**示例**:
6118
6119```ts
6120import { sensor } from '@kit.SensorServiceKit';
6121
6122function callback(data: sensor.LightResponse) {
6123  console.info('Succeeded in invoking off. Illumination: ' + data.intensity);
6124}
6125
6126sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
6127```
6128
6129### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
6130
6131off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
6132
6133取消订阅传感器数据。
6134
6135> **说明**:
6136>
6137> 从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)<sup>9+</sup>代替。
6138
6139**系统能力**:SystemCapability.Sensors.Sensor
6140
6141**参数**:
6142
6143| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6144| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6145| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 是   | 要取消订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
6146| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6147
6148**示例**:
6149
6150```ts
6151import { sensor } from '@kit.SensorServiceKit';
6152
6153function callback(data: sensor.AmbientTemperatureResponse) {
6154  console.info('Succeeded in invoking off. Temperature: ' + data.temperature);
6155}
6156
6157sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
6158```
6159
6160### BAROMETER<sup>(deprecated)</sup>
6161
6162off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
6163
6164取消订阅传感器数据。
6165
6166> **说明**:
6167>
6168> 从API version 9 开始不再维护,建议使用[sensor.off.BAROMETER](#barometer9-2)<sup>9+</sup>代替。
6169
6170**系统能力**:SystemCapability.Sensors.Sensor
6171
6172**参数**:
6173
6174| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6175| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6176| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | 是   | 要取消订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。     |
6177| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt;      | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6178
6179**示例**:
6180
6181```ts
6182import { sensor } from '@kit.SensorServiceKit';
6183
6184function callback(data: sensor.BarometerResponse) {
6185  console.info('Succeeded in invoking off. Atmospheric pressure: ' + data.pressure);
6186}
6187
6188sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
6189```
6190
6191### GRAVITY<sup>(deprecated)</sup>
6192
6193off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
6194
6195取消订阅传感器数据。
6196
6197> **说明**:
6198>
6199> 从API version 9 开始不再维护,建议使用[sensor.off.GRAVITY](#gravity9-2)<sup>9+</sup>代替。
6200
6201**系统能力**:SystemCapability.Sensors.Sensor
6202
6203**参数**:
6204
6205| 参数名   | 类型                                                       | 必填 | 说明                                                         |
6206| -------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6207| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | 是   | 要取消订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。         |
6208| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt;        | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6209
6210**示例**:
6211
6212```ts
6213import { sensor } from '@kit.SensorServiceKit';
6214
6215function callback(data: sensor.GravityResponse) {
6216  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6217  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6218  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6219}
6220
6221sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
6222```
6223
6224### GYROSCOPE<sup>(deprecated)</sup>
6225
6226off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
6227
6228取消订阅传感器数据。
6229
6230> **说明**:
6231>
6232> 从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE](#gyroscope9-2)<sup>9+</sup>代替。
6233
6234**需要权限**:ohos.permission.GYROSCOPE
6235
6236**系统能力**:SystemCapability.Sensors.Sensor
6237
6238**参数**:
6239
6240| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6241| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6242| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | 是   | 要取消订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。     |
6243| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt;      | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6244
6245**示例**:
6246
6247```ts
6248import { sensor } from '@kit.SensorServiceKit';
6249
6250function callback(data: sensor.GyroscopeResponse) {
6251  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6252  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6253  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6254}
6255
6256sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
6257```
6258
6259### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
6260
6261off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
6262
6263取消订阅传感器数据。
6264
6265> **说明**:
6266>
6267> 从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)<sup>9+</sup>代替。
6268
6269**需要权限**:ohos.permission.GYROSCOPE
6270
6271**系统能力**:SystemCapability.Sensors.Sensor
6272
6273**参数**:
6274
6275| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6276| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6277| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 要取消订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
6278| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6279
6280**示例**:
6281
6282```ts
6283import { sensor } from '@kit.SensorServiceKit';
6284
6285function callback(data: sensor.GyroscopeUncalibratedResponse) {
6286  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6287  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6288  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6289}
6290
6291sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
6292```
6293
6294### HALL<sup>(deprecated)</sup>
6295
6296off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
6297
6298取消订阅传感器数据。
6299
6300> **说明**:
6301>
6302> 从API version 9 开始不再维护,建议使用[sensor.off.HALL](#hall9-2)<sup>9+</sup>代替。
6303
6304**系统能力**:SystemCapability.Sensors.Sensor
6305
6306**参数**:
6307
6308| 参数名   | 类型                                                    | 必填 | 说明                                                         |
6309| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6310| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | 是   | 要取消订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。            |
6311| callback | Callback&lt;[HallResponse](#hallresponse)&gt;           | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6312
6313**示例**:
6314
6315```ts
6316import { sensor } from '@kit.SensorServiceKit';
6317
6318function callback(data: sensor.HallResponse) {
6319  console.info('Succeeded in invoking off. Status: ' + data.status);
6320}
6321
6322sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
6323```
6324
6325### HEART_RATE<sup>(deprecated)</sup>
6326
6327off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
6328
6329取消订阅传感器数据。
6330
6331> **说明**:
6332>
6333> 从API version 9 开始不再维护,建议使用[sensor.off.HEART_RATE](#heart_rate9-2)<sup>9+</sup>代替。
6334
6335**需要权限**:ohos.permission.HEALTH_DATA
6336
6337**系统能力**:SystemCapability.Sensors.Sensor
6338
6339**参数**:
6340
6341| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6342| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6343| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | 是   | 要取消订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。      |
6344| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt;      | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6345
6346**示例**:
6347
6348```ts
6349import { sensor } from '@kit.SensorServiceKit';
6350
6351function callback(data: sensor.HeartRateResponse) {
6352  console.info('Succeeded in invoking off. Humidity: ' + data.heartRate);
6353}
6354
6355sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
6356```
6357
6358### HUMIDITY<sup>(deprecated)</sup>
6359
6360off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
6361
6362取消订阅传感器数据。
6363
6364> **说明**:
6365>
6366> 从API version 9 开始不再维护,建议使用[sensor.off.HUMIDITY](#humidity9-2)<sup>9+</sup>代替。
6367
6368**系统能力**:SystemCapability.Sensors.Sensor
6369
6370**参数**:
6371
6372| 参数名   | 类型                                                        | 必填 | 说明                                                         |
6373| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
6374| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | 是   | 要取消订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。        |
6375| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt;       | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6376
6377**示例**:
6378
6379```ts
6380import { sensor } from '@kit.SensorServiceKit';
6381
6382function callback(data: sensor.HumidityResponse) {
6383  console.info('Succeeded in invoking off. Humidity: ' + data.humidity);
6384}
6385
6386sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
6387```
6388
6389### LINEAR_ACCELERATION<sup>(deprecated)</sup>
6390
6391off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
6392
6393取消订阅传感器数据。
6394
6395> **说明**:
6396>
6397> 从API version 9 开始不再维护,建议使用[sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)<sup>9+</sup>代替。
6398
6399**需要权限**:ohos.permission.ACCELEROMETER
6400
6401**系统能力**:SystemCapability.Sensors.Sensor
6402
6403**参数**:
6404
6405| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6406| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6407| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 要取消订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
6408| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6409
6410**示例**:
6411
6412```ts
6413import { sensor } from '@kit.SensorServiceKit';
6414
6415function callback(data: sensor.LinearAccelerometerResponse) {
6416  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6417  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6418  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6419}
6420
6421sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
6422```
6423
6424### MAGNETIC_FIELD<sup>(deprecated)</sup>
6425
6426 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
6427
6428取消订阅传感器数据。
6429
6430> **说明**:
6431>
6432> 从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)<sup>9+</sup>代替。
6433
6434**系统能力**:SystemCapability.Sensors.Sensor
6435
6436**参数**:
6437
6438| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6439| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6440| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | 是   | 要取消订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。  |
6441| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6442
6443**示例**:
6444
6445```ts
6446import { sensor } from '@kit.SensorServiceKit';
6447
6448function callback(data: sensor.MagneticFieldResponse) {
6449  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6450  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6451  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6452}
6453
6454sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
6455```
6456
6457### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
6458
6459 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
6460
6461取消订阅传感器数据。
6462
6463> **说明**:
6464>
6465> 从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)<sup>9+</sup>代替。
6466
6467**系统能力**:SystemCapability.Sensors.Sensor
6468
6469**参数**:
6470
6471| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6472| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6473| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 是   | 要取消订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
6474| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6475
6476**示例**:
6477
6478```ts
6479import { sensor } from '@kit.SensorServiceKit';
6480
6481function callback(data: sensor.MagneticFieldUncalibratedResponse) {
6482  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6483  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6484  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6485  console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX);
6486  console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY);
6487  console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ);
6488}
6489
6490sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
6491```
6492
6493### ORIENTATION<sup>(deprecated)</sup>
6494
6495 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
6496
6497取消订阅传感器数据。
6498
6499> **说明**:
6500>
6501> 从API version 9 开始不再维护,建议使用[sensor.off.ORIENTATION](#orientation9-2)<sup>9+</sup>代替。
6502
6503**系统能力**:SystemCapability.Sensors.Sensor
6504
6505**参数**:
6506
6507| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6508| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6509| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | 是   | 要取消订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。     |
6510| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt;  | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6511
6512**示例**:
6513
6514```ts
6515import { sensor } from '@kit.SensorServiceKit';
6516
6517function callback(data: sensor.OrientationResponse) {
6518  console.info('Succeeded in invoking off. The device rotates at an angle around the X axis: ' + data.beta);
6519  console.info('Succeeded in invoking off. The device rotates at an angle around the Y axis: ' + data.gamma);
6520  console.info('Succeeded in invoking off. The device rotates at an angle around the Z axis: ' + data.alpha);
6521}
6522
6523sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
6524```
6525
6526### PEDOMETER<sup>(deprecated)</sup>
6527
6528off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
6529
6530取消订阅传感器数据。
6531
6532> **说明**:
6533>
6534> 从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER](#pedometer9-2)<sup>9+</sup>代替。
6535
6536**需要权限**:ohos.permission.ACTIVITY_MOTION
6537
6538**系统能力**:SystemCapability.Sensors.Sensor
6539
6540**参数**:
6541
6542| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6543| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6544| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | 是   | 要取消订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。       |
6545| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt;      | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6546
6547**示例**:
6548
6549```ts
6550import { sensor } from '@kit.SensorServiceKit';
6551
6552function callback(data: sensor.PedometerResponse) {
6553  console.info('Succeeded in invoking off. Steps: ' + data.steps);
6554}
6555
6556sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
6557```
6558
6559### PEDOMETER_DETECTION<sup>(deprecated)</sup>
6560
6561off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
6562
6563取消订阅传感器数据。
6564
6565> **说明**:
6566>
6567> 从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)<sup>9+</sup>代替。
6568
6569**需要权限**:ohos.permission.ACTIVITY_MOTION
6570
6571**系统能力**:SystemCapability.Sensors.Sensor
6572
6573**参数**:
6574
6575| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6576| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6577| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 要取消订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
6578| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6579
6580**示例**:
6581
6582```ts
6583import { sensor } from '@kit.SensorServiceKit';
6584
6585function callback(data: sensor.PedometerDetectionResponse) {
6586  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6587}
6588
6589sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
6590```
6591
6592### PROXIMITY<sup>(deprecated)</sup>
6593
6594off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
6595
6596取消订阅传感器数据。
6597
6598> **说明**:
6599>
6600> 从API version 9 开始不再维护,建议使用[sensor.off.PROXIMITY](#proximity9-2)<sup>9+</sup>代替。
6601
6602**系统能力**:SystemCapability.Sensors.Sensor
6603
6604**参数**:
6605
6606| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6607| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6608| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | 是   | 要取消订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。     |
6609| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt;      | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6610
6611**示例**:
6612
6613```ts
6614import { sensor } from '@kit.SensorServiceKit';
6615
6616function callback(data: sensor.ProximityResponse) {
6617  console.info('Succeeded in invoking off. Distance: ' + data.distance);
6618}
6619
6620sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
6621```
6622
6623### ROTATION_VECTOR<sup>(deprecated)</sup>
6624
6625off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
6626
6627取消订阅传感器数据。
6628
6629> **说明**:
6630>
6631> 从API version 9 开始不再维护,建议使用[sensor.off.ROTATION_VECTOR](#rotation_vector9-2)<sup>9+</sup>代替。
6632
6633**系统能力**:SystemCapability.Sensors.Sensor
6634
6635**参数**:
6636
6637| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6638| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6639| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | 是   | 要取消订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
6640| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6641
6642**示例**:
6643
6644```ts
6645import { sensor } from '@kit.SensorServiceKit';
6646
6647function callback(data: sensor.RotationVectorResponse) {
6648  console.info('Succeeded in invoking off. X-coordinate component: ' + data.x);
6649  console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y);
6650  console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z);
6651  console.info('Succeeded in invoking off. Scalar quantity: ' + data.w);
6652}
6653
6654sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
6655```
6656
6657### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
6658
6659off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
6660
6661取消订阅有效运动传感器数据。
6662
6663> **说明**:
6664>
6665> 从API version 9 开始不再维护,建议使用[sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)<sup>9+</sup>代替。
6666
6667**系统能力**:SystemCapability.Sensors.Sensor
6668
6669**参数**:
6670
6671| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6672| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6673| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 是   | 要取消订阅的有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
6674| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6675
6676**示例**:
6677
6678```ts
6679import { sensor } from '@kit.SensorServiceKit';
6680
6681function callback(data: sensor.SignificantMotionResponse) {
6682  console.info('Succeeded in invoking off. Scalar data: ' + data.scalar);
6683}
6684
6685sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
6686```
6687
6688### WEAR_DETECTION<sup>(deprecated)</sup>
6689
6690off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
6691
6692取消订阅传感器数据。
6693
6694> **说明**:
6695>
6696> 从API version 9 开始不再维护,建议使用[sensor.off.WEAR_DETECTION](#wear_detection9-2)<sup>9+</sup>代替。
6697
6698**系统能力**:SystemCapability.Sensors.Sensor
6699
6700**参数**:
6701
6702| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6703| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6704| type     | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | 是   | 要取消订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
6705| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
6706
6707**示例**:
6708
6709```ts
6710import { sensor } from '@kit.SensorServiceKit';
6711
6712function accCallback(data: sensor.WearDetectionResponse) {
6713  console.info('Succeeded in invoking off. Wear status: ' + data.value);
6714}
6715
6716sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
6717```
6718
6719## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6720
6721transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
6722
6723旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系,使用Callback异步方式返回结果。
6724
6725> **说明**:
6726>
6727> 从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9)<sup>9+</sup>代替。
6728
6729**系统能力**:SystemCapability.Sensors.Sensor
6730
6731**参数**:
6732
6733| 参数名           | 类型                                      | 必填 | 说明                       |
6734| ---------------- | ----------------------------------------- | ---- | -------------------------- |
6735| inRotationVector | Array&lt;number&gt;                       | 是   | 表示旋转矩阵。             |
6736| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 表示坐标系方向。           |
6737| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | 是   | 异步返回转换后的旋转矩阵。 |
6738
6739**示例**:
6740
6741```ts
6742import { sensor } from '@kit.SensorServiceKit';
6743import { BusinessError } from '@kit.BasicServicesKit';
6744
6745sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 },
6746                                 (err: BusinessError, data: Array<number>) => {
6747  if (err) {
6748    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6749    return;
6750  }
6751  console.info("Succeeded in starting Operation. Data obtained: " + data);
6752  for (let i = 0; i < data.length; i++) {
6753    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6754  }
6755})
6756```
6757## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
6758
6759transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
6760
6761旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系,使用Promise异步方式返回结果。
6762
6763> **说明**:
6764>
6765> 从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)<sup>9+</sup>代替。
6766
6767**系统能力**:SystemCapability.Sensors.Sensor
6768
6769**参数**:
6770
6771| 参数名              | 类型                                       | 必填   | 说明       |
6772| ---------------- | ---------------------------------------- | ---- | -------- |
6773| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。  |
6774| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。 |
6775
6776**返回值**:
6777
6778| 类型                               | 说明                               |
6779| ---------------------------------- | ---------------------------------- |
6780| Promise&lt;Array&lt;number&gt;&gt; | 使用异步方式返回转换后的旋转矩阵。 |
6781
6782**示例**:
6783
6784```ts
6785import { sensor } from '@kit.SensorServiceKit';
6786import { BusinessError } from '@kit.BasicServicesKit';
6787
6788const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 });
6789promise.then((data: Array<number>) => {
6790  console.info("Succeeded in starting Operation");
6791  for (let i = 0; i < data.length; i++) {
6792    console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]);
6793  }
6794}).catch((err: BusinessError) => {
6795  console.error(`Failed to operate.`);
6796})
6797```
6798
6799## sensor.getGeomagneticField<sup>(deprecated)</sup>
6800
6801getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
6802
6803获取地球上特定位置的地磁场,使用callback异步方式返回结果。
6804
6805> **说明**:
6806>
6807> 从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)<sup>9+</sup>代替。
6808
6809**系统能力**:SystemCapability.Sensors.Sensor
6810
6811**参数**:
6812
6813| 参数名          | 类型                                                         | 必填 | 说明                               |
6814| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
6815| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置。                         |
6816| timeMillis      | number                                                       | 是   | 表示获取磁偏角的时间,单位为毫秒。 |
6817| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 异步返回磁场信息。                 |
6818
6819**示例**:
6820
6821```ts
6822import { sensor } from '@kit.SensorServiceKit';
6823import { BusinessError } from '@kit.BasicServicesKit';
6824
6825sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000,
6826                           (err: BusinessError, data: sensor.GeomagneticResponse) => {
6827  if (err) {
6828    console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`);
6829    return;
6830  }
6831  console.info('Succeeded in getting sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
6832  data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
6833  ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
6834});
6835```
6836## sensor.getGeomagneticField<sup>(deprecated)</sup>
6837
6838getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
6839
6840获取地球上特定位置的地磁场,使用Promise异步方式返回结果。
6841
6842> **说明**:
6843>
6844> 从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)<sup>9+</sup>代替。
6845
6846**系统能力**:SystemCapability.Sensors.Sensor
6847
6848**参数**:
6849
6850| 参数名             | 类型                                  | 必填   | 说明                |
6851| --------------- | ----------------------------------- | ---- | ----------------- |
6852| locationOptions | [LocationOptions](#locationoptions) | 是    | 地理位置。             |
6853| timeMillis      | number                              | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
6854
6855**返回值**:
6856
6857| 类型                                                       | 说明                       |
6858| ---------------------------------------------------------- | -------------------------- |
6859| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 使用异步方式返回磁场信息。 |
6860
6861**示例**:
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
6881根据气压值获取设备所在的海拔高度,使用Callback异步方式返回结果。
6882
6883> **说明**:
6884>
6885> 从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9)<sup>9+</sup>代替。
6886
6887**系统能力**:SystemCapability.Sensors.Sensor
6888
6889**参数**:
6890
6891| 参数名          | 类型                        | 必填 | 说明                                   |
6892| --------------- | --------------------------- | ---- | -------------------------------------- |
6893| seaPressure     | number                      | 是   | 表示海平面气压值,单位为hPa。          |
6894| currentPressure | number                      | 是   | 表示设备所在高度的气压值,单位为hPa。  |
6895| callback        | AsyncCallback&lt;number&gt; | 是   | 异步返回设备所在的海拔高度,单位为米。 |
6896
6897**示例**:
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
6916根据气压值获取设备所在的海拔高度,使用Promise异步方式返回结果。
6917
6918> **说明**:
6919>
6920> 从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)<sup>9+</sup>代替。
6921
6922**系统能力**:SystemCapability.Sensors.Sensor
6923
6924**参数**:
6925
6926| 参数名             | 类型     | 必填   | 说明                   |
6927| --------------- | ------ | ---- | -------------------- |
6928| seaPressure     | number | 是    | 表示海平面气压值,单位为hPa。     |
6929| currentPressure | number | 是    | 表示设备所在高度的气压值,单位为hPa。 |
6930
6931**返回值**:
6932
6933| 类型                  | 说明                                             |
6934| --------------------- | ------------------------------------------------ |
6935| Promise&lt;number&gt; | 使用异步方式返回设备所在的海拔高度(单位:米)。 |
6936
6937**示例**:
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
6956根据倾斜矩阵计算地磁倾斜角,使用Callback异步方式返回结果。
6957
6958> **说明**:
6959>
6960> 从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9)<sup>9+</sup>代替。
6961
6962**系统能力**:SystemCapability.Sensors.Sensor
6963
6964**参数**:
6965
6966| 参数名            | 类型                        | 必填 | 说明                             |
6967| ----------------- | --------------------------- | ---- | -------------------------------- |
6968| inclinationMatrix | Array&lt;number&gt;         | 是   | 表示倾斜矩阵。                   |
6969| callback          | AsyncCallback&lt;number&gt; | 是   | 异步返回地磁倾斜角,单位为弧度。 |
6970
6971**示例**:
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
6990根据倾斜矩阵计算地磁倾斜角,使用Promise异步方式返回结果。
6991
6992> **说明**:
6993>
6994> 从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9-1)<sup>9+</sup>代替。
6995
6996**系统能力**:SystemCapability.Sensors.Sensor
6997
6998**参数**:
6999
7000| 参数名               | 类型                  | 必填   | 说明      |
7001| ----------------- | ------------------- | ---- | ------- |
7002| inclinationMatrix | Array&lt;number&gt; | 是    | 表示倾斜矩阵。 |
7003
7004**返回值**:
7005
7006| 类型                  | 说明                                     |
7007| --------------------- | ---------------------------------------- |
7008| Promise&lt;number&gt; | 使用异步方式返回地磁倾斜角,单位为弧度。 |
7009
7010**示例**:
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
7028获取两个旋转矩阵之间的角度变化,使用Callback异步方式返回结果。
7029
7030> **说明**:
7031>
7032> 从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9)<sup>9+</sup>代替。
7033
7034**系统能力**:SystemCapability.Sensors.Sensor
7035
7036**参数**:
7037
7038| 参数名                | 类型                                     | 必填 | 说明                                  |
7039| --------------------- | ---------------------------------------- | ---- | ------------------------------------- |
7040| currentRotationMatrix | Array&lt;number&gt;                      | 是   | 表示当前旋转矩阵。                    |
7041| preRotationMatrix     | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                        |
7042| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 异步返回z、x、y轴方向的旋转角度变化。 |
7043
7044**示例**:
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
7066获取两个旋转矩阵之间的角度变化,使用Promise异步方式返回结果。
7067
7068> **说明**:
7069>
7070> 从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9-1)<sup>9+</sup>代替。
7071
7072**系统能力**:SystemCapability.Sensors.Sensor
7073
7074**参数**:
7075
7076| 参数名                   | 类型                  | 必填   | 说明        |
7077| --------------------- | ------------------- | ---- | --------- |
7078| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
7079| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
7080
7081**返回值**:
7082
7083| 类型                               | 说明                                          |
7084| ---------------------------------- | --------------------------------------------- |
7085| Promise&lt;Array&lt;number&gt;&gt; | 使用异步方式返回z、x、y轴方向的旋转角度变化。 |
7086
7087**示例**:
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
7109将旋转矢量转换为旋转矩阵,使用Callback异步方式返回结果。
7110
7111> **说明**:
7112>
7113> 从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9)<sup>9+</sup>代替。
7114
7115**系统能力**:SystemCapability.Sensors.Sensor
7116
7117**参数**:
7118
7119| 参数名         | 类型                                     | 必填 | 说明               |
7120| -------------- | ---------------------------------------- | ---- | ------------------ |
7121| rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。     |
7122| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 异步返回旋转矩阵。 |
7123
7124**示例**:
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
7146将旋转矢量转换为旋转矩阵,使用Promise异步方式返回结果。
7147
7148> **说明**:
7149>
7150> 从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)<sup>9+</sup>代替。
7151
7152**系统能力**:SystemCapability.Sensors.Sensor
7153
7154**参数**:
7155
7156| 参数名            | 类型                  | 必填   | 说明      |
7157| -------------- | ------------------- | ---- | ------- |
7158| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
7159
7160**返回值**:
7161
7162| 类型                               | 说明                       |
7163| ---------------------------------- | -------------------------- |
7164| Promise&lt;Array&lt;number&gt;&gt; | 使用异步方式返回旋转矩阵。 |
7165
7166**示例**:
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
7187将旋转矢量转换为四元数,使用Callback异步方式返回结果。
7188
7189> **说明**:
7190>
7191> 从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9)<sup>9+</sup>代替。
7192
7193**系统能力**:SystemCapability.Sensors.Sensor
7194
7195**参数**:
7196
7197| 参数名         | 类型                                     | 必填 | 说明             |
7198| -------------- | ---------------------------------------- | ---- | ---------------- |
7199| rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。   |
7200| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 异步返回四元数。 |
7201
7202**示例**:
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
7224将旋转矢量转换为四元数,使用Promise异步方式返回结果。
7225
7226> **说明**:
7227>
7228> 从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9-1)<sup>9+</sup>代替。
7229
7230**系统能力**:SystemCapability.Sensors.Sensor
7231
7232**参数**:
7233
7234| 参数名            | 类型                  | 必填   | 说明      |
7235| -------------- | ------------------- | ---- | ------- |
7236| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
7237
7238**返回值**:
7239
7240| 类型                               | 说明                     |
7241| ---------------------------------- | ------------------------ |
7242| Promise&lt;Array&lt;number&gt;&gt; | 使用异步方式返回四元数。 |
7243
7244**示例**:
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
7265根据旋转矩阵计算设备的方向,使用Callback异步方式返回结果。
7266
7267> **说明**:
7268>
7269> 从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9)<sup>9+</sup>代替。
7270
7271**系统能力**:SystemCapability.Sensors.Sensor
7272
7273**参数**:
7274
7275| 参数名         | 类型                                     | 必填 | 说明                                  |
7276| -------------- | ---------------------------------------- | ---- | ------------------------------------- |
7277| rotationMatrix | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                        |
7278| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 异步返回围绕z、x、y轴方向的旋转角度。 |
7279
7280**示例**:
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
7302根据旋转矩阵计算设备的方向,使用Promise异步方式返回结果。
7303
7304> **说明**:
7305>
7306> 从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9-1)<sup>9+</sup>代替。
7307
7308**系统能力**:SystemCapability.Sensors.Sensor
7309
7310**参数**:
7311
7312| 参数名            | 类型                  | 必填   | 说明      |
7313| -------------- | ------------------- | ---- | ------- |
7314| rotationMatrix | Array&lt;number&gt; | 是    | 表示旋转矩阵。 |
7315
7316**返回值**:
7317
7318| 类型                               | 说明                                          |
7319| ---------------------------------- | --------------------------------------------- |
7320| Promise&lt;Array&lt;number&gt;&gt; | 使用异步方式返回围绕z、x、y轴方向的旋转角度。 |
7321
7322**示例**:
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
7343根据重力矢量和地磁矢量计算旋转矩阵,使用Callback异步方式返回结果。
7344
7345> **说明**:
7346>
7347> 从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)<sup>9+</sup>代替。
7348
7349**系统能力**:SystemCapability.Sensors.Sensor
7350
7351**参数**:
7352
7353| 参数名      | 类型                                                         | 必填 | 说明               |
7354| ----------- | ------------------------------------------------------------ | ---- | ------------------ |
7355| gravity     | Array&lt;number&gt;                                          | 是   | 表示重力向量。     |
7356| geomagnetic | Array&lt;number&gt;                                          | 是   | 表示地磁矢量。     |
7357| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是   | 异步返回旋转矩阵。 |
7358
7359**示例**:
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
7379根据重力矢量和地磁矢量计算旋转矩阵,使用Promise异步方式返回结果。
7380
7381> **说明**:
7382>
7383> 从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)<sup>9+</sup>代替。
7384
7385**系统能力**:SystemCapability.Sensors.Sensor
7386
7387**参数**:
7388
7389| 参数名         | 类型                  | 必填   | 说明      |
7390| ----------- | ------------------- | ---- | ------- |
7391| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
7392| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
7393
7394**返回值**:
7395
7396| 类型                                                         | 说明                       |
7397| ------------------------------------------------------------ | -------------------------- |
7398| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 使用异步方式返回旋转矩阵。 |
7399
7400**示例**:
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