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