js-apis-sensor.md 119.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

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

L
li-yaoyao777 已提交
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
监听线性加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。

C
cff-gite 已提交
61
从API Version9开始该接口不再维护,请使用[sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)
H
h00514358 已提交
62

L
li-yaoyao777 已提交
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
h00514358 已提交
74
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
75 76 77 78 79

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

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

L
li-yaoyao777 已提交
80
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

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

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

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

L
li-yaoyao777 已提交
108
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
109 110 111

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

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

H
HelloCrease 已提交
119
**示例:** 
H
HelloCrease 已提交
120
  ```js
C
cff-gite 已提交
121
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
122 123 124 125 126 127
      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);
128 129
  },
      {interval: 10000000}
Z
zengyawen 已提交
130 131
  );
  ```
Z
zengyawen 已提交
132

H
HelloCrease 已提交
133
### GRAVITY
Z
zengyawen 已提交
134

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

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

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

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

H
HelloCrease 已提交
148
**示例:** 
H
HelloCrease 已提交
149
  ```js
C
cff-gite 已提交
150
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
151
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
152 153
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
154 155
  },
      {interval: 10000000}
Z
zengyawen 已提交
156 157
  );
  ```
Z
zengyawen 已提交
158

H
HelloCrease 已提交
159
### GYROSCOPE
Z
zengyawen 已提交
160

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

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

L
li-yaoyao777 已提交
165
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
166 167 168

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

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

H
HelloCrease 已提交
176
**示例:** 
H
HelloCrease 已提交
177
  ```js
C
cff-gite 已提交
178
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
179
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
180 181
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
182 183
  },
      {interval: 10000000}
Z
zengyawen 已提交
184 185
  );
  ```
Z
zengyawen 已提交
186

H
HelloCrease 已提交
187
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
188

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

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

L
li-yaoyao777 已提交
193
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
194 195 196

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

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

H
HelloCrease 已提交
204
**示例:** 
H
HelloCrease 已提交
205
  ```js
C
cff-gite 已提交
206
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
207
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
208 209
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
210
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
211 212
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
213 214
  },
      {interval: 10000000}
Z
zengyawen 已提交
215 216
  );
  ```
Z
zengyawen 已提交
217

H
HelloCrease 已提交
218
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
219

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

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

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

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

H
HelloCrease 已提交
233
**示例:** 
H
HelloCrease 已提交
234
  ```js
C
cff-gite 已提交
235
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
236
      console.info('Scalar data: ' + data.scalar);
237 238
  },
      {interval: 10000000}
Z
zengyawen 已提交
239 240
  );
  ```
Z
zengyawen 已提交
241

H
HelloCrease 已提交
242
### PEDOMETER_DETECTION
Z
zengyawen 已提交
243

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

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

C
cff-gite 已提交
248
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
249 250 251

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

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

H
HelloCrease 已提交
259
**示例:** 
H
HelloCrease 已提交
260
  ```js
C
cff-gite 已提交
261
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
262
      console.info('Scalar data: ' + data.scalar);
263 264
  },
      {interval: 10000000}
Z
zengyawen 已提交
265 266
  );
  ```
Z
zengyawen 已提交
267

H
HelloCrease 已提交
268
### PEDOMETER
Z
zengyawen 已提交
269

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

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

C
cff-gite 已提交
274
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
275 276 277

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

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

H
HelloCrease 已提交
285
**示例:** 
H
HelloCrease 已提交
286
  ```js
C
cff-gite 已提交
287
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
288
      console.info('Steps: ' + data.steps);
289 290
  },
      {interval: 10000000}
Z
zengyawen 已提交
291 292
  );
  ```
Z
zengyawen 已提交
293

H
HelloCrease 已提交
294
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
295

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

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

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

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

H
HelloCrease 已提交
309
**示例:** 
C
cff-gite 已提交
310

H
HelloCrease 已提交
311
  ```js
C
cff-gite 已提交
312
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
313
      console.info('Temperature: ' + data.temperature);
314 315
  },
      {interval: 10000000}
Z
zengyawen 已提交
316 317
  );
  ```
Z
zengyawen 已提交
318

H
HelloCrease 已提交
319
### MAGNETIC_FIELD
Z
zengyawen 已提交
320

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

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

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

H
HelloCrease 已提交
327
**参数:** 
C
cff-gite 已提交
328

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

H
HelloCrease 已提交
335
**示例:** 
H
HelloCrease 已提交
336
  ```js
C
cff-gite 已提交
337
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
338 339 340
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
341 342
  },
      {interval: 10000000}
Z
zengyawen 已提交
343 344
  );
  ```
Z
zengyawen 已提交
345

H
HelloCrease 已提交
346
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
347

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

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

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

H
HelloCrease 已提交
354
**参数:** 
C
cff-gite 已提交
355

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

H
HelloCrease 已提交
362
**示例:** 
H
HelloCrease 已提交
363
  ```js
C
cff-gite 已提交
364
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
365 366 367 368
      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 已提交
369 370
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
371 372
  },
      {interval: 10000000}
Z
zengyawen 已提交
373 374
  );
  ```
Z
zengyawen 已提交
375

H
HelloCrease 已提交
376
### PROXIMITY
Z
zengyawen 已提交
377

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

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

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

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

H
HelloCrease 已提交
391
**示例:** 
H
HelloCrease 已提交
392
  ```js
C
cff-gite 已提交
393
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
394
      console.info('Distance: ' + data.distance);
395 396
  },
      {interval: 10000000}
Z
zengyawen 已提交
397 398
  );
  ```
Z
zengyawen 已提交
399

H
HelloCrease 已提交
400
### HUMIDITY
Z
zengyawen 已提交
401

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

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

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

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

H
HelloCrease 已提交
415
**示例:** 
C
cff-gite 已提交
416

H
HelloCrease 已提交
417
  ```js
C
cff-gite 已提交
418
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
419
      console.info('Humidity: ' + data.humidity);
420 421
  },
      {interval: 10000000}
Z
zengyawen 已提交
422 423
  );
  ```
Z
zengyawen 已提交
424

H
HelloCrease 已提交
425
### BAROMETER
Z
zengyawen 已提交
426

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

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

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

H
HelloCrease 已提交
433
**参数:** 
C
cff-gite 已提交
434

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

H
HelloCrease 已提交
441
**示例:** 
C
cff-gite 已提交
442

H
HelloCrease 已提交
443
  ```js
C
cff-gite 已提交
444
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
445
      console.info('Atmospheric pressure: ' + data.pressure);
446 447
  },
      {interval: 10000000}
Z
zengyawen 已提交
448 449
  );
  ```
Z
zengyawen 已提交
450

H
HelloCrease 已提交
451
### HALL
Z
zengyawen 已提交
452

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

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

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

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

H
HelloCrease 已提交
466
**示例:** 
H
HelloCrease 已提交
467
  ```js
C
cff-gite 已提交
468
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
469
      console.info('Status: ' + data.status);
470 471
  },
      {interval: 10000000}
Z
zengyawen 已提交
472 473
  );
  ```
Z
zengyawen 已提交
474

H
HelloCrease 已提交
475
### AMBIENT_LIGHT
Z
zengyawen 已提交
476

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

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

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

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

H
HelloCrease 已提交
490
**示例:** 
H
HelloCrease 已提交
491
  ```js
C
cff-gite 已提交
492
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
493 494 495
      console.info(' Illumination: ' + data.intensity);
  },
      {interval: 10000000}
Z
zengyawen 已提交
496 497
  );
  ```
Z
zengyawen 已提交
498

H
HelloCrease 已提交
499
### ORIENTATION
Z
zengyawen 已提交
500

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

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

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

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

H
HelloCrease 已提交
514
**示例:** 
H
HelloCrease 已提交
515
  ```js
C
cff-gite 已提交
516
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
C
cff-gite 已提交
517 518 519
      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);
520 521
  },
      {interval: 10000000}
Z
zengyawen 已提交
522 523
  );
  ```
Z
zengyawen 已提交
524

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

C
cff-gite 已提交
527
on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
C
cff-gite 已提交
528 529 530

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

C
cff-gite 已提交
531
从API Version9开始该接口不再维护,请使用[sensor.on.HEART_BEAT_RATE](#heart_beat_rate9)
H
h00514358 已提交
532

C
cff-gite 已提交
533
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
534 535 536

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

H
HelloCrease 已提交
537
**参数:** 
C
cff-gite 已提交
538

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

H
h00514358 已提交
544
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

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 已提交
571
### ROTATION_VECTOR
Z
zengyawen 已提交
572

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

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

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

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

H
HelloCrease 已提交
586
**示例:** 
H
HelloCrease 已提交
587
  ```js
C
cff-gite 已提交
588
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
Z
zengyawen 已提交
589 590 591
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
592
      console.info('Scalar quantity: ' + data.w);
593 594
  },
      {interval: 10000000}
Z
zengyawen 已提交
595 596
  );
  ```
Z
zengyawen 已提交
597

H
HelloCrease 已提交
598
### WEAR_DETECTION
Z
zengyawen 已提交
599

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

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

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

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

H
HelloCrease 已提交
613
**示例:** 
H
HelloCrease 已提交
614
  ```js
C
cff-gite 已提交
615
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
Z
zengyawen 已提交
616
      console.info('Wear status: ' + data.value);
617 618
  },
      {interval: 10000000}
Z
zengyawen 已提交
619 620
  );
  ```
Z
zengyawen 已提交
621

H
HelloCrease 已提交
622
## sensor.once
Z
zengyawen 已提交
623

H
HelloCrease 已提交
624
### ACCELEROMETER
Z
zengyawen 已提交
625

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

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

L
li-yaoyao777 已提交
630
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
631 632 633

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

H
HelloCrease 已提交
634
**参数:** 
C
cff-gite 已提交
635

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

H
HelloCrease 已提交
641
**示例:** 
H
HelloCrease 已提交
642
  ```js
C
cff-gite 已提交
643
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
644 645 646
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
647
    }
Z
zengyawen 已提交
648 649
  );
  ```
Z
zengyawen 已提交
650

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

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

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

C
cff-gite 已提交
657
从API Version9开始该接口不再维护,请用[sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9)
H
h00514358 已提交
658

L
li-yaoyao777 已提交
659
**需要权限**:ohos.permission.ACCELERATION
C
cff-gite 已提交
660 661 662

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

H
HelloCrease 已提交
663
**参数:** 
C
cff-gite 已提交
664

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

H
h00514358 已提交
670
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
671 672 673

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

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

L
li-yaoyao777 已提交
676
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695

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

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

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

L
li-yaoyao777 已提交
702
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
703 704 705

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

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

H
HelloCrease 已提交
712
**示例:** 
Z
zengyawen 已提交
713
  ```
C
cff-gite 已提交
714
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
715 716 717 718 719 720
      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 已提交
721
    }
Z
zengyawen 已提交
722 723
  );
  ```
Z
zengyawen 已提交
724

H
HelloCrease 已提交
725
### GRAVITY
Z
zengyawen 已提交
726

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

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

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

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

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

H
HelloCrease 已提交
749
### GYROSCOPE
Z
zengyawen 已提交
750

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

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

L
li-yaoyao777 已提交
755
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
756 757 758

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

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

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

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

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

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

L
li-yaoyao777 已提交
781
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
782 783 784

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

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

H
HelloCrease 已提交
791
**示例:** 
H
HelloCrease 已提交
792
  ```js
C
cff-gite 已提交
793
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
794 795 796 797 798 799
      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 已提交
800
    }
Z
zengyawen 已提交
801 802
  );
  ```
Z
zengyawen 已提交
803

H
HelloCrease 已提交
804
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
805

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

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

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

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

H
HelloCrease 已提交
818
**示例:** 
H
HelloCrease 已提交
819
  ```js
C
cff-gite 已提交
820
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
Z
zengyawen 已提交
821
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
822
    }
Z
zengyawen 已提交
823 824
  );
  ```
Z
zengyawen 已提交
825

H
HelloCrease 已提交
826
### PEDOMETER_DETECTION
Z
zengyawen 已提交
827

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

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

C
cff-gite 已提交
832
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
833 834 835

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

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

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

H
HelloCrease 已提交
850
### PEDOMETER
Z
zengyawen 已提交
851

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

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

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

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

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

H
HelloCrease 已提交
866
**示例:** 
H
HelloCrease 已提交
867
  ```js
C
cff-gite 已提交
868
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
Z
zengyawen 已提交
869
      console.info('Steps: ' + data.steps);
Z
zengyawen 已提交
870
    }
Z
zengyawen 已提交
871 872
  );
  ```
Z
zengyawen 已提交
873

H
HelloCrease 已提交
874
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
875

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

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

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

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

H
HelloCrease 已提交
888
**示例:** 
H
HelloCrease 已提交
889
  ```js
C
cff-gite 已提交
890
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
Z
zengyawen 已提交
891
      console.info('Temperature: ' + data.temperature);
Z
zengyawen 已提交
892
    }
Z
zengyawen 已提交
893 894
  );
  ```
Z
zengyawen 已提交
895

H
HelloCrease 已提交
896
### MAGNETIC_FIELD
Z
zengyawen 已提交
897

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

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

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

H
HelloCrease 已提交
904
**参数:** 
C
cff-gite 已提交
905

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

H
HelloCrease 已提交
911
**示例:** 
H
HelloCrease 已提交
912
  ```js
C
cff-gite 已提交
913
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
Z
zengyawen 已提交
914 915 916
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
917
    }
Z
zengyawen 已提交
918 919
  );
  ```
Z
zengyawen 已提交
920

H
HelloCrease 已提交
921
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
922

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

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

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

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

H
HelloCrease 已提交
935
**示例:** 
H
HelloCrease 已提交
936
  ```js
C
cff-gite 已提交
937
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
938 939 940 941 942 943
      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 已提交
944
    }
Z
zengyawen 已提交
945 946
  );
  ```
Z
zengyawen 已提交
947

H
HelloCrease 已提交
948
### PROXIMITY
Z
zengyawen 已提交
949

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

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

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

H
HelloCrease 已提交
956
**参数:** 
C
cff-gite 已提交
957

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

H
HelloCrease 已提交
963
**示例:** 
H
HelloCrease 已提交
964
  ```js
L
li-yaoyao777 已提交
965
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
Z
zengyawen 已提交
966
      console.info('Distance: ' + data.distance);
Z
zengyawen 已提交
967
    }
Z
zengyawen 已提交
968 969
  );
  ```
Z
zengyawen 已提交
970

H
HelloCrease 已提交
971
### HUMIDITY
Z
zengyawen 已提交
972

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

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

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

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

H
HelloCrease 已提交
985
**示例:** 
H
HelloCrease 已提交
986
  ```js
C
cff-gite 已提交
987
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
Z
zengyawen 已提交
988
      console.info('Humidity: ' + data.humidity);
Z
zengyawen 已提交
989
    }
Z
zengyawen 已提交
990 991
  );
  ```
Z
zengyawen 已提交
992

H
HelloCrease 已提交
993
### BAROMETER
Z
zengyawen 已提交
994

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

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

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

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

H
HelloCrease 已提交
1007
**示例:** 
H
HelloCrease 已提交
1008
  ```js
C
cff-gite 已提交
1009
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
Z
zengyawen 已提交
1010
      console.info('Atmospheric pressure: ' + data.pressure);
Z
zengyawen 已提交
1011
    }
Z
zengyawen 已提交
1012 1013
  );
  ```
Z
zengyawen 已提交
1014

H
HelloCrease 已提交
1015
### HALL
Z
zengyawen 已提交
1016

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

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

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

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

H
HelloCrease 已提交
1029
**示例:** 
H
HelloCrease 已提交
1030
  ```js
C
cff-gite 已提交
1031
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
Z
zengyawen 已提交
1032
      console.info('Status: ' + data.status);
Z
zengyawen 已提交
1033
    }
Z
zengyawen 已提交
1034 1035
  );
  ```
Z
zengyawen 已提交
1036

H
HelloCrease 已提交
1037
### AMBIENT_LIGHT
Z
zengyawen 已提交
1038

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

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

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

H
HelloCrease 已提交
1045
**参数:** 
C
cff-gite 已提交
1046

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

H
HelloCrease 已提交
1052
**示例:** 
C
cff-gite 已提交
1053

H
HelloCrease 已提交
1054
  ```js
C
cff-gite 已提交
1055
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
1056
      console.info(' Illumination: ' + data.intensity);
Z
zengyawen 已提交
1057
    }
Z
zengyawen 已提交
1058 1059
  );
  ```
Z
zengyawen 已提交
1060

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

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

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

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

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

H
HelloCrease 已提交
1075
**示例:** 
H
HelloCrease 已提交
1076
  ```js
C
cff-gite 已提交
1077
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
C
cff-gite 已提交
1078 1079 1080
      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 已提交
1081
    }
Z
zengyawen 已提交
1082 1083
  );
  ```
Z
zengyawen 已提交
1084

H
HelloCrease 已提交
1085
### ROTATION_VECTOR
Z
zengyawen 已提交
1086

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

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

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

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

H
HelloCrease 已提交
1099
**示例:** 
H
HelloCrease 已提交
1100
  ```js
C
cff-gite 已提交
1101
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
Z
zengyawen 已提交
1102 1103 1104
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
1105
      console.info('Scalar quantity: ' + data.w);
Z
zengyawen 已提交
1106
    }
Z
zengyawen 已提交
1107 1108
  );
  ```
Z
zengyawen 已提交
1109

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

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

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

C
cff-gite 已提交
1116
从API Version9开始该接口不再维护,请使用[sensor.once.HEART_BEAT_RATE](#heart_beat_rate9)
H
h00514358 已提交
1117

C
cff-gite 已提交
1118
**需要权限**:ohos.permission.HEART_RATE  
C
cff-gite 已提交
1119 1120 1121

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

H
HelloCrease 已提交
1122
**参数:** 
C
cff-gite 已提交
1123

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

H
h00514358 已提交
1129
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1130 1131 1132

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

H
h00514358 已提交
1133
订阅一次心率传感器数据。
H
h00514358 已提交
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152

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

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

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

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

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

H
HelloCrease 已提交
1167
**示例:** 
H
HelloCrease 已提交
1168
  ```js
C
cff-gite 已提交
1169
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
Z
zengyawen 已提交
1170
      console.info("Wear status: "+ data.value);
Z
zengyawen 已提交
1171
    }
Z
zengyawen 已提交
1172 1173
  );
  ```
Z
zengyawen 已提交
1174

H
HelloCrease 已提交
1175 1176 1177
## sensor.off

### ACCELEROMETER
Z
zengyawen 已提交
1178

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

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

L
li-yaoyao777 已提交
1183
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1184 1185 1186

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

H
HelloCrease 已提交
1187
**参数:** 
C
cff-gite 已提交
1188

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

H
HelloCrease 已提交
1194
**示例:** 
C
cff-gite 已提交
1195

H
HelloCrease 已提交
1196
```js
C
cff-gite 已提交
1197 1198 1199 1200 1201 1202 1203 1204
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 已提交
1205
### ACCELEROMETER_UNCALIBRATED
C
cff-gite 已提交
1206

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

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

L
li-yaoyao777 已提交
1211
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1212

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

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

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

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

H
HelloCrease 已提交
1224
```js
C
cff-gite 已提交
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
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 已提交
1236
### AMBIENT_LIGHT
C
cff-gite 已提交
1237

C
cff-gite 已提交
1238
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
1239 1240 1241 1242 1243

取消订阅传感器数据。

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

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

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

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

H
HelloCrease 已提交
1253
```js
C
cff-gite 已提交
1254 1255 1256 1257 1258 1259
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

H
HelloCrease 已提交
1260
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1261

C
cff-gite 已提交
1262
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
C
cff-gite 已提交
1263 1264 1265 1266 1267

取消订阅传感器数据。

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

H
HelloCrease 已提交
1268
**参数:** 
C
cff-gite 已提交
1269

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

H
HelloCrease 已提交
1275
**示例:** 
C
cff-gite 已提交
1276

H
HelloCrease 已提交
1277
```js
C
cff-gite 已提交
1278 1279 1280 1281 1282 1283
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

H
HelloCrease 已提交
1284
### AMBIENT_TEMPERATURE
C
cff-gite 已提交
1285

C
cff-gite 已提交
1286
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
C
cff-gite 已提交
1287 1288 1289 1290 1291

取消订阅传感器数据。

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

H
HelloCrease 已提交
1292
**参数:** 
C
cff-gite 已提交
1293

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

H
HelloCrease 已提交
1299
**示例:** 
C
cff-gite 已提交
1300

H
HelloCrease 已提交
1301
```js
C
cff-gite 已提交
1302 1303 1304 1305 1306 1307
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

H
HelloCrease 已提交
1308
### GRAVITY
C
cff-gite 已提交
1309

C
cff-gite 已提交
1310
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
C
cff-gite 已提交
1311 1312 1313 1314 1315

取消订阅传感器数据。

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

H
HelloCrease 已提交
1316
**参数:** 
C
cff-gite 已提交
1317

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

H
HelloCrease 已提交
1323
**示例:** 
C
cff-gite 已提交
1324

H
HelloCrease 已提交
1325
```js
C
cff-gite 已提交
1326 1327 1328 1329 1330 1331 1332 1333
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 已提交
1334
### GYROSCOPE
C
cff-gite 已提交
1335

C
cff-gite 已提交
1336
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
C
cff-gite 已提交
1337 1338 1339

取消订阅传感器数据。

L
li-yaoyao777 已提交
1340
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
1341 1342 1343

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

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

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

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

H
HelloCrease 已提交
1353
```js
C
cff-gite 已提交
1354 1355 1356 1357 1358 1359 1360 1361
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 已提交
1362
### GYROSCOPE_UNCALIBRATED
C
cff-gite 已提交
1363

H
HelloCrease 已提交
1364
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1365 1366 1367

取消订阅传感器数据。

L
li-yaoyao777 已提交
1368
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
1369 1370 1371

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

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

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

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

H
HelloCrease 已提交
1381
```js
C
cff-gite 已提交
1382 1383 1384 1385 1386 1387 1388 1389
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 已提交
1390
### HALL
C
cff-gite 已提交
1391

C
cff-gite 已提交
1392
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
C
cff-gite 已提交
1393 1394 1395 1396 1397

取消订阅传感器数据。

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

H
HelloCrease 已提交
1398
**参数:** 
C
cff-gite 已提交
1399

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

H
HelloCrease 已提交
1405
**示例:** 
C
cff-gite 已提交
1406

H
HelloCrease 已提交
1407
```js
C
cff-gite 已提交
1408 1409 1410 1411 1412 1413
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

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

C
cff-gite 已提交
1416
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
C
cff-gite 已提交
1417 1418 1419

取消订阅传感器数据。

C
cff-gite 已提交
1420
从API Version9开始该接口不再维护,请使用[sensor.off.HEART_BEAT_RATE](#heart_beat_rate9)
H
h00514358 已提交
1421

C
cff-gite 已提交
1422
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
1423 1424 1425

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

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

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

H
h00514358 已提交
1433
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458

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

C
cff-gite 已提交
1461
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
C
cff-gite 已提交
1462 1463 1464 1465 1466

取消订阅传感器数据。

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

H
HelloCrease 已提交
1467
**参数:** 
C
cff-gite 已提交
1468

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

H
HelloCrease 已提交
1474
**示例:** 
C
cff-gite 已提交
1475

H
HelloCrease 已提交
1476
```js
C
cff-gite 已提交
1477 1478 1479 1480 1481 1482
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

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

C
cff-gite 已提交
1485
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
C
cff-gite 已提交
1486 1487 1488

取消订阅传感器数据。

C
cff-gite 已提交
1489
从API Version9开始该接口不再维护,请使用[sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9)
H
h00514358 已提交
1490

L
li-yaoyao777 已提交
1491
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1492 1493 1494

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

H
HelloCrease 已提交
1495
**参数:** 
C
cff-gite 已提交
1496

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

H
h00514358 已提交
1502
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
1503 1504 1505 1506 1507

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

取消订阅传感器数据。

L
li-yaoyao777 已提交
1508
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529

**系统能力**: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 已提交
1530
### MAGNETIC_FIELD
C
cff-gite 已提交
1531

C
cff-gite 已提交
1532
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
C
cff-gite 已提交
1533 1534 1535 1536 1537

取消订阅传感器数据。

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

H
HelloCrease 已提交
1538
**参数:** 
C
cff-gite 已提交
1539

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

H
HelloCrease 已提交
1545
**示例:** 
C
cff-gite 已提交
1546

H
HelloCrease 已提交
1547
```js
C
cff-gite 已提交
1548 1549 1550 1551 1552 1553 1554 1555
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 已提交
1556
### MAGNETIC_FIELD_UNCALIBRATED
C
cff-gite 已提交
1557

C
cff-gite 已提交
1558
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
1559 1560 1561 1562 1563

取消订阅传感器数据。

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

H
HelloCrease 已提交
1564
**参数:** 
C
cff-gite 已提交
1565

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

H
HelloCrease 已提交
1571
**示例:** 
C
cff-gite 已提交
1572

H
HelloCrease 已提交
1573
```js
C
cff-gite 已提交
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584
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 已提交
1585
### ORIENTATION
C
cff-gite 已提交
1586

C
cff-gite 已提交
1587
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
C
cff-gite 已提交
1588 1589 1590 1591 1592

取消订阅传感器数据。

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

H
HelloCrease 已提交
1593
**参数:** 
C
cff-gite 已提交
1594

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

H
HelloCrease 已提交
1600
**示例:** 
C
cff-gite 已提交
1601

H
HelloCrease 已提交
1602
```js
C
cff-gite 已提交
1603
function callback(data) {
C
cff-gite 已提交
1604 1605 1606
    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 已提交
1607 1608 1609 1610
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```

H
HelloCrease 已提交
1611
### PEDOMETER
C
cff-gite 已提交
1612

C
cff-gite 已提交
1613
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
C
cff-gite 已提交
1614 1615 1616

取消订阅传感器数据。

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

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

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

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

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

H
HelloCrease 已提交
1630
```js
C
cff-gite 已提交
1631 1632 1633 1634 1635 1636
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

H
HelloCrease 已提交
1637
### PEDOMETER_DETECTION
C
cff-gite 已提交
1638

C
cff-gite 已提交
1639
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
C
cff-gite 已提交
1640 1641 1642 1643 1644 1645 1646

取消订阅传感器数据。

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

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

H
HelloCrease 已提交
1647
**参数:** 
C
cff-gite 已提交
1648

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

H
HelloCrease 已提交
1654
**示例:** 
C
cff-gite 已提交
1655

H
HelloCrease 已提交
1656
```js
C
cff-gite 已提交
1657 1658 1659 1660 1661 1662
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

H
HelloCrease 已提交
1663
### PROXIMITY
C
cff-gite 已提交
1664

C
cff-gite 已提交
1665
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
C
cff-gite 已提交
1666 1667 1668 1669 1670

取消订阅传感器数据。

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

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

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

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

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

H
HelloCrease 已提交
1687
### ROTATION_VECTOR
C
cff-gite 已提交
1688

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

取消订阅传感器数据。

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

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

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

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

H
HelloCrease 已提交
1704
```js
C
cff-gite 已提交
1705 1706 1707 1708
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 已提交
1709
    console.info('Scalar quantity: ' + data.w);
C
cff-gite 已提交
1710 1711 1712 1713
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```

H
HelloCrease 已提交
1714
### SIGNIFICANT_MOTION
C
cff-gite 已提交
1715

C
cff-gite 已提交
1716
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
C
cff-gite 已提交
1717 1718 1719 1720 1721

取消订阅传感器数据。

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

H
HelloCrease 已提交
1722
**参数:** 
C
cff-gite 已提交
1723

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

H
HelloCrease 已提交
1729
**示例:** 
C
cff-gite 已提交
1730

H
HelloCrease 已提交
1731
```js
C
cff-gite 已提交
1732 1733 1734 1735 1736 1737
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```

H
HelloCrease 已提交
1738
### WEAR_DETECTION
C
cff-gite 已提交
1739

C
cff-gite 已提交
1740
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
1741 1742 1743 1744 1745

取消订阅传感器数据。

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

H
HelloCrease 已提交
1746
**参数:** 
C
cff-gite 已提交
1747

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

H
HelloCrease 已提交
1753
**示例:** 
C
cff-gite 已提交
1754

H
HelloCrease 已提交
1755
```js
C
cff-gite 已提交
1756 1757 1758 1759 1760
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
Z
zengyawen 已提交
1761

Z
zengyawen 已提交
1762 1763 1764 1765 1766 1767
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
1770
**参数:** 
Z
zengyawen 已提交
1771

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

H
HelloCrease 已提交
1778
**示例:** 
Z
zengyawen 已提交
1779

H
HelloCrease 已提交
1780
```js
C
cff-gite 已提交
1781
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
H
HelloCrease 已提交
1782 1783 1784 1785
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
H
HelloCrease 已提交
1786
    console.info("Operation successed. Data obtained: " + data);
H
HelloCrease 已提交
1787 1788 1789 1790 1791
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
Z
zengyawen 已提交
1792 1793 1794 1795 1796 1797
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
1800
**参数:** 
Z
zengyawen 已提交
1801

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

H
HelloCrease 已提交
1807
**返回值:** 
Z
zengyawen 已提交
1808

H
HelloCrease 已提交
1809 1810 1811
| 类型                                 | 说明          |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |
Z
zengyawen 已提交
1812

H
HelloCrease 已提交
1813
**示例:** 
Z
zengyawen 已提交
1814

H
HelloCrease 已提交
1815
```js
C
cff-gite 已提交
1816
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
H
HelloCrease 已提交
1817 1818 1819 1820 1821 1822 1823 1824 1825
    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 已提交
1826

Z
zengyawen 已提交
1827
## sensor.getGeomagneticField
Z
zengyawen 已提交
1828

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

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

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

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

H
HelloCrease 已提交
1842
**示例:** 
H
HelloCrease 已提交
1843
```js
C
cff-gite 已提交
1844
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
H
HelloCrease 已提交
1845 1846 1847 1848
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
C
cff-gite 已提交
1849
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
H
HelloCrease 已提交
1850 1851 1852 1853
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});
```
Z
zengyawen 已提交
1854 1855 1856 1857 1858 1859
## sensor.getGeomagneticField

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

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

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

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

H
HelloCrease 已提交
1868 1869 1870 1871
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
Z
zengyawen 已提交
1872

H
HelloCrease 已提交
1873
**示例:** 
H
HelloCrease 已提交
1874
  ```js
C
cff-gite 已提交
1875
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
Z
zengyawen 已提交
1876
      promise.then((data) => {
Z
zengyawen 已提交
1877 1878 1879
          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 已提交
1880
      }).catch((reason) => {
Z
zengyawen 已提交
1881 1882
          console.info('Operation failed.');
  })
Z
zengyawen 已提交
1883 1884
  ```

Z
zengyawen 已提交
1885 1886 1887 1888 1889 1890
## sensor.getAltitude

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

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

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

H
HelloCrease 已提交
1893
**参数:** 
Z
zengyawen 已提交
1894

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

H
HelloCrease 已提交
1901
**示例:** 
Z
zengyawen 已提交
1902

H
HelloCrease 已提交
1903
  ```js
Z
zengyawen 已提交
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919
  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 已提交
1920 1921
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1922
**参数:** 
Z
zengyawen 已提交
1923

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

H
HelloCrease 已提交
1929
**返回值:** 
Z
zengyawen 已提交
1930

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

H
HelloCrease 已提交
1935
**示例:** 
Z
zengyawen 已提交
1936

H
HelloCrease 已提交
1937
  ```js
Z
zengyawen 已提交
1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
  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 已提交
1953 1954
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
1955
**参数:** 
Z
zengyawen 已提交
1956

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

H
HelloCrease 已提交
1962
**示例:** 
Z
zengyawen 已提交
1963

H
HelloCrease 已提交
1964
  ```js
Z
zengyawen 已提交
1965 1966
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
C
cff-gite 已提交
1967
          console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + 
Z
zengyawen 已提交
1968 1969 1970
                        err.message);
          return;
      }
H
HelloCrease 已提交
1971
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
Z
zengyawen 已提交
1972 1973 1974 1975 1976 1977 1978 1979 1980
  })
  ```

## sensor.getGeomagneticDip

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

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

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

H
HelloCrease 已提交
1983
**参数:** 
Z
zengyawen 已提交
1984

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

H
HelloCrease 已提交
1989
**返回值:** 
Z
zengyawen 已提交
1990

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

H
HelloCrease 已提交
1995
**示例:** 
Z
zengyawen 已提交
1996

H
HelloCrease 已提交
1997
  ```js
Z
zengyawen 已提交
1998 1999
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
C
cff-gite 已提交
2000
          console.info('getGeomagneticDip_promise successed', data);
Z
zengyawen 已提交
2001 2002 2003 2004 2005 2006 2007
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

H
HelloCrease 已提交
2008
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
2009 2010 2011

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

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

H
HelloCrease 已提交
2014
**参数:** 
Z
zengyawen 已提交
2015

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

H
HelloCrease 已提交
2022
**示例:** 
Z
zengyawen 已提交
2023

H
HelloCrease 已提交
2024
  ```js
Z
zengyawen 已提交
2025 2026
  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 已提交
2027
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2028 2029 2030 2031
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2032
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
      }
  })
  ```


## sensor. getAngleModify

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

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

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

H
HelloCrease 已提交
2046
**参数:** 
Z
zengyawen 已提交
2047

H
HelloCrease 已提交
2048 2049 2050 2051
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
2052

H
HelloCrease 已提交
2053
**返回值:** 
Z
zengyawen 已提交
2054

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

H
HelloCrease 已提交
2059
**示例:** 
Z
zengyawen 已提交
2060

H
HelloCrease 已提交
2061
  ```js
Z
zengyawen 已提交
2062 2063
  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 已提交
2064
          console.info('getAngleModifiy_promise success');
Z
zengyawen 已提交
2065
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2066
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2067 2068
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2069
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2070 2071 2072 2073 2074 2075 2076 2077 2078 2079
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2082
**参数:** 
Z
zengyawen 已提交
2083

H
HelloCrease 已提交
2084 2085 2086 2087
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
2088

H
HelloCrease 已提交
2089
**示例:** 
Z
zengyawen 已提交
2090

H
HelloCrease 已提交
2091
  ```js
Z
zengyawen 已提交
2092 2093
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
H
HelloCrease 已提交
2094
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2095 2096 2097
                        err.message);
          return;
      }
C
cff-gite 已提交
2098
      for (var i=0; i < data.length; i++) {
L
li-yaoyao777 已提交
2099
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
      }
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2113
**参数:** 
Z
zengyawen 已提交
2114

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

H
HelloCrease 已提交
2119
**返回值:** 
Z
zengyawen 已提交
2120

H
HelloCrease 已提交
2121 2122 2123
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
2124

H
HelloCrease 已提交
2125
**示例:** 
Z
zengyawen 已提交
2126

H
HelloCrease 已提交
2127
  ```js
Z
zengyawen 已提交
2128 2129
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
H
HelloCrease 已提交
2130
          console.info('createRotationMatrix_promise success');
C
cff-gite 已提交
2131
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2132
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2133 2134
          }
      }).catch((reason) => {
H
HelloCrease 已提交
2135
          console.info("promise::catch", reason);
Z
zengyawen 已提交
2136 2137 2138 2139 2140 2141 2142 2143 2144 2145
  })	
  ```


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
2148
**参数:** 
Z
zengyawen 已提交
2149

H
HelloCrease 已提交
2150 2151 2152 2153
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
2154

H
HelloCrease 已提交
2155
**示例:** 
Z
zengyawen 已提交
2156

H
HelloCrease 已提交
2157
  ```js
Z
zengyawen 已提交
2158 2159
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2160
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
2161 2162 2163 2164
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
2165
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176
      }
  })
  ```


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
2179
**参数:** 
Z
zengyawen 已提交
2180

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

H
HelloCrease 已提交
2185
**返回值:** 
Z
zengyawen 已提交
2186

H
HelloCrease 已提交
2187 2188 2189
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
2190

H
HelloCrease 已提交
2191
**示例:** 
Z
zengyawen 已提交
2192

H
HelloCrease 已提交
2193
  ```js
Z
zengyawen 已提交
2194 2195 2196 2197
  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 已提交
2198
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211
          }
      }).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 已提交
2212 2213
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2214
**参数:** 
Z
zengyawen 已提交
2215

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

H
HelloCrease 已提交
2221
**示例:** 
Z
zengyawen 已提交
2222

H
HelloCrease 已提交
2223
  ```js
Z
zengyawen 已提交
2224 2225
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
2226
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
Z
zengyawen 已提交
2227 2228 2229
                        err.message);
          return;
      }
H
HelloCrease 已提交
2230
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
Z
zengyawen 已提交
2231
      for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
2232
          console.info("sensor_getDirection_callback" + data[i]);
Z
zengyawen 已提交
2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
      }
  })
  ```


## sensor.getDirection

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

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

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

H
HelloCrease 已提交
2246
**参数:** 
Z
zengyawen 已提交
2247

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

H
HelloCrease 已提交
2252
**返回值:** 
Z
zengyawen 已提交
2253

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

H
HelloCrease 已提交
2258
**示例:** 
Z
zengyawen 已提交
2259

H
HelloCrease 已提交
2260
  ```js
Z
zengyawen 已提交
2261 2262
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
H
HelloCrease 已提交
2263
          console.info('sensor_getAltitude_Promise success', data);
Z
zengyawen 已提交
2264
          for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
2265
              console.info("sensor_getDirection_promise" + data[i]);
Z
zengyawen 已提交
2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
          }
      }).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 已提交
2279 2280
**系统能力**:SystemCapability.Sensors.Sensor

H
HelloCrease 已提交
2281
**参数:** 
Z
zengyawen 已提交
2282

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

H
HelloCrease 已提交
2289
**示例:** 
Z
zengyawen 已提交
2290

H
HelloCrease 已提交
2291
  ```js
Z
zengyawen 已提交
2292 2293
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
L
li-yaoyao777 已提交
2294
          console.error('error code is: ' + err.code + ', message: ' + err.message);
Z
zengyawen 已提交
2295 2296
          return;
      }
L
li-yaoyao777 已提交
2297
      console.info(JSON.stringify(data));
Z
zengyawen 已提交
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
2310
**参数:** 
Z
zengyawen 已提交
2311

H
HelloCrease 已提交
2312 2313 2314 2315
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
2316

H
HelloCrease 已提交
2317
**返回值:** 
Z
zengyawen 已提交
2318

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

H
HelloCrease 已提交
2323
**示例:** 
Z
zengyawen 已提交
2324

H
HelloCrease 已提交
2325
  ```js
Z
zengyawen 已提交
2326 2327
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
L
li-yaoyao777 已提交
2328
          console.info(JSON.stringify(data));
Z
zengyawen 已提交
2329
      }).catch((err) => {
H
HelloCrease 已提交
2330
          console.info('promise failed');
Z
zengyawen 已提交
2331 2332 2333
  })
  ```

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

C
cff-gite 已提交
2336
 getSensorLists(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
C
cff-gite 已提交
2337 2338 2339 2340 2341 2342 2343

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

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

**参数:** 

C
cff-gite 已提交
2344 2345 2346
| 参数名   | 类型                                           | 必填 | 说明             |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
2347 2348 2349

**示例:** 

C
cff-gite 已提交
2350
```js
C
cff-gite 已提交
2351
sensor.getSensorLists((error, data) => {
C
cff-gite 已提交
2352
    if (error) {
C
cff-gite 已提交
2353
        console.error('getSensorLists failed');
C
cff-gite 已提交
2354
    } else {
C
cff-gite 已提交
2355
        console.info("getSensorLists callback in" + data.length);
C
cff-gite 已提交
2356
        for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
2357
            console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
2358
        }
C
cff-gite 已提交
2359 2360
    }
});
C
cff-gite 已提交
2361 2362
```

C
cff-gite 已提交
2363
## sensor.getSensorLists<sup>9+</sup>
C
cff-gite 已提交
2364 2365 2366 2367 2368 2369 2370 2371 2372

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

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

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

**返回值:** 

C
cff-gite 已提交
2373 2374 2375
| 参数名  | 类型                                     | 必填 | 说明             |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
2376 2377 2378

**示例:** 

C
cff-gite 已提交
2379
```js
C
cff-gite 已提交
2380 2381
sensor.getSensorLists().then((data) => {
    console.info("getSensorLists promise in" + data.length);
C
cff-gite 已提交
2382
    for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
2383
        console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
2384 2385
     }
}, (error)=>{
C
cff-gite 已提交
2386
    console.error('getSensorLists failed');
C
cff-gite 已提交
2387
});
C
cff-gite 已提交
2388 2389
```

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

C
cff-gite 已提交
2392
getSingleSensor(type: SensorType, callback: AsyncCallback&lt;Sensor&gt;): void
C
cff-gite 已提交
2393 2394 2395 2396 2397 2398 2399

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

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

**参数:** 

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

C
cff-gite 已提交
2405
**示例:**
C
cff-gite 已提交
2406

C
cff-gite 已提交
2407
```js
C
cff-gite 已提交
2408 2409
 sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => {
     if (error) {
C
cff-gite 已提交
2410
         console.error('getSingleSensor failed');
C
cff-gite 已提交
2411 2412 2413 2414
     } else {
         console.info("getSingleSensor " + JSON.stringify(data));
     }
});
C
cff-gite 已提交
2415 2416
```

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

C
cff-gite 已提交
2419
 getSingleSensor(type: SensorType): Promise&lt;Sensor&gt;
C
cff-gite 已提交
2420 2421 2422 2423 2424 2425 2426

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

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

**参数:** 

C
cff-gite 已提交
2427 2428 2429
| 参数名 | 类型       | 必填 | 说明         |
| ------ | ---------- | ---- | ------------ |
| type   | SensorType | 是   | 传感器类型。 |
C
cff-gite 已提交
2430 2431 2432

**返回值:** 

C
cff-gite 已提交
2433 2434 2435
| 参数名  | 类型                              | 必填 | 说明             |
| ------- | --------------------------------- | ---- | ---------------- |
| promise | Promise&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
C
cff-gite 已提交
2436 2437 2438

**示例:**

C
cff-gite 已提交
2439
```js
C
cff-gite 已提交
2440 2441 2442 2443 2444
sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER).then((data) => {
    console.info("getSingleSensor " + JSON.stringify(data));
}, (error)=>{
    console.error('getSingleSensor failed');
});
C
cff-gite 已提交
2445 2446
```

Z
zengyawen 已提交
2447
## SensorType
Z
zengyawen 已提交
2448 2449 2450

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

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

Z
zengyawen 已提交
2453

C
cff-gite 已提交
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
| 名称                                                      | 默认值 | 说明                   |
| --------------------------------------------------------- | ------ | ---------------------- |
| 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 已提交
2479 2480


Z
zengyawen 已提交
2481 2482 2483 2484
## Response

传感器数据的时间戳。

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

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

C
cff-gite 已提交
2491
## Sensor<sup>9+</sup>
C
cff-gite 已提交
2492 2493 2494 2495 2496

指示传感器信息。

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

C
cff-gite 已提交
2497 2498 2499 2500 2501 2502 2503 2504 2505 2506
| 名称            | 参数类型 | 说明                   |
| --------------- | -------- | ---------------------- |
| sensorName      | string   | 传感器名称。           |
| venderName      | string   | 传感器供应商。         |
| firmwareVersion | string   | 传感器固件版本。       |
| hardwareVersion | string   | 传感器硬件版本。       |
| sensorTypeId    | number   | 传感器类型id。         |
| maxRange        | number   | 传感器的最大测量范围。 |
| precision       | number   | 传感器精度。           |
| power           | number   | 传感器电源。           |
C
cff-gite 已提交
2507

Z
zengyawen 已提交
2508
## AccelerometerResponse
Z
zengyawen 已提交
2509

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

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

Z
zengyawen 已提交
2514

H
HelloCrease 已提交
2515 2516 2517 2518 2519
| 名称   | 参数类型   | 可读   | 可写   | 说明                     |
| ---- | ------ | ---- | ---- | ---------------------- |
| x    | number | 是    | 是    | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2520 2521 2522


## LinearAccelerometerResponse
Z
zengyawen 已提交
2523

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

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

Z
zengyawen 已提交
2528

H
HelloCrease 已提交
2529 2530 2531 2532 2533
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2534 2535 2536


## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
2537

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

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

Z
zengyawen 已提交
2542

H
HelloCrease 已提交
2543 2544 2545 2546 2547 2548 2549 2550
| 名称    | 参数类型   | 可读   | 可写   | 说明                           |
| ----- | ------ | ---- | ---- | ---------------------------- |
| 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 已提交
2551 2552 2553


## GravityResponse
Z
zengyawen 已提交
2554

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

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

Z
zengyawen 已提交
2559

H
HelloCrease 已提交
2560 2561 2562 2563 2564
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
2565 2566 2567


## OrientationResponse
Z
zengyawen 已提交
2568

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

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

Z
zengyawen 已提交
2573

H
HelloCrease 已提交
2574 2575
| 名称    | 参数类型   | 可读   | 可写   | 说明                |
| ----- | ------ | ---- | ---- | ----------------- |
2576
| alpha | number | 是    | 是    | 设备围绕Z轴的旋转角度,单位:度。 |
H
HelloCrease 已提交
2577 2578
| beta  | number | 是    | 是    | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是    | 是    | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
2579 2580 2581


## RotationVectorResponse
Z
zengyawen 已提交
2582

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

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

Z
zengyawen 已提交
2587

H
HelloCrease 已提交
2588 2589 2590 2591 2592 2593
| 名称   | 参数类型   | 可读   | 可写   | 说明        |
| ---- | ------ | ---- | ---- | --------- |
| x    | number | 是    | 是    | 旋转矢量x轴分量。 |
| y    | number | 是    | 是    | 旋转矢量y轴分量。 |
| z    | number | 是    | 是    | 旋转矢量z轴分量。 |
| w    | number | 是    | 是    | 标量。       |
Z
zengyawen 已提交
2594 2595 2596


## GyroscopeResponse
Z
zengyawen 已提交
2597

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

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

Z
zengyawen 已提交
2602

H
HelloCrease 已提交
2603 2604 2605 2606 2607
| 名称   | 参数类型   | 可读   | 可写   | 说明                  |
| ---- | ------ | ---- | ---- | ------------------- |
| x    | number | 是    | 是    | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number | 是    | 是    | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number | 是    | 是    | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
2608 2609 2610


## GyroscopeUncalibratedResponse
Z
zengyawen 已提交
2611

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

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

Z
zengyawen 已提交
2616

H
HelloCrease 已提交
2617 2618 2619 2620 2621 2622 2623 2624
| 名称    | 参数类型   | 可读   | 可写   | 说明                       |
| ----- | ------ | ---- | ---- | ------------------------ |
| 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 已提交
2625 2626 2627


## SignificantMotionResponse
Z
zengyawen 已提交
2628

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

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

Z
zengyawen 已提交
2633

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


## ProximityResponse
Z
zengyawen 已提交
2640

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

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

Z
zengyawen 已提交
2645

H
HelloCrease 已提交
2646 2647 2648
| 名称       | 参数类型   | 可读   | 可写   | 说明                           |
| -------- | ------ | ---- | ---- | ---------------------------- |
| distance | number | 是    | 是    | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
2649 2650 2651


## LightResponse
Z
zengyawen 已提交
2652

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

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

Z
zengyawen 已提交
2657

H
HelloCrease 已提交
2658 2659 2660
| 名称        | 参数类型   | 可读   | 可写   | 说明          |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | 是    | 是    | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
2661 2662 2663


## HallResponse
Z
zengyawen 已提交
2664

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

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

Z
zengyawen 已提交
2669

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


## MagneticFieldResponse
Z
zengyawen 已提交
2676

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

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

Z
zengyawen 已提交
2681

C
cff-gite 已提交
2682 2683 2684 2685 2686
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
Z
zengyawen 已提交
2687 2688 2689


## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
2690

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

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

Z
zengyawen 已提交
2695

H
HelloCrease 已提交
2696 2697 2698 2699 2700 2701 2702 2703
| 名称    | 参数类型   | 可读   | 可写   | 说明                     |
| ----- | ------ | ---- | ---- | ---------------------- |
| 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 已提交
2704 2705 2706


## PedometerResponse
Z
zengyawen 已提交
2707

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

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

Z
zengyawen 已提交
2712

H
HelloCrease 已提交
2713 2714 2715
| 名称    | 参数类型   | 可读   | 可写   | 说明       |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | 是    | 是    | 用户的行走步数。 |
Z
zengyawen 已提交
2716 2717 2718


## HumidityResponse
Z
zengyawen 已提交
2719

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

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

Z
zengyawen 已提交
2724

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


C
cff-gite 已提交
2730
## PedometerDetectionResponse
Z
zengyawen 已提交
2731

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

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

Z
zengyawen 已提交
2736

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


## AmbientTemperatureResponse
Z
zengyawen 已提交
2743

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

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

Z
zengyawen 已提交
2748

H
HelloCrease 已提交
2749 2750 2751
| 名称          | 参数类型   | 可读   | 可写   | 说明            |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | 是    | 是    | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
2752 2753 2754


## BarometerResponse
Z
zengyawen 已提交
2755

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

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

Z
zengyawen 已提交
2760

H
HelloCrease 已提交
2761 2762 2763
| 名称       | 参数类型   | 可读   | 可写   | 说明           |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | 是    | 是    | 压力值(单位:帕斯卡)。 |
Z
zengyawen 已提交
2764 2765 2766


## HeartRateResponse
Z
zengyawen 已提交
2767

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

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

Z
zengyawen 已提交
2772

H
HelloCrease 已提交
2773 2774 2775
| 名称        | 参数类型   | 可读   | 可写   | 说明                    |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | 是    | 是    | 心率值。测量用户的心率数值,单位:bpm。 |
Z
zengyawen 已提交
2776 2777 2778


## WearDetectionResponse
Z
zengyawen 已提交
2779

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

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

Z
zengyawen 已提交
2784

H
HelloCrease 已提交
2785 2786 2787
| 名称    | 参数类型   | 可读   | 可写   | 说明                        |
| ----- | ------ | ---- | ---- | ------------------------- |
| value | number | 是    | 是    | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
Z
zengyawen 已提交
2788 2789 2790 2791


## Options

Z
zengyawen 已提交
2792
设置传感器上报频率。
Z
zengyawen 已提交
2793

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

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

Z
zengyawen 已提交
2800 2801
## RotationMatrixResponse

C
cff-gite 已提交
2802 2803 2804
设置旋转矩阵响应对象。

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

H
HelloCrease 已提交
2806 2807 2808 2809
| 名称          | 参数类型                | 可读   | 可写   | 说明    |
| ----------- | ------------------- | ---- | ---- | ----- |
| rotation    | Array&lt;number&gt; | 是    | 是    | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是    | 是    | 倾斜矩阵。 |
Z
zengyawen 已提交
2810 2811 2812 2813


## CoordinatesOptions

C
cff-gite 已提交
2814 2815 2816
设置坐标选项对象。

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

H
HelloCrease 已提交
2818 2819 2820 2821
| 名称   | 参数类型   | 可读   | 可写   | 说明     |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | 是    | 是    | x坐标方向。 |
| y    | number | 是    | 是    | y坐标方向。 |
Z
zengyawen 已提交
2822

Z
zengyawen 已提交
2823 2824 2825

## GeomagneticResponse

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

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

H
HelloCrease 已提交
2830 2831 2832 2833 2834 2835 2836 2837 2838
| 名称              | 参数类型   | 可读   | 可写   | 说明                        |
| --------------- | ------ | ---- | ---- | ------------------------- |
| x               | number | 是    | 是    | 地磁场的北分量。                  |
| y               | number | 是    | 是    | 地磁场的东分量。                  |
| z               | number | 是    | 是    | 地磁场的垂直分量。                 |
| geomagneticDip  | number | 是    | 是    | 地磁倾角,即地球磁场线与水平面的夹角。       |
| deflectionAngle | number | 是    | 是    | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number | 是    | 是    | 地磁场的水平强度。                 |
| totalIntensity  | number | 是    | 是    | 地磁场的总强度。                  |
Z
zengyawen 已提交
2839 2840 2841

## LocationOptions

C
cff-gite 已提交
2842 2843 2844 2845
指示地理位置。

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

H
HelloCrease 已提交
2846 2847 2848 2849 2850
| 名称        | 参数类型   | 可读   | 可写   | 说明    |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | 是    | 是    | 纬度。   |
| longitude | number | 是    | 是    | 经度。   |
| altitude  | number | 是    | 是    | 海拔高度。 |