js-apis-sensor.md 117.1 KB
Newer Older
Z
zengyawen 已提交
1
# 传感器
Z
zengyawen 已提交
2

C
cff-gite 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15
## 模块说明

sensor模块提供订阅传感器数据基本能力,包括订阅、取消订阅传感器数据,获取传感器列表,以及通用的传感器算法接口如通过气压值计算海拔高度、通过旋转矩阵计算设备方向等。

传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。根据用途可分为以下六大类:

- 运动类:加速度、陀螺仪、重力、线性加速度传感器等
- 姿态类:旋转矢量、方向传感器等
- 环境类:磁力计、气压、湿度传感器等
- 光线类:环境光、接近光、色温传感器等
- 健康类:心率、心跳传感器等
- 其它:霍尔传感器、手握传感器等

H
HelloCrease 已提交
16
> **说明:**
Z
zengyawen 已提交
17
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
18

Z
zengyawen 已提交
19 20

## 导入模块
Z
zengyawen 已提交
21

H
HelloCrease 已提交
22
```js
Z
zengyawen 已提交
23 24 25
import sensor from '@ohos.sensor';
```

H
HelloCrease 已提交
26
## sensor.on
Z
zengyawen 已提交
27

H
HelloCrease 已提交
28
### ACCELEROMETER
Z
zengyawen 已提交
29

C
cff-gite 已提交
30
on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>,options?: Options): void
Z
zengyawen 已提交
31 32 33

监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。

C
cff-gite 已提交
34 35 36 37
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
38
**参数:** 
C
cff-gite 已提交
39

H
HelloCrease 已提交
40 41 42 43 44
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | 是    | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
45

H
HelloCrease 已提交
46
**示例:** 
H
HelloCrease 已提交
47
  ```js
C
cff-gite 已提交
48
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
49
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
50 51
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
52 53
  },
      {interval: 10000000}
Z
zengyawen 已提交
54 55
  );
  ```
Z
zengyawen 已提交
56

H
h00514358 已提交
57
### LINEAR_ACCELERATION<sup>deprecated</sup>
Z
zengyawen 已提交
58

C
cff-gite 已提交
59
on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void
Z
zengyawen 已提交
60

Z
zengyawen 已提交
61 62
监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。

H
h00514358 已提交
63
从API Version9开始该接口不再维护,推荐使用sensor.on.LINEAR_ACCELEROMETER
H
h00514358 已提交
64

C
cff-gite 已提交
65 66 67 68
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
69 70 71 72 73 74
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
75

H
HelloCrease 已提交
76
**示例:** 
H
HelloCrease 已提交
77
  ```js
C
cff-gite 已提交
78
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){
Z
zengyawen 已提交
79 80 81
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
82 83
  },
      {interval: 10000000}
Z
zengyawen 已提交
84 85
  );
  ```
Z
zengyawen 已提交
86

H
h00514358 已提交
87
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void

监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。


**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELEROMETER。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |

**示例:**
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,function(data){
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
      {interval: 10000000}
  );
  ```

H
HelloCrease 已提交
116
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
117

C
cff-gite 已提交
118
on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
119

Z
zengyawen 已提交
120
监听未校准加速度计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
121

C
cff-gite 已提交
122 123 124 125
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
126 127 128 129 130 131
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是    | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
132

H
HelloCrease 已提交
133
**示例:** 
H
HelloCrease 已提交
134
  ```js
C
cff-gite 已提交
135
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
136 137 138 139 140 141
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
142 143
  },
      {interval: 10000000}
Z
zengyawen 已提交
144 145
  );
  ```
Z
zengyawen 已提交
146

H
HelloCrease 已提交
147
### GRAVITY
Z
zengyawen 已提交
148

C
cff-gite 已提交
149
on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
150

Z
zengyawen 已提交
151
监听重力传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
152

C
cff-gite 已提交
153 154
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
155 156 157 158 159 160
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                    |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。   |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。        |
Z
zengyawen 已提交
161

H
HelloCrease 已提交
162
**示例:** 
H
HelloCrease 已提交
163
  ```js
C
cff-gite 已提交
164
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
165
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
166 167
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
168 169
  },
      {interval: 10000000}
Z
zengyawen 已提交
170 171
  );
  ```
Z
zengyawen 已提交
172

H
HelloCrease 已提交
173
### GYROSCOPE
Z
zengyawen 已提交
174

C
cff-gite 已提交
175
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
Z
zengyawen 已提交
176

Z
zengyawen 已提交
177
监听陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
178

C
cff-gite 已提交
179
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限
C
cff-gite 已提交
180 181 182

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
183 184 185 186 187 188
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。   |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是    | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
189

H
HelloCrease 已提交
190
**示例:** 
H
HelloCrease 已提交
191
  ```js
C
cff-gite 已提交
192
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
193
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
194 195
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
196 197
  },
      {interval: 10000000}
Z
zengyawen 已提交
198 199
  );
  ```
Z
zengyawen 已提交
200

H
HelloCrease 已提交
201
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
202

C
cff-gite 已提交
203
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
204

Z
zengyawen 已提交
205
监听未校准陀螺仪传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
206

C
cff-gite 已提交
207
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限
C
cff-gite 已提交
208 209 210

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
211 212 213 214 215 216
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率。                           |
Z
zengyawen 已提交
217

H
HelloCrease 已提交
218
**示例:** 
H
HelloCrease 已提交
219
  ```js
C
cff-gite 已提交
220
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
221
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
222 223
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
224
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
225 226
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
227 228
  },
      {interval: 10000000}
Z
zengyawen 已提交
229 230
  );
  ```
Z
zengyawen 已提交
231

H
HelloCrease 已提交
232
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
233

C
cff-gite 已提交
234
on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;, options?: Options): void
Z
zengyawen 已提交
235

Z
zengyawen 已提交
236
监听大幅动作传感器数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
237

C
cff-gite 已提交
238 239
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
240 241 242 243 244 245
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是    | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
246

H
HelloCrease 已提交
247
**示例:** 
H
HelloCrease 已提交
248
  ```js
C
cff-gite 已提交
249
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
250
      console.info('Scalar data: ' + data.scalar);
251 252
  },
      {interval: 10000000}
Z
zengyawen 已提交
253 254
  );
  ```
Z
zengyawen 已提交
255

H
HelloCrease 已提交
256
### PEDOMETER_DETECTION
Z
zengyawen 已提交
257

C
cff-gite 已提交
258
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;, options?: Options): void
Z
zengyawen 已提交
259

Z
zengyawen 已提交
260
监听计步检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
261

C
cff-gite 已提交
262
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
263 264 265

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
266 267 268 269 270 271
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是    | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
272

H
HelloCrease 已提交
273
**示例:** 
H
HelloCrease 已提交
274
  ```js
C
cff-gite 已提交
275
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
276
      console.info('Scalar data: ' + data.scalar);
277 278
  },
      {interval: 10000000}
Z
zengyawen 已提交
279 280
  );
  ```
Z
zengyawen 已提交
281

H
HelloCrease 已提交
282
### PEDOMETER
Z
zengyawen 已提交
283

C
cff-gite 已提交
284
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
Z
zengyawen 已提交
285

Z
zengyawen 已提交
286
监听计步传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
287

C
cff-gite 已提交
288
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
289 290 291

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
292 293 294 295 296 297
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。   |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。          |
Z
zengyawen 已提交
298

H
HelloCrease 已提交
299
**示例:** 
H
HelloCrease 已提交
300
  ```js
C
cff-gite 已提交
301
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
302
      console.info('Steps: ' + data.steps);
303 304
  },
      {interval: 10000000}
Z
zengyawen 已提交
305 306
  );
  ```
Z
zengyawen 已提交
307

H
HelloCrease 已提交
308
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
309

C
cff-gite 已提交
310
on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;AmbientTemperatureResponse&gt;,  options?: Options): void
Z
zengyawen 已提交
311

Z
zengyawen 已提交
312
监听环境温度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
313

C
cff-gite 已提交
314 315
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
316 317 318 319 320 321
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是    | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
322

H
HelloCrease 已提交
323
**示例:** 
H
HelloCrease 已提交
324
  ```js
C
cff-gite 已提交
325
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
326
      console.info('Temperature: ' + data.temperature);
327 328
  },
      {interval: 10000000}
Z
zengyawen 已提交
329 330
  );
  ```
Z
zengyawen 已提交
331

H
HelloCrease 已提交
332
### MAGNETIC_FIELD
Z
zengyawen 已提交
333

C
cff-gite 已提交
334
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
Z
zengyawen 已提交
335

Z
zengyawen 已提交
336
监听磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
337

C
cff-gite 已提交
338 339
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
340 341 342 343 344 345
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是    | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
346

H
HelloCrease 已提交
347
**示例:** 
H
HelloCrease 已提交
348
  ```js
C
cff-gite 已提交
349
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
350 351 352
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
353 354
  },
      {interval: 10000000}
Z
zengyawen 已提交
355 356
  );
  ```
Z
zengyawen 已提交
357

H
HelloCrease 已提交
358
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
359

H
HelloCrease 已提交
360
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
361

Z
zengyawen 已提交
362
监听未校准磁场传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
363

C
cff-gite 已提交
364 365
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
366 367 368 369 370 371
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是    | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
372

H
HelloCrease 已提交
373
**示例:** 
H
HelloCrease 已提交
374
  ```js
C
cff-gite 已提交
375
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
376 377 378 379
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
380 381
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
382 383
  },
      {interval: 10000000}
Z
zengyawen 已提交
384 385
  );
  ```
Z
zengyawen 已提交
386

H
HelloCrease 已提交
387
### PROXIMITY
Z
zengyawen 已提交
388

C
cff-gite 已提交
389
on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
390

Z
zengyawen 已提交
391
监听接近光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
392

C
cff-gite 已提交
393 394
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
395 396 397 398 399 400
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。   |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是    | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
401

H
HelloCrease 已提交
402
**示例:** 
H
HelloCrease 已提交
403
  ```js
C
cff-gite 已提交
404
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
405
      console.info('Distance: ' + data.distance);
406 407
  },
      {interval: 10000000}
Z
zengyawen 已提交
408 409
  );
  ```
Z
zengyawen 已提交
410

H
HelloCrease 已提交
411
### HUMIDITY
Z
zengyawen 已提交
412

C
cff-gite 已提交
413
on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
414

Z
zengyawen 已提交
415
监听湿度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
416

C
cff-gite 已提交
417 418
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
419 420 421 422 423 424
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                     |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。   |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。         |
Z
zengyawen 已提交
425

H
HelloCrease 已提交
426
**示例:** 
H
HelloCrease 已提交
427
  ```js
C
cff-gite 已提交
428
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
429
      console.info('Humidity: ' + data.humidity);
430 431
  },
      {interval: 10000000}
Z
zengyawen 已提交
432 433
  );
  ```
Z
zengyawen 已提交
434

H
HelloCrease 已提交
435
### BAROMETER
Z
zengyawen 已提交
436

C
cff-gite 已提交
437
on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;,options?: Options): void
Z
zengyawen 已提交
438

Z
zengyawen 已提交
439
监听气压计传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
440

C
cff-gite 已提交
441 442
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
443 444 445 446 447 448
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。   |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是    | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
449

H
HelloCrease 已提交
450
**示例:** 
H
HelloCrease 已提交
451
  ```js
C
cff-gite 已提交
452
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
453
      console.info('Atmospheric pressure: ' + data.pressure);
454 455
  },
      {interval: 10000000}
Z
zengyawen 已提交
456 457
  );
  ```
Z
zengyawen 已提交
458

H
HelloCrease 已提交
459
### HALL
Z
zengyawen 已提交
460

C
cff-gite 已提交
461
on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
Z
zengyawen 已提交
462

Z
zengyawen 已提交
463
监听霍尔传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
464

C
cff-gite 已提交
465 466
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
467 468 469 470 471 472
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
473

H
HelloCrease 已提交
474
**示例:** 
H
HelloCrease 已提交
475
  ```js
C
cff-gite 已提交
476
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
477
      console.info('Status: ' + data.status);
478 479
  },
      {interval: 10000000}
Z
zengyawen 已提交
480 481
  );
  ```
Z
zengyawen 已提交
482

H
HelloCrease 已提交
483
### AMBIENT_LIGHT
Z
zengyawen 已提交
484

C
cff-gite 已提交
485
on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
Z
zengyawen 已提交
486

Z
zengyawen 已提交
487
监听环境光传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
488

C
cff-gite 已提交
489 490
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
491 492 493 494 495 496
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是    | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。     |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
497

H
HelloCrease 已提交
498
**示例:** 
H
HelloCrease 已提交
499
  ```js
C
cff-gite 已提交
500
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
501 502 503
      console.info(' Illumination: ' + data.intensity);
  },
      {interval: 10000000}
Z
zengyawen 已提交
504 505
  );
  ```
Z
zengyawen 已提交
506

H
HelloCrease 已提交
507
### ORIENTATION
Z
zengyawen 已提交
508

C
cff-gite 已提交
509
on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
Z
zengyawen 已提交
510

Z
zengyawen 已提交
511
监听方向传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
512

C
cff-gite 已提交
513 514
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
515 516 517 518 519 520
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION   |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是    | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
521

H
HelloCrease 已提交
522
**示例:** 
H
HelloCrease 已提交
523
  ```js
C
cff-gite 已提交
524
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
C
cff-gite 已提交
525 526 527
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
528 529
  },
      {interval: 10000000}
Z
zengyawen 已提交
530 531
  );
  ```
Z
zengyawen 已提交
532

H
h00514358 已提交
533
### HEART_RATE<sup>deprecated</sup>
C
cff-gite 已提交
534

C
cff-gite 已提交
535
on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
C
cff-gite 已提交
536 537 538

监听心率传感器数据变化一次。

H
h00514358 已提交
539
从API Version9开始该接口不再维护,推荐使用sensor.on.HEART_BEAT_RATE
H
h00514358 已提交
540

C
cff-gite 已提交
541 542 543 544
**需要权限**:ohos.permission.READ_HEALTH_DATA 

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
545
**参数:** 
C
cff-gite 已提交
546

H
HelloCrease 已提交
547 548 549 550
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。   |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
C
cff-gite 已提交
551

H
HelloCrease 已提交
552
**示例:** 
C
cff-gite 已提交
553

H
HelloCrease 已提交
554
```js
C
cff-gite 已提交
555 556 557 558 559 560
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);
```
Z
zengyawen 已提交
561

H
h00514358 已提交
562
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

on(type: SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void

监听心率传感器数据变化一次。

**需要权限**:ohos.permission.READ_HEALTH_DATA

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**

| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_BEAT_RATE。   |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |

**示例:**

```js
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);
```

H
HelloCrease 已提交
589
### ROTATION_VECTOR
Z
zengyawen 已提交
590

C
cff-gite 已提交
591
on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;RotationVectorResponse&gt;,options?: Options): void
Z
zengyawen 已提交
592

Z
zengyawen 已提交
593
监听旋转矢量传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
594

C
cff-gite 已提交
595 596
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
597 598 599 600 601 602
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
603

H
HelloCrease 已提交
604
**示例:** 
H
HelloCrease 已提交
605
  ```js
C
cff-gite 已提交
606
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
Z
zengyawen 已提交
607 608 609
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
610
      console.info('Scalar quantity: ' + data.w);
611 612
  },
      {interval: 10000000}
Z
zengyawen 已提交
613 614
  );
  ```
Z
zengyawen 已提交
615

H
HelloCrease 已提交
616
### WEAR_DETECTION
Z
zengyawen 已提交
617

C
cff-gite 已提交
618
on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,options?: Options): void
Z
zengyawen 已提交
619

Z
zengyawen 已提交
620
监听佩戴检测传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
621

C
cff-gite 已提交
622 623
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
624 625 626 627 628 629
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是    | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
630

H
HelloCrease 已提交
631
**示例:** 
H
HelloCrease 已提交
632
  ```js
C
cff-gite 已提交
633
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
Z
zengyawen 已提交
634
      console.info('Wear status: ' + data.value);
635 636
  },
      {interval: 10000000}
Z
zengyawen 已提交
637 638
  );
  ```
Z
zengyawen 已提交
639

H
HelloCrease 已提交
640
## sensor.once
Z
zengyawen 已提交
641

H
HelloCrease 已提交
642
### ACCELEROMETER
Z
zengyawen 已提交
643

C
cff-gite 已提交
644
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
Z
zengyawen 已提交
645

Z
zengyawen 已提交
646
监听加速度传感器的数据变化一次。
Z
zengyawen 已提交
647

C
cff-gite 已提交
648 649 650 651
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
652 653 654 655 656
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。   |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是    | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
Z
zengyawen 已提交
657

H
HelloCrease 已提交
658
**示例:** 
H
HelloCrease 已提交
659
  ```js
C
cff-gite 已提交
660
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
661 662 663
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
664
    }
Z
zengyawen 已提交
665 666
  );
  ```
Z
zengyawen 已提交
667

H
h00514358 已提交
668
### LINEAR_ACCELERATION<sup>deprecated</sup>
Z
zengyawen 已提交
669

C
cff-gite 已提交
670
once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
671

Z
zengyawen 已提交
672
监听线性加速度传感器数据变化一次。
Z
zengyawen 已提交
673

H
h00514358 已提交
674
从API Version9开始该接口不再维护,推荐使用sensor.once.LINEAR_ACCELEROMETER
H
h00514358 已提交
675

C
cff-gite 已提交
676 677 678 679
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
680 681 682 683 684
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
Z
zengyawen 已提交
685

H
HelloCrease 已提交
686
**示例:** 
H
HelloCrease 已提交
687
  ```js
C
cff-gite 已提交
688
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) {
Z
zengyawen 已提交
689 690 691
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
692
    }
Z
zengyawen 已提交
693 694
  );
  ```
Z
zengyawen 已提交
695

H
h00514358 已提交
696
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
697 698 699

once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,callback:Callback&lt;LinearAccelerometerResponse&gt;): void

H
h00514358 已提交
700
订阅一次线性加速度传感器数据。
H
h00514358 已提交
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721

**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELEROMETER。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |

**示例:**
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```

H
HelloCrease 已提交
722
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
723

C
cff-gite 已提交
724
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
Z
zengyawen 已提交
725

Z
zengyawen 已提交
726
监听未校准加速度传感器的数据变化一次。
Z
zengyawen 已提交
727

C
cff-gite 已提交
728 729 730 731
**需要权限**:ohos.permission.ACCELEROMETER ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
732 733 734 735 736
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是    | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
Z
zengyawen 已提交
737

H
HelloCrease 已提交
738
**示例:** 
Z
zengyawen 已提交
739
  ```
C
cff-gite 已提交
740
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
741 742 743 744 745 746
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
Z
zengyawen 已提交
747
    }
Z
zengyawen 已提交
748 749
  );
  ```
Z
zengyawen 已提交
750

H
HelloCrease 已提交
751
### GRAVITY
Z
zengyawen 已提交
752

C
cff-gite 已提交
753
once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
754

Z
zengyawen 已提交
755
监听重力传感器的数据变化一次。
Z
zengyawen 已提交
756

C
cff-gite 已提交
757 758
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
759 760 761 762 763
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。         |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
Z
zengyawen 已提交
764

H
HelloCrease 已提交
765
**示例:** 
H
HelloCrease 已提交
766
  ```js
C
cff-gite 已提交
767
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
Z
zengyawen 已提交
768 769 770
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
771
    }
Z
zengyawen 已提交
772 773
  );
  ```
Z
zengyawen 已提交
774

H
HelloCrease 已提交
775
### GYROSCOPE
Z
zengyawen 已提交
776

C
cff-gite 已提交
777
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
Z
zengyawen 已提交
778

Z
zengyawen 已提交
779
监听陀螺仪传感器的数据变化一次。
Z
zengyawen 已提交
780

C
cff-gite 已提交
781 782 783 784
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
785 786 787 788 789
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。       |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是    | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
Z
zengyawen 已提交
790

H
HelloCrease 已提交
791
**示例:** 
H
HelloCrease 已提交
792
  ```js
C
cff-gite 已提交
793
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
Z
zengyawen 已提交
794 795 796
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
797
    }
Z
zengyawen 已提交
798 799
  );
  ```
Z
zengyawen 已提交
800

H
HelloCrease 已提交
801
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
802

C
cff-gite 已提交
803
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
804

Z
zengyawen 已提交
805
监听未校准陀螺仪传感器的数据变化一次。
Z
zengyawen 已提交
806

C
cff-gite 已提交
807 808 809 810
**需要权限**:ohos.permission.GYROSCOPE ,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
811 812 813 814 815
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
Z
zengyawen 已提交
816

H
HelloCrease 已提交
817
**示例:** 
H
HelloCrease 已提交
818
  ```js
C
cff-gite 已提交
819
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
820 821 822 823 824 825
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
Z
zengyawen 已提交
826
    }
Z
zengyawen 已提交
827 828
  );
  ```
Z
zengyawen 已提交
829

H
HelloCrease 已提交
830
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
831

C
cff-gite 已提交
832
once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
833

Z
zengyawen 已提交
834
监听有效运动传感器的数据变化一次。
Z
zengyawen 已提交
835

C
cff-gite 已提交
836 837
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
838 839 840 841 842
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是    | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
Z
zengyawen 已提交
843

H
HelloCrease 已提交
844
**示例:** 
H
HelloCrease 已提交
845
  ```js
C
cff-gite 已提交
846
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
Z
zengyawen 已提交
847
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
848
    }
Z
zengyawen 已提交
849 850
  );
  ```
Z
zengyawen 已提交
851

H
HelloCrease 已提交
852
### PEDOMETER_DETECTION
Z
zengyawen 已提交
853

C
cff-gite 已提交
854
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void
Z
zengyawen 已提交
855

Z
zengyawen 已提交
856
监听计步检测传感器数据变化一次。
Z
zengyawen 已提交
857

C
cff-gite 已提交
858
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
859 860 861

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
862 863 864 865 866
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是    | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
Z
zengyawen 已提交
867

H
HelloCrease 已提交
868
**示例:** 
H
HelloCrease 已提交
869
  ```js
C
cff-gite 已提交
870
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
Z
zengyawen 已提交
871
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
872
    }
Z
zengyawen 已提交
873 874
  );
  ```
Z
zengyawen 已提交
875

H
HelloCrease 已提交
876
### PEDOMETER
Z
zengyawen 已提交
877

C
cff-gite 已提交
878
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
879

Z
zengyawen 已提交
880
监听计步器传感器数据变化一次。
Z
zengyawen 已提交
881

C
cff-gite 已提交
882
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
883 884 885

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
886 887 888 889 890
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。        |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
Z
zengyawen 已提交
891

H
HelloCrease 已提交
892
**示例:** 
H
HelloCrease 已提交
893
  ```js
C
cff-gite 已提交
894
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
Z
zengyawen 已提交
895
      console.info('Steps: ' + data.steps);
Z
zengyawen 已提交
896
    }
Z
zengyawen 已提交
897 898
  );
  ```
Z
zengyawen 已提交
899

H
HelloCrease 已提交
900
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
901

C
cff-gite 已提交
902
once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void
Z
zengyawen 已提交
903

Z
zengyawen 已提交
904
监听环境温度传感器数据变化一次。
Z
zengyawen 已提交
905

C
cff-gite 已提交
906 907
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
908 909 910 911 912
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是    | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
Z
zengyawen 已提交
913

H
HelloCrease 已提交
914
**示例:** 
H
HelloCrease 已提交
915
  ```js
C
cff-gite 已提交
916
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
Z
zengyawen 已提交
917
      console.info('Temperature: ' + data.temperature);
Z
zengyawen 已提交
918
    }
Z
zengyawen 已提交
919 920
  );
  ```
Z
zengyawen 已提交
921

H
HelloCrease 已提交
922
### MAGNETIC_FIELD
Z
zengyawen 已提交
923

C
cff-gite 已提交
924
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
Z
zengyawen 已提交
925

Z
zengyawen 已提交
926
监听磁场传感器数据变化一次。
Z
zengyawen 已提交
927

C
cff-gite 已提交
928 929
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
930 931 932 933 934
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。   |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是    | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
Z
zengyawen 已提交
935

H
HelloCrease 已提交
936
**示例:** 
H
HelloCrease 已提交
937
  ```js
C
cff-gite 已提交
938
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
Z
zengyawen 已提交
939 940 941
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
942
    }
Z
zengyawen 已提交
943 944
  );
  ```
Z
zengyawen 已提交
945

H
HelloCrease 已提交
946
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
947

C
cff-gite 已提交
948
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
949

Z
zengyawen 已提交
950
监听未校准磁场传感器数据变化一次。
Z
zengyawen 已提交
951

C
cff-gite 已提交
952 953
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
954 955 956 957 958
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是    | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
Z
zengyawen 已提交
959

H
HelloCrease 已提交
960
**示例:** 
H
HelloCrease 已提交
961
  ```js
C
cff-gite 已提交
962
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
963 964 965 966 967 968
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
Z
zengyawen 已提交
969
    }
Z
zengyawen 已提交
970 971
  );
  ```
Z
zengyawen 已提交
972

H
HelloCrease 已提交
973
### PROXIMITY
Z
zengyawen 已提交
974

C
cff-gite 已提交
975
once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
Z
zengyawen 已提交
976

Z
zengyawen 已提交
977
监听接近光传感器数据变化一次。
Z
zengyawen 已提交
978

C
cff-gite 已提交
979 980
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
981 982 983 984 985
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。       |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是    | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
Z
zengyawen 已提交
986

H
HelloCrease 已提交
987
**示例:** 
H
HelloCrease 已提交
988
  ```js
L
li-yaoyao777 已提交
989
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
Z
zengyawen 已提交
990
      console.info('Distance: ' + data.distance);
Z
zengyawen 已提交
991
    }
Z
zengyawen 已提交
992 993
  );
  ```
Z
zengyawen 已提交
994

H
HelloCrease 已提交
995
### HUMIDITY
Z
zengyawen 已提交
996

C
cff-gite 已提交
997
once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void
Z
zengyawen 已提交
998

Z
zengyawen 已提交
999
监听湿度传感器数据变化一次。
Z
zengyawen 已提交
1000

C
cff-gite 已提交
1001 1002
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1003 1004 1005 1006 1007
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。         |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
Z
zengyawen 已提交
1008

H
HelloCrease 已提交
1009
**示例:** 
H
HelloCrease 已提交
1010
  ```js
C
cff-gite 已提交
1011
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
Z
zengyawen 已提交
1012
      console.info('Humidity: ' + data.humidity);
Z
zengyawen 已提交
1013
    }
Z
zengyawen 已提交
1014 1015
  );
  ```
Z
zengyawen 已提交
1016

H
HelloCrease 已提交
1017
### BAROMETER
Z
zengyawen 已提交
1018

C
cff-gite 已提交
1019
once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
Z
zengyawen 已提交
1020

Z
zengyawen 已提交
1021
监听气压计传感器数据变化一次。
Z
zengyawen 已提交
1022

C
cff-gite 已提交
1023 1024
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1025 1026 1027 1028 1029
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。       |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是    | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
Z
zengyawen 已提交
1030

H
HelloCrease 已提交
1031
**示例:** 
H
HelloCrease 已提交
1032
  ```js
C
cff-gite 已提交
1033
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
Z
zengyawen 已提交
1034
      console.info('Atmospheric pressure: ' + data.pressure);
Z
zengyawen 已提交
1035
    }
Z
zengyawen 已提交
1036 1037
  );
  ```
Z
zengyawen 已提交
1038

H
HelloCrease 已提交
1039
### HALL
Z
zengyawen 已提交
1040

C
cff-gite 已提交
1041
once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
Z
zengyawen 已提交
1042

Z
zengyawen 已提交
1043
监听霍尔传感器数据变化一次。
Z
zengyawen 已提交
1044

C
cff-gite 已提交
1045 1046
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1047 1048 1049 1050 1051
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type     | [SensorType](#sensortype)                | 是    | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
Z
zengyawen 已提交
1052

H
HelloCrease 已提交
1053
**示例:** 
H
HelloCrease 已提交
1054
  ```js
C
cff-gite 已提交
1055
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
Z
zengyawen 已提交
1056
      console.info('Status: ' + data.status);
Z
zengyawen 已提交
1057
    }
Z
zengyawen 已提交
1058 1059
  );
  ```
Z
zengyawen 已提交
1060

H
HelloCrease 已提交
1061
### AMBIENT_LIGHT
Z
zengyawen 已提交
1062

C
cff-gite 已提交
1063
once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
Z
zengyawen 已提交
1064

Z
zengyawen 已提交
1065
监听环境光传感器数据变化一次。
Z
zengyawen 已提交
1066

C
cff-gite 已提交
1067 1068
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1069 1070 1071 1072 1073
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                     |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是    | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
Z
zengyawen 已提交
1074

H
HelloCrease 已提交
1075
**示例:** 
H
HelloCrease 已提交
1076
  ```js
C
cff-gite 已提交
1077
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
1078
      console.info(' Illumination: ' + data.intensity);
Z
zengyawen 已提交
1079
    }
Z
zengyawen 已提交
1080 1081
  );
  ```
Z
zengyawen 已提交
1082

H
HelloCrease 已提交
1083
### ORIENTATION
Z
zengyawen 已提交
1084

C
cff-gite 已提交
1085
once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
Z
zengyawen 已提交
1086

Z
zengyawen 已提交
1087
监听方向传感器数据变化一次。
Z
zengyawen 已提交
1088

C
cff-gite 已提交
1089 1090
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1091 1092 1093 1094 1095
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。      |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是    | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
Z
zengyawen 已提交
1096

H
HelloCrease 已提交
1097
**示例:** 
H
HelloCrease 已提交
1098
  ```js
C
cff-gite 已提交
1099
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
C
cff-gite 已提交
1100 1101 1102
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
Z
zengyawen 已提交
1103
    }
Z
zengyawen 已提交
1104 1105
  );
  ```
Z
zengyawen 已提交
1106

H
HelloCrease 已提交
1107
### ROTATION_VECTOR
Z
zengyawen 已提交
1108

C
cff-gite 已提交
1109
once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
Z
zengyawen 已提交
1110

Z
zengyawen 已提交
1111
监听旋转矢量传感器数据变化一次。
Z
zengyawen 已提交
1112

C
cff-gite 已提交
1113 1114
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1115 1116 1117 1118 1119
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
Z
zengyawen 已提交
1120

H
HelloCrease 已提交
1121
**示例:** 
H
HelloCrease 已提交
1122
  ```js
C
cff-gite 已提交
1123
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
Z
zengyawen 已提交
1124 1125 1126
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
1127
      console.info('Scalar quantity: ' + data.w);
Z
zengyawen 已提交
1128
    }
Z
zengyawen 已提交
1129 1130
  );
  ```
Z
zengyawen 已提交
1131

H
h00514358 已提交
1132
### HEART_RATE<sup>deprecated</sup>
Z
zengyawen 已提交
1133

C
cff-gite 已提交
1134
once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
Z
zengyawen 已提交
1135

Z
zengyawen 已提交
1136
监听心率传感器数据变化一次。
Z
zengyawen 已提交
1137

H
h00514358 已提交
1138
从API Version9开始该接口不再维护,推荐使用sensor.once.HEART_BEAT_RATE
H
h00514358 已提交
1139

C
cff-gite 已提交
1140
**需要权限**:ohos.permission.READ_HEALTH_DATA 
C
cff-gite 已提交
1141 1142 1143

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1144 1145 1146 1147 1148
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。       |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
Z
zengyawen 已提交
1149

H
HelloCrease 已提交
1150
**示例:** 
H
HelloCrease 已提交
1151
  ```js
C
cff-gite 已提交
1152
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
Z
zengyawen 已提交
1153
      console.info("Heart rate: " + data.heartRate);
Z
zengyawen 已提交
1154
    }
Z
zengyawen 已提交
1155 1156
  );
  ```
Z
zengyawen 已提交
1157

H
h00514358 已提交
1158
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1159 1160 1161

once(type: SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback: Callback&lt;HeartRateResponse&gt;): void

H
h00514358 已提交
1162
订阅一次心率传感器数据。
H
h00514358 已提交
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181

**需要权限**:ohos.permission.READ_HEALTH_DATA

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 心率传感器类型为SENSOR_TYPE_ID_HEART_BEAT_RATE。       |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |

**示例:**
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, function(data) {
      console.info("Heart rate: " + data.heartRate);
    }
  );
  ```

H
HelloCrease 已提交
1182
### WEAR_DETECTION
Z
zengyawen 已提交
1183

C
cff-gite 已提交
1184
once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
Z
zengyawen 已提交
1185

Z
zengyawen 已提交
1186
监听佩戴检测传感器数据变化一次。
Z
zengyawen 已提交
1187

C
cff-gite 已提交
1188 1189
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1190 1191 1192 1193 1194
**参数:** 
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是    | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
Z
zengyawen 已提交
1195

H
HelloCrease 已提交
1196
**示例:** 
H
HelloCrease 已提交
1197
  ```js
C
cff-gite 已提交
1198
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
Z
zengyawen 已提交
1199
      console.info("Wear status: "+ data.value);
Z
zengyawen 已提交
1200
    }
Z
zengyawen 已提交
1201 1202
  );
  ```
Z
zengyawen 已提交
1203

H
HelloCrease 已提交
1204 1205 1206
## sensor.off

### ACCELEROMETER
Z
zengyawen 已提交
1207

C
cff-gite 已提交
1208
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
C
cff-gite 已提交
1209 1210

取消订阅传感器数据。
Z
zengyawen 已提交
1211

C
cff-gite 已提交
1212 1213 1214 1215
**需要权限**:ohos.permission.ACCELEROMETER, 该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1216
**参数:** 
C
cff-gite 已提交
1217

H
HelloCrease 已提交
1218 1219 1220 1221
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是    | 取消注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
C
cff-gite 已提交
1222

H
HelloCrease 已提交
1223
**示例:** 
C
cff-gite 已提交
1224

H
HelloCrease 已提交
1225
```js
C
cff-gite 已提交
1226 1227 1228 1229 1230 1231 1232 1233
function callback(data) {
    console.info('x-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
```

H
HelloCrease 已提交
1234
### ACCELEROMETER_UNCALIBRATED
C
cff-gite 已提交
1235

C
cff-gite 已提交
1236
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
Z
zengyawen 已提交
1237

Z
zengyawen 已提交
1238
取消订阅传感器数据。
Z
zengyawen 已提交
1239

C
cff-gite 已提交
1240 1241
**需要权限**:ohos.permission.ACCELEROMETER, 该权限为系统权限

C
cff-gite 已提交
1242 1243
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1244
**参数:** 
C
cff-gite 已提交
1245

H
HelloCrease 已提交
1246 1247 1248 1249
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是    | 取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
Z
zengyawen 已提交
1250

H
HelloCrease 已提交
1251
**示例:** 
C
cff-gite 已提交
1252

H
HelloCrease 已提交
1253
```js
C
cff-gite 已提交
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
```

H
HelloCrease 已提交
1265
### AMBIENT_LIGHT
C
cff-gite 已提交
1266

C
cff-gite 已提交
1267
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
1268 1269 1270 1271 1272

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1273
**参数:** 
C
cff-gite 已提交
1274

H
HelloCrease 已提交
1275 1276 1277 1278
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是    | 取消注册环境光传感器的回调函数,上报的数据类型为LightResponse。   |
C
cff-gite 已提交
1279

H
HelloCrease 已提交
1280
**示例:** 
C
cff-gite 已提交
1281

H
HelloCrease 已提交
1282
```js
C
cff-gite 已提交
1283 1284 1285 1286 1287 1288
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

H
HelloCrease 已提交
1289
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1290

C
cff-gite 已提交
1291
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
C
cff-gite 已提交
1292 1293 1294 1295 1296

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1297
**参数:** 
C
cff-gite 已提交
1298

H
HelloCrease 已提交
1299 1300 1301 1302
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是    | 取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
C
cff-gite 已提交
1303

H
HelloCrease 已提交
1304
**示例:** 
C
cff-gite 已提交
1305

H
HelloCrease 已提交
1306
```js
C
cff-gite 已提交
1307 1308 1309 1310 1311 1312
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

H
HelloCrease 已提交
1313
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1314

C
cff-gite 已提交
1315
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
C
cff-gite 已提交
1316 1317 1318 1319 1320

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1321
**参数:** 
C
cff-gite 已提交
1322

H
HelloCrease 已提交
1323 1324 1325 1326
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。 |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是    | 取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
C
cff-gite 已提交
1327

H
HelloCrease 已提交
1328
**示例:** 
C
cff-gite 已提交
1329

H
HelloCrease 已提交
1330
```js
C
cff-gite 已提交
1331 1332 1333 1334 1335 1336
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

H
HelloCrease 已提交
1337
### GRAVITY
C
cff-gite 已提交
1338

C
cff-gite 已提交
1339
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
C
cff-gite 已提交
1340 1341 1342 1343 1344

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1345
**参数:** 
C
cff-gite 已提交
1346

H
HelloCrease 已提交
1347 1348 1349 1350
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。    |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
C
cff-gite 已提交
1351

H
HelloCrease 已提交
1352
**示例:** 
C
cff-gite 已提交
1353

H
HelloCrease 已提交
1354
```js
C
cff-gite 已提交
1355 1356 1357 1358 1359 1360 1361 1362
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
```

H
HelloCrease 已提交
1363
### GYROSCOPE
C
cff-gite 已提交
1364

C
cff-gite 已提交
1365
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
C
cff-gite 已提交
1366 1367 1368 1369 1370 1371 1372

取消订阅传感器数据。

**需要权限**:ohos.permission.GYROSCOPE, 该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1373
**参数:** 
C
cff-gite 已提交
1374

H
HelloCrease 已提交
1375 1376 1377 1378
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。 |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是    | 取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
C
cff-gite 已提交
1379

H
HelloCrease 已提交
1380
**示例:** 
C
cff-gite 已提交
1381

H
HelloCrease 已提交
1382
```js
C
cff-gite 已提交
1383 1384 1385 1386 1387 1388 1389 1390
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
```

H
HelloCrease 已提交
1391
### GYROSCOPE_UNCALIBRATED
C
cff-gite 已提交
1392

H
HelloCrease 已提交
1393
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1394 1395 1396 1397 1398 1399 1400

取消订阅传感器数据。

**需要权限**:ohos.permission.GYROSCOPE, 该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1401
**参数:** 
C
cff-gite 已提交
1402

H
HelloCrease 已提交
1403 1404 1405 1406
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
1407

H
HelloCrease 已提交
1408
**示例:** 
C
cff-gite 已提交
1409

H
HelloCrease 已提交
1410
```js
C
cff-gite 已提交
1411 1412 1413 1414 1415 1416 1417 1418
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
```

H
HelloCrease 已提交
1419
### HALL
C
cff-gite 已提交
1420

C
cff-gite 已提交
1421
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
C
cff-gite 已提交
1422 1423 1424 1425 1426

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1427
**参数:** 
C
cff-gite 已提交
1428

H
HelloCrease 已提交
1429 1430 1431 1432
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。       |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 取消注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
C
cff-gite 已提交
1433

H
HelloCrease 已提交
1434
**示例:** 
C
cff-gite 已提交
1435

H
HelloCrease 已提交
1436
```js
C
cff-gite 已提交
1437 1438 1439 1440 1441 1442
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

H
h00514358 已提交
1443
### HEART_RATE<sup>deprecated</sup>
C
cff-gite 已提交
1444

C
cff-gite 已提交
1445
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
C
cff-gite 已提交
1446 1447 1448

取消订阅传感器数据。

H
h00514358 已提交
1449
从API Version9开始该接口不再维护,推荐使用sensor.off.HEART_BEAT_RATE
H
h00514358 已提交
1450

C
cff-gite 已提交
1451 1452 1453 1454
**需要权限**:ohos.permission.READ_HEALTH_DATA

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1455
**参数:** 
C
cff-gite 已提交
1456

H
HelloCrease 已提交
1457 1458 1459 1460
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)[SensorType](#sensortype) | 是    | 要取消订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。 |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 取消注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
C
cff-gite 已提交
1461

H
HelloCrease 已提交
1462
**示例:** 
C
cff-gite 已提交
1463

H
HelloCrease 已提交
1464
```js
C
cff-gite 已提交
1465 1466 1467 1468 1469 1470
function callback(data) {
    console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
```

H
h00514358 已提交
1471
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496

off(type: SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void

取消订阅传感器数据。

**需要权限**:ohos.permission.READ_HEALTH_DATA

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**

| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)[SensorType](#sensortype) | 是    | 要取消订阅的心率传感器类型为SENSOR_TYPE_ID_HEART_BEAT_RATE。 |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是    | 取消注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |

**示例:**

```js
function callback(data) {
    console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback);
```

H
HelloCrease 已提交
1497
### HUMIDITY
C
cff-gite 已提交
1498

C
cff-gite 已提交
1499
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
C
cff-gite 已提交
1500 1501 1502 1503 1504

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1505
**参数:** 
C
cff-gite 已提交
1506

H
HelloCrease 已提交
1507 1508 1509 1510
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。   |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
C
cff-gite 已提交
1511

H
HelloCrease 已提交
1512
**示例:** 
C
cff-gite 已提交
1513

H
HelloCrease 已提交
1514
```js
C
cff-gite 已提交
1515 1516 1517 1518 1519 1520
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

H
h00514358 已提交
1521
### LINEAR_ACCELERATION<sup>deprecated</sup>
C
cff-gite 已提交
1522

C
cff-gite 已提交
1523
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
C
cff-gite 已提交
1524 1525 1526

取消订阅传感器数据。

H
h00514358 已提交
1527
从API Version9开始该接口不再维护,推荐使用sensor.off.LINEAR_ACCELEROMETER
H
h00514358 已提交
1528

C
cff-gite 已提交
1529 1530 1531 1532
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1533
**参数:** 
C
cff-gite 已提交
1534

H
HelloCrease 已提交
1535 1536 1537 1538
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 取消注册性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
C
cff-gite 已提交
1539

H
HelloCrease 已提交
1540
**示例:** 
C
cff-gite 已提交
1541

H
HelloCrease 已提交
1542
```js
C
cff-gite 已提交
1543 1544 1545 1546 1547 1548 1549 1550
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
```

H
h00514358 已提交
1551
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578

off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void

取消订阅传感器数据。

**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限

**系统能力**:SystemCapability.Sensors.Sensor

**参数:**

| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELEROMETER。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是    | 取消注册性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |

**示例:**

```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER, callback);
```

H
HelloCrease 已提交
1579
### MAGNETIC_FIELD
C
cff-gite 已提交
1580

C
cff-gite 已提交
1581
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
C
cff-gite 已提交
1582 1583 1584 1585 1586

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1587
**参数:** 
C
cff-gite 已提交
1588

H
HelloCrease 已提交
1589 1590 1591 1592
| 参数名              | 类型                                       | 必填   | 说明                                       |
| ---------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type             | [SensorType](#sensortype)                | 是    | 要取消订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。 |
| callbackcallback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是    | 取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
C
cff-gite 已提交
1593

H
HelloCrease 已提交
1594
**示例:** 
C
cff-gite 已提交
1595

H
HelloCrease 已提交
1596
```js
C
cff-gite 已提交
1597 1598 1599 1600 1601 1602 1603 1604
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
```

H
HelloCrease 已提交
1605
### MAGNETIC_FIELD_UNCALIBRATED
C
cff-gite 已提交
1606

C
cff-gite 已提交
1607
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
1608 1609 1610 1611 1612

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1613
**参数:** 
C
cff-gite 已提交
1614

H
HelloCrease 已提交
1615 1616 1617 1618
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是    | 取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
1619

H
HelloCrease 已提交
1620
**示例:** 
C
cff-gite 已提交
1621

H
HelloCrease 已提交
1622
```js
C
cff-gite 已提交
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
```

H
HelloCrease 已提交
1634
### ORIENTATION
C
cff-gite 已提交
1635

C
cff-gite 已提交
1636
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
C
cff-gite 已提交
1637 1638 1639 1640 1641

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1642
**参数:** 
C
cff-gite 已提交
1643

H
HelloCrease 已提交
1644 1645 1646 1647
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是    | 取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
C
cff-gite 已提交
1648

H
HelloCrease 已提交
1649
**示例:** 
C
cff-gite 已提交
1650

H
HelloCrease 已提交
1651
```js
C
cff-gite 已提交
1652
function callback(data) {
C
cff-gite 已提交
1653 1654 1655
    console.info('The device rotates at an angle around the X axis: ' + data.beta);
    console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
    console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
C
cff-gite 已提交
1656 1657 1658 1659
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```

H
HelloCrease 已提交
1660
### PEDOMETER
C
cff-gite 已提交
1661

C
cff-gite 已提交
1662
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
C
cff-gite 已提交
1663 1664 1665

取消订阅传感器数据。

C
cff-gite 已提交
1666
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
1667

C
cff-gite 已提交
1668 1669
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1670
**参数:** 
C
cff-gite 已提交
1671

H
HelloCrease 已提交
1672 1673 1674 1675
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。  |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
C
cff-gite 已提交
1676

H
HelloCrease 已提交
1677
**示例:** 
C
cff-gite 已提交
1678

H
HelloCrease 已提交
1679
```js
C
cff-gite 已提交
1680 1681 1682 1683 1684 1685
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

H
HelloCrease 已提交
1686
### PEDOMETER_DETECTION
C
cff-gite 已提交
1687

C
cff-gite 已提交
1688
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
C
cff-gite 已提交
1689 1690 1691 1692 1693 1694 1695

取消订阅传感器数据。

**需要权限**:ohos.permission.ACTIVITY_MOTION

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1696
**参数:** 
C
cff-gite 已提交
1697

H
HelloCrease 已提交
1698 1699 1700 1701
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是    | 取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
C
cff-gite 已提交
1702

H
HelloCrease 已提交
1703
**示例:** 
C
cff-gite 已提交
1704

H
HelloCrease 已提交
1705
```js
C
cff-gite 已提交
1706 1707 1708 1709 1710 1711
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

H
HelloCrease 已提交
1712
### PROXIMITY
C
cff-gite 已提交
1713

C
cff-gite 已提交
1714
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
C
cff-gite 已提交
1715 1716 1717 1718 1719

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1720
**参数:** 
C
cff-gite 已提交
1721

H
HelloCrease 已提交
1722 1723 1724 1725
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。 |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是    | 取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
C
cff-gite 已提交
1726

H
HelloCrease 已提交
1727
**示例:** 
C
cff-gite 已提交
1728

H
HelloCrease 已提交
1729
```js
C
cff-gite 已提交
1730 1731 1732 1733 1734 1735
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```

H
HelloCrease 已提交
1736
### ROTATION_VECTOR
C
cff-gite 已提交
1737

C
cff-gite 已提交
1738
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
C
cff-gite 已提交
1739 1740 1741 1742 1743

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1744
**参数:** 
C
cff-gite 已提交
1745

H
HelloCrease 已提交
1746 1747 1748 1749
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
C
cff-gite 已提交
1750

H
HelloCrease 已提交
1751
**示例:** 
C
cff-gite 已提交
1752

H
HelloCrease 已提交
1753
```js
C
cff-gite 已提交
1754 1755 1756 1757
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
1758
    console.info('Scalar quantity: ' + data.w);
C
cff-gite 已提交
1759 1760 1761 1762
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```

H
HelloCrease 已提交
1763
### SIGNIFICANT_MOTION
C
cff-gite 已提交
1764

C
cff-gite 已提交
1765
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
C
cff-gite 已提交
1766 1767 1768 1769 1770

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1771
**参数:** 
C
cff-gite 已提交
1772

H
HelloCrease 已提交
1773 1774 1775 1776
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是    | 取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
C
cff-gite 已提交
1777

H
HelloCrease 已提交
1778
**示例:** 
C
cff-gite 已提交
1779

H
HelloCrease 已提交
1780
```js
C
cff-gite 已提交
1781 1782 1783 1784 1785 1786
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```

H
HelloCrease 已提交
1787
### WEAR_DETECTION
C
cff-gite 已提交
1788

C
cff-gite 已提交
1789
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
1790 1791 1792 1793 1794

取消订阅传感器数据。

**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1795
**参数:** 
C
cff-gite 已提交
1796

H
HelloCrease 已提交
1797 1798 1799 1800
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要取消订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是    | 取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
C
cff-gite 已提交
1801

H
HelloCrease 已提交
1802
**示例:** 
C
cff-gite 已提交
1803

H
HelloCrease 已提交
1804
```js
C
cff-gite 已提交
1805 1806 1807 1808 1809
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
Z
zengyawen 已提交
1810

Z
zengyawen 已提交
1811 1812 1813 1814 1815 1816
## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
1817 1818
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1819
**参数:** 
Z
zengyawen 已提交
1820

H
HelloCrease 已提交
1821 1822 1823 1824 1825
| 参数名              | 类型                                       | 必填   | 说明          |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。     |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。    |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回转换后的旋转矩阵。 |
Z
zengyawen 已提交
1826

H
HelloCrease 已提交
1827
**示例:** 
Z
zengyawen 已提交
1828

H
HelloCrease 已提交
1829 1830
```js
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
H
HelloCrease 已提交
1831 1832 1833 1834
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
H
HelloCrease 已提交
1835
    console.info("Operation successed. Data obtained: " + data);
H
HelloCrease 已提交
1836 1837 1838 1839 1840
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
Z
zengyawen 已提交
1841 1842 1843 1844 1845 1846
## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;

旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
1847 1848
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1849
**参数:** 
Z
zengyawen 已提交
1850

H
HelloCrease 已提交
1851 1852 1853 1854
| 参数名              | 类型                                       | 必填   | 说明       |
| ---------------- | ---------------------------------------- | ---- | -------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。  |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。 |
Z
zengyawen 已提交
1855

H
HelloCrease 已提交
1856
**返回值:** 
Z
zengyawen 已提交
1857

H
HelloCrease 已提交
1858 1859 1860
| 类型                                 | 说明          |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |
Z
zengyawen 已提交
1861

H
HelloCrease 已提交
1862
**示例:** 
Z
zengyawen 已提交
1863

H
HelloCrease 已提交
1864 1865
```js
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
H
HelloCrease 已提交
1866 1867 1868 1869 1870 1871 1872 1873 1874
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
```
Z
zengyawen 已提交
1875

Z
zengyawen 已提交
1876
## sensor.getGeomagneticField
Z
zengyawen 已提交
1877

Z
zengyawen 已提交
1878
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
Z
zengyawen 已提交
1879

Z
zengyawen 已提交
1880
获取地球上特定位置的地磁场。
Z
zengyawen 已提交
1881

C
cff-gite 已提交
1882 1883
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1884 1885 1886 1887 1888 1889
**参数:** 
| 参数名             | 类型                                       | 必填   | 说明                |
| --------------- | ---------------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions)      | 是    | 地理位置。             |
| timeMillis      | number                                   | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是    | 返回磁场信息。           |
Z
zengyawen 已提交
1890

H
HelloCrease 已提交
1891
**示例:** 
H
HelloCrease 已提交
1892 1893
```js
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
H
HelloCrease 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
    console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});
```
Z
zengyawen 已提交
1903 1904 1905 1906 1907 1908
## sensor.getGeomagneticField

getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;

获取地球上特定位置的地磁场。

C
cff-gite 已提交
1909 1910
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1911 1912 1913 1914 1915
**参数:** 
| 参数名             | 类型                                  | 必填   | 说明                |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | 是    | 地理位置。             |
| timeMillis      | number                              | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
Z
zengyawen 已提交
1916

H
HelloCrease 已提交
1917 1918 1919 1920
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
Z
zengyawen 已提交
1921

H
HelloCrease 已提交
1922
**示例:** 
H
HelloCrease 已提交
1923 1924
  ```js
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
Z
zengyawen 已提交
1925
      promise.then((data) => {
Z
zengyawen 已提交
1926 1927 1928
          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
Z
zengyawen 已提交
1929
      }).catch((reason) => {
Z
zengyawen 已提交
1930 1931
          console.info('Operation failed.');
  })
Z
zengyawen 已提交
1932 1933
  ```

Z
zengyawen 已提交
1934 1935 1936 1937 1938 1939
## sensor.getAltitude

getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void

根据气压值获取设备所在的海拔高度。

C
cff-gite 已提交
1940 1941
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1942
**参数:** 
Z
zengyawen 已提交
1943

H
HelloCrease 已提交
1944 1945 1946 1947 1948
| 参数名             | 类型                          | 必填   | 说明                   |
| --------------- | --------------------------- | ---- | -------------------- |
| seaPressure     | number                      | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number                      | 是    | 表示设备所在高度的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是    | 返回设备所在的海拔高度,单位为米。    |
Z
zengyawen 已提交
1949

H
HelloCrease 已提交
1950
**示例:** 
Z
zengyawen 已提交
1951

H
HelloCrease 已提交
1952
  ```js
Z
zengyawen 已提交
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968
  sensor.getAltitude(0, 200, function(err, data)  {
      if (err) {
          console.error(
  "Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
          console.info("Successed to get getAltitude interface get data: " + data);
  });
  ```

## sensor.getAltitude

getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;

根据气压值获取设备所在的海拔高度。

C
cff-gite 已提交
1969 1970
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1971
**参数:** 
Z
zengyawen 已提交
1972

H
HelloCrease 已提交
1973 1974 1975 1976
| 参数名             | 类型     | 必填   | 说明                   |
| --------------- | ------ | ---- | -------------------- |
| seaPressure     | number | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number | 是    | 表示设备所在高度的气压值,单位为hPa。 |
Z
zengyawen 已提交
1977

H
HelloCrease 已提交
1978
**返回值:** 
Z
zengyawen 已提交
1979

H
HelloCrease 已提交
1980 1981 1982
| 类型                    | 说明                 |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |
Z
zengyawen 已提交
1983

H
HelloCrease 已提交
1984
**示例:** 
Z
zengyawen 已提交
1985

H
HelloCrease 已提交
1986
  ```js
Z
zengyawen 已提交
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```


## sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void

根据倾斜矩阵计算地磁倾斜角。

C
cff-gite 已提交
2002 2003
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2004
**参数:** 
Z
zengyawen 已提交
2005

H
HelloCrease 已提交
2006 2007 2008 2009
| 参数名               | 类型                          | 必填   | 说明             |
| ----------------- | --------------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt;         | 是    | 表示倾斜矩阵。        |
| callback          | AsyncCallback&lt;number&gt; | 是    | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
2010

H
HelloCrease 已提交
2011
**示例:** 
Z
zengyawen 已提交
2012

H
HelloCrease 已提交
2013
  ```js
Z
zengyawen 已提交
2014 2015
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2016
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2017 2018 2019
                        err.message);
          return;
      }
H
HelloCrease 已提交
2020
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
Z
zengyawen 已提交
2021 2022 2023 2024 2025 2026 2027 2028 2029
  })
  ```

## sensor.getGeomagneticDip

getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;

根据倾斜矩阵计算地磁倾斜角。

C
cff-gite 已提交
2030 2031
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2032
**参数:** 
Z
zengyawen 已提交
2033

H
HelloCrease 已提交
2034 2035 2036
| 参数名               | 类型                  | 必填   | 说明      |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | 是    | 表示倾斜矩阵。 |
Z
zengyawen 已提交
2037

H
HelloCrease 已提交
2038
**返回值:** 
Z
zengyawen 已提交
2039

H
HelloCrease 已提交
2040 2041 2042
| 类型                    | 说明             |
| --------------------- | -------------- |
| Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
2043

H
HelloCrease 已提交
2044
**示例:** 
Z
zengyawen 已提交
2045

H
HelloCrease 已提交
2046
  ```js
Z
zengyawen 已提交
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info(' getGeomagneticDip_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

H
HelloCrease 已提交
2057
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
2058 2059 2060

获取两个旋转矩阵之间的角度变化。

C
cff-gite 已提交
2061 2062
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2063
**参数:** 
Z
zengyawen 已提交
2064

H
HelloCrease 已提交
2065 2066 2067 2068 2069
| 参数名                   | 类型                                       | 必填   | 说明                 |
| --------------------- | ---------------------------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | 是    | 表示当前旋转矩阵。          |
| preRotationMatrix     | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
2070

H
HelloCrease 已提交
2071
**示例:** 
Z
zengyawen 已提交
2072

H
HelloCrease 已提交
2073
  ```js
Z
zengyawen 已提交
2074 2075
  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)  {
      if (err) {
H
HelloCrease 已提交
2076
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2077 2078 2079 2080
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2081
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
      }
  })
  ```


## sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

获取两个旋转矩阵之间的角度变化。

C
cff-gite 已提交
2093 2094
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2095
**参数:** 
Z
zengyawen 已提交
2096

H
HelloCrease 已提交
2097 2098 2099 2100
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
2101

H
HelloCrease 已提交
2102
**返回值:** 
Z
zengyawen 已提交
2103

H
HelloCrease 已提交
2104 2105 2106
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
2107

H
HelloCrease 已提交
2108
**示例:** 
Z
zengyawen 已提交
2109

H
HelloCrease 已提交
2110
  ```js
Z
zengyawen 已提交
2111 2112
  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]);
      promise.then((data) => {
H
HelloCrease 已提交
2113
          console.info('getAngleModifiy_promise success');
Z
zengyawen 已提交
2114
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2115
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2116 2117
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2118
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

将旋转矢量转换为旋转矩阵。

C
cff-gite 已提交
2129 2130
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2131
**参数:** 
Z
zengyawen 已提交
2132

H
HelloCrease 已提交
2133 2134 2135 2136
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
2137

H
HelloCrease 已提交
2138
**示例:** 
Z
zengyawen 已提交
2139

H
HelloCrease 已提交
2140
  ```js
Z
zengyawen 已提交
2141 2142
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
H
HelloCrease 已提交
2143
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2144 2145 2146
                        err.message);
          return;
      }
C
cff-gite 已提交
2147
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2148
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
      }
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

将旋转矢量转换为旋转矩阵。

C
cff-gite 已提交
2160 2161
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2162
**参数:** 
Z
zengyawen 已提交
2163

H
HelloCrease 已提交
2164 2165 2166
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
2167

H
HelloCrease 已提交
2168
**返回值:** 
Z
zengyawen 已提交
2169

H
HelloCrease 已提交
2170 2171 2172
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
2173

H
HelloCrease 已提交
2174
**示例:** 
Z
zengyawen 已提交
2175

H
HelloCrease 已提交
2176
  ```js
Z
zengyawen 已提交
2177 2178
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
H
HelloCrease 已提交
2179
          console.info('createRotationMatrix_promise success');
C
cff-gite 已提交
2180
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2181
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2182 2183
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2184
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
  })	
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

将旋转矢量转换为四元数。

C
cff-gite 已提交
2195 2196
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2197
**参数:** 
Z
zengyawen 已提交
2198

H
HelloCrease 已提交
2199 2200 2201 2202
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
2203

H
HelloCrease 已提交
2204
**示例:** 
Z
zengyawen 已提交
2205

H
HelloCrease 已提交
2206
  ```js
Z
zengyawen 已提交
2207 2208
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2209
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2210 2211 2212 2213
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2214
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225
      }
  })
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

将旋转矢量转换为四元数。

C
cff-gite 已提交
2226 2227
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2228
**参数:** 
Z
zengyawen 已提交
2229

H
HelloCrease 已提交
2230 2231 2232
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
2233

H
HelloCrease 已提交
2234
**返回值:** 
Z
zengyawen 已提交
2235

H
HelloCrease 已提交
2236 2237 2238
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
2239

H
HelloCrease 已提交
2240
**示例:** 
Z
zengyawen 已提交
2241

H
HelloCrease 已提交
2242
  ```js
Z
zengyawen 已提交
2243 2244 2245 2246
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2247
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

根据旋转矩阵计算设备的方向。

C
cff-gite 已提交
2261 2262
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2263
**参数:** 
Z
zengyawen 已提交
2264

H
HelloCrease 已提交
2265 2266 2267 2268
| 参数名            | 类型                                       | 必填   | 说明                 |
| -------------- | ---------------------------------------- | ---- | ------------------ |
| rotationMatrix | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
2269

H
HelloCrease 已提交
2270
**示例:** 
Z
zengyawen 已提交
2271

H
HelloCrease 已提交
2272
  ```js
Z
zengyawen 已提交
2273 2274
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2275
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
Z
zengyawen 已提交
2276 2277 2278
                        err.message);
          return;
      }
H
HelloCrease 已提交
2279
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
Z
zengyawen 已提交
2280
      for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
2281
          console.info("sensor_getDirection_callback" + data[i]);
Z
zengyawen 已提交
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
      }
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

根据旋转矩阵计算设备的方向。

C
cff-gite 已提交
2293 2294
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2295
**参数:** 
Z
zengyawen 已提交
2296

H
HelloCrease 已提交
2297 2298 2299
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | 是    | 表示旋转矩阵。 |
Z
zengyawen 已提交
2300

H
HelloCrease 已提交
2301
**返回值:** 
Z
zengyawen 已提交
2302

H
HelloCrease 已提交
2303 2304 2305
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
2306

H
HelloCrease 已提交
2307
**示例:** 
Z
zengyawen 已提交
2308

H
HelloCrease 已提交
2309
  ```js
Z
zengyawen 已提交
2310 2311
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
H
HelloCrease 已提交
2312
          console.info('sensor_getAltitude_Promise success', data);
Z
zengyawen 已提交
2313
          for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
2314
              console.info("sensor_getDirection_promise" + data[i]);
Z
zengyawen 已提交
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void

根据重力矢量和地磁矢量计算旋转矩阵。

C
cff-gite 已提交
2328 2329
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2330
**参数:** 
Z
zengyawen 已提交
2331

H
HelloCrease 已提交
2332 2333 2334 2335 2336
| 参数名         | 类型                                       | 必填   | 说明      |
| ----------- | ---------------------------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt;                      | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt;                      | 是    | 表示地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
2337

H
HelloCrease 已提交
2338
**示例:** 
Z
zengyawen 已提交
2339

H
HelloCrease 已提交
2340
  ```js
Z
zengyawen 已提交
2341 2342
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2343
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
Z
zengyawen 已提交
2344 2345 2346
                        err.message);
          return;
      }
C
cff-gite 已提交
2347
      for (var i=0; i < data.rotation.length; i++) {
H
HelloCrease 已提交
2348
          console.info("data[" + i + "]: " + data[i])
Z
zengyawen 已提交
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
      }
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;

根据重力矢量和地磁矢量计算旋转矩阵。

C
cff-gite 已提交
2360 2361
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2362
**参数:** 
Z
zengyawen 已提交
2363

H
HelloCrease 已提交
2364 2365 2366 2367
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
2368

H
HelloCrease 已提交
2369
**返回值:** 
Z
zengyawen 已提交
2370

H
HelloCrease 已提交
2371 2372 2373
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
2374

H
HelloCrease 已提交
2375
**示例:** 
Z
zengyawen 已提交
2376

H
HelloCrease 已提交
2377
  ```js
Z
zengyawen 已提交
2378 2379
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
H
HelloCrease 已提交
2380
          console.info('createRotationMatrix_promise successed');
C
cff-gite 已提交
2381
          for (var i=0; i < data.rotation.length; i++) {
H
HelloCrease 已提交
2382
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2383 2384
          }
      }).catch((err) => {
H
HelloCrease 已提交
2385
          console.info('promise failed');
Z
zengyawen 已提交
2386 2387 2388
  })
  ```

Z
zengyawen 已提交
2389

Z
zengyawen 已提交
2390
## SensorType
Z
zengyawen 已提交
2391 2392 2393

表示要订阅或取消订阅的传感器类型。

C
cff-gite 已提交
2394 2395
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2396

H
HelloCrease 已提交
2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408
| 名称                                       | 默认值  | 说明          |
| ---------------------------------------- | ---- | ----------- |
| SENSOR_TYPE_ID_ACCELEROMETER             | 1    | 加速度传感器。     |
| SENSOR_TYPE_ID_GYROSCOPE                 | 2    | 陀螺仪传感器。     |
| SENSOR_TYPE_ID_AMBIENT_LIGHT             | 5    | 环境光传感器。     |
| SENSOR_TYPE_ID_MAGNETIC_FIELD            | 6    | 磁场传感器。      |
| SENSOR_TYPE_ID_BAROMETER                 | 8    | 气压计传感器。     |
| SENSOR_TYPE_ID_HALL                      | 10   | 霍尔传感器。      |
| SENSOR_TYPE_ID_PROXIMITY                 | 12   | 接近光传感器。     |
| SENSOR_TYPE_ID_HUMIDITY                  | 13   | 湿度传感器。      |
| SENSOR_TYPE_ID_ORIENTATION               | 256  | 方向传感器。      |
| SENSOR_TYPE_ID_GRAVITY                   | 257  | 重力传感器。      |
H
h00514358 已提交
2409 2410
| SENSOR_TYPE_ID_LINEAR_ACCELERATION<sup>deprecated</sup>       | 258  | 线性加速度传感器。   |
| SENSOR_TYPE_ID_LINEAR_ACCELEROMETER       | 258  | 线性加速度传感器。   |
H
HelloCrease 已提交
2411 2412 2413 2414 2415 2416 2417
| SENSOR_TYPE_ID_ROTATION_VECTOR           | 259  | 旋转矢量传感器。    |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE       | 260  | 环境温度传感器。    |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | 未校准磁场传感器。   |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED    | 263  | 未校准陀螺仪传感器。  |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION        | 264  | 有效运动传感器。    |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION       | 265  | 计步检测传感器。    |
| SENSOR_TYPE_ID_PEDOMETER                 | 266  | 计步传感器。      |
H
h00514358 已提交
2418 2419
| SENSOR_TYPE_ID_HEART_RATE<sup>deprecated</sup>                | 278  | 心率传感器。      |
| SENSOR_TYPE_ID_HEART_BEAT_RATE                | 278  | 心率传感器。      |
H
HelloCrease 已提交
2420 2421
| SENSOR_TYPE_ID_WEAR_DETECTION            | 280  | 佩戴检测传感器。    |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281  | 未校准加速度计传感器。 |
Z
zengyawen 已提交
2422 2423


Z
zengyawen 已提交
2424 2425 2426 2427
## Response

传感器数据的时间戳。

C
cff-gite 已提交
2428 2429
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2430 2431 2432
| 名称        | 参数类型   | 可读   | 可写   | 说明           |
| --------- | ------ | ---- | ---- | ------------ |
| timestamp | number | 是    | 是    | 传感器数据上报的时间戳。 |
Z
zengyawen 已提交
2433 2434


Z
zengyawen 已提交
2435
## AccelerometerResponse
Z
zengyawen 已提交
2436

Z
zengyawen 已提交
2437
加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2438

C
cff-gite 已提交
2439 2440
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2441

H
HelloCrease 已提交
2442 2443 2444 2445 2446
| 名称   | 参数类型   | 可读   | 可写   | 说明                     |
| ---- | ------ | ---- | ---- | ---------------------- |
| x    | number | 是    | 是    | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2447 2448 2449


## LinearAccelerometerResponse
Z
zengyawen 已提交
2450

Z
zengyawen 已提交
2451
线性加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2452

C
cff-gite 已提交
2453 2454
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2455

H
HelloCrease 已提交
2456 2457 2458 2459 2460
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2461 2462 2463


## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
2464

Z
zengyawen 已提交
2465
未校准加速度计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2466

C
cff-gite 已提交
2467 2468
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2469

H
HelloCrease 已提交
2470 2471 2472 2473 2474 2475 2476 2477
| 名称    | 参数类型   | 可读   | 可写   | 说明                           |
| ----- | ------ | ---- | ---- | ---------------------------- |
| x     | number | 是    | 是    | 施加在设备x轴未校准的加速度,单位 : m/s2。    |
| y     | number | 是    | 是    | 施加在设备y轴未校准的加速度,单位 : m/s2。    |
| z     | number | 是    | 是    | 施加在设备z轴未校准的加速度,单位 : m/s2。    |
| biasX | number | 是    | 是    | 施加在设备x轴未校准的加速度偏量,单位 : m/s2。  |
| biasY | number | 是    | 是    | 施加在设备上y轴未校准的加速度偏量,单位 : m/s2。 |
| biasZ | number | 是    | 是    | 施加在设备z轴未校准的加速度偏量,单位 : m/s2。  |
Z
zengyawen 已提交
2478 2479 2480


## GravityResponse
Z
zengyawen 已提交
2481

Z
zengyawen 已提交
2482
重力传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2483

C
cff-gite 已提交
2484 2485
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2486

H
HelloCrease 已提交
2487 2488 2489 2490 2491
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2492 2493 2494


## OrientationResponse
Z
zengyawen 已提交
2495

Z
zengyawen 已提交
2496
方向传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2497

C
cff-gite 已提交
2498 2499
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2500

H
HelloCrease 已提交
2501 2502
| 名称    | 参数类型   | 可读   | 可写   | 说明                |
| ----- | ------ | ---- | ---- | ----------------- |
2503
| alpha | number | 是    | 是    | 设备围绕Z轴的旋转角度,单位:度。 |
H
HelloCrease 已提交
2504 2505
| beta  | number | 是    | 是    | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是    | 是    | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
2506 2507 2508


## RotationVectorResponse
Z
zengyawen 已提交
2509

Z
zengyawen 已提交
2510
旋转矢量传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2511

C
cff-gite 已提交
2512 2513
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2514

H
HelloCrease 已提交
2515 2516 2517 2518 2519 2520
| 名称   | 参数类型   | 可读   | 可写   | 说明        |
| ---- | ------ | ---- | ---- | --------- |
| x    | number | 是    | 是    | 旋转矢量x轴分量。 |
| y    | number | 是    | 是    | 旋转矢量y轴分量。 |
| z    | number | 是    | 是    | 旋转矢量z轴分量。 |
| w    | number | 是    | 是    | 标量。       |
Z
zengyawen 已提交
2521 2522 2523


## GyroscopeResponse
Z
zengyawen 已提交
2524

Z
zengyawen 已提交
2525
陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2526

C
cff-gite 已提交
2527 2528
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2529

H
HelloCrease 已提交
2530 2531 2532 2533 2534
| 名称   | 参数类型   | 可读   | 可写   | 说明                  |
| ---- | ------ | ---- | ---- | ------------------- |
| x    | number | 是    | 是    | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number | 是    | 是    | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number | 是    | 是    | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
2535 2536 2537


## GyroscopeUncalibratedResponse
Z
zengyawen 已提交
2538

Z
zengyawen 已提交
2539
未校准陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2540

C
cff-gite 已提交
2541 2542
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2543

H
HelloCrease 已提交
2544 2545 2546 2547 2548 2549 2550 2551
| 名称    | 参数类型   | 可读   | 可写   | 说明                       |
| ----- | ------ | ---- | ---- | ------------------------ |
| x     | number | 是    | 是    | 设备x轴未校准的旋转角速度,单位rad/s。   |
| y     | number | 是    | 是    | 设备y轴未校准的旋转角速度,单位rad/s。   |
| z     | number | 是    | 是    | 设备z轴未校准的旋转角速度,单位rad/s。   |
| biasX | number | 是    | 是    | 设备x轴未校准的旋转角速度偏量,单位rad/s。 |
| biasY | number | 是    | 是    | 设备y轴未校准的旋转角速度偏量,单位rad/s。 |
| biasZ | number | 是    | 是    | 设备z轴未校准的旋转角速度偏量,单位rad/s。 |
Z
zengyawen 已提交
2552 2553 2554


## SignificantMotionResponse
Z
zengyawen 已提交
2555

Z
zengyawen 已提交
2556
有效运动传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2557

C
cff-gite 已提交
2558 2559
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2560

H
HelloCrease 已提交
2561 2562 2563
| 名称     | 参数类型   | 可读   | 可写   | 说明                                       |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| scalar | number | 是    | 是    | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 |
Z
zengyawen 已提交
2564 2565 2566


## ProximityResponse
Z
zengyawen 已提交
2567

Z
zengyawen 已提交
2568
接近光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2569

C
cff-gite 已提交
2570 2571
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2572

H
HelloCrease 已提交
2573 2574 2575
| 名称       | 参数类型   | 可读   | 可写   | 说明                           |
| -------- | ------ | ---- | ---- | ---------------------------- |
| distance | number | 是    | 是    | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
2576 2577 2578


## LightResponse
Z
zengyawen 已提交
2579

Z
zengyawen 已提交
2580
环境光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2581

C
cff-gite 已提交
2582 2583
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2584

H
HelloCrease 已提交
2585 2586 2587
| 名称        | 参数类型   | 可读   | 可写   | 说明          |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | 是    | 是    | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
2588 2589 2590


## HallResponse
Z
zengyawen 已提交
2591

Z
zengyawen 已提交
2592
霍尔传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2593

C
cff-gite 已提交
2594 2595
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2596

H
HelloCrease 已提交
2597 2598 2599
| 名称     | 参数类型   | 可读   | 可写   | 说明                                |
| ------ | ------ | ---- | ---- | --------------------------------- |
| status | number | 是    | 是    | 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示有,1表示没有。 |
Z
zengyawen 已提交
2600 2601 2602


## MagneticFieldResponse
Z
zengyawen 已提交
2603

Z
zengyawen 已提交
2604
磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2605

C
cff-gite 已提交
2606 2607
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2608

C
cff-gite 已提交
2609 2610 2611 2612 2613
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
Z
zengyawen 已提交
2614 2615 2616


## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
2617

Z
zengyawen 已提交
2618
未校准磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2619

C
cff-gite 已提交
2620 2621
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2622

H
HelloCrease 已提交
2623 2624 2625 2626 2627 2628 2629 2630
| 名称    | 参数类型   | 可读   | 可写   | 说明                     |
| ----- | ------ | ---- | ---- | ---------------------- |
| x     | number | 是    | 是    | x轴未校准环境磁场强度,单位 : μT。   |
| y     | number | 是    | 是    | y轴未校准环境磁场强度,单位 : μT。   |
| z     | number | 是    | 是    | z轴未校准环境磁场强度,单位 : μT。   |
| biasX | number | 是    | 是    | x轴未校准环境磁场强度偏量,单位 : μT。 |
| biasY | number | 是    | 是    | y轴未校准环境磁场强度偏量,单位 : μT。 |
| biasZ | number | 是    | 是    | z轴未校准环境磁场强度偏量,单位 : μT。 |
Z
zengyawen 已提交
2631 2632 2633


## PedometerResponse
Z
zengyawen 已提交
2634

Z
zengyawen 已提交
2635
计步传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2636

C
cff-gite 已提交
2637 2638
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2639

H
HelloCrease 已提交
2640 2641 2642
| 名称    | 参数类型   | 可读   | 可写   | 说明       |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | 是    | 是    | 用户的行走步数。 |
Z
zengyawen 已提交
2643 2644 2645


## HumidityResponse
Z
zengyawen 已提交
2646

Z
zengyawen 已提交
2647
湿度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2648

C
cff-gite 已提交
2649 2650
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2651

H
HelloCrease 已提交
2652 2653 2654
| 名称       | 参数类型   | 可读   | 可写   | 说明                                   |
| -------- | ------ | ---- | ---- | ------------------------------------ |
| humidity | number | 是    | 是    | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |
Z
zengyawen 已提交
2655 2656


C
cff-gite 已提交
2657
## PedometerDetectionResponse
Z
zengyawen 已提交
2658

Z
zengyawen 已提交
2659
计步检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2660

C
cff-gite 已提交
2661 2662
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2663

H
HelloCrease 已提交
2664 2665 2666
| 名称     | 参数类型   | 可读   | 可写   | 说明                                       |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| scalar | number | 是    | 是    | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |
Z
zengyawen 已提交
2667 2668 2669


## AmbientTemperatureResponse
Z
zengyawen 已提交
2670

Z
zengyawen 已提交
2671
温度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2672

C
cff-gite 已提交
2673 2674
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2675

H
HelloCrease 已提交
2676 2677 2678
| 名称          | 参数类型   | 可读   | 可写   | 说明            |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | 是    | 是    | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
2679 2680 2681


## BarometerResponse
Z
zengyawen 已提交
2682

Z
zengyawen 已提交
2683
气压计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2684

C
cff-gite 已提交
2685 2686
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2687

H
HelloCrease 已提交
2688 2689 2690
| 名称       | 参数类型   | 可读   | 可写   | 说明           |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | 是    | 是    | 压力值(单位:帕斯卡)。 |
Z
zengyawen 已提交
2691 2692 2693


## HeartRateResponse
Z
zengyawen 已提交
2694

Z
zengyawen 已提交
2695
心率传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2696

C
cff-gite 已提交
2697 2698
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2699

H
HelloCrease 已提交
2700 2701 2702
| 名称        | 参数类型   | 可读   | 可写   | 说明                    |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | 是    | 是    | 心率值。测量用户的心率数值,单位:bpm。 |
Z
zengyawen 已提交
2703 2704 2705


## WearDetectionResponse
Z
zengyawen 已提交
2706

Z
zengyawen 已提交
2707
佩戴检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
2708

C
cff-gite 已提交
2709 2710
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

Z
zengyawen 已提交
2711

H
HelloCrease 已提交
2712 2713 2714
| 名称    | 参数类型   | 可读   | 可写   | 说明                        |
| ----- | ------ | ---- | ---- | ------------------------- |
| value | number | 是    | 是    | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
Z
zengyawen 已提交
2715 2716 2717 2718


## Options

Z
zengyawen 已提交
2719
设置传感器上报频率。
Z
zengyawen 已提交
2720

C
cff-gite 已提交
2721 2722
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2723 2724
| 名称       | 参数类型   | 说明                          |
| -------- | ------ | --------------------------- |
Z
zengyawen 已提交
2725 2726
| interval | number | 表示传感器的上报频率,默认值为200000000ns。 |

Z
zengyawen 已提交
2727 2728
## RotationMatrixResponse

C
cff-gite 已提交
2729 2730 2731
设置旋转矩阵响应对象。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2732

H
HelloCrease 已提交
2733 2734 2735 2736
| 名称          | 参数类型                | 可读   | 可写   | 说明    |
| ----------- | ------------------- | ---- | ---- | ----- |
| rotation    | Array&lt;number&gt; | 是    | 是    | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是    | 是    | 倾斜矩阵。 |
Z
zengyawen 已提交
2737 2738 2739 2740


## CoordinatesOptions

C
cff-gite 已提交
2741 2742 2743
设置坐标选项对象。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2744

H
HelloCrease 已提交
2745 2746 2747 2748
| 名称   | 参数类型   | 可读   | 可写   | 说明     |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | 是    | 是    | x坐标方向。 |
| y    | number | 是    | 是    | y坐标方向。 |
Z
zengyawen 已提交
2749

Z
zengyawen 已提交
2750 2751 2752

## GeomagneticResponse

Z
zengyawen 已提交
2753
设置地磁响应对象,继承于[Response](#response)
Z
zengyawen 已提交
2754

C
cff-gite 已提交
2755 2756
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2757 2758 2759 2760 2761 2762 2763 2764 2765
| 名称              | 参数类型   | 可读   | 可写   | 说明                        |
| --------------- | ------ | ---- | ---- | ------------------------- |
| x               | number | 是    | 是    | 地磁场的北分量。                  |
| y               | number | 是    | 是    | 地磁场的东分量。                  |
| z               | number | 是    | 是    | 地磁场的垂直分量。                 |
| geomagneticDip  | number | 是    | 是    | 地磁倾角,即地球磁场线与水平面的夹角。       |
| deflectionAngle | number | 是    | 是    | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number | 是    | 是    | 地磁场的水平强度。                 |
| totalIntensity  | number | 是    | 是    | 地磁场的总强度。                  |
Z
zengyawen 已提交
2766 2767 2768

## LocationOptions

C
cff-gite 已提交
2769 2770 2771 2772
指示地理位置。

**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2773 2774 2775 2776 2777
| 名称        | 参数类型   | 可读   | 可写   | 说明    |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | 是    | 是    | 纬度。   |
| longitude | number | 是    | 是    | 经度。   |
| altitude  | number | 是    | 是    | 海拔高度。 |