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

C
cff-gite 已提交
3 4 5 6 7 8 9 10 11 12 13
sensor模块提供订阅传感器数据基本能力,包括订阅、取消订阅传感器数据,获取传感器列表,以及通用的传感器算法接口如通过气压值计算海拔高度、通过旋转矩阵计算设备方向等。

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

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

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

Z
zengyawen 已提交
17 18

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

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

H
HelloCrease 已提交
24
## sensor.on
Z
zengyawen 已提交
25

H
HelloCrease 已提交
26
### ACCELEROMETER
Z
zengyawen 已提交
27

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

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

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

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

H
HelloCrease 已提交
36
**参数:** 
C
cff-gite 已提交
37

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

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

C
cff-gite 已提交
55
### LINEAR_ACCELERATION<sup>(deprecated)</sup>
Z
zengyawen 已提交
56

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

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

H
h00514358 已提交
61
从API Version9开始该接口不再维护,推荐使用sensor.on.LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
62

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

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

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

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

H
h00514358 已提交
85
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
86 87 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

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 已提交
113
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
114

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

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

C
cff-gite 已提交
119
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限
C
cff-gite 已提交
120 121 122

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

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

H
HelloCrease 已提交
130
**示例:** 
H
HelloCrease 已提交
131
  ```js
C
cff-gite 已提交
132
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
133 134 135 136 137 138
      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);
139 140
  },
      {interval: 10000000}
Z
zengyawen 已提交
141 142
  );
  ```
Z
zengyawen 已提交
143

H
HelloCrease 已提交
144
### GRAVITY
Z
zengyawen 已提交
145

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

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

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

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

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

H
HelloCrease 已提交
170
### GYROSCOPE
Z
zengyawen 已提交
171

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

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

C
cff-gite 已提交
176
**需要权限**:ohos.permission.GYROSCOPE,该权限为系统权限
C
cff-gite 已提交
177 178 179

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

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

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

H
HelloCrease 已提交
198
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
199

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

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

C
cff-gite 已提交
204
**需要权限**:ohos.permission.GYROSCOPE,该权限为系统权限
C
cff-gite 已提交
205 206 207

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

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

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

H
HelloCrease 已提交
229
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
230

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

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

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

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

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

H
HelloCrease 已提交
253
### PEDOMETER_DETECTION
Z
zengyawen 已提交
254

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

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

C
cff-gite 已提交
259
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
260 261 262

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

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

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

H
HelloCrease 已提交
279
### PEDOMETER
Z
zengyawen 已提交
280

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

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

C
cff-gite 已提交
285
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
286 287 288

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

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

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

H
HelloCrease 已提交
305
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
306

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

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

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

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

H
HelloCrease 已提交
320
**示例:** 
C
cff-gite 已提交
321

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

H
HelloCrease 已提交
330
### MAGNETIC_FIELD
Z
zengyawen 已提交
331

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

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

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

H
HelloCrease 已提交
338
**参数:** 
C
cff-gite 已提交
339

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

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

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

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

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

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

H
HelloCrease 已提交
365
**参数:** 
C
cff-gite 已提交
366

H
HelloCrease 已提交
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
**示例:** 
C
cff-gite 已提交
427

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

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

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

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

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

H
HelloCrease 已提交
444
**参数:** 
C
cff-gite 已提交
445

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

H
HelloCrease 已提交
452
**示例:** 
C
cff-gite 已提交
453

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

H
HelloCrease 已提交
462
### HALL
Z
zengyawen 已提交
463

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

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

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

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

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

H
HelloCrease 已提交
486
### AMBIENT_LIGHT
Z
zengyawen 已提交
487

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

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

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

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

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

H
HelloCrease 已提交
510
### ORIENTATION
Z
zengyawen 已提交
511

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

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

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

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

H
HelloCrease 已提交
525
**示例:** 
H
HelloCrease 已提交
526
  ```js
C
cff-gite 已提交
527
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
C
cff-gite 已提交
528 529 530
      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);
531 532
  },
      {interval: 10000000}
Z
zengyawen 已提交
533 534
  );
  ```
Z
zengyawen 已提交
535

C
cff-gite 已提交
536
### HEART_RATE<sup>(deprecated)</sup>
C
cff-gite 已提交
537

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

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

H
h00514358 已提交
542
从API Version9开始该接口不再维护,推荐使用sensor.on.HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
543

C
cff-gite 已提交
544 545 546 547
**需要权限**:ohos.permission.READ_HEALTH_DATA 

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

H
HelloCrease 已提交
548
**参数:** 
C
cff-gite 已提交
549

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

H
HelloCrease 已提交
555
**示例:** 
C
cff-gite 已提交
556

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

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

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 已提交
592
### ROTATION_VECTOR
Z
zengyawen 已提交
593

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

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

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

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

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

H
HelloCrease 已提交
619
### WEAR_DETECTION
Z
zengyawen 已提交
620

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

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

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

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

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

H
HelloCrease 已提交
643
## sensor.once
Z
zengyawen 已提交
644

H
HelloCrease 已提交
645
### ACCELEROMETER
Z
zengyawen 已提交
646

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

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

C
cff-gite 已提交
651
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限
C
cff-gite 已提交
652 653 654

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

H
HelloCrease 已提交
655
**参数:** 
C
cff-gite 已提交
656

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

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

C
cff-gite 已提交
672
### LINEAR_ACCELERATION<sup>(deprecated)</sup>
Z
zengyawen 已提交
673

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

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

H
h00514358 已提交
678
从API Version9开始该接口不再维护,推荐使用sensor.once.LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
679

C
cff-gite 已提交
680
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限
C
cff-gite 已提交
681 682 683

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

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

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

H
h00514358 已提交
700
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
701 702 703

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

H
h00514358 已提交
704
订阅一次线性加速度传感器数据。
H
h00514358 已提交
705

C
cff-gite 已提交
706
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限
H
h00514358 已提交
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725

**系统能力**: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 已提交
726
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
727

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

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

C
cff-gite 已提交
732
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限
C
cff-gite 已提交
733 734 735

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

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

H
HelloCrease 已提交
742
**示例:** 
Z
zengyawen 已提交
743
  ```
C
cff-gite 已提交
744
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
745 746 747 748 749 750
      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 已提交
751
    }
Z
zengyawen 已提交
752 753
  );
  ```
Z
zengyawen 已提交
754

H
HelloCrease 已提交
755
### GRAVITY
Z
zengyawen 已提交
756

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

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

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

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

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

H
HelloCrease 已提交
779
### GYROSCOPE
Z
zengyawen 已提交
780

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

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

C
cff-gite 已提交
785
**需要权限**:ohos.permission.GYROSCOPE,该权限为系统权限
C
cff-gite 已提交
786 787 788

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

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

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

H
HelloCrease 已提交
805
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
806

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

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

C
cff-gite 已提交
811
**需要权限**:ohos.permission.GYROSCOPE,该权限为系统权限
C
cff-gite 已提交
812 813 814

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

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

H
HelloCrease 已提交
821
**示例:** 
H
HelloCrease 已提交
822
  ```js
C
cff-gite 已提交
823
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
824 825 826 827 828 829
      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 已提交
830
    }
Z
zengyawen 已提交
831 832
  );
  ```
Z
zengyawen 已提交
833

H
HelloCrease 已提交
834
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
835

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

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

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

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

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

H
HelloCrease 已提交
856
### PEDOMETER_DETECTION
Z
zengyawen 已提交
857

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

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

C
cff-gite 已提交
862
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
863 864 865

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

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

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

H
HelloCrease 已提交
880
### PEDOMETER
Z
zengyawen 已提交
881

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

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

C
cff-gite 已提交
886
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
887 888 889

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

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

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

H
HelloCrease 已提交
904
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
905

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

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

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

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

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

H
HelloCrease 已提交
926
### MAGNETIC_FIELD
Z
zengyawen 已提交
927

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

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

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

H
HelloCrease 已提交
934
**参数:** 
C
cff-gite 已提交
935

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

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

H
HelloCrease 已提交
951
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
952

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

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

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

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

H
HelloCrease 已提交
965
**示例:** 
H
HelloCrease 已提交
966
  ```js
C
cff-gite 已提交
967
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
968 969 970 971 972 973
      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 已提交
974
    }
Z
zengyawen 已提交
975 976
  );
  ```
Z
zengyawen 已提交
977

H
HelloCrease 已提交
978
### PROXIMITY
Z
zengyawen 已提交
979

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

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

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

H
HelloCrease 已提交
986
**参数:** 
C
cff-gite 已提交
987

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

H
HelloCrease 已提交
993
**示例:** 
H
HelloCrease 已提交
994
  ```js
L
li-yaoyao777 已提交
995
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
Z
zengyawen 已提交
996
      console.info('Distance: ' + data.distance);
Z
zengyawen 已提交
997
    }
Z
zengyawen 已提交
998 999
  );
  ```
Z
zengyawen 已提交
1000

H
HelloCrease 已提交
1001
### HUMIDITY
Z
zengyawen 已提交
1002

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

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

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

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

H
HelloCrease 已提交
1015
**示例:** 
H
HelloCrease 已提交
1016
  ```js
C
cff-gite 已提交
1017
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
Z
zengyawen 已提交
1018
      console.info('Humidity: ' + data.humidity);
Z
zengyawen 已提交
1019
    }
Z
zengyawen 已提交
1020 1021
  );
  ```
Z
zengyawen 已提交
1022

H
HelloCrease 已提交
1023
### BAROMETER
Z
zengyawen 已提交
1024

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

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

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

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

H
HelloCrease 已提交
1037
**示例:** 
H
HelloCrease 已提交
1038
  ```js
C
cff-gite 已提交
1039
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
Z
zengyawen 已提交
1040
      console.info('Atmospheric pressure: ' + data.pressure);
Z
zengyawen 已提交
1041
    }
Z
zengyawen 已提交
1042 1043
  );
  ```
Z
zengyawen 已提交
1044

H
HelloCrease 已提交
1045
### HALL
Z
zengyawen 已提交
1046

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

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

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

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

H
HelloCrease 已提交
1059
**示例:** 
H
HelloCrease 已提交
1060
  ```js
C
cff-gite 已提交
1061
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
Z
zengyawen 已提交
1062
      console.info('Status: ' + data.status);
Z
zengyawen 已提交
1063
    }
Z
zengyawen 已提交
1064 1065
  );
  ```
Z
zengyawen 已提交
1066

H
HelloCrease 已提交
1067
### AMBIENT_LIGHT
Z
zengyawen 已提交
1068

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

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

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

H
HelloCrease 已提交
1075
**参数:** 
C
cff-gite 已提交
1076

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

H
HelloCrease 已提交
1082
**示例:** 
C
cff-gite 已提交
1083

H
HelloCrease 已提交
1084
  ```js
C
cff-gite 已提交
1085
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
1086
      console.info(' Illumination: ' + data.intensity);
Z
zengyawen 已提交
1087
    }
Z
zengyawen 已提交
1088 1089
  );
  ```
Z
zengyawen 已提交
1090

H
HelloCrease 已提交
1091
### ORIENTATION
Z
zengyawen 已提交
1092

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

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

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

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

H
HelloCrease 已提交
1105
**示例:** 
H
HelloCrease 已提交
1106
  ```js
C
cff-gite 已提交
1107
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
C
cff-gite 已提交
1108 1109 1110
      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 已提交
1111
    }
Z
zengyawen 已提交
1112 1113
  );
  ```
Z
zengyawen 已提交
1114

H
HelloCrease 已提交
1115
### ROTATION_VECTOR
Z
zengyawen 已提交
1116

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

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

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

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

H
HelloCrease 已提交
1129
**示例:** 
H
HelloCrease 已提交
1130
  ```js
C
cff-gite 已提交
1131
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
Z
zengyawen 已提交
1132 1133 1134
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
1135
      console.info('Scalar quantity: ' + data.w);
Z
zengyawen 已提交
1136
    }
Z
zengyawen 已提交
1137 1138
  );
  ```
Z
zengyawen 已提交
1139

C
cff-gite 已提交
1140
### HEART_RATE<sup>(deprecated)</sup>
Z
zengyawen 已提交
1141

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

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

H
h00514358 已提交
1146
从API Version9开始该接口不再维护,推荐使用sensor.once.HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1147

C
cff-gite 已提交
1148
**需要权限**:ohos.permission.READ_HEALTH_DATA 
C
cff-gite 已提交
1149 1150 1151

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

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

H
HelloCrease 已提交
1158
**示例:** 
H
HelloCrease 已提交
1159
  ```js
C
cff-gite 已提交
1160
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
Z
zengyawen 已提交
1161
      console.info("Heart rate: " + data.heartRate);
Z
zengyawen 已提交
1162
    }
Z
zengyawen 已提交
1163 1164
  );
  ```
Z
zengyawen 已提交
1165

H
h00514358 已提交
1166
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1167 1168 1169

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

H
h00514358 已提交
1170
订阅一次心率传感器数据。
H
h00514358 已提交
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189

**需要权限**: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 已提交
1190
### WEAR_DETECTION
Z
zengyawen 已提交
1191

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

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

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

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

H
HelloCrease 已提交
1204
**示例:** 
H
HelloCrease 已提交
1205
  ```js
C
cff-gite 已提交
1206
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
Z
zengyawen 已提交
1207
      console.info("Wear status: "+ data.value);
Z
zengyawen 已提交
1208
    }
Z
zengyawen 已提交
1209 1210
  );
  ```
Z
zengyawen 已提交
1211

H
HelloCrease 已提交
1212 1213 1214
## sensor.off

### ACCELEROMETER
Z
zengyawen 已提交
1215

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

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

C
cff-gite 已提交
1220 1221 1222 1223
**需要权限**:ohos.permission.ACCELEROMETER, 该权限为系统权限

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

H
HelloCrease 已提交
1224
**参数:** 
C
cff-gite 已提交
1225

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

H
HelloCrease 已提交
1231
**示例:** 
C
cff-gite 已提交
1232

H
HelloCrease 已提交
1233
```js
C
cff-gite 已提交
1234 1235 1236 1237 1238 1239 1240 1241
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 已提交
1242
### ACCELEROMETER_UNCALIBRATED
C
cff-gite 已提交
1243

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

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

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

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

H
HelloCrease 已提交
1252
**参数:** 
C
cff-gite 已提交
1253

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

H
HelloCrease 已提交
1259
**示例:** 
C
cff-gite 已提交
1260

H
HelloCrease 已提交
1261
```js
C
cff-gite 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
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 已提交
1273
### AMBIENT_LIGHT
C
cff-gite 已提交
1274

C
cff-gite 已提交
1275
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
1276 1277 1278 1279 1280

取消订阅传感器数据。

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

H
HelloCrease 已提交
1281
**参数:** 
C
cff-gite 已提交
1282

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

H
HelloCrease 已提交
1288
**示例:** 
C
cff-gite 已提交
1289

H
HelloCrease 已提交
1290
```js
C
cff-gite 已提交
1291 1292 1293 1294 1295 1296
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

H
HelloCrease 已提交
1297
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1298

C
cff-gite 已提交
1299
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
C
cff-gite 已提交
1300 1301 1302 1303 1304

取消订阅传感器数据。

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

H
HelloCrease 已提交
1305
**参数:** 
C
cff-gite 已提交
1306

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

H
HelloCrease 已提交
1312
**示例:** 
C
cff-gite 已提交
1313

H
HelloCrease 已提交
1314
```js
C
cff-gite 已提交
1315 1316 1317 1318 1319 1320
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

H
HelloCrease 已提交
1321
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1322

C
cff-gite 已提交
1323
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
C
cff-gite 已提交
1324 1325 1326 1327 1328

取消订阅传感器数据。

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

H
HelloCrease 已提交
1329
**参数:** 
C
cff-gite 已提交
1330

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

H
HelloCrease 已提交
1336
**示例:** 
C
cff-gite 已提交
1337

H
HelloCrease 已提交
1338
```js
C
cff-gite 已提交
1339 1340 1341 1342 1343 1344
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

H
HelloCrease 已提交
1345
### GRAVITY
C
cff-gite 已提交
1346

C
cff-gite 已提交
1347
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
C
cff-gite 已提交
1348 1349 1350 1351 1352

取消订阅传感器数据。

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

H
HelloCrease 已提交
1353
**参数:** 
C
cff-gite 已提交
1354

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

H
HelloCrease 已提交
1360
**示例:** 
C
cff-gite 已提交
1361

H
HelloCrease 已提交
1362
```js
C
cff-gite 已提交
1363 1364 1365 1366 1367 1368 1369 1370
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 已提交
1371
### GYROSCOPE
C
cff-gite 已提交
1372

C
cff-gite 已提交
1373
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
C
cff-gite 已提交
1374 1375 1376 1377 1378 1379 1380

取消订阅传感器数据。

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

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

H
HelloCrease 已提交
1381
**参数:** 
C
cff-gite 已提交
1382

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

H
HelloCrease 已提交
1388
**示例:** 
C
cff-gite 已提交
1389

H
HelloCrease 已提交
1390
```js
C
cff-gite 已提交
1391 1392 1393 1394 1395 1396 1397 1398
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 已提交
1399
### GYROSCOPE_UNCALIBRATED
C
cff-gite 已提交
1400

H
HelloCrease 已提交
1401
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1402 1403 1404 1405 1406 1407 1408

取消订阅传感器数据。

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

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

H
HelloCrease 已提交
1409
**参数:** 
C
cff-gite 已提交
1410

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

H
HelloCrease 已提交
1416
**示例:** 
C
cff-gite 已提交
1417

H
HelloCrease 已提交
1418
```js
C
cff-gite 已提交
1419 1420 1421 1422 1423 1424 1425 1426
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 已提交
1427
### HALL
C
cff-gite 已提交
1428

C
cff-gite 已提交
1429
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
C
cff-gite 已提交
1430 1431 1432 1433 1434

取消订阅传感器数据。

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

H
HelloCrease 已提交
1435
**参数:** 
C
cff-gite 已提交
1436

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

H
HelloCrease 已提交
1442
**示例:** 
C
cff-gite 已提交
1443

H
HelloCrease 已提交
1444
```js
C
cff-gite 已提交
1445 1446 1447 1448 1449 1450
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

C
cff-gite 已提交
1451
### HEART_RATE<sup>(deprecated)</sup>
C
cff-gite 已提交
1452

C
cff-gite 已提交
1453
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
C
cff-gite 已提交
1454 1455 1456

取消订阅传感器数据。

H
h00514358 已提交
1457
从API Version9开始该接口不再维护,推荐使用sensor.off.HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1458

C
cff-gite 已提交
1459 1460 1461 1462
**需要权限**:ohos.permission.READ_HEALTH_DATA

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

H
HelloCrease 已提交
1463
**参数:** 
C
cff-gite 已提交
1464

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

H
HelloCrease 已提交
1470
**示例:** 
C
cff-gite 已提交
1471

H
HelloCrease 已提交
1472
```js
C
cff-gite 已提交
1473 1474 1475 1476 1477 1478
function callback(data) {
    console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
```

H
h00514358 已提交
1479
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504

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 已提交
1505
### HUMIDITY
C
cff-gite 已提交
1506

C
cff-gite 已提交
1507
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
C
cff-gite 已提交
1508 1509 1510 1511 1512

取消订阅传感器数据。

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

H
HelloCrease 已提交
1513
**参数:** 
C
cff-gite 已提交
1514

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

H
HelloCrease 已提交
1520
**示例:** 
C
cff-gite 已提交
1521

H
HelloCrease 已提交
1522
```js
C
cff-gite 已提交
1523 1524 1525 1526 1527 1528
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

C
cff-gite 已提交
1529
### LINEAR_ACCELERATION<sup>(deprecated)</sup>
C
cff-gite 已提交
1530

C
cff-gite 已提交
1531
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
C
cff-gite 已提交
1532 1533 1534

取消订阅传感器数据。

H
h00514358 已提交
1535
从API Version9开始该接口不再维护,推荐使用sensor.off.LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
1536

C
cff-gite 已提交
1537 1538 1539 1540
**需要权限**:ohos.permission.ACCELEROMETER,该权限为系统权限

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

H
HelloCrease 已提交
1541
**参数:** 
C
cff-gite 已提交
1542

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

H
HelloCrease 已提交
1548
**示例:** 
C
cff-gite 已提交
1549

H
HelloCrease 已提交
1550
```js
C
cff-gite 已提交
1551 1552 1553 1554 1555 1556 1557 1558
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 已提交
1559
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586

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 已提交
1587
### MAGNETIC_FIELD
C
cff-gite 已提交
1588

C
cff-gite 已提交
1589
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
C
cff-gite 已提交
1590 1591 1592 1593 1594

取消订阅传感器数据。

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

H
HelloCrease 已提交
1595
**参数:** 
C
cff-gite 已提交
1596

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

H
HelloCrease 已提交
1602
**示例:** 
C
cff-gite 已提交
1603

H
HelloCrease 已提交
1604
```js
C
cff-gite 已提交
1605 1606 1607 1608 1609 1610 1611 1612
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 已提交
1613
### MAGNETIC_FIELD_UNCALIBRATED
C
cff-gite 已提交
1614

C
cff-gite 已提交
1615
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
1616 1617 1618 1619 1620

取消订阅传感器数据。

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

H
HelloCrease 已提交
1621
**参数:** 
C
cff-gite 已提交
1622

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

H
HelloCrease 已提交
1628
**示例:** 
C
cff-gite 已提交
1629

H
HelloCrease 已提交
1630
```js
C
cff-gite 已提交
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
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 已提交
1642
### ORIENTATION
C
cff-gite 已提交
1643

C
cff-gite 已提交
1644
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
C
cff-gite 已提交
1645 1646 1647 1648 1649

取消订阅传感器数据。

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

H
HelloCrease 已提交
1650
**参数:** 
C
cff-gite 已提交
1651

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

H
HelloCrease 已提交
1657
**示例:** 
C
cff-gite 已提交
1658

H
HelloCrease 已提交
1659
```js
C
cff-gite 已提交
1660
function callback(data) {
C
cff-gite 已提交
1661 1662 1663
    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 已提交
1664 1665 1666 1667
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```

H
HelloCrease 已提交
1668
### PEDOMETER
C
cff-gite 已提交
1669

C
cff-gite 已提交
1670
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
C
cff-gite 已提交
1671 1672 1673

取消订阅传感器数据。

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

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

H
HelloCrease 已提交
1678
**参数:** 
C
cff-gite 已提交
1679

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

H
HelloCrease 已提交
1685
**示例:** 
C
cff-gite 已提交
1686

H
HelloCrease 已提交
1687
```js
C
cff-gite 已提交
1688 1689 1690 1691 1692 1693
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

H
HelloCrease 已提交
1694
### PEDOMETER_DETECTION
C
cff-gite 已提交
1695

C
cff-gite 已提交
1696
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
C
cff-gite 已提交
1697 1698 1699 1700 1701 1702 1703

取消订阅传感器数据。

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

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

H
HelloCrease 已提交
1704
**参数:** 
C
cff-gite 已提交
1705

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

H
HelloCrease 已提交
1711
**示例:** 
C
cff-gite 已提交
1712

H
HelloCrease 已提交
1713
```js
C
cff-gite 已提交
1714 1715 1716 1717 1718 1719
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

H
HelloCrease 已提交
1720
### PROXIMITY
C
cff-gite 已提交
1721

C
cff-gite 已提交
1722
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
C
cff-gite 已提交
1723 1724 1725 1726 1727

取消订阅传感器数据。

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

H
HelloCrease 已提交
1728
**参数:** 
C
cff-gite 已提交
1729

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

H
HelloCrease 已提交
1735
**示例:** 
C
cff-gite 已提交
1736

H
HelloCrease 已提交
1737
```js
C
cff-gite 已提交
1738 1739 1740 1741 1742 1743
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```

H
HelloCrease 已提交
1744
### ROTATION_VECTOR
C
cff-gite 已提交
1745

C
cff-gite 已提交
1746
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
C
cff-gite 已提交
1747 1748 1749 1750 1751

取消订阅传感器数据。

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

H
HelloCrease 已提交
1752
**参数:** 
C
cff-gite 已提交
1753

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

H
HelloCrease 已提交
1759
**示例:** 
C
cff-gite 已提交
1760

H
HelloCrease 已提交
1761
```js
C
cff-gite 已提交
1762 1763 1764 1765
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 已提交
1766
    console.info('Scalar quantity: ' + data.w);
C
cff-gite 已提交
1767 1768 1769 1770
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```

H
HelloCrease 已提交
1771
### SIGNIFICANT_MOTION
C
cff-gite 已提交
1772

C
cff-gite 已提交
1773
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
C
cff-gite 已提交
1774 1775 1776 1777 1778

取消订阅传感器数据。

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

H
HelloCrease 已提交
1779
**参数:** 
C
cff-gite 已提交
1780

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

H
HelloCrease 已提交
1786
**示例:** 
C
cff-gite 已提交
1787

H
HelloCrease 已提交
1788
```js
C
cff-gite 已提交
1789 1790 1791 1792 1793 1794
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```

H
HelloCrease 已提交
1795
### WEAR_DETECTION
C
cff-gite 已提交
1796

C
cff-gite 已提交
1797
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
1798 1799 1800 1801 1802

取消订阅传感器数据。

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

H
HelloCrease 已提交
1803
**参数:** 
C
cff-gite 已提交
1804

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

H
HelloCrease 已提交
1810
**示例:** 
C
cff-gite 已提交
1811

H
HelloCrease 已提交
1812
```js
C
cff-gite 已提交
1813 1814 1815 1816 1817
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
Z
zengyawen 已提交
1818

Z
zengyawen 已提交
1819 1820 1821 1822 1823 1824
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
1827
**参数:** 
Z
zengyawen 已提交
1828

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

H
HelloCrease 已提交
1835
**示例:** 
Z
zengyawen 已提交
1836

H
HelloCrease 已提交
1837
```js
C
cff-gite 已提交
1838
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
H
HelloCrease 已提交
1839 1840 1841 1842
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
H
HelloCrease 已提交
1843
    console.info("Operation successed. Data obtained: " + data);
H
HelloCrease 已提交
1844 1845 1846 1847 1848
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
Z
zengyawen 已提交
1849 1850 1851 1852 1853 1854
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
1857
**参数:** 
Z
zengyawen 已提交
1858

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

H
HelloCrease 已提交
1864
**返回值:** 
Z
zengyawen 已提交
1865

H
HelloCrease 已提交
1866 1867 1868
| 类型                                 | 说明          |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |
Z
zengyawen 已提交
1869

H
HelloCrease 已提交
1870
**示例:** 
Z
zengyawen 已提交
1871

H
HelloCrease 已提交
1872
```js
C
cff-gite 已提交
1873
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
H
HelloCrease 已提交
1874 1875 1876 1877 1878 1879 1880 1881 1882
    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 已提交
1883

Z
zengyawen 已提交
1884
## sensor.getGeomagneticField
Z
zengyawen 已提交
1885

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

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

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

H
HelloCrease 已提交
1892
**参数:** 
C
cff-gite 已提交
1893 1894 1895 1896 1897
| 参数名          | 类型                                                         | 必填 | 说明                               |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置。                         |
| timeMillis      | number                                                       | 是   | 表示获取磁偏角的时间,单位为毫秒。 |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 返回磁场信息。                     |
Z
zengyawen 已提交
1898

H
HelloCrease 已提交
1899
**示例:** 
H
HelloCrease 已提交
1900
```js
C
cff-gite 已提交
1901
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
H
HelloCrease 已提交
1902 1903 1904 1905
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
C
cff-gite 已提交
1906
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
H
HelloCrease 已提交
1907 1908 1909 1910
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});
```
Z
zengyawen 已提交
1911 1912 1913 1914 1915 1916
## sensor.getGeomagneticField

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

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

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

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

H
HelloCrease 已提交
1925 1926 1927 1928
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
Z
zengyawen 已提交
1929

H
HelloCrease 已提交
1930
**示例:** 
H
HelloCrease 已提交
1931
  ```js
C
cff-gite 已提交
1932
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
Z
zengyawen 已提交
1933
      promise.then((data) => {
Z
zengyawen 已提交
1934 1935 1936
          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 已提交
1937
      }).catch((reason) => {
Z
zengyawen 已提交
1938 1939
          console.info('Operation failed.');
  })
Z
zengyawen 已提交
1940 1941
  ```

Z
zengyawen 已提交
1942 1943 1944 1945 1946 1947
## sensor.getAltitude

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

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

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

H
HelloCrease 已提交
1950
**参数:** 
Z
zengyawen 已提交
1951

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

H
HelloCrease 已提交
1958
**示例:** 
Z
zengyawen 已提交
1959

H
HelloCrease 已提交
1960
  ```js
Z
zengyawen 已提交
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
  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 已提交
1977 1978
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1979
**参数:** 
Z
zengyawen 已提交
1980

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

H
HelloCrease 已提交
1986
**返回值:** 
Z
zengyawen 已提交
1987

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

H
HelloCrease 已提交
1992
**示例:** 
Z
zengyawen 已提交
1993

H
HelloCrease 已提交
1994
  ```js
Z
zengyawen 已提交
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
  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 已提交
2010 2011
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2012
**参数:** 
Z
zengyawen 已提交
2013

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

H
HelloCrease 已提交
2019
**示例:** 
Z
zengyawen 已提交
2020

H
HelloCrease 已提交
2021
  ```js
Z
zengyawen 已提交
2022 2023
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
C
cff-gite 已提交
2024
          console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + 
Z
zengyawen 已提交
2025 2026 2027
                        err.message);
          return;
      }
H
HelloCrease 已提交
2028
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
Z
zengyawen 已提交
2029 2030 2031 2032 2033 2034 2035 2036 2037
  })
  ```

## sensor.getGeomagneticDip

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

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

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

H
HelloCrease 已提交
2040
**参数:** 
Z
zengyawen 已提交
2041

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

H
HelloCrease 已提交
2046
**返回值:** 
Z
zengyawen 已提交
2047

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

H
HelloCrease 已提交
2052
**示例:** 
Z
zengyawen 已提交
2053

H
HelloCrease 已提交
2054
  ```js
Z
zengyawen 已提交
2055 2056
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
C
cff-gite 已提交
2057
          console.info('getGeomagneticDip_promise successed', data);
Z
zengyawen 已提交
2058 2059 2060 2061 2062 2063 2064
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

H
HelloCrease 已提交
2065
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
2066 2067 2068

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

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

H
HelloCrease 已提交
2071
**参数:** 
Z
zengyawen 已提交
2072

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

H
HelloCrease 已提交
2079
**示例:** 
Z
zengyawen 已提交
2080

H
HelloCrease 已提交
2081
  ```js
Z
zengyawen 已提交
2082 2083
  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 已提交
2084
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2085 2086 2087 2088
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2089
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
      }
  })
  ```


## sensor. getAngleModify

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

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

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

H
HelloCrease 已提交
2103
**参数:** 
Z
zengyawen 已提交
2104

H
HelloCrease 已提交
2105 2106 2107 2108
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
2109

H
HelloCrease 已提交
2110
**返回值:** 
Z
zengyawen 已提交
2111

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

H
HelloCrease 已提交
2116
**示例:** 
Z
zengyawen 已提交
2117

H
HelloCrease 已提交
2118
  ```js
Z
zengyawen 已提交
2119 2120
  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 已提交
2121
          console.info('getAngleModifiy_promise success');
Z
zengyawen 已提交
2122
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2123
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2124 2125
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2126
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2139
**参数:** 
Z
zengyawen 已提交
2140

H
HelloCrease 已提交
2141 2142 2143 2144
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
2145

H
HelloCrease 已提交
2146
**示例:** 
Z
zengyawen 已提交
2147

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


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2170
**参数:** 
Z
zengyawen 已提交
2171

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

H
HelloCrease 已提交
2176
**返回值:** 
Z
zengyawen 已提交
2177

H
HelloCrease 已提交
2178 2179 2180
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
2181

H
HelloCrease 已提交
2182
**示例:** 
Z
zengyawen 已提交
2183

H
HelloCrease 已提交
2184
  ```js
Z
zengyawen 已提交
2185 2186
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
H
HelloCrease 已提交
2187
          console.info('createRotationMatrix_promise success');
C
cff-gite 已提交
2188
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2189
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2190 2191
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2192
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2193 2194 2195 2196 2197 2198 2199 2200 2201 2202
  })	
  ```


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
2205
**参数:** 
Z
zengyawen 已提交
2206

H
HelloCrease 已提交
2207 2208 2209 2210
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
2211

H
HelloCrease 已提交
2212
**示例:** 
Z
zengyawen 已提交
2213

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


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
2236
**参数:** 
Z
zengyawen 已提交
2237

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

H
HelloCrease 已提交
2242
**返回值:** 
Z
zengyawen 已提交
2243

H
HelloCrease 已提交
2244 2245 2246
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
2247

H
HelloCrease 已提交
2248
**示例:** 
Z
zengyawen 已提交
2249

H
HelloCrease 已提交
2250
  ```js
Z
zengyawen 已提交
2251 2252 2253 2254
  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 已提交
2255
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268
          }
      }).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 已提交
2269 2270
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2271
**参数:** 
Z
zengyawen 已提交
2272

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

H
HelloCrease 已提交
2278
**示例:** 
Z
zengyawen 已提交
2279

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


## sensor.getDirection

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

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

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

H
HelloCrease 已提交
2303
**参数:** 
Z
zengyawen 已提交
2304

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

H
HelloCrease 已提交
2309
**返回值:** 
Z
zengyawen 已提交
2310

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

H
HelloCrease 已提交
2315
**示例:** 
Z
zengyawen 已提交
2316

H
HelloCrease 已提交
2317
  ```js
Z
zengyawen 已提交
2318 2319
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
H
HelloCrease 已提交
2320
          console.info('sensor_getAltitude_Promise success', data);
Z
zengyawen 已提交
2321
          for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
2322
              console.info("sensor_getDirection_promise" + data[i]);
Z
zengyawen 已提交
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
          }
      }).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 已提交
2336 2337
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2338
**参数:** 
Z
zengyawen 已提交
2339

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

H
HelloCrease 已提交
2346
**示例:** 
Z
zengyawen 已提交
2347

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


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2370
**参数:** 
Z
zengyawen 已提交
2371

H
HelloCrease 已提交
2372 2373 2374 2375
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
2376

H
HelloCrease 已提交
2377
**返回值:** 
Z
zengyawen 已提交
2378

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

H
HelloCrease 已提交
2383
**示例:** 
Z
zengyawen 已提交
2384

H
HelloCrease 已提交
2385
  ```js
Z
zengyawen 已提交
2386 2387
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
H
HelloCrease 已提交
2388
          console.info('createRotationMatrix_promise successed');
C
cff-gite 已提交
2389
          for (var i=0; i < data.rotation.length; i++) {
H
HelloCrease 已提交
2390
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2391 2392
          }
      }).catch((err) => {
H
HelloCrease 已提交
2393
          console.info('promise failed');
Z
zengyawen 已提交
2394 2395 2396
  })
  ```

C
cff-gite 已提交
2397
## sensor.getSensorLists<sup>9+</sup>
C
cff-gite 已提交
2398

C
cff-gite 已提交
2399
 getSensorLists(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
C
cff-gite 已提交
2400 2401 2402 2403 2404 2405 2406

获取设备上的所有传感器信息。

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

**参数:** 

C
cff-gite 已提交
2407 2408 2409
| 参数名   | 类型                                           | 必填 | 说明             |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
2410 2411 2412

**示例:** 

C
cff-gite 已提交
2413
```js
C
cff-gite 已提交
2414
sensor.getSensorLists((error, data) => {
C
cff-gite 已提交
2415
    if (error) {
C
cff-gite 已提交
2416
        console.error('getSensorLists failed');
C
cff-gite 已提交
2417
    } else {
C
cff-gite 已提交
2418
        console.info("getSensorLists callback in" + data.length);
C
cff-gite 已提交
2419
        for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
2420
            console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
2421
        }
C
cff-gite 已提交
2422 2423
    }
});
C
cff-gite 已提交
2424 2425
```

C
cff-gite 已提交
2426
## sensor.getSensorLists<sup>9+</sup>
C
cff-gite 已提交
2427 2428 2429 2430 2431 2432 2433 2434 2435

 getSensorLists(): Promise< Array&lt;Sensor&gt;>

获取设备上的所有传感器信息。

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

**返回值:** 

C
cff-gite 已提交
2436 2437 2438
| 参数名  | 类型                                     | 必填 | 说明             |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
2439 2440 2441

**示例:** 

C
cff-gite 已提交
2442
```js
C
cff-gite 已提交
2443 2444
sensor.getSensorLists().then((data) => {
    console.info("getSensorLists promise in" + data.length);
C
cff-gite 已提交
2445
    for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
2446
        console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
2447 2448
     }
}, (error)=>{
C
cff-gite 已提交
2449
    console.error('getSensorLists failed');
C
cff-gite 已提交
2450
});
C
cff-gite 已提交
2451 2452
```

C
cff-gite 已提交
2453
##  sensor.getSingleSensor<sup>9+</sup>
C
cff-gite 已提交
2454

C
cff-gite 已提交
2455
getSingleSensor(type: SensorType, callback: AsyncCallback&lt;Sensor&gt;): void
C
cff-gite 已提交
2456 2457 2458 2459 2460 2461 2462

获取指定类型的传感器信息。

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

**参数:** 

C
cff-gite 已提交
2463 2464 2465 2466
| 参数名   | 类型                                    | 必填 | 说明             |
| -------- | --------------------------------------- | ---- | ---------------- |
| type     | SensorType                              | 是   | 传感器类型。     |
| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
C
cff-gite 已提交
2467

C
cff-gite 已提交
2468
**示例:**
C
cff-gite 已提交
2469

C
cff-gite 已提交
2470
```js
C
cff-gite 已提交
2471 2472
 sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => {
     if (error) {
C
cff-gite 已提交
2473
         console.error('getSingleSensor failed');
C
cff-gite 已提交
2474 2475 2476 2477
     } else {
         console.info("getSingleSensor " + JSON.stringify(data));
     }
});
C
cff-gite 已提交
2478 2479
```

C
cff-gite 已提交
2480
##  sensor.getSingleSensor<sup>9+</sup>
C
cff-gite 已提交
2481

C
cff-gite 已提交
2482
 getSingleSensor(type: SensorType): Promise&lt;Sensor&gt;
C
cff-gite 已提交
2483 2484 2485 2486 2487 2488 2489

获取指定类型的传感器信息。

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

**参数:** 

C
cff-gite 已提交
2490 2491 2492
| 参数名 | 类型       | 必填 | 说明         |
| ------ | ---------- | ---- | ------------ |
| type   | SensorType | 是   | 传感器类型。 |
C
cff-gite 已提交
2493 2494 2495

**返回值:** 

C
cff-gite 已提交
2496 2497 2498
| 参数名  | 类型                              | 必填 | 说明             |
| ------- | --------------------------------- | ---- | ---------------- |
| promise | Promise&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
C
cff-gite 已提交
2499 2500 2501

**示例:**

C
cff-gite 已提交
2502
```js
C
cff-gite 已提交
2503 2504 2505 2506 2507
sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER).then((data) => {
    console.info("getSingleSensor " + JSON.stringify(data));
}, (error)=>{
    console.error('getSingleSensor failed');
});
C
cff-gite 已提交
2508 2509
```

Z
zengyawen 已提交
2510
## SensorType
Z
zengyawen 已提交
2511 2512 2513

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

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

Z
zengyawen 已提交
2516

C
cff-gite 已提交
2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541
| 名称                                                      | 默认值 | 说明                   |
| --------------------------------------------------------- | ------ | ---------------------- |
| 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    | 重力传感器。           |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION<sup>(deprecated)</sup> | 258    | 线性加速度传感器。     |
| SENSOR_TYPE_ID_LINEAR_ACCELEROMETER<sup>9+</sup>          | 258    | 线性加速度传感器。     |
| 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    | 计步传感器。           |
| SENSOR_TYPE_ID_HEART_RATE<sup>(deprecated)</sup>          | 278    | 心率传感器。           |
| SENSOR_TYPE_ID_HEART_BEAT_RATE<sup>9+</sup>               | 278    | 心率传感器。           |
| SENSOR_TYPE_ID_WEAR_DETECTION                             | 280    | 佩戴检测传感器。       |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED                 | 281    | 未校准加速度计传感器。 |
Z
zengyawen 已提交
2542 2543


Z
zengyawen 已提交
2544 2545 2546 2547
## Response

传感器数据的时间戳。

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

C
cff-gite 已提交
2550 2551 2552 2553
| 名称      | 参数类型 | 可读 | 可写 | 说明                     |
| --------- | -------- | ---- | ---- | ------------------------ |
| timestamp | number   | 是   | 是   | 传感器数据上报的时间戳。 |

C
cff-gite 已提交
2554
## Sensor<sup>9+</sup>
C
cff-gite 已提交
2555 2556 2557 2558 2559

指示传感器信息。

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

C
cff-gite 已提交
2560 2561 2562 2563 2564 2565 2566 2567 2568 2569
| 名称            | 参数类型 | 说明                   |
| --------------- | -------- | ---------------------- |
| sensorName      | string   | 传感器名称。           |
| venderName      | string   | 传感器供应商。         |
| firmwareVersion | string   | 传感器固件版本。       |
| hardwareVersion | string   | 传感器硬件版本。       |
| sensorTypeId    | number   | 传感器类型id。         |
| maxRange        | number   | 传感器的最大测量范围。 |
| precision       | number   | 传感器精度。           |
| power           | number   | 传感器电源。           |
C
cff-gite 已提交
2570

Z
zengyawen 已提交
2571
## AccelerometerResponse
Z
zengyawen 已提交
2572

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

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

Z
zengyawen 已提交
2577

H
HelloCrease 已提交
2578 2579 2580 2581 2582
| 名称   | 参数类型   | 可读   | 可写   | 说明                     |
| ---- | ------ | ---- | ---- | ---------------------- |
| x    | number | 是    | 是    | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2583 2584 2585


## LinearAccelerometerResponse
Z
zengyawen 已提交
2586

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

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

Z
zengyawen 已提交
2591

H
HelloCrease 已提交
2592 2593 2594 2595 2596
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2597 2598 2599


## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
2600

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

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

Z
zengyawen 已提交
2605

H
HelloCrease 已提交
2606 2607 2608 2609 2610 2611 2612 2613
| 名称    | 参数类型   | 可读   | 可写   | 说明                           |
| ----- | ------ | ---- | ---- | ---------------------------- |
| 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 已提交
2614 2615 2616


## GravityResponse
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
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2628 2629 2630


## OrientationResponse
Z
zengyawen 已提交
2631

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

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

Z
zengyawen 已提交
2636

H
HelloCrease 已提交
2637 2638
| 名称    | 参数类型   | 可读   | 可写   | 说明                |
| ----- | ------ | ---- | ---- | ----------------- |
2639
| alpha | number | 是    | 是    | 设备围绕Z轴的旋转角度,单位:度。 |
H
HelloCrease 已提交
2640 2641
| beta  | number | 是    | 是    | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是    | 是    | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
2642 2643 2644


## RotationVectorResponse
Z
zengyawen 已提交
2645

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

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

Z
zengyawen 已提交
2650

H
HelloCrease 已提交
2651 2652 2653 2654 2655 2656
| 名称   | 参数类型   | 可读   | 可写   | 说明        |
| ---- | ------ | ---- | ---- | --------- |
| x    | number | 是    | 是    | 旋转矢量x轴分量。 |
| y    | number | 是    | 是    | 旋转矢量y轴分量。 |
| z    | number | 是    | 是    | 旋转矢量z轴分量。 |
| w    | number | 是    | 是    | 标量。       |
Z
zengyawen 已提交
2657 2658 2659


## GyroscopeResponse
Z
zengyawen 已提交
2660

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

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

Z
zengyawen 已提交
2665

H
HelloCrease 已提交
2666 2667 2668 2669 2670
| 名称   | 参数类型   | 可读   | 可写   | 说明                  |
| ---- | ------ | ---- | ---- | ------------------- |
| x    | number | 是    | 是    | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number | 是    | 是    | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number | 是    | 是    | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
2671 2672 2673


## GyroscopeUncalibratedResponse
Z
zengyawen 已提交
2674

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

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

Z
zengyawen 已提交
2679

H
HelloCrease 已提交
2680 2681 2682 2683 2684 2685 2686 2687
| 名称    | 参数类型   | 可读   | 可写   | 说明                       |
| ----- | ------ | ---- | ---- | ------------------------ |
| 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 已提交
2688 2689 2690


## SignificantMotionResponse
Z
zengyawen 已提交
2691

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

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

Z
zengyawen 已提交
2696

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


## ProximityResponse
Z
zengyawen 已提交
2703

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

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

Z
zengyawen 已提交
2708

H
HelloCrease 已提交
2709 2710 2711
| 名称       | 参数类型   | 可读   | 可写   | 说明                           |
| -------- | ------ | ---- | ---- | ---------------------------- |
| distance | number | 是    | 是    | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
2712 2713 2714


## LightResponse
Z
zengyawen 已提交
2715

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

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

Z
zengyawen 已提交
2720

H
HelloCrease 已提交
2721 2722 2723
| 名称        | 参数类型   | 可读   | 可写   | 说明          |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | 是    | 是    | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
2724 2725 2726


## HallResponse
Z
zengyawen 已提交
2727

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

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

Z
zengyawen 已提交
2732

C
cff-gite 已提交
2733 2734
| 名称   | 参数类型 | 可读 | 可写 | 说明                                                         |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2735
| status | number   | 是   | 是   | 显示霍尔状态。测量设备周围是否存在磁力吸引,0表示没有,大于0表示有。 |
Z
zengyawen 已提交
2736 2737 2738


## MagneticFieldResponse
Z
zengyawen 已提交
2739

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

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

Z
zengyawen 已提交
2744

C
cff-gite 已提交
2745 2746 2747 2748 2749
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
Z
zengyawen 已提交
2750 2751 2752


## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
2753

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

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

Z
zengyawen 已提交
2758

H
HelloCrease 已提交
2759 2760 2761 2762 2763 2764 2765 2766
| 名称    | 参数类型   | 可读   | 可写   | 说明                     |
| ----- | ------ | ---- | ---- | ---------------------- |
| 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 已提交
2767 2768 2769


## PedometerResponse
Z
zengyawen 已提交
2770

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

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

Z
zengyawen 已提交
2775

H
HelloCrease 已提交
2776 2777 2778
| 名称    | 参数类型   | 可读   | 可写   | 说明       |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | 是    | 是    | 用户的行走步数。 |
Z
zengyawen 已提交
2779 2780 2781


## HumidityResponse
Z
zengyawen 已提交
2782

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

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

Z
zengyawen 已提交
2787

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


C
cff-gite 已提交
2793
## PedometerDetectionResponse
Z
zengyawen 已提交
2794

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

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

Z
zengyawen 已提交
2799

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


## AmbientTemperatureResponse
Z
zengyawen 已提交
2806

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

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

Z
zengyawen 已提交
2811

H
HelloCrease 已提交
2812 2813 2814
| 名称          | 参数类型   | 可读   | 可写   | 说明            |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | 是    | 是    | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
2815 2816 2817


## BarometerResponse
Z
zengyawen 已提交
2818

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

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

Z
zengyawen 已提交
2823

H
HelloCrease 已提交
2824 2825 2826
| 名称       | 参数类型   | 可读   | 可写   | 说明           |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | 是    | 是    | 压力值(单位:帕斯卡)。 |
Z
zengyawen 已提交
2827 2828 2829


## HeartRateResponse
Z
zengyawen 已提交
2830

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

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

Z
zengyawen 已提交
2835

H
HelloCrease 已提交
2836 2837 2838
| 名称        | 参数类型   | 可读   | 可写   | 说明                    |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | 是    | 是    | 心率值。测量用户的心率数值,单位:bpm。 |
Z
zengyawen 已提交
2839 2840 2841


## WearDetectionResponse
Z
zengyawen 已提交
2842

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

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

Z
zengyawen 已提交
2847

H
HelloCrease 已提交
2848 2849 2850
| 名称    | 参数类型   | 可读   | 可写   | 说明                        |
| ----- | ------ | ---- | ---- | ------------------------- |
| value | number | 是    | 是    | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
Z
zengyawen 已提交
2851 2852 2853 2854


## Options

Z
zengyawen 已提交
2855
设置传感器上报频率。
Z
zengyawen 已提交
2856

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

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

Z
zengyawen 已提交
2863 2864
## RotationMatrixResponse

C
cff-gite 已提交
2865 2866 2867
设置旋转矩阵响应对象。

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

H
HelloCrease 已提交
2869 2870 2871 2872
| 名称          | 参数类型                | 可读   | 可写   | 说明    |
| ----------- | ------------------- | ---- | ---- | ----- |
| rotation    | Array&lt;number&gt; | 是    | 是    | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是    | 是    | 倾斜矩阵。 |
Z
zengyawen 已提交
2873 2874 2875 2876


## CoordinatesOptions

C
cff-gite 已提交
2877 2878 2879
设置坐标选项对象。

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

H
HelloCrease 已提交
2881 2882 2883 2884
| 名称   | 参数类型   | 可读   | 可写   | 说明     |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | 是    | 是    | x坐标方向。 |
| y    | number | 是    | 是    | y坐标方向。 |
Z
zengyawen 已提交
2885

Z
zengyawen 已提交
2886 2887 2888

## GeomagneticResponse

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

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

H
HelloCrease 已提交
2893 2894 2895 2896 2897 2898 2899 2900 2901
| 名称              | 参数类型   | 可读   | 可写   | 说明                        |
| --------------- | ------ | ---- | ---- | ------------------------- |
| x               | number | 是    | 是    | 地磁场的北分量。                  |
| y               | number | 是    | 是    | 地磁场的东分量。                  |
| z               | number | 是    | 是    | 地磁场的垂直分量。                 |
| geomagneticDip  | number | 是    | 是    | 地磁倾角,即地球磁场线与水平面的夹角。       |
| deflectionAngle | number | 是    | 是    | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number | 是    | 是    | 地磁场的水平强度。                 |
| totalIntensity  | number | 是    | 是    | 地磁场的总强度。                  |
Z
zengyawen 已提交
2902 2903 2904

## LocationOptions

C
cff-gite 已提交
2905 2906 2907 2908
指示地理位置。

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

H
HelloCrease 已提交
2909 2910 2911 2912 2913
| 名称        | 参数类型   | 可读   | 可写   | 说明    |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | 是    | 是    | 纬度。   |
| longitude | number | 是    | 是    | 经度。   |
| altitude  | number | 是    | 是    | 海拔高度。 |