js-apis-sensor.md 242.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';
```

C
cff-gite 已提交
24
## sensor.on<sup>9+</sup>
Z
zengyawen 已提交
25

C
cff-gite 已提交
26
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39

on(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void

订阅加速度计传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
40
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的加速度传感器类型为 ACCELEROMETER。                   |
C
cff-gite 已提交
41 42 43
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
44 45
**错误码**

C
cff-gite 已提交
46
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
47 48 49 50 51

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
52 53 54
**示例:** 

```js
C
cff-gite 已提交
55 56 57 58 59 60 61 62 63
try {
    sensor.on(sensor.SensorId.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} );
} catch(err) {
        console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
64 65
```

C
cff-gite 已提交
66
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
67

C
cff-gite 已提交
68
on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;,options?: Options): void
C
cff-gite 已提交
69 70 71 72 73 74 75 76 77 78 79

订阅未校准的加速度计传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
80
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的未校准加速度传感器类型为ACCELEROMETER_UNCALIBRATED。 |
C
cff-gite 已提交
81 82 83
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
84 85
**错误码**

C
cff-gite 已提交
86
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
87 88 89 90 91

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
92 93 94
**示例:** 

```js
C
cff-gite 已提交
95 96 97 98 99 100 101 102 103 104 105 106
try {
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED,function(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);
      }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
107 108
```

C
cff-gite 已提交
109
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
110 111 112 113 114 115 116 117 118 119 120

on(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void

订阅环境光传感器数据。

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

**参数:** 

| 参数名   | 类型                                            | 必填 | 说明                                                        |
| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
C
cff-gite 已提交
121
| type     | [SensorId](#sensorid9)                          | 是   | 要订阅的环境光传感器类型为AMBIENT_LIGHT。                   |
C
cff-gite 已提交
122 123 124
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| options  | [Options](#options)                             | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。           |

C
cff-gite 已提交
125 126
**错误码**

C
cff-gite 已提交
127
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
128 129 130 131 132

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
133 134 135
**示例:** 

```js
C
cff-gite 已提交
136
try {
C
cff-gite 已提交
137 138
  sensor.on(sensor.SensorId.AMBIENT_LIGHT,function(data){
      console.info('Illumination: ' + data.intensity);
C
cff-gite 已提交
139 140 141 142
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
143 144
```

C
cff-gite 已提交
145
###  AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
146 147 148 149 150 151 152 153 154 155 156

on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;,options?: Options): void

订阅环境温度传感器数据。

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
157
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的环境温度传感器类型为AMBIENT_TEMPERATURE。            |
C
cff-gite 已提交
158 159 160
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
161 162
**错误码**

C
cff-gite 已提交
163
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
164 165 166 167 168

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
169 170 171
**示例:**

```js
C
cff-gite 已提交
172
try {
C
cff-gite 已提交
173 174
  sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE,function(data){
      console.info('Temperature: ' + data.temperature);
C
cff-gite 已提交
175 176 177 178
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
179 180
```

C
cff-gite 已提交
181
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
182 183 184 185 186 187 188 189 190 191 192

on(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;, options?: Options): void

订阅气压计传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
193
| type     | [SensorId](#sensorid9)                                  | 是   | 要订阅的气压计传感器类型为BAROMETER。                        |
C
cff-gite 已提交
194 195 196
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
197 198
**错误码**

C
cff-gite 已提交
199
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
200 201 202 203 204

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
205 206 207
**示例:**

```js
C
cff-gite 已提交
208
try {
C
cff-gite 已提交
209 210
  sensor.on(sensor.SensorId.BAROMETER,function(data){
      console.info('Atmospheric pressure: ' + data.pressure);
C
cff-gite 已提交
211 212 213 214
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
215 216
```

C
cff-gite 已提交
217
###  GRAVITY<sup>9+</sup>
C
cff-gite 已提交
218 219 220 221 222 223 224 225 226 227 228

on(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void

订阅重力传感器数据。

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

**参数:** 

| 参数名   | 类型                                                | 必填 | 说明                                                        |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
C
cff-gite 已提交
229
| type     | [SensorId](#sensorid9)                              | 是   | 要订阅的重力传感器类型为GRAVITY。                           |
C
cff-gite 已提交
230 231 232
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| options  | [Options](#options)                                 | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。           |

C
cff-gite 已提交
233 234
**错误码**

C
cff-gite 已提交
235
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
236 237 238 239 240

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
241 242 243
**示例:**

```js
C
cff-gite 已提交
244
try {
C
cff-gite 已提交
245 246 247 248
  sensor.on(sensor.SensorId.GRAVITY,function(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 已提交
249 250 251 252
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
253 254
```

C
cff-gite 已提交
255
###  GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
256 257 258 259 260

on(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;,options?: Options): void

订阅校准的陀螺仪传感器数据。

C
cff-gite 已提交
261
**需要权限**:ohos.permission.GYROSCOPE 
C
cff-gite 已提交
262 263 264 265 266 267 268

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
269
| type     | [SensorId](#sensorid9)                                  | 是   | 要订阅的陀螺仪传感器类型为GYROSCOPE。                        |
C
cff-gite 已提交
270 271 272
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 返回注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
273 274
**错误码**

C
cff-gite 已提交
275
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
276 277 278 279 280

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
281 282 283
**示例:**

```js
C
cff-gite 已提交
284
try {
C
cff-gite 已提交
285 286 287 288
  sensor.on(sensor.SensorId.GYROSCOPE,function(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 已提交
289 290 291 292
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
293 294
```

C
cff-gite 已提交
295
###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
296 297 298 299 300 301

on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;,
      options?: Options): void

订阅未经校准的陀螺仪传感器数据

C
cff-gite 已提交
302
**需要权限**:ohos.permission.GYROSCOPE 
C
cff-gite 已提交
303 304 305 306 307 308 309

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
310
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的未校准陀螺仪传感器类型为GYROSCOPE_UNCALIBRATED。     |
C
cff-gite 已提交
311 312 313
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
314 315
**错误码**

C
cff-gite 已提交
316
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
317 318 319 320 321

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
322 323 324
**示例:**

```js
C
cff-gite 已提交
325
try {
C
cff-gite 已提交
326 327 328 329 330 331 332
  sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED,function(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);
C
cff-gite 已提交
333 334 335 336
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
337 338
```

C
cff-gite 已提交
339
###  HALL<sup>9+</sup>
C
cff-gite 已提交
340 341 342

on(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void

C
cff-gite 已提交
343
订阅霍尔传感器数据。
C
cff-gite 已提交
344 345 346 347 348 349 350

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

**参数:** 

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
351
| type     | [SensorId](#sensorid9)                        | 是   | 要订阅的霍尔传感器类型为HALL。                               |
C
cff-gite 已提交
352 353 354
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
| options  | [Options](#options)                           | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
355 356
**错误码**

C
cff-gite 已提交
357
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
358 359 360 361 362

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
363 364 365
**示例:**

```js
C
cff-gite 已提交
366
try {
C
cff-gite 已提交
367 368
  sensor.on(sensor.SensorId.HALL,function(data){
      console.info('Status: ' + data.status);
C
cff-gite 已提交
369 370 371 372
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
373 374
```

C
cff-gite 已提交
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
###   HEART_RATE<sup>9+</sup>

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

订阅心率传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | 是   | 要订阅的心率传感器类型为HEART_RATE。                         |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

**错误码**

以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

**示例:**

```js
try {
    sensor.on(sensor.SensorId.HEART_RATE,function(data){
        console.info('Heart rate: ' + data.heartRate);
    }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
413
###  HUMIDITY<sup>9+</sup>
C
cff-gite 已提交
414 415 416 417 418 419 420 421 422 423 424

on(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void

订阅湿度传感器数据。

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

**参数:** 

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
425
| type     | [SensorId](#sensorid9)                                | 是   | 要订阅的湿度传感器类型为HUMIDITY。                           |
C
cff-gite 已提交
426 427 428
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| options  | [Options](#options)                                   | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
429 430
**错误码**

C
cff-gite 已提交
431
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
432 433 434 435 436

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
437 438 439
**示例:**

```js
C
cff-gite 已提交
440
try {
C
cff-gite 已提交
441 442
  sensor.on(sensor.SensorId.HUMIDITY,function(data){
      console.info('Humidity: ' + data.humidity);
C
cff-gite 已提交
443 444 445 446
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
447 448
```

C
cff-gite 已提交
449
###   LINEAR_ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489

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

订阅线性加速度传感器数据。

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

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

**参数:** 

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

**错误码**

以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

**示例:**

```js
try {
  sensor.on(sensor.SensorId.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} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
490
###  MAGNETIC_FIELD<sup>9+</sup>
C
cff-gite 已提交
491 492 493 494 495 496 497 498 499 500 501

on(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void

订阅磁场传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
502
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的磁场传感器类型为MAGNETIC_FIELD。                     |
C
cff-gite 已提交
503 504 505
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
506 507
**错误码**

C
cff-gite 已提交
508
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
509 510 511 512 513

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
514 515 516
**示例:**

```js
C
cff-gite 已提交
517
try {
C
cff-gite 已提交
518 519 520 521
  sensor.on(sensor.SensorId.MAGNETIC_FIELD,function(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 已提交
522 523 524 525
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
526 527
```

C
cff-gite 已提交
528
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
529

C
cff-gite 已提交
530
on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
C
cff-gite 已提交
531 532 533 534 535 536 537 538 539

订阅未校准的磁场传感器数据

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
540
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的未校准磁场传感器类型为MAGNETIC_FIELD_UNCALIBRATED。  |
C
cff-gite 已提交
541 542 543
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
544 545
**错误码**

C
cff-gite 已提交
546
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
547 548 549 550 551

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

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

```js
C
cff-gite 已提交
555
try {
C
cff-gite 已提交
556 557 558 559 560 561 562
  sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED,function(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);
C
cff-gite 已提交
563 564 565 566
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
567 568
```

C
cff-gite 已提交
569
### ORIENTATION<sup>9+</sup>
C
cff-gite 已提交
570 571 572 573 574 575 576

on(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;,options?: Options): void

订阅定向传感器数据。

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

C
cff-gite 已提交
577 578
**错误码**

C
cff-gite 已提交
579
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
580 581 582 583 584

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
585 586 587 588
**参数:**

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
589
| type     | [SensorId](#sensorid9)                                      | 是   | 要订阅的方向传感器类型为ORIENTATION。                        |
C
cff-gite 已提交
590 591 592 593 594 595
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| options  | [Options](#options)                                         | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

**示例:**

```js
C
cff-gite 已提交
596
try {
C
cff-gite 已提交
597 598 599 600
  sensor.on(sensor.SensorId.ORIENTATION,function(data){
      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 已提交
601 602 603 604
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
605 606
```

C
cff-gite 已提交
607
### PEDOMETER<sup>9+</sup>
C
cff-gite 已提交
608 609 610 611 612 613 614 615 616

on(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void

订阅计步器传感器数据。

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

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

C
cff-gite 已提交
617 618
**错误码**

C
cff-gite 已提交
619
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
620 621 622 623 624

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
625 626 627 628
**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
629
| type     | [SensorId](#sensorid9)                                  | 是   | 要订阅的计步传感器类型为PEDOMETER。                          |
C
cff-gite 已提交
630 631 632 633 634 635
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

**示例:**

```js
C
cff-gite 已提交
636
try {
C
cff-gite 已提交
637 638
  sensor.on(sensor.SensorId.PEDOMETER,function(data){
      console.info('Steps: ' + data.steps);
C
cff-gite 已提交
639 640 641 642
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
643 644
```

C
cff-gite 已提交
645
### PEDOMETER_DETECTION<sup>9+</sup>
C
cff-gite 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659

on(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;,
        options?: Options): void

订阅计步器检测传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
660
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的计步检测传感器类型为PEDOMETER_DETECTION。            |
C
cff-gite 已提交
661 662 663
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
664 665
**错误码**

C
cff-gite 已提交
666
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
667 668 669 670 671

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
672 673 674
**示例:**

```js
C
cff-gite 已提交
675
try {
C
cff-gite 已提交
676 677
  sensor.on(sensor.SensorId.PEDOMETER_DETECTION,function(data){
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
678 679 680 681
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
682 683
```

C
cff-gite 已提交
684
### PROXIMITY<sup>9+</sup>
C
cff-gite 已提交
685 686 687 688 689 690 691 692 693 694 695

on(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;, options?: Options): void

订阅接近传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
696
| type     | [SensorId](#sensorid9)                                  | 是   | 要订阅的接近光传感器类型为PROXIMITY。                        |
C
cff-gite 已提交
697 698 699
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
700 701
**错误码**

C
cff-gite 已提交
702
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
703 704 705 706 707

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
708 709 710
**示例:** 

```js
C
cff-gite 已提交
711
try {
C
cff-gite 已提交
712 713
  sensor.on(sensor.SensorId.PROXIMITY,function(data){
      console.info('Distance: ' + data.distance);
C
cff-gite 已提交
714 715 716 717
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
718 719
```

C
cff-gite 已提交
720
### ROTATION_VECTOR<sup>9+</sup>
C
cff-gite 已提交
721 722 723 724 725 726 727 728 729 730 731 732

on(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;,
        options?: Options): void

订阅旋转矢量传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
733
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的旋转矢量传感器类型为ROTATION_VECTOR。                |
C
cff-gite 已提交
734 735 736
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
737 738
**错误码**

C
cff-gite 已提交
739
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
740 741 742 743 744

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
745 746 747
**示例:** 

```js
C
cff-gite 已提交
748
try {
C
cff-gite 已提交
749 750 751 752 753
  sensor.on(sensor.SensorId.ROTATION_VECTOR,function(data){
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('Scalar quantity: ' + data.w);
C
cff-gite 已提交
754 755 756 757
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
758 759
```

C
cff-gite 已提交
760
### SIGNIFICANT_MOTION<sup>9+</sup>
C
cff-gite 已提交
761 762 763 764 765 766 767 768 769 770 771 772

on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;,
        options?: Options): void

订阅重要的运动传感器数据。

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
773
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的大幅动作传感器类型为SIGNIFICANT_MOTION。             |
C
cff-gite 已提交
774 775 776
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
777 778
**错误码**

C
cff-gite 已提交
779
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
780 781 782 783 784

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
785 786 787
**示例:** 

```js
C
cff-gite 已提交
788
try {
C
cff-gite 已提交
789 790
  sensor.on(sensor.SensorId.SIGNIFICANT_MOTION,function(data){
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
791 792 793 794
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
795 796
```

C
cff-gite 已提交
797
###  WEAR_DETECTION<sup>9+</sup>
C
cff-gite 已提交
798 799 800 801

on(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,
        options?: Options): void

C
cff-gite 已提交
802
订阅佩戴检测传感器数据。
C
cff-gite 已提交
803 804 805 806 807 808 809

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
810
| type     | [SensorId](#sensorid9)                                       | 是   | 要订阅的佩戴检测传感器类型为WEAR_DETECTION。                 |
C
cff-gite 已提交
811 812 813
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |

C
cff-gite 已提交
814 815
**错误码**

C
cff-gite 已提交
816
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
817 818 819 820 821

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
822 823 824
**示例:** 

```js
C
cff-gite 已提交
825
try {
C
cff-gite 已提交
826 827
  sensor.on(sensor.SensorId.WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
C
cff-gite 已提交
828 829 830 831
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
C
cff-gite 已提交
832 833
```

C
cff-gite 已提交
834
## sensor.once<sup>9+</sup>
C
cff-gite 已提交
835

C
cff-gite 已提交
836
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
837 838 839 840 841 842 843 844 845 846 847 848 849

once(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void

订阅一次加速度计传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
850
| type     | [SensorId](#sensorid9)                                       | 是   | 加速度传感器类型为ACCELEROMETER。                            |
C
cff-gite 已提交
851 852
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |

C
cff-gite 已提交
853 854
**错误码**

C
cff-gite 已提交
855
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
856 857 858 859 860

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
861 862 863
**示例:** 

```js
C
cff-gite 已提交
864
try {
C
cff-gite 已提交
865 866 867 868 869 870
  sensor.once(sensor.SensorId.ACCELEROMETER,function(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 已提交
871
} catch(err) {
C
cff-gite 已提交
872
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
873
}
C
cff-gite 已提交
874 875
```

C
cff-gite 已提交
876
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
877

C
cff-gite 已提交
878
once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
879 880 881 882 883 884 885 886 887 888 889

订阅一次未校准的加速度计传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
890
| type     | [SensorId](#sensorid9)                                       | 是   | 未校准加速度传感器类型为ACCELEROMETER_UNCALIBRATED。         |
C
cff-gite 已提交
891 892
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |

C
cff-gite 已提交
893 894
**错误码**

C
cff-gite 已提交
895
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
896 897 898 899 900

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
901 902 903
**示例:** 

```js
C
cff-gite 已提交
904
try {
C
cff-gite 已提交
905 906 907 908 909 910 911 912 913
  sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function(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);
    }
  );
C
cff-gite 已提交
914
} catch(err) {
C
cff-gite 已提交
915
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
916
}
C
cff-gite 已提交
917 918
```

C
cff-gite 已提交
919
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
920 921 922 923 924 925 926 927 928 929 930

once(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void

订阅环境光传感器数据一次。

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

**参数:** 

| 参数名   | 类型                                            | 必填 | 说明                                                         |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
931
| type     | [SensorId](#sensorid9)                          | 是   | 环境光传感器类型为AMBIENT_LIGHT。                            |
C
cff-gite 已提交
932 933
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |

C
cff-gite 已提交
934 935
**错误码**

C
cff-gite 已提交
936
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
937 938 939 940 941

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
942 943 944
**示例:** 

```js
C
cff-gite 已提交
945 946 947 948 949 950
try {
   sensor.once(sensor.SensorId.AMBIENT_LIGHT, function(data) {
       console.info('Illumination: ' + data.intensity);
     }
   );
} catch(err) {
C
cff-gite 已提交
951
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
952
}
C
cff-gite 已提交
953 954
```

C
cff-gite 已提交
955
### AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
956 957 958 959 960 961

once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;): void

一次订阅环境温度传感器数据。

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

C
cff-gite 已提交
963 964 965 966
**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
967
| type     | [SensorId](#sensorid9)                                       | 是   | 环境温度传感器类型为AMBIENT_TEMPERATURE。                    |
C
cff-gite 已提交
968 969
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |

C
cff-gite 已提交
970 971
**错误码**

C
cff-gite 已提交
972
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
973 974 975 976 977

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
978 979 980
**示例:** 

```js
C
cff-gite 已提交
981 982 983 984 985 986
try {
   sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, function(data) {
       console.info('Temperature: ' + data.temperature);
     }
   );
} catch(err) {
C
cff-gite 已提交
987
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
988
}
C
cff-gite 已提交
989 990
```

C
cff-gite 已提交
991
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
992 993 994 995 996 997

once(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void

订阅一次气压计传感器数据。

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

C
cff-gite 已提交
999 1000 1001 1002
**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1003
| type     | [SensorId](#sensorid9)                                  | 是   | 气压计传感器类型为BAROMETER。                                |
C
cff-gite 已提交
1004 1005
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |

C
cff-gite 已提交
1006 1007
**错误码**

C
cff-gite 已提交
1008
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1009 1010 1011 1012 1013

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1014 1015 1016
**示例:** 

```js
C
cff-gite 已提交
1017 1018 1019 1020 1021 1022
try {
   sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
       console.info('Atmospheric pressure: ' + data.pressure);
     }
   );
} catch(err) {
C
cff-gite 已提交
1023
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1024
}
C
cff-gite 已提交
1025 1026
```

C
cff-gite 已提交
1027
### GRAVITY<sup>9+</sup>
C
cff-gite 已提交
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

once(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;): void

订阅一次重力传感器数据。

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

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1039
| type     | [SensorId](#sensorid9)                              | 是   | 重力传感器类型为GRAVITY。                                    |
C
cff-gite 已提交
1040 1041
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |

C
cff-gite 已提交
1042 1043
**错误码**

C
cff-gite 已提交
1044
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1045 1046 1047 1048 1049

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1050 1051 1052
**示例:**

```js
C
cff-gite 已提交
1053 1054 1055 1056 1057 1058 1059 1060
try {
   sensor.once(sensor.SensorId.GRAVITY, function(data) {
       console.info('X-coordinate component: ' + data.x);
       console.info('Y-coordinate component: ' + data.y);
       console.info('Z-coordinate component: ' + data.z);
     }
   );
} catch(err) {
C
cff-gite 已提交
1061
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1062
}
C
cff-gite 已提交
1063 1064
```

C
cff-gite 已提交
1065
### GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078

once(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void

订阅一次陀螺仪传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1079
| type     | [SensorId](#sensorid9)                                  | 是   | 陀螺仪传感器类型为GYROSCOPE。                                |
C
cff-gite 已提交
1080 1081
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |

C
cff-gite 已提交
1082 1083
**错误码**

C
cff-gite 已提交
1084
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1085 1086 1087 1088 1089

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1090 1091 1092
**示例:**

```js
C
cff-gite 已提交
1093 1094 1095 1096 1097 1098 1099 1100
try {
   sensor.once(sensor.SensorId.GYROSCOPE, function(data) {
       console.info('X-coordinate component: ' + data.x);
       console.info('Y-coordinate component: ' + data.y);
       console.info('Z-coordinate component: ' + data.z);
     }
   );
} catch(err) {
C
cff-gite 已提交
1101
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1102
}
C
cff-gite 已提交
1103 1104
```

C
cff-gite 已提交
1105
### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
1106

C
cff-gite 已提交
1107
once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

一次订阅未校准的陀螺仪传感器数据。

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1119
| type     | [SensorId](#sensorid9)                                       | 是   | 未校准陀螺仪传感器类型为GYROSCOPE_UNCALIBRATED。             |
C
cff-gite 已提交
1120 1121
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |

C
cff-gite 已提交
1122 1123
**错误码**

C
cff-gite 已提交
1124
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1125 1126 1127 1128 1129

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1130 1131 1132
**示例:**

```js
C
cff-gite 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
try {
    sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function(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);
      }
    );
} catch(err) {
C
cff-gite 已提交
1144
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1145
}
C
cff-gite 已提交
1146 1147
```

C
cff-gite 已提交
1148
### HALL<sup>9+</sup>
C
cff-gite 已提交
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159

once(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;): void

订阅一次霍尔传感器数据。

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

**参数:** 

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1160
| type     | [SensorId](#sensorid9)                        | 是   | 霍尔传感器类型为HALL。                                       |
C
cff-gite 已提交
1161 1162
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |

C
cff-gite 已提交
1163 1164
**错误码**

C
cff-gite 已提交
1165
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1166 1167 1168 1169 1170

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1171 1172 1173
**示例:**

```js
C
cff-gite 已提交
1174 1175 1176 1177 1178 1179
try {
    sensor.once(sensor.SensorId.HALL, function(data) {
        console.info('Status: ' + data.status);
      }
    );
} catch(err) {
C
cff-gite 已提交
1180
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1181
}
C
cff-gite 已提交
1182 1183
```

C
cff-gite 已提交
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
### HEART_RATE<sup>9+</sup>

once(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void

订阅一次心率传感器数据。

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

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

**参数:** 

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

**错误码**

以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

**示例:**

```js
try {
    sensor.once(sensor.SensorId.HEART_BEAT_RATE, function(data) {
        console.info('Heart rate: ' + data.heartRate);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
### HUMIDITY<sup>9+</sup>

once(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void

订阅一次湿度传感器数据。

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

**参数:** 

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1234
| type     | [SensorId](#sensorid9)                                | 是   | 湿度传感器类型为HUMIDITY。                                   |
C
cff-gite 已提交
1235 1236
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |

C
cff-gite 已提交
1237 1238
**错误码**

C
cff-gite 已提交
1239
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1240 1241 1242 1243 1244

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1245 1246 1247
**示例:**

```js
C
cff-gite 已提交
1248 1249 1250 1251 1252 1253
try {
    sensor.once(sensor.SensorId.HUMIDITY, function(data) {
        console.info('Humidity: ' + data.humidity);
      }
    );
} catch(err) {
C
cff-gite 已提交
1254
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1255
}
C
cff-gite 已提交
1256 1257
```

C
cff-gite 已提交
1258
### LINEAR_ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297

once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerometerResponse&gt;): void

订阅一次线性加速度传感器数据。

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

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

**参数:** 

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

**错误码**

以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

**示例:**

```js
try {
    sensor.once(sensor.SensorId.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);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
### MAGNETIC_FIELD<sup>9+</sup>

once(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void

订阅一次磁场传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1310
| type     | [SensorId](#sensorid9)                                       | 是   | 磁场传感器类型为MAGNETIC_FIELD。                             |
C
cff-gite 已提交
1311 1312
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |

C
cff-gite 已提交
1313 1314
**错误码**

C
cff-gite 已提交
1315
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1316 1317 1318 1319 1320

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1321 1322 1323
**示例:**

```js
C
cff-gite 已提交
1324 1325 1326 1327 1328 1329 1330 1331
try {
   sensor.once(sensor.SensorId.MAGNETIC_FIELD, function(data) {
       console.info('X-coordinate component: ' + data.x);
       console.info('Y-coordinate component: ' + data.y);
       console.info('Z-coordinate component: ' + data.z);
     }
   );
} catch(err) {
C
cff-gite 已提交
1332
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1333
}
C
cff-gite 已提交
1334 1335 1336 1337
```

### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>

C
cff-gite 已提交
1338
once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
1339 1340 1341 1342 1343 1344 1345 1346 1347

订阅一次未经校准的磁场传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1348
| type     | [SensorId](#sensorid9)                                       | 是   | 未校准磁场传感器类型为MAGNETIC_FIELD_UNCALIBRATED。          |
C
cff-gite 已提交
1349 1350
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |

C
cff-gite 已提交
1351 1352
**错误码**

C
cff-gite 已提交
1353
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1354 1355 1356 1357 1358

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

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

```js
C
cff-gite 已提交
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
try {
    sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function(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);
      }
    );
} catch(err) {
C
cff-gite 已提交
1373
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1374
}
C
cff-gite 已提交
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
```

### ORIENTATION<sup>9+</sup>

once(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void

订阅一次定向传感器数据。

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

**参数:** 

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1389
| type     | [SensorId](#sensorid9)                                      | 是   | 方向传感器类型为ORIENTATION。                                |
C
cff-gite 已提交
1390 1391
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |

C
cff-gite 已提交
1392 1393
**错误码**

C
cff-gite 已提交
1394
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1395 1396 1397 1398 1399

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1400 1401 1402
**示例:**

```js
C
cff-gite 已提交
1403 1404 1405 1406 1407 1408 1409 1410
try {
   sensor.once(sensor.SensorId.ORIENTATION, function(data) {
       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);
     }
   );
} catch(err) {
C
cff-gite 已提交
1411
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1412
}
C
cff-gite 已提交
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
```

### PEDOMETER<sup>9+</sup>

once(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void

订阅一次计步器传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1429
| type     | [SensorId](#sensorid9)                                  | 是   | 计步传感器类型为PEDOMETER。                                  |
C
cff-gite 已提交
1430 1431
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |

C
cff-gite 已提交
1432 1433
**错误码**

C
cff-gite 已提交
1434
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1435 1436 1437 1438 1439

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1440 1441 1442
**示例:**

```js
C
cff-gite 已提交
1443 1444 1445 1446 1447 1448
try {
    sensor.once(sensor.SensorId.PEDOMETER, function(data) {
        console.info('Steps: ' + data.steps);
      }
    );
} catch(err) {
C
cff-gite 已提交
1449
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1450
}
C
cff-gite 已提交
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
```

### PEDOMETER_DETECTION<sup>9+</sup>

once(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;): void

订阅一次计步器检测传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1467
| type     | [SensorId](#sensorid9)                                       | 是   | 计步检测传感器类型为PEDOMETER_DETECTION。                    |
C
cff-gite 已提交
1468 1469
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |

C
cff-gite 已提交
1470 1471
**错误码**

C
cff-gite 已提交
1472
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1473 1474 1475 1476 1477

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1478 1479 1480
**示例:**

```js
C
cff-gite 已提交
1481 1482 1483 1484 1485 1486
try {
    sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function(data) {
        console.info('Scalar data: ' + data.scalar);
      }
    );
} catch(err) {
C
cff-gite 已提交
1487
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1488
}
C
cff-gite 已提交
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
```

### PROXIMITY<sup>9+</sup>

once(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void

订阅一次接近传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1503
| type     | [SensorId](#sensorid9)                                  | 是   | 接近光传感器类型为PROXIMITY。                                |
C
cff-gite 已提交
1504 1505
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |

C
cff-gite 已提交
1506 1507
**错误码**

C
cff-gite 已提交
1508
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1509 1510 1511 1512 1513

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1514 1515 1516
**示例:**

```js
C
cff-gite 已提交
1517 1518 1519 1520 1521 1522
try {
   sensor.once(sensor.SensorId.PROXIMITY, function(data) {
       console.info('Distance: ' + data.distance);
     }
   );
} catch(err) {
C
cff-gite 已提交
1523
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1524
}
C
cff-gite 已提交
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
```

### ROTATION_VECTOR<sup>9+</sup>

once(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void

订阅一次旋转矢量传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1539
| type     | [SensorId](#sensorid9)                                       | 是   | 旋转矢量传感器类型为ROTATION_VECTOR。                        |
C
cff-gite 已提交
1540 1541
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |

C
cff-gite 已提交
1542 1543
**错误码**

C
cff-gite 已提交
1544
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1545 1546 1547 1548 1549

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1550 1551 1552
**示例:** 

```js
C
cff-gite 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561
try {
   sensor.once(sensor.SensorId.ROTATION_VECTOR, function(data) {
       console.info('X-coordinate component: ' + data.x);
       console.info('Y-coordinate component: ' + data.y);
       console.info('Z-coordinate component: ' + data.z);
       console.info('Scalar quantity: ' + data.w);
     }
   );
} catch(err) {
C
cff-gite 已提交
1562
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1563
}
C
cff-gite 已提交
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
```

### SIGNIFICANT_MOTION<sup>9+</sup>

once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;): void

订阅一次重要的运动传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1578
| type     | [SensorId](#sensorid9)                                       | 是   | 有效运动传感器类型为SIGNIFICANT_MOTION。                     |
C
cff-gite 已提交
1579 1580
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |

C
cff-gite 已提交
1581 1582
**错误码**

C
cff-gite 已提交
1583
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1584 1585 1586 1587 1588

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1589 1590 1591
**示例:** 

```js
C
cff-gite 已提交
1592 1593 1594 1595 1596 1597
try {
   sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function(data) {
       console.info('Scalar data: ' + data.scalar);
     }
   );
} catch(err) {
C
cff-gite 已提交
1598
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1599
}
C
cff-gite 已提交
1600 1601 1602 1603 1604 1605
```

### WEAR_DETECTION<sup>9+</sup>

once(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void

C
cff-gite 已提交
1606
订阅一次佩戴检测传感器数据。
C
cff-gite 已提交
1607 1608 1609 1610 1611 1612 1613

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1614
| type     | [SensorId](#sensorid9)                                       | 是   | 佩戴检测传感器类型为WEAR_DETECTION。                         |
C
cff-gite 已提交
1615 1616
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |

C
cff-gite 已提交
1617 1618
**错误码**

C
cff-gite 已提交
1619
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1620 1621 1622 1623 1624

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
1625 1626 1627
**示例:** 

```js
C
cff-gite 已提交
1628 1629 1630 1631 1632 1633
try {
   sensor.once(sensor.SensorId.WEAR_DETECTION, function(data) {
       console.info("Wear status: "+ data.value);
     }
   );
} catch(err) {
C
cff-gite 已提交
1634
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1635
}
C
cff-gite 已提交
1636 1637
```

C
cff-gite 已提交
1638
## sensor.off<sup>9+</sup>
C
cff-gite 已提交
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653

### ACCELEROMETER<sup>9+</sup> 

off(type: SensorId.ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void

取消订阅加速度计传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1654
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的加速度传感器类型为ACCELEROMETER。                |
C
cff-gite 已提交
1655 1656 1657 1658 1659
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 取消注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |

**示例:**

```js
C
cff-gite 已提交
1660 1661 1662 1663 1664 1665 1666 1667
try {
    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.SensorId.ACCELEROMETER, callback);
} catch(err) {
C
cff-gite 已提交
1668
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1669 1670 1671 1672 1673
}
```

### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>  

C
cff-gite 已提交
1674
off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685

取消订阅未校准的加速度计传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1686
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的未校准加速度计传感器类型为ACCELEROMETER_UNCALIBRATED。 |
C
cff-gite 已提交
1687 1688 1689 1690 1691
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |

**示例:**

```js
C
cff-gite 已提交
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
try {
    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.SensorId.ACCELEROMETER_UNCALIBRATED, callback);
} catch(err) {
C
cff-gite 已提交
1703
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
}
```

### AMBIENT_LIGHT<sup>9+</sup> 

off(type: SensorId.AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void

取消订阅环境光传感器数据。

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

**参数:**

| 参数名   | 类型                                            | 必填 | 说明                                                         |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1719
| type     | [SensorId](#sensorid9)                          | 是   | 要取消订阅的环境光传感器类型为AMBIENT_LIGHT。                |
C
cff-gite 已提交
1720 1721 1722 1723 1724
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 取消注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |

**示例:**

```js
C
cff-gite 已提交
1725 1726 1727 1728 1729 1730
try {
    function callback(data) {
        console.info('Illumination: ' + data.intensity);
    }
    sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback);
} catch(err) {
C
cff-gite 已提交
1731
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
}
```

### AMBIENT_TEMPERATURE<sup>9+</sup> 

off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void

取消订阅环境温度传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1747
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的环境温度传感器类型为AMBIENT_TEMPERATURE。        |
C
cff-gite 已提交
1748 1749 1750 1751 1752
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |

**示例:**

```js
C
cff-gite 已提交
1753 1754 1755 1756 1757 1758
try {
    function callback(data) {
        console.info('Temperature: ' + data.temperature);
    }
    sensor.off( sensor.SensorId.AMBIENT_TEMPERATURE, callback);
} catch(err) {
C
cff-gite 已提交
1759
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774
}
```

### BAROMETER<sup>9+</sup>  

off(type: SensorId.BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void

取消订阅气压计传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1775
| type     | [SensorId](#sensorid9)                                  | 是   | 要取消订阅的气压计传感器类型为BAROMETER。                    |
C
cff-gite 已提交
1776 1777 1778 1779 1780
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |

**示例:**

```js
C
cff-gite 已提交
1781 1782 1783 1784 1785 1786
try {
    function callback(data) {
        console.info('Atmospheric pressure: ' + data.pressure);
    }
    sensor.off(sensor.SensorId.BAROMETER, callback);
} catch(err) {
C
cff-gite 已提交
1787
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
}
```

### GRAVITY<sup>9+</sup> 

off(type: SensorId.GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void

取消订阅重力传感器数据。

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

**参数:** 

| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1803
| type     | [SensorId](#sensorid9)                              | 是   | 要取消订阅的重力传感器类型为GRAVITY。                        |
C
cff-gite 已提交
1804 1805 1806 1807 1808
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |

**示例:**

```js
C
cff-gite 已提交
1809 1810 1811 1812 1813 1814 1815 1816
try {
    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.SensorId.GRAVITY, callback);
} catch(err) {
C
cff-gite 已提交
1817
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
}
```

### GYROSCOPE<sup>9+</sup> 

off(type: SensorId.GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void

取消订阅陀螺仪传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1835
| type     | [SensorId](#sensorid9)                                  | 是   | 要取消订阅的陀螺仪传感器类型为GYROSCOPE。                    |
C
cff-gite 已提交
1836 1837 1838 1839 1840
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |

**示例:**

```js
C
cff-gite 已提交
1841 1842 1843 1844 1845 1846 1847 1848
try {
    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.SensorId.GYROSCOPE, callback);
} catch(err) {
C
cff-gite 已提交
1849
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1850 1851 1852 1853 1854
}
```

### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 

C
cff-gite 已提交
1855
off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866

 取消订阅未校准的陀螺仪传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1867
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的未校准陀螺仪传感器类型为GYROSCOPE_UNCALIBRATED。 |
C
cff-gite 已提交
1868 1869 1870 1871 1872
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |

**示例:**

```js
C
cff-gite 已提交
1873 1874 1875 1876 1877 1878 1879 1880
try {
    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.SensorId.GYROSCOPE_UNCALIBRATED, callback);
} catch(err) {
C
cff-gite 已提交
1881
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
}
```

### HALL<sup>9+</sup> 

off(type: SensorId.HALL, callback?: Callback&lt;HallResponse&gt;): void

取消订阅霍尔传感器数据。

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

**参数:**

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1897
| type     | [SensorId](#sensorid9)                        | 是   | 要取消订阅的霍尔传感器类型为HALL。                           |
C
cff-gite 已提交
1898 1899 1900 1901 1902
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 取消注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |

**示例:**

```js
C
cff-gite 已提交
1903 1904 1905 1906 1907 1908
try {
    function callback(data) {
        console.info('Status: ' + data.status);
    }
    sensor.off(sensor.SensorId.HALL, callback);
} catch(err) {
C
cff-gite 已提交
1909
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1910 1911 1912
}
```

C
cff-gite 已提交
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
### HEART_RATE<sup>9+</sup> 

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

取消订阅心率传感器数据。

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

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

**参数:**

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

**示例:**

```js
try {
    function callback(data) {
        console.info("Heart rate: " + data.heartRate);
    }
    sensor.off(sensor.SensorId.HEART_RATE, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
### HUMIDITY<sup>9+</sup> 

off(type: SensorId.HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void

取消订阅湿度传感器数据。

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

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1955
| type     | [SensorId](#sensorid9)                                | 是   | 要取消订阅的湿度传感器类型为HUMIDITY。                       |
C
cff-gite 已提交
1956 1957 1958 1959 1960
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |

**示例:**

```js
C
cff-gite 已提交
1961 1962 1963 1964 1965 1966
try {
    function callback(data) {
        console.info('Humidity: ' + data.humidity);
    }
    sensor.off(sensor.SensorId.HUMIDITY, callback);
} catch(err) {
C
cff-gite 已提交
1967
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1968 1969 1970
}
```

C
cff-gite 已提交
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002
### LINEAR_ACCELEROMETER<sup>9+</sup> 

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

取消订阅线性加速度传感器数据。

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

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

**参数:**

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

**示例:**

```js
try {
    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.SensorId.LINEAR_ACCELEROMETER, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

C
cff-gite 已提交
2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
### MAGNETIC_FIELD<sup>9+</sup> 

off(type: SensorId.MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void

取消订阅磁场传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2015
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的磁场传感器类型为MAGNETIC_FIELD。                 |
C
cff-gite 已提交
2016 2017 2018 2019 2020
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |

**示例:**

```js
C
cff-gite 已提交
2021 2022 2023 2024 2025 2026 2027 2028
try {
    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.SensorId.MAGNETIC_FIELD, callback);
} catch(err) {
C
cff-gite 已提交
2029
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2030 2031 2032 2033 2034
}
```

### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 

C
cff-gite 已提交
2035
off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
2036 2037 2038 2039 2040 2041 2042 2043 2044

取消订阅未校准的磁场传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2045
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的未校准磁场传感器类型为MAGNETIC_FIELD_UNCALIBRATED。 |
C
cff-gite 已提交
2046 2047 2048 2049 2050
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |

**示例:**

```js
C
cff-gite 已提交
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
try {
    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.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback);
} catch(err) {
C
cff-gite 已提交
2062
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
}
```

### ORIENTATION<sup>9+</sup> 

off(type: SensorId.ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void

取消订阅方向传感器数据。

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

**参数:**

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2078
| type     | [SensorId](#sensorid9)                                      | 是   | 要取消订阅的方向传感器类型为ORIENTATION。                    |
C
cff-gite 已提交
2079 2080 2081 2082 2083
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |

**示例:**

```js
C
cff-gite 已提交
2084 2085 2086 2087 2088 2089 2090 2091
try {
    function callback(data) {
        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);
    }
    sensor.off(sensor.SensorId.ORIENTATION, callback);
} catch(err) {
C
cff-gite 已提交
2092
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
}
```

### PEDOMETER<sup>9+</sup>

off(type: SensorId.PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void

取消订阅计步器传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2110
| type     | [SensorId](#sensorid9)                                  | 是   | 要取消订阅的计步传感器类型为PEDOMETER。                      |
C
cff-gite 已提交
2111 2112 2113 2114 2115
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |

**示例:**

```js
C
cff-gite 已提交
2116 2117 2118 2119 2120 2121
try {
    function callback(data) {
        console.info('Steps: ' + data.steps);
    }
    sensor.off(sensor.SensorId.PEDOMETER, callback);
} catch(err) {
C
cff-gite 已提交
2122
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139
}
```

### PEDOMETER_DETECTION<sup>9+</sup> 

off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void

取消订阅计步器检测传感器数据。

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2140
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的计步检测传感器类型为PEDOMETER_DETECTION。        |
C
cff-gite 已提交
2141 2142 2143 2144 2145
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |

**示例:**

```js
C
cff-gite 已提交
2146 2147 2148 2149 2150 2151
try {
    function callback(data) {
        console.info('Scalar data: ' + data.scalar);
    }
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback);
} catch(err) {
C
cff-gite 已提交
2152
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
}
```

### PROXIMITY<sup>9+</sup>  

off(type: SensorId.PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void

取消订阅接近传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2168
| type     | [SensorId](#sensorid9)                                  | 是   | 要取消订阅的接近光传感器类型为PROXIMITY。                    |
C
cff-gite 已提交
2169 2170 2171 2172 2173
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |

**示例:**

```js
C
cff-gite 已提交
2174 2175 2176 2177 2178 2179
try {
    function callback(data) {
        console.info('Distance: ' + data.distance);
    }
    sensor.off(sensor.SensorId.PROXIMITY, callback);
} catch(err) {
C
cff-gite 已提交
2180
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
}
```

### ROTATION_VECTOR<sup>9+</sup> 

off(type: SensorId.ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void

取消订阅旋转矢量传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2196
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的旋转矢量传感器类型为ROTATION_VECTOR。            |
C
cff-gite 已提交
2197 2198 2199 2200 2201
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |

**示例:**

```js
C
cff-gite 已提交
2202 2203 2204 2205 2206 2207 2208 2209 2210
try {
    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('Scalar quantity: ' + data.w);
    }
    sensor.off(sensor.SensorId.ROTATION_VECTOR, callback);
} catch(err) {
C
cff-gite 已提交
2211
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226
}
```

### SIGNIFICANT_MOTION<sup>9+</sup> 

off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void

取消订阅重要的运动传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2227
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的大幅动作传感器类型为SIGNIFICANT_MOTION。         |
C
cff-gite 已提交
2228 2229 2230 2231 2232
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |

**示例:**

```js
C
cff-gite 已提交
2233 2234 2235 2236 2237 2238
try {
    function callback(data) {
        console.info('Scalar data: ' + data.scalar);
    }
    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback);
} catch(err) {
C
cff-gite 已提交
2239
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2240 2241 2242 2243 2244 2245 2246
}
```

### WEAR_DETECTION<sup>9+</sup> 

off(type: SensorId.WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void

C
cff-gite 已提交
2247
取消订阅佩戴检测传感器数据。
C
cff-gite 已提交
2248 2249 2250 2251 2252 2253 2254

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2255
| type     | [SensorId](#sensorid9)                                       | 是   | 要取消订阅的佩戴检测传感器类型为WEAR_DETECTION。             |
C
cff-gite 已提交
2256 2257 2258 2259 2260
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |

**示例:**

```js
C
cff-gite 已提交
2261 2262 2263 2264 2265 2266
try {
    function accCallback(data) {
        console.info('Wear status: ' + data.value);
    }
    sensor.off(sensor.SensorId.WEAR_DETECTION, accCallback);
} catch(err) {
C
cff-gite 已提交
2267
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2268 2269 2270
}
```

C
cff-gite 已提交
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286
## sensor.getGeomagneticInfo<sup>9+</sup> 

getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void

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

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

**参数:** 

| 参数名          | 类型                                                         | 必填 | 说明                               |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置。                         |
| timeMillis      | number                                                       | 是   | 表示获取磁偏角的时间,单位为毫秒。 |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 返回磁场信息。                     |

C
cff-gite 已提交
2287 2288 2289 2290 2291 2292 2293 2294
**错误码**

以下错误码的详细介绍请参见 [sensor.getGeomagneticInfo错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329
**示例:** 

```js
try {
    sensor.getGeomagneticInfo({latitude:80, longitude:0, altitude:0}, 1580486400000, function(data)  {
    console.info('sensor_getGeomagneticInfo_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
    });
} catch (err) {
        console.error('getGeomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

## sensor.getGeomagneticInfo<sup>9+</sup> 

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

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

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

**参数:** 

| 参数名          | 类型                                | 必填 | 说明                               |
| --------------- | ----------------------------------- | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions) | 是   | 地理位置。                         |
| timeMillis      | number                              | 是   | 表示获取磁偏角的时间,单位为毫秒。 |

**返回值:** 

| 类型                                                       | 说明           |
| ---------------------------------------------------------- | -------------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |

C
cff-gite 已提交
2330 2331 2332 2333 2334 2335 2336 2337
**错误码**

以下错误码的详细介绍请参见 [sensor.getGeomagneticInfo错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354
**示例:** 

```js
try {
      const promise = sensor.getGeomagneticInfo({latitude:80, longitude:0, altitude:0}, 1580486400000);
      promise.then((data) => {
          console.info('sensor_getGeomagneticInfo_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
      }).catch((reason) => {
          console.info('Operation failed.');
  })
} catch (err) {
        console.error('getGeomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2355
## sensor.getDeviceAltitude<sup>9+</sup> 
C
cff-gite 已提交
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370

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

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

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

**参数:** 

| 参数名          | 类型                        | 必填 | 说明                                  |
| --------------- | --------------------------- | ---- | ------------------------------------- |
| seaPressure     | number                      | 是   | 表示海平面气压值,单位为hPa。         |
| currentPressure | number                      | 是   | 表示设备所在高度的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是   | 返回设备所在的海拔高度,单位为米。    |

C
cff-gite 已提交
2371 2372 2373 2374 2375 2376 2377 2378
**错误码**

以下错误码的详细介绍请参见 [sensor.getDeviceAltitude错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2379 2380 2381 2382
**示例:**

```js
try {
C
cff-gite 已提交
2383
  sensor.getDeviceAltitude(0, 200, function(data)  {
C
cff-gite 已提交
2384
          console.info('Successed to get getDeviceAltitude interface get data: ' + data);
C
cff-gite 已提交
2385 2386 2387 2388 2389 2390
  });
} catch (err) {
        console.error('getDeviceAltitude failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2391
## sensor.getDeviceAltitude<sup>9+</sup> 
C
cff-gite 已提交
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411

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

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

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

**参数:** 

| 参数名          | 类型   | 必填 | 说明                                  |
| --------------- | ------ | ---- | ------------------------------------- |
| seaPressure     | number | 是   | 表示海平面气压值,单位为hPa。         |
| currentPressure | number | 是   | 表示设备所在高度的气压值,单位为hPa。 |

**返回值:** 

| 类型                  | 说明                                 |
| --------------------- | ------------------------------------ |
| Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |

C
cff-gite 已提交
2412 2413 2414 2415 2416 2417 2418 2419
**错误码**

以下错误码的详细介绍请参见 [sensor.getDeviceAltitude错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434
**示例:** 

```js
try {
  const promise = sensor.getDeviceAltitude (0, 200);
      promise.then((data) => {
          console.info('sensor_getDeviceAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
} catch (err) {
        console.error('getDeviceAltitude failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2435
## sensor.getInclination<sup>9+</sup> 
C
cff-gite 已提交
2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449

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

从倾角矩阵计算地磁倾角的弧度。

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

**参数:**

| 参数名            | 类型                        | 必填 | 说明                         |
| ----------------- | --------------------------- | ---- | ---------------------------- |
| inclinationMatrix | Array&lt;number&gt;         | 是   | 表示倾斜矩阵。               |
| callback          | AsyncCallback&lt;number&gt; | 是   | 返回地磁倾斜角,单位为弧度。 |

C
cff-gite 已提交
2450 2451 2452 2453 2454 2455 2456 2457
**错误码**

以下错误码的详细介绍请参见 [sensor.getInclination错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2458 2459 2460 2461
**示例:** 

```js
try {
C
cff-gite 已提交
2462
  sensor.getInclination ([1, 0, 0, 0, 1, 0, 0, 0, 1], function(data)  {
C
cff-gite 已提交
2463
          console.info('Successed to get getInclination  interface get data: ' + data);
C
cff-gite 已提交
2464 2465 2466 2467 2468 2469
  })
} catch (err) {
        console.error('getInclination failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2470
## sensor.getInclination<sup>9+</sup> 
C
cff-gite 已提交
2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489

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

 从倾角矩阵计算地磁倾角的弧度。

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

**参数:**

| 参数名            | 类型                | 必填 | 说明           |
| ----------------- | ------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt; | 是   | 表示倾斜矩阵。 |

**返回值:** 

| 类型                  | 说明                         |
| --------------------- | ---------------------------- |
| Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |

C
cff-gite 已提交
2490 2491 2492 2493 2494 2495 2496 2497
**错误码**

以下错误码的详细介绍请参见 [sensor.getInclination错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
**示例:** 

```js
try {
  const promise = sensor.getInclination ([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('getInclination_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
} catch (err) {
        console.error('getInclination failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2513
## sensor.getAngleVariation<sup>9+</sup>
C
cff-gite 已提交
2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529

 getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;,
        callback: AsyncCallback<Array&lt;number&gt;>): void

得到两个旋转矩阵之间的角度变化。

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

**参数:**

| 参数名                | 类型                                     | 必填 | 说明                              |
| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
| currentRotationMatrix | Array&lt;number&gt;                      | 是   | 表示当前旋转矩阵。                |
| preRotationMatrix     | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                    |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回z、x、y轴方向的旋转角度变化。 |

C
cff-gite 已提交
2530 2531 2532 2533 2534 2535 2536 2537
**错误码**

以下错误码的详细介绍请参见 [sensor.getAngleVariation错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2538 2539 2540 2541
**示例:** 

```js
try {
C
cff-gite 已提交
2542
  sensor.getAngleVariation([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(data)  {
C
cff-gite 已提交
2543 2544 2545 2546 2547 2548 2549 2550 2551
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
} catch (err) {
        console.error('getAngleVariation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2552
## sensor.getAngleVariation<sup>9+</sup>
C
cff-gite 已提交
2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572

getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise<Array&lt;number&gt;> 

得到两个旋转矩阵之间的角度变化。

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

**参数:**

| 参数名                | 类型                | 必填 | 说明               |
| --------------------- | ------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt; | 是   | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是   |                    |

**返回值:** 

| 类型                               | 说明                              |
| ---------------------------------- | --------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |

C
cff-gite 已提交
2573 2574 2575 2576 2577 2578 2579 2580
**错误码**

以下错误码的详细介绍请参见 [sensor.getAngleVariation错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2581 2582 2583 2584 2585 2586 2587
**示例:** 

```js
try {
  const promise = sensor.getAngleVariation([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) => {
          for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2588
              console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2589 2590
          }
      }).catch((reason) => {
C
cff-gite 已提交
2591
          console.info('promise::catch ', reason);
C
cff-gite 已提交
2592 2593 2594 2595 2596 2597
  })
} catch (err) {
        console.error('getAngleVariation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2598
## sensor.getRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612

getRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback<Array&lt;number&gt;>): void

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

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

**参数:** 

| 参数名         | 类型                                     | 必填 | 说明           |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回旋转矩阵。 |

C
cff-gite 已提交
2613 2614 2615 2616 2617 2618 2619 2620
**错误码**

以下错误码的详细介绍请参见 [sensor.getRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2621 2622 2623 2624
**示例:** 

```js
try {
C
cff-gite 已提交
2625
  sensor.getRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(data) {
C
cff-gite 已提交
2626
      for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2627
          console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2628 2629 2630 2631 2632 2633 2634
      }
  })
} catch (err) {
        console.error('getRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2635
## sensor.getRotationMatrix<sup>9+</sup>
C
cff-gite 已提交
2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654

getRotationMatrix(rotationVector: Array&lt;number&gt;): Promise<Array<number&gt;> 

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

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt; | 是   | 表示旋转矢量。 |

**返回值:**

| 类型                               | 说明           |
| ---------------------------------- | -------------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |

C
cff-gite 已提交
2655 2656 2657 2658 2659 2660 2661 2662
**错误码**

以下错误码的详细介绍请参见 [sensor.getRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2663 2664 2665 2666 2667 2668 2669
**示例:** 

```js
try {
  const promise = sensor.getRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2670
              console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2671 2672
          }
      }).catch((reason) => {
C
cff-gite 已提交
2673
          console.info('promise::catch ', reason);
C
cff-gite 已提交
2674 2675 2676 2677 2678 2679
  })
} catch (err) {
        console.error('getRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2680
## sensor.transformRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696

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

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

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

**参数:** 

| 参数名           | 类型                                      | 必填 | 说明                   |
| ---------------- | ----------------------------------------- | ---- | ---------------------- |
| inRotationVector | Array&lt;number&gt;                       | 是   | 表示旋转矩阵。         |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 表示坐标系方向。       |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | 是   | 返回转换后的旋转矩阵。 |

C
cff-gite 已提交
2697 2698 2699 2700 2701 2702 2703 2704
**错误码**

以下错误码的详细介绍请参见 [sensor.transformRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2705 2706 2707 2708
**示例:** 

```js
try {
C
cff-gite 已提交
2709 2710
    sensor.transformRotationMatrix([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(data) {
        for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2711
            console.info('transformRotationMatrix  data[' + i + '] = ' + data[i]);
C
cff-gite 已提交
2712 2713
        }
    })
C
cff-gite 已提交
2714 2715 2716 2717 2718
} catch (err) {
        console.error('transformRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2719
## sensor.transformRotationMatrix<sup>9+</sup>
C
cff-gite 已提交
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739

transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise<Array&lt;number&gt;> 

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

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

**参数:**

| 参数名           | 类型                                      | 必填 | 说明             |
| ---------------- | ----------------------------------------- | ---- | ---------------- |
| inRotationVector | Array&lt;number&gt;                       | 是   | 表示旋转矩阵。   |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 表示坐标系方向。 |

**返回值:**

| 类型                               | 说明                   |
| ---------------------------------- | ---------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |

C
cff-gite 已提交
2740 2741 2742 2743 2744 2745 2746 2747
**错误码**

以下错误码的详细介绍请参见 [sensor.transformRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2748 2749 2750 2751 2752 2753 2754
**示例:**

```js
try {
    const promise = sensor.transformRotationMatrix([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
    promise.then((data) => {
        for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2755
            console.info('transformRotationMatrix  data[' + i + '] = ' + data[i]);
C
cff-gite 已提交
2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779
        }
    }).catch((err) => {
           console.info("Operation failed");
})
} catch (err) {
        console.error('transformRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

## sensor.getQuaternion<sup>9+</sup> 

getQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback<Array&lt;number&gt;>): void 

将旋转向量转换为归一化四元数。

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

**参数:** 

| 参数名         | 类型                                     | 必填 | 说明           |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt;                      | 是   | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回四元数。   |

C
cff-gite 已提交
2780 2781 2782 2783 2784 2785 2786 2787
**错误码**

以下错误码的详细介绍请参见 [sensor.getQuaternion错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2788 2789 2790 2791 2792 2793
**示例:**

```js
try {
    sensor.getQuaternion ([0.20046076, 0.21907, 0.73978853, 0.60376877], function(data)  {
      for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2794
          console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821
      }
  })
} catch (err) {
        console.error('getQuaternion failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

## sensor.getQuaternion<sup>9+</sup>

getQuaternion(rotationVector: Array&lt;number&gt;): Promise<Array&lt;number&gt;> 

将旋转向量转换为归一化四元数。

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt; | 是   | 表示旋转矢量。 |

**返回值:**

| 类型                               | 说明         |
| ---------------------------------- | ------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |

C
cff-gite 已提交
2822 2823 2824 2825 2826 2827 2828 2829
**错误码**

以下错误码的详细介绍请参见 [sensor.getQuaternion错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2830 2831 2832 2833 2834 2835 2836 2837
**示例:** 

```js
try {
  const promise = sensor.getQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('getQuaternionn_promise successed');
          for (var i=0; i < data.length; i++) {
C
cff-gite 已提交
2838
              console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862
          }
      }).catch((err) => {
          console.info('promise failed');
  })
} catch (err) {
        console.error('getQuaternion failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

## sensor.getOrientation<sup>9+</sup>

getOrientation(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback<Array&lt;number&gt;>): void 

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

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

**参数:**

| 参数名         | 类型                                     | 必填 | 说明                              |
| -------------- | ---------------------------------------- | ---- | --------------------------------- |
| rotationMatrix | Array&lt;number&gt;                      | 是   | 表示旋转矩阵。                    |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 返回围绕z、x、y轴方向的旋转角度。 |

C
cff-gite 已提交
2863 2864 2865 2866 2867 2868 2869 2870
**错误码**

以下错误码的详细介绍请参见 [sensor.getOrientation错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2871 2872 2873 2874 2875 2876 2877
**示例:** 

```js
try {
  sensor.getOrientation([1, 0, 0, 0, 1, 0, 0, 0, 1], function(data)  {
      console.info("SensorJsAPI--->Successed to get getOrientation interface get data: " + data);
      for (var i = 1; i < data.length; i++) {
C
cff-gite 已提交
2878
          console.info('sensor_getOrientation_callback ' + data[i]);
C
cff-gite 已提交
2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
      }
  })
} catch (err) {
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

## sensor.getOrientation<sup>9+</sup>

getOrientation(rotationMatrix: Array&lt;number&gt;): Promise<Array&lt;number&gt;> 

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

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
| rotationMatrix | Array&lt;number&gt; | 是   | 表示旋转矩阵。 |

**返回值:**

| 类型                               | 说明                              |
| ---------------------------------- | --------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |

C
cff-gite 已提交
2906 2907 2908 2909 2910 2911 2912 2913
**错误码**

以下错误码的详细介绍请参见 [sensor.getOrientation错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2914 2915 2916 2917 2918 2919 2920 2921
**示例:** 

```js
try {
  const promise = sensor.getOrientation([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('sensor_getOrientation_Promise success', data);
          for (var i = 1; i < data.length; i++) {
C
cff-gite 已提交
2922
              console.info('sensor_getOrientation_promise ' + data[i]);
C
cff-gite 已提交
2923 2924 2925 2926 2927 2928 2929 2930 2931
          }
      }).catch((err) => {
          console.info('promise failed');
  })
} catch (err) {
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2932
## sensor.getRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947

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

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

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

**参数:** 

| 参数名      | 类型                                                         | 必填 | 说明           |
| ----------- | ------------------------------------------------------------ | ---- | -------------- |
| gravity     | Array&lt;number&gt;                                          | 是   | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt;                                          | 是   | 表示地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是   | 返回旋转矩阵。 |

C
cff-gite 已提交
2948 2949 2950 2951 2952 2953 2954 2955
**错误码**

以下错误码的详细介绍请参见 [sensor.getRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2956 2957 2958 2959 2960
**示例:**

```js
try {
  sensor.getRotationMatrix ([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(data)  {
C
cff-gite 已提交
2961
      console.info('sensor_getRotationMatrix_callback ' + JSON.stringify(data));
C
cff-gite 已提交
2962 2963 2964 2965 2966 2967
  })
} catch (err) {
        console.error('getRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
2968
## sensor.getRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2969

C
cff-gite 已提交
2970
getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
C
cff-gite 已提交
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988

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

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

**参数:** 

| 参数名      | 类型                | 必填 | 说明           |
| ----------- | ------------------- | ---- | -------------- |
| gravity     | Array&lt;number&gt; | 是   | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是   | 表示地磁矢量。 |

**返回值:** 

| 类型                                                         | 说明           |
| ------------------------------------------------------------ | -------------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |

C
cff-gite 已提交
2989 2990 2991 2992 2993 2994 2995 2996
**错误码**

以下错误码的详细介绍请参见 [sensor.getRotationMatrix错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
2997 2998 2999 3000 3001 3002
**示例:** 

```js
try {
  const promise = sensor.getRotationMatrix ([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
C
cff-gite 已提交
3003
          console.info('sensor_getRotationMatrix_callback ' + JSON.stringify(data));
C
cff-gite 已提交
3004 3005 3006 3007 3008 3009 3010 3011
      }).catch((err) => {
          console.info('promise failed');
  })
} catch (err) {
        console.error('getRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

C
cff-gite 已提交
3012
## sensor.getSensorList<sup>9+</sup>
C
cff-gite 已提交
3013

C
cff-gite 已提交
3014
 getSensorList(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
C
cff-gite 已提交
3015

C
cff-gite 已提交
3016
获取设备上的所有传感器信息。
C
cff-gite 已提交
3017

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

C
cff-gite 已提交
3020
**参数:** 
C
cff-gite 已提交
3021

C
cff-gite 已提交
3022 3023 3024
| 参数名   | 类型                                           | 必填 | 说明             |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
Z
zengyawen 已提交
3025

C
cff-gite 已提交
3026 3027 3028 3029 3030 3031 3032 3033
**错误码**

以下错误码的详细介绍请参见 [sensor.getSensorList错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
3034
**示例:** 
Z
zengyawen 已提交
3035

C
cff-gite 已提交
3036
```js
C
cff-gite 已提交
3037 3038
try {
    sensor.getSensorList((data) => {
C
cff-gite 已提交
3039
        console.info('getSensorList callback in ' + data.length);
C
cff-gite 已提交
3040 3041 3042
        for (var i = 0; i < data.length; i++) {
            console.info("getSensorList " + JSON.stringify(data[i]));
        }
C
cff-gite 已提交
3043 3044 3045 3046
    });
} catch (err) {
        console.error('getSensorList failed. Error code: ' + err.code + '; message: ' + err.message);
}
C
cff-gite 已提交
3047
```
Z
zengyawen 已提交
3048

C
cff-gite 已提交
3049
## sensor.getSensorList<sup>9+</sup>
C
cff-gite 已提交
3050

C
cff-gite 已提交
3051 3052 3053
 getSensorList(): Promise< Array&lt;Sensor&gt;>

获取设备上的所有传感器信息。
C
cff-gite 已提交
3054 3055 3056

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

C
cff-gite 已提交
3057
**返回值:** 
C
cff-gite 已提交
3058

C
cff-gite 已提交
3059 3060 3061
| 参数名  | 类型                                     | 必填 | 说明             |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
Z
zengyawen 已提交
3062

C
cff-gite 已提交
3063 3064 3065 3066 3067 3068 3069 3070
**错误码**

以下错误码的详细介绍请参见 [sensor.getSensorList错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

H
HelloCrease 已提交
3071
**示例:** 
C
cff-gite 已提交
3072

C
cff-gite 已提交
3073
```js
C
cff-gite 已提交
3074 3075
try {
    sensor.getSensorList().then((data) => {
C
cff-gite 已提交
3076
        console.info('getSensorList promise in ' + data.length);
C
cff-gite 已提交
3077 3078 3079 3080 3081 3082 3083 3084 3085
        for (var i = 0; i < data.length; i++) {
            console.info("getSensorList " + JSON.stringify(data[i]));
        }
    }, (error)=>{
        console.error('getSensorList failed');
    });
} catch (err) {
        console.error('getSensorList failed. Error code: ' + err.code + '; message: ' + err.message);
}
C
cff-gite 已提交
3086
```
Z
zengyawen 已提交
3087

C
cff-gite 已提交
3088
##  sensor.getSingleSensor<sup>9+</sup>
Z
zengyawen 已提交
3089

C
cff-gite 已提交
3090
getSingleSensor(type: SensorId, callback: AsyncCallback&lt;Sensor&gt;): void
H
h00514358 已提交
3091

C
cff-gite 已提交
3092
获取指定类型的传感器信息。
C
cff-gite 已提交
3093 3094 3095

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

H
HelloCrease 已提交
3096
**参数:** 
C
cff-gite 已提交
3097

C
cff-gite 已提交
3098 3099
| 参数名   | 类型                                    | 必填 | 说明             |
| -------- | --------------------------------------- | ---- | ---------------- |
C
cff-gite 已提交
3100
| type     | [SensorId](#sensorid9)                  | 是   | 传感器类型。     |
C
cff-gite 已提交
3101
| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
H
h00514358 已提交
3102

C
cff-gite 已提交
3103 3104 3105 3106 3107 3108 3109 3110
**错误码**

以下错误码的详细介绍请参见 [sensor.getSingleSensor错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
3111
**示例:**
H
h00514358 已提交
3112

C
cff-gite 已提交
3113
```js
C
cff-gite 已提交
3114 3115
try {
    sensor.getSingleSensor(sensor.SensorId.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) =>     {
C
cff-gite 已提交
3116
        console.info('getSingleSensor ' + JSON.stringify(data));
C
cff-gite 已提交
3117 3118 3119 3120
    });
} catch (err) {
        console.error('getSingleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
}
C
cff-gite 已提交
3121
```
H
h00514358 已提交
3122

C
cff-gite 已提交
3123
##  sensor.getSingleSensor<sup>9+</sup>
H
h00514358 已提交
3124

C
cff-gite 已提交
3125
 getSingleSensor(type: SensorId): Promise&lt;Sensor&gt;
H
h00514358 已提交
3126

C
cff-gite 已提交
3127
获取指定类型的传感器信息。
H
h00514358 已提交
3128

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

C
cff-gite 已提交
3131
**参数:** 
H
h00514358 已提交
3132

C
cff-gite 已提交
3133 3134 3135
| 参数名 | 类型                   | 必填 | 说明         |
| ------ | ---------------------- | ---- | ------------ |
| type   | [SensorId](#sensorid9) | 是   | 传感器类型。 |
Z
zengyawen 已提交
3136

C
cff-gite 已提交
3137
**返回值:** 
Z
zengyawen 已提交
3138

C
cff-gite 已提交
3139 3140 3141
| 参数名  | 类型                              | 必填 | 说明             |
| ------- | --------------------------------- | ---- | ---------------- |
| promise | Promise&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
Z
zengyawen 已提交
3142

C
cff-gite 已提交
3143 3144 3145 3146 3147 3148 3149 3150
**错误码**

以下错误码的详细介绍请参见 [sensor.getSingleSensor错误码](../errorcodes/errorcode-sensor.md)

| 错误码ID | 错误信息           |
| -------- | ------------------ |
| 14500101 | Service exception. |

C
cff-gite 已提交
3151
**示例:**
C
cff-gite 已提交
3152

C
cff-gite 已提交
3153
```js
C
cff-gite 已提交
3154 3155
try {
    sensor.getSingleSensor(sensor.SensorId.SENSOR_TYPE_ID_ACCELEROMETER).then((data) => {
C
cff-gite 已提交
3156
        console.info('getSingleSensor '+ JSON.stringify(data));
C
cff-gite 已提交
3157 3158 3159 3160 3161 3162
    }, (error)=>{
        console.error('getSingleSensor failed');
    });
} catch (err) {
        console.error('getSingleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
}
C
cff-gite 已提交
3163
```
C
cff-gite 已提交
3164

C
cff-gite 已提交
3165
## SensorId<sup>9+</sup>
C
cff-gite 已提交
3166

C
cff-gite 已提交
3167
表示要订阅或取消订阅的传感器类型。
C
cff-gite 已提交
3168

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

C
cff-gite 已提交
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193
| 名称                        | 默认值 | 说明                   |
| --------------------------- | ------ | ---------------------- |
| ACCELEROMETER               | 1      | 加速度传感器。         |
| GYROSCOPE                   | 2      | 陀螺仪传感器。         |
| AMBIENT_LIGHT               | 5      | 环境光传感器。         |
| MAGNETIC_FIELD              | 6      | 磁场传感器。           |
| BAROMETER                   | 8      | 气压计传感器。         |
| HALL                        | 10     | 霍尔传感器。           |
| PROXIMITY                   | 12     | 接近光传感器。         |
| HUMIDITY                    | 13     | 湿度传感器。           |
| ORIENTATION                 | 256    | 方向传感器。           |
| GRAVITY                     | 257    | 重力传感器。           |
| LINEAR_ACCELEROMETER        | 258    | 线性加速度传感器。     |
| ROTATION_VECTOR             | 259    | 旋转矢量传感器。       |
| AMBIENT_TEMPERATURE         | 260    | 环境温度传感器。       |
| MAGNETIC_FIELD_UNCALIBRATED | 261    | 未校准磁场传感器。     |
| GYROSCOPE_UNCALIBRATED      | 263    | 未校准陀螺仪传感器。   |
| SIGNIFICANT_MOTION          | 264    | 有效运动传感器。       |
| PEDOMETER_DETECTION         | 265    | 计步检测传感器。       |
| PEDOMETER                   | 266    | 计步传感器。           |
| HEART_RATE                  | 278    | 心率传感器。           |
| WEAR_DETECTION              | 280    | 佩戴检测传感器。       |
| ACCELEROMETER_UNCALIBRATED  | 281    | 未校准加速度计传感器。 |
Z
zengyawen 已提交
3194

C
cff-gite 已提交
3195
## SensorType<sup>(deprecated)</sup>
Z
zengyawen 已提交
3196

C
cff-gite 已提交
3197
表示要订阅或取消订阅的传感器类型。
Z
zengyawen 已提交
3198

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

C
cff-gite 已提交
3201

C
cff-gite 已提交
3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224
| 名称                                       | 默认值 | 说明                   |
| ------------------------------------------ | ------ | ---------------------- |
| 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         | 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                  | 278    | 心率传感器。           |
| SENSOR_TYPE_ID_WEAR_DETECTION              | 280    | 佩戴检测传感器。       |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED  | 281    | 未校准加速度计传感器。 |
C
cff-gite 已提交
3225

C
cff-gite 已提交
3226

C
cff-gite 已提交
3227
## Response
Z
zengyawen 已提交
3228

C
cff-gite 已提交
3229
传感器数据的时间戳。
Z
zengyawen 已提交
3230

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

C
cff-gite 已提交
3233 3234 3235
| 名称      | 参数类型 | 可读 | 可写 | 说明                     |
| --------- | -------- | ---- | ---- | ------------------------ |
| timestamp | number   | 是   | 是   | 传感器数据上报的时间戳。 |
Z
zengyawen 已提交
3236

C
cff-gite 已提交
3237
## Sensor<sup>9+</sup>
Z
zengyawen 已提交
3238

C
cff-gite 已提交
3239
指示传感器信息。
C
cff-gite 已提交
3240

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

C
cff-gite 已提交
3243 3244
| 名称            | 参数类型 | 说明                   |
| --------------- | -------- | ---------------------- |
C
cff-gite 已提交
3245
| sensorName      | string   | 传感器名称。           |
C
cff-gite 已提交
3246 3247 3248 3249 3250 3251 3252 3253 3254
| venderName      | string   | 传感器供应商。         |
| firmwareVersion | string   | 传感器固件版本。       |
| hardwareVersion | string   | 传感器硬件版本。       |
| sensorId        | number   | 传感器类型id。         |
| maxRange        | number   | 传感器的最大测量范围。 |
| minSamplePeriod | number   | 允许的最小采样周期。   |
| maxSamplePeriod | number   | 允许的最大采样周期。   |
| precision       | number   | 传感器精度。           |
| power           | number   | 传感器电源。           |
C
cff-gite 已提交
3255

C
cff-gite 已提交
3256
## AccelerometerResponse
C
cff-gite 已提交
3257

C
cff-gite 已提交
3258
加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3259

C
cff-gite 已提交
3260
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3261 3262


C
cff-gite 已提交
3263 3264 3265 3266 3267
| 名称 | 参数类型 | 可读 | 可写 | 说明                                 |
| ---- | -------- | ---- | ---- | ------------------------------------ |
| x    | number   | 是   | 是   | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3268 3269


C
cff-gite 已提交
3270
## LinearAccelerometerResponse
C
cff-gite 已提交
3271

C
cff-gite 已提交
3272
线性加速度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3273

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

C
cff-gite 已提交
3276

C
cff-gite 已提交
3277 3278 3279 3280 3281
| 名称 | 参数类型 | 可读 | 可写 | 说明                                     |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | 是   | 是   | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3282

Z
zengyawen 已提交
3283

C
cff-gite 已提交
3284
## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
3285

C
cff-gite 已提交
3286
未校准加速度计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3287

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

C
cff-gite 已提交
3290

C
cff-gite 已提交
3291 3292 3293 3294 3295 3296 3297 3298
| 名称  | 参数类型 | 可读 | 可写 | 说明                                             |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| 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。   |
C
cff-gite 已提交
3299

C
cff-gite 已提交
3300

C
cff-gite 已提交
3301
## GravityResponse
Z
zengyawen 已提交
3302

C
cff-gite 已提交
3303
重力传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3304

C
cff-gite 已提交
3305
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3306 3307


C
cff-gite 已提交
3308 3309 3310 3311 3312
| 名称 | 参数类型 | 可读 | 可写 | 说明                                     |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | 是   | 是   | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3313

C
cff-gite 已提交
3314

C
cff-gite 已提交
3315
## OrientationResponse
C
cff-gite 已提交
3316

C
cff-gite 已提交
3317
方向传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3318

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

Z
zengyawen 已提交
3321

C
cff-gite 已提交
3322 3323 3324 3325 3326
| 名称  | 参数类型 | 可读 | 可写 | 说明                              |
| ----- | -------- | ---- | ---- | --------------------------------- |
| alpha | number   | 是   | 是   | 设备围绕Z轴的旋转角度,单位:度。 |
| beta  | number   | 是   | 是   | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number   | 是   | 是   | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
3327 3328


C
cff-gite 已提交
3329
## RotationVectorResponse
Z
zengyawen 已提交
3330

C
cff-gite 已提交
3331
旋转矢量传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3332

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

C
cff-gite 已提交
3335

C
cff-gite 已提交
3336 3337 3338 3339 3340 3341
| 名称 | 参数类型 | 可读 | 可写 | 说明              |
| ---- | -------- | ---- | ---- | ----------------- |
| x    | number   | 是   | 是   | 旋转矢量x轴分量。 |
| y    | number   | 是   | 是   | 旋转矢量y轴分量。 |
| z    | number   | 是   | 是   | 旋转矢量z轴分量。 |
| w    | number   | 是   | 是   | 标量。            |
C
cff-gite 已提交
3342

C
cff-gite 已提交
3343

C
cff-gite 已提交
3344
## GyroscopeResponse
Z
zengyawen 已提交
3345

C
cff-gite 已提交
3346
陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3347

C
cff-gite 已提交
3348
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3349 3350


C
cff-gite 已提交
3351 3352 3353 3354 3355
| 名称 | 参数类型 | 可读 | 可写 | 说明                             |
| ---- | -------- | ---- | ---- | -------------------------------- |
| x    | number   | 是   | 是   | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number   | 是   | 是   | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number   | 是   | 是   | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
3356

C
cff-gite 已提交
3357

C
cff-gite 已提交
3358
## GyroscopeUncalibratedResponse
C
cff-gite 已提交
3359

C
cff-gite 已提交
3360
未校准陀螺仪传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3361

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

C
cff-gite 已提交
3364

C
cff-gite 已提交
3365 3366 3367 3368 3369 3370 3371 3372
| 名称  | 参数类型 | 可读 | 可写 | 说明                                       |
| ----- | -------- | ---- | ---- | ------------------------------------------ |
| 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 已提交
3373 3374


C
cff-gite 已提交
3375
## SignificantMotionResponse
Z
zengyawen 已提交
3376

C
cff-gite 已提交
3377
有效运动传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3378

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

C
cff-gite 已提交
3381

C
cff-gite 已提交
3382 3383 3384
| 名称   | 参数类型 | 可读 | 可写 | 说明                                                         |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | 是   | 是   | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 |
C
cff-gite 已提交
3385

Z
zengyawen 已提交
3386

C
cff-gite 已提交
3387
## ProximityResponse
C
cff-gite 已提交
3388

C
cff-gite 已提交
3389
接近光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3390

C
cff-gite 已提交
3391
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3392 3393


C
cff-gite 已提交
3394 3395 3396
| 名称     | 参数类型 | 可读 | 可写 | 说明                                                   |
| -------- | -------- | ---- | ---- | ------------------------------------------------------ |
| distance | number   | 是   | 是   | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
3397

C
cff-gite 已提交
3398

C
cff-gite 已提交
3399
## LightResponse
C
cff-gite 已提交
3400

C
cff-gite 已提交
3401
环境光传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3402

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

Z
zengyawen 已提交
3405

C
cff-gite 已提交
3406 3407 3408
| 名称      | 参数类型 | 可读 | 可写 | 说明                   |
| --------- | -------- | ---- | ---- | ---------------------- |
| intensity | number   | 是   | 是   | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
3409 3410


C
cff-gite 已提交
3411
## HallResponse
Z
zengyawen 已提交
3412

C
cff-gite 已提交
3413
霍尔传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3414

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

C
cff-gite 已提交
3417

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

Z
zengyawen 已提交
3422

C
cff-gite 已提交
3423
## MagneticFieldResponse
Z
zengyawen 已提交
3424

C
cff-gite 已提交
3425
磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3426

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

C
cff-gite 已提交
3429

C
cff-gite 已提交
3430 3431 3432 3433 3434
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
C
cff-gite 已提交
3435

C
cff-gite 已提交
3436

C
cff-gite 已提交
3437
## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
3438

C
cff-gite 已提交
3439
未校准磁场传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3440

C
cff-gite 已提交
3441
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3442 3443


C
cff-gite 已提交
3444 3445 3446 3447 3448 3449 3450 3451
| 名称  | 参数类型 | 可读 | 可写 | 说明                                   |
| ----- | -------- | ---- | ---- | -------------------------------------- |
| 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 已提交
3452 3453


C
cff-gite 已提交
3454
## PedometerResponse
C
cff-gite 已提交
3455

C
cff-gite 已提交
3456
计步传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3457

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

Z
zengyawen 已提交
3460

C
cff-gite 已提交
3461 3462 3463
| 名称  | 参数类型 | 可读 | 可写 | 说明             |
| ----- | -------- | ---- | ---- | ---------------- |
| steps | number   | 是   | 是   | 用户的行走步数。 |
C
cff-gite 已提交
3464

Z
zengyawen 已提交
3465

C
cff-gite 已提交
3466
## HumidityResponse
Z
zengyawen 已提交
3467

C
cff-gite 已提交
3468
湿度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3469

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

C
cff-gite 已提交
3472

C
cff-gite 已提交
3473 3474 3475
| 名称     | 参数类型 | 可读 | 可写 | 说明                                                      |
| -------- | -------- | ---- | ---- | --------------------------------------------------------- |
| humidity | number   | 是   | 是   | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |
C
cff-gite 已提交
3476

C
cff-gite 已提交
3477

C
cff-gite 已提交
3478
## PedometerDetectionResponse
Z
zengyawen 已提交
3479

C
cff-gite 已提交
3480
计步检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3481

C
cff-gite 已提交
3482
**系统能力**:以下各项对应的系统能力均为SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
3483 3484


C
cff-gite 已提交
3485 3486 3487
| 名称   | 参数类型 | 可读 | 可写 | 说明                                                         |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | 是   | 是   | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |
Z
zengyawen 已提交
3488

C
cff-gite 已提交
3489

C
cff-gite 已提交
3490
## AmbientTemperatureResponse
C
cff-gite 已提交
3491

C
cff-gite 已提交
3492
温度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3493

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

C
cff-gite 已提交
3496

C
cff-gite 已提交
3497 3498 3499
| 名称        | 参数类型 | 可读 | 可写 | 说明                       |
| ----------- | -------- | ---- | ---- | -------------------------- |
| temperature | number   | 是   | 是   | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
3500 3501


C
cff-gite 已提交
3502
## BarometerResponse
Z
zengyawen 已提交
3503

C
cff-gite 已提交
3504
气压计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3505

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

C
cff-gite 已提交
3508

C
cff-gite 已提交
3509 3510 3511
| 名称     | 参数类型 | 可读 | 可写 | 说明                     |
| -------- | -------- | ---- | ---- | ------------------------ |
| pressure | number   | 是   | 是   | 压力值(单位:帕斯卡)。 |
C
cff-gite 已提交
3512

Z
zengyawen 已提交
3513

C
cff-gite 已提交
3514
## HeartRateResponse
Z
zengyawen 已提交
3515

C
cff-gite 已提交
3516
心率传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3517

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


C
cff-gite 已提交
3521 3522 3523
| 名称      | 参数类型 | 可读 | 可写 | 说明                                    |
| --------- | -------- | ---- | ---- | --------------------------------------- |
| heartRate | number   | 是   | 是   | 心率值。测量用户的心率数值,单位:bpm。 |
H
h00514358 已提交
3524

C
cff-gite 已提交
3525

C
cff-gite 已提交
3526
## WearDetectionResponse
C
cff-gite 已提交
3527

C
cff-gite 已提交
3528
佩戴检测传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3529

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

H
h00514358 已提交
3532

C
cff-gite 已提交
3533 3534 3535
| 名称  | 参数类型 | 可读 | 可写 | 说明                                             |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| value | number   | 是   | 是   | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
H
h00514358 已提交
3536 3537


C
cff-gite 已提交
3538
## Options
H
h00514358 已提交
3539

C
cff-gite 已提交
3540
设置传感器上报频率。
H
h00514358 已提交
3541

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

C
cff-gite 已提交
3544 3545 3546
| 名称     | 参数类型 | 说明                                        |
| -------- | -------- | ------------------------------------------- |
| interval | number   | 表示传感器的上报频率,默认值为200000000ns。 |
H
h00514358 已提交
3547

C
cff-gite 已提交
3548
## RotationMatrixResponse
H
h00514358 已提交
3549

C
cff-gite 已提交
3550
设置旋转矩阵响应对象。
H
h00514358 已提交
3551

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

C
cff-gite 已提交
3554 3555 3556 3557
| 名称        | 参数类型            | 可读 | 可写 | 说明       |
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | 是   | 是   | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是   | 是   | 倾斜矩阵。 |
Z
zengyawen 已提交
3558 3559


C
cff-gite 已提交
3560
## CoordinatesOptions
C
cff-gite 已提交
3561

C
cff-gite 已提交
3562
设置坐标选项对象。
C
cff-gite 已提交
3563

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

C
cff-gite 已提交
3566 3567 3568 3569
| 名称 | 参数类型 | 可读 | 可写 | 说明        |
| ---- | -------- | ---- | ---- | ----------- |
| x    | number   | 是   | 是   | x坐标方向。 |
| y    | number   | 是   | 是   | y坐标方向。 |
Z
zengyawen 已提交
3570

Z
zengyawen 已提交
3571

C
cff-gite 已提交
3572
## GeomagneticResponse
Z
zengyawen 已提交
3573

C
cff-gite 已提交
3574
设置地磁响应对象,继承于[Response](#response)
Z
zengyawen 已提交
3575

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

C
cff-gite 已提交
3578 3579 3580 3581 3582 3583 3584 3585 3586
| 名称            | 参数类型 | 可读 | 可写 | 说明                                               |
| --------------- | -------- | ---- | ---- | -------------------------------------------------- |
| x               | number   | 是   | 是   | 地磁场的北分量。                                   |
| y               | number   | 是   | 是   | 地磁场的东分量。                                   |
| z               | number   | 是   | 是   | 地磁场的垂直分量。                                 |
| geomagneticDip  | number   | 是   | 是   | 地磁倾角,即地球磁场线与水平面的夹角。             |
| deflectionAngle | number   | 是   | 是   | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number   | 是   | 是   | 地磁场的水平强度。                                 |
| totalIntensity  | number   | 是   | 是   | 地磁场的总强度。                                   |
C
cff-gite 已提交
3587

C
cff-gite 已提交
3588
## LocationOptions
C
cff-gite 已提交
3589

C
cff-gite 已提交
3590
指示地理位置。
C
cff-gite 已提交
3591

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

C
cff-gite 已提交
3594 3595 3596 3597 3598
| 名称      | 参数类型 | 可读 | 可写 | 说明       |
| --------- | -------- | ---- | ---- | ---------- |
| latitude  | number   | 是   | 是   | 纬度。     |
| longitude | number   | 是   | 是   | 经度。     |
| altitude  | number   | 是   | 是   | 海拔高度。 |
Z
zengyawen 已提交
3599

C
cff-gite 已提交
3600
## sensor.on<sup>(deprecated)</sup>
Z
zengyawen 已提交
3601

C
cff-gite 已提交
3602
### ACCELEROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
3603

C
cff-gite 已提交
3604
on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
Z
zengyawen 已提交
3605

C
cff-gite 已提交
3606
监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
3607

C
cff-gite 已提交
3608
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER](#accelerometer9)代替。
C
cff-gite 已提交
3609

L
li-yaoyao777 已提交
3610
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3611 3612 3613

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

H
HelloCrease 已提交
3614
**参数:** 
C
cff-gite 已提交
3615

H
HelloCrease 已提交
3616 3617
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
3618 3619 3620
| type     | [SensorType](#sensortype)                | 是    | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是    | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
3621

H
HelloCrease 已提交
3622
**示例:** 
C
cff-gite 已提交
3623

H
HelloCrease 已提交
3624
  ```js
C
cff-gite 已提交
3625
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
3626 3627 3628
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3629 3630
  },
      {interval: 10000000}
Z
zengyawen 已提交
3631 3632
  );
  ```
Z
zengyawen 已提交
3633

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

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

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

C
cff-gite 已提交
3640
从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELERATION](#linear_accelerometer9)代替。 
C
cff-gite 已提交
3641

C
cff-gite 已提交
3642
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3643 3644 3645

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

H
HelloCrease 已提交
3646
**参数:** 
C
cff-gite 已提交
3647

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

C
cff-gite 已提交
3654
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
3655

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

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

C
cff-gite 已提交
3660
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)代替。
C
cff-gite 已提交
3661

L
li-yaoyao777 已提交
3662
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3663 3664 3665

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

H
HelloCrease 已提交
3666
**参数:** 
C
cff-gite 已提交
3667

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

H
HelloCrease 已提交
3674
**示例:** 
C
cff-gite 已提交
3675 3676
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
3677 3678 3679 3680 3681 3682
      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);
C
cff-gite 已提交
3683 3684
  },
      {interval: 10000000}
Z
zengyawen 已提交
3685 3686
  );
  ```
Z
zengyawen 已提交
3687

C
cff-gite 已提交
3688
### GRAVITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
3689

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

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

C
cff-gite 已提交
3694
从API version 9 开始不再维护,建议使用[sensor.on.GRAVITY](#gravity9)代替。
C
cff-gite 已提交
3695

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

H
HelloCrease 已提交
3698
**参数:** 
C
cff-gite 已提交
3699

C
cff-gite 已提交
3700 3701 3702 3703 3704
| 参数名      | 类型                                       | 必填   | 说明                                    |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。   |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。        |
Z
zengyawen 已提交
3705

H
HelloCrease 已提交
3706
**示例:** 
H
HelloCrease 已提交
3707
  ```js
C
cff-gite 已提交
3708
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
Z
zengyawen 已提交
3709 3710 3711
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3712 3713
  },
      {interval: 10000000}
Z
zengyawen 已提交
3714 3715
  );
  ```
Z
zengyawen 已提交
3716

C
cff-gite 已提交
3717
### GYROSCOPE<sup>(deprecated)</sup>
Z
zengyawen 已提交
3718

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

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

C
cff-gite 已提交
3723
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE](#gyroscope9)代替。
C
cff-gite 已提交
3724

L
li-yaoyao777 已提交
3725
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3726 3727 3728

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

H
HelloCrease 已提交
3729
**参数:** 
C
cff-gite 已提交
3730

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

H
HelloCrease 已提交
3737
**示例:** 
H
HelloCrease 已提交
3738
  ```js
C
cff-gite 已提交
3739
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
Z
zengyawen 已提交
3740 3741 3742
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3743 3744
  },
      {interval: 10000000}
Z
zengyawen 已提交
3745 3746
  );
  ```
Z
zengyawen 已提交
3747

C
cff-gite 已提交
3748
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
3749

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

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

C
cff-gite 已提交
3754
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)代替。
C
cff-gite 已提交
3755

L
li-yaoyao777 已提交
3756
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3757 3758 3759

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

H
HelloCrease 已提交
3760
**参数:** 
C
cff-gite 已提交
3761

H
HelloCrease 已提交
3762 3763
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
3764 3765 3766
| type     | [SensorType](#sensortype)                | 是    | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率。                           |
Z
zengyawen 已提交
3767

H
HelloCrease 已提交
3768
**示例:** 
H
HelloCrease 已提交
3769
  ```js
C
cff-gite 已提交
3770
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
Z
zengyawen 已提交
3771 3772 3773 3774 3775 3776
      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);
C
cff-gite 已提交
3777 3778
  },
      {interval: 10000000}
Z
zengyawen 已提交
3779 3780
  );
  ```
Z
zengyawen 已提交
3781

C
cff-gite 已提交
3782
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
3783

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

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

C
cff-gite 已提交
3788
从API version 9 开始不再维护,建议使用[sensor.on.SIGNIFICANT_MOTION](#significant_motion9) 代替。
C
cff-gite 已提交
3789

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

H
HelloCrease 已提交
3792
**参数:** 
C
cff-gite 已提交
3793

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

H
HelloCrease 已提交
3800
**示例:** 
H
HelloCrease 已提交
3801
  ```js
C
cff-gite 已提交
3802
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
3803
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
3804 3805
  },
      {interval: 10000000}
Z
zengyawen 已提交
3806 3807
  );
  ```
Z
zengyawen 已提交
3808

C
cff-gite 已提交
3809
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
3810

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

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

C
cff-gite 已提交
3815
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)代替。 
C
cff-gite 已提交
3816

C
cff-gite 已提交
3817
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
3818 3819 3820

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

H
HelloCrease 已提交
3821
**参数:** 
C
cff-gite 已提交
3822

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

H
HelloCrease 已提交
3829
**示例:** 
H
HelloCrease 已提交
3830
  ```js
C
cff-gite 已提交
3831
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
3832
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
3833 3834
  },
      {interval: 10000000}
Z
zengyawen 已提交
3835 3836
  );
  ```
Z
zengyawen 已提交
3837

C
cff-gite 已提交
3838
### PEDOMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
3839

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

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

C
cff-gite 已提交
3844
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER](#pedometer9)代替。
C
cff-gite 已提交
3845

C
cff-gite 已提交
3846
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
3847 3848 3849

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

H
HelloCrease 已提交
3850
**参数:** 
C
cff-gite 已提交
3851

C
cff-gite 已提交
3852 3853 3854 3855 3856
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。   |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。          |
Z
zengyawen 已提交
3857

H
HelloCrease 已提交
3858
**示例:** 
H
HelloCrease 已提交
3859
  ```js
C
cff-gite 已提交
3860
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
3861
      console.info('Steps: ' + data.steps);
C
cff-gite 已提交
3862 3863
  },
      {interval: 10000000}
Z
zengyawen 已提交
3864 3865
  );
  ```
Z
zengyawen 已提交
3866

C
cff-gite 已提交
3867
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
Z
zengyawen 已提交
3868

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

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

C
cff-gite 已提交
3873
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)代替。
C
cff-gite 已提交
3874

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

H
HelloCrease 已提交
3877
**参数:** 
C
cff-gite 已提交
3878

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

H
HelloCrease 已提交
3885
**示例:** 
C
cff-gite 已提交
3886

H
HelloCrease 已提交
3887
  ```js
C
cff-gite 已提交
3888
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
3889
      console.info('Temperature: ' + data.temperature);
C
cff-gite 已提交
3890 3891
  },
      {interval: 10000000}
Z
zengyawen 已提交
3892 3893
  );
  ```
Z
zengyawen 已提交
3894

C
cff-gite 已提交
3895
### MAGNETIC_FIELD<sup>(deprecated)</sup>
Z
zengyawen 已提交
3896

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

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

C
cff-gite 已提交
3901
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD](#magnetic_field9)代替。  
C
cff-gite 已提交
3902

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

H
HelloCrease 已提交
3905
**参数:** 
C
cff-gite 已提交
3906

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

H
HelloCrease 已提交
3913
**示例:** 
C
cff-gite 已提交
3914

H
HelloCrease 已提交
3915
  ```js
C
cff-gite 已提交
3916
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
3917 3918 3919
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3920 3921
  },
      {interval: 10000000}
Z
zengyawen 已提交
3922 3923
  );
  ```
Z
zengyawen 已提交
3924

C
cff-gite 已提交
3925
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
3926

C
cff-gite 已提交
3927
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
3928

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

C
cff-gite 已提交
3931
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)代替。 
C
cff-gite 已提交
3932

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

H
HelloCrease 已提交
3935
**参数:** 
C
cff-gite 已提交
3936

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

H
HelloCrease 已提交
3943
**示例:** 
H
HelloCrease 已提交
3944
  ```js
C
cff-gite 已提交
3945
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
Z
zengyawen 已提交
3946 3947 3948 3949 3950 3951
      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);
C
cff-gite 已提交
3952 3953
  },
      {interval: 10000000}
Z
zengyawen 已提交
3954 3955
  );
  ```
Z
zengyawen 已提交
3956

C
cff-gite 已提交
3957
### PROXIMITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
3958

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

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

C
cff-gite 已提交
3963
从API version 9 开始不再维护,建议使用[sensor.on.PROXIMITY](#proximity9)代替。 
C
cff-gite 已提交
3964

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

H
HelloCrease 已提交
3967
**参数:** 
C
cff-gite 已提交
3968

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

H
HelloCrease 已提交
3975
**示例:** 
H
HelloCrease 已提交
3976
  ```js
C
cff-gite 已提交
3977
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
3978
      console.info('Distance: ' + data.distance);
C
cff-gite 已提交
3979 3980
  },
      {interval: 10000000}
Z
zengyawen 已提交
3981 3982
  );
  ```
Z
zengyawen 已提交
3983

C
cff-gite 已提交
3984
### HUMIDITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
3985

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

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

C
cff-gite 已提交
3990
从API version 9 开始不再维护,建议使用[sensor.on.HUMIDITY](#humidity9)代替。  
C
cff-gite 已提交
3991

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

H
HelloCrease 已提交
3994
**参数:** 
C
cff-gite 已提交
3995

C
cff-gite 已提交
3996 3997 3998 3999 4000
| 参数名      | 类型                                       | 必填   | 说明                                     |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。   |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。         |
Z
zengyawen 已提交
4001

H
HelloCrease 已提交
4002
**示例:** 
C
cff-gite 已提交
4003

H
HelloCrease 已提交
4004
  ```js
C
cff-gite 已提交
4005
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
4006
      console.info('Humidity: ' + data.humidity);
C
cff-gite 已提交
4007 4008
  },
      {interval: 10000000}
Z
zengyawen 已提交
4009 4010
  );
  ```
Z
zengyawen 已提交
4011

C
cff-gite 已提交
4012
### BAROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
4013

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

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

C
cff-gite 已提交
4018
从API version 9 开始不再维护,建议使用[sensor.on.BAROMETER](#barometer9)代替。
C
cff-gite 已提交
4019

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

H
HelloCrease 已提交
4022
**参数:** 
C
cff-gite 已提交
4023

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

H
HelloCrease 已提交
4030
**示例:** 
C
cff-gite 已提交
4031

H
HelloCrease 已提交
4032
  ```js
C
cff-gite 已提交
4033
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
4034
      console.info('Atmospheric pressure: ' + data.pressure);
C
cff-gite 已提交
4035 4036
  },
      {interval: 10000000}
Z
zengyawen 已提交
4037 4038
  );
  ```
Z
zengyawen 已提交
4039

C
cff-gite 已提交
4040
### HALL<sup>(deprecated)</sup>
Z
zengyawen 已提交
4041

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

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

C
cff-gite 已提交
4046
从API version 9 开始不再维护,建议使用[sensor.on.HALL](#hall9)代替。
C
cff-gite 已提交
4047

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

H
HelloCrease 已提交
4050
**参数:** 
C
cff-gite 已提交
4051

C
cff-gite 已提交
4052 4053 4054 4055 4056
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
4057

H
HelloCrease 已提交
4058
**示例:** 
H
HelloCrease 已提交
4059
  ```js
C
cff-gite 已提交
4060
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
4061
      console.info('Status: ' + data.status);
C
cff-gite 已提交
4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072
  },
      {interval: 10000000}
  );
  ```

### AMBIENT_LIGHT<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4073
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_LIGHT](#ambient_light9)代替。
C
cff-gite 已提交
4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100

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

**参数:** 

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

**示例:** 

  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
      console.info(' Illumination: ' + data.intensity);
  },
      {interval: 10000000}
  );
  ```

### ORIENTATION<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4101
从API version 9 开始不再维护,建议使用[sensor.on.ORIENTATION](#orientation9)代替。
C
cff-gite 已提交
4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120

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

**参数:** 

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

**示例:** 
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
      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);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4121 4122
  );
  ```
Z
zengyawen 已提交
4123

C
cff-gite 已提交
4124 4125 4126 4127 4128 4129
### HEART_RATE<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4130 4131
从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9)代替。

C
cff-gite 已提交
4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143
**需要权限**:ohos.permission.HEALTH_DATA 

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

**参数:** 

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

### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
4144

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

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

C
cff-gite 已提交
4149
从API version 9 开始不再维护,建议使用[sensor.on.ROTATION_VECTOR](#rotation_vector9)代替。
C
cff-gite 已提交
4150

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

H
HelloCrease 已提交
4153
**参数:** 
C
cff-gite 已提交
4154

C
cff-gite 已提交
4155 4156 4157 4158 4159
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
4160

H
HelloCrease 已提交
4161
**示例:** 
H
HelloCrease 已提交
4162
  ```js
C
cff-gite 已提交
4163 4164 4165 4166 4167 4168 4169
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('Scalar quantity: ' + data.w);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4170 4171
  );
  ```
Z
zengyawen 已提交
4172

C
cff-gite 已提交
4173
### WEAR_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
4174

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

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

C
cff-gite 已提交
4179
从API version 9 开始不再维护,建议使用[sensor.on.WEAR_DETECTION](#wear_detection9)代替。
C
cff-gite 已提交
4180

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

H
HelloCrease 已提交
4183
**参数:** 
C
cff-gite 已提交
4184

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

H
HelloCrease 已提交
4191
**示例:** 
H
HelloCrease 已提交
4192
  ```js
C
cff-gite 已提交
4193 4194 4195 4196
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4197 4198
  );
  ```
Z
zengyawen 已提交
4199

C
cff-gite 已提交
4200
## sensor.once<sup>(deprecated)</sup>
Z
zengyawen 已提交
4201

C
cff-gite 已提交
4202
### ACCELEROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
4203

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

C
cff-gite 已提交
4206 4207
监听加速度传感器的数据变化一次。

C
cff-gite 已提交
4208
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER](#accelerometer9-1)代替。
C
cff-gite 已提交
4209 4210

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4211

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

H
HelloCrease 已提交
4214
**参数:** 
C
cff-gite 已提交
4215

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

H
HelloCrease 已提交
4221
**示例:** 
H
HelloCrease 已提交
4222
  ```js
C
cff-gite 已提交
4223
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
4224 4225 4226
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
4227
    }
Z
zengyawen 已提交
4228 4229
  );
  ```
Z
zengyawen 已提交
4230

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

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

C
cff-gite 已提交
4235
监听线性加速度传感器数据变化一次。
Z
zengyawen 已提交
4236

C
cff-gite 已提交
4237
从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELERATION](#linear_accelerometer9-1)代替。
C
cff-gite 已提交
4238

C
cff-gite 已提交
4239
**需要权限**:ohos.permission.ACCELERATION
C
cff-gite 已提交
4240 4241 4242

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

H
HelloCrease 已提交
4243
**参数:** 
C
cff-gite 已提交
4244

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

C
cff-gite 已提交
4250
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
4251

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

C
cff-gite 已提交
4254
监听未校准加速度传感器的数据变化一次。
Z
zengyawen 已提交
4255

C
cff-gite 已提交
4256
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)代替。
C
cff-gite 已提交
4257 4258

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4259

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

H
HelloCrease 已提交
4262
**参数:** 
C
cff-gite 已提交
4263

H
HelloCrease 已提交
4264 4265
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4266 4267
| type     | [SensorType](#sensortype)                | 是    | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是    | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
Z
zengyawen 已提交
4268

H
HelloCrease 已提交
4269
**示例:** 
C
cff-gite 已提交
4270 4271 4272 4273 4274 4275 4276 4277
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(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);
Z
zengyawen 已提交
4278
    }
Z
zengyawen 已提交
4279 4280
  );
  ```
Z
zengyawen 已提交
4281

C
cff-gite 已提交
4282
### GRAVITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
4283

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

C
cff-gite 已提交
4286
监听重力传感器的数据变化一次。
C
cff-gite 已提交
4287

C
cff-gite 已提交
4288
从API version 9 开始不再维护,建议使用[sensor.once.GRAVITY](#gravity9-1)代替。
C
cff-gite 已提交
4289

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

H
HelloCrease 已提交
4292
**参数:** 
C
cff-gite 已提交
4293

C
cff-gite 已提交
4294 4295 4296 4297
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。         |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
Z
zengyawen 已提交
4298

H
HelloCrease 已提交
4299
**示例:** 
C
cff-gite 已提交
4300 4301 4302 4303 4304 4305 4306 4307
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(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 已提交
4308

C
cff-gite 已提交
4309
### GYROSCOPE<sup>(deprecated)</sup>
C
cff-gite 已提交
4310

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

C
cff-gite 已提交
4313
监听陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4314

C
cff-gite 已提交
4315
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE](#gyroscope9-1)代替。
C
cff-gite 已提交
4316

C
cff-gite 已提交
4317
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4318

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

H
HelloCrease 已提交
4321
**参数:** 
C
cff-gite 已提交
4322

H
HelloCrease 已提交
4323 4324
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4325 4326
| type     | [SensorType](#sensortype)                | 是    | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。       |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是    | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
C
cff-gite 已提交
4327

H
HelloCrease 已提交
4328
**示例:** 
C
cff-gite 已提交
4329 4330 4331 4332 4333 4334 4335 4336
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(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 已提交
4337

C
cff-gite 已提交
4338
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4339

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

C
cff-gite 已提交
4342
监听未校准陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4343

C
cff-gite 已提交
4344
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)代替。
C
cff-gite 已提交
4345

C
cff-gite 已提交
4346
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4347

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

H
HelloCrease 已提交
4350
**参数:** 
C
cff-gite 已提交
4351

H
HelloCrease 已提交
4352 4353
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4354 4355
| type     | [SensorType](#sensortype)                | 是    | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
4356

H
HelloCrease 已提交
4357
**示例:** 
C
cff-gite 已提交
4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(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);
    }
  );
  ```
C
cff-gite 已提交
4369

C
cff-gite 已提交
4370
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4371

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

C
cff-gite 已提交
4374
监听有效运动传感器的数据变化一次。
C
cff-gite 已提交
4375

C
cff-gite 已提交
4376
从API version 9 开始不再维护,建议使用[sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)代替。
C
cff-gite 已提交
4377

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

H
HelloCrease 已提交
4380
**参数:** 
C
cff-gite 已提交
4381

H
HelloCrease 已提交
4382 4383
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4384 4385
| type     | [SensorType](#sensortype)                | 是    | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是    | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
C
cff-gite 已提交
4386

H
HelloCrease 已提交
4387
**示例:** 
C
cff-gite 已提交
4388 4389 4390 4391 4392 4393
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4394

C
cff-gite 已提交
4395
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4396

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

C
cff-gite 已提交
4399
监听计步检测传感器数据变化一次。
C
cff-gite 已提交
4400

C
cff-gite 已提交
4401
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)代替。
C
cff-gite 已提交
4402

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

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

H
HelloCrease 已提交
4407
**参数:** 
C
cff-gite 已提交
4408

H
HelloCrease 已提交
4409 4410
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4411 4412
| type     | [SensorType](#sensortype)                | 是    | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是    | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
C
cff-gite 已提交
4413

H
HelloCrease 已提交
4414
**示例:** 
C
cff-gite 已提交
4415 4416 4417 4418 4419 4420
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4421

C
cff-gite 已提交
4422
### PEDOMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4423

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

C
cff-gite 已提交
4426
监听计步器传感器数据变化一次。
C
cff-gite 已提交
4427

C
cff-gite 已提交
4428
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER](#pedometer9-1)代替。
C
cff-gite 已提交
4429

C
cff-gite 已提交
4430
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
4431 4432 4433

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

H
HelloCrease 已提交
4434
**参数:** 
C
cff-gite 已提交
4435

H
HelloCrease 已提交
4436 4437
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4438 4439
| type     | [SensorType](#sensortype)                | 是    | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。        |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
C
cff-gite 已提交
4440

H
HelloCrease 已提交
4441
**示例:** 
C
cff-gite 已提交
4442 4443 4444 4445 4446 4447
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
      console.info('Steps: ' + data.steps);
    }
  );
  ```
C
cff-gite 已提交
4448

C
cff-gite 已提交
4449
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
C
cff-gite 已提交
4450

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

C
cff-gite 已提交
4453
监听环境温度传感器数据变化一次。
C
cff-gite 已提交
4454

C
cff-gite 已提交
4455
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)代替。
C
cff-gite 已提交
4456 4457 4458

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

H
HelloCrease 已提交
4459
**参数:** 
C
cff-gite 已提交
4460

H
HelloCrease 已提交
4461 4462
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4463 4464
| type     | [SensorType](#sensortype)                | 是    | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是    | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
C
cff-gite 已提交
4465

H
HelloCrease 已提交
4466
**示例:** 
C
cff-gite 已提交
4467 4468 4469 4470 4471 4472
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
      console.info('Temperature: ' + data.temperature);
    }
  );
  ```
C
cff-gite 已提交
4473

C
cff-gite 已提交
4474
### MAGNETIC_FIELD<sup>(deprecated)</sup>
C
cff-gite 已提交
4475

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

C
cff-gite 已提交
4478
监听磁场传感器数据变化一次。
C
cff-gite 已提交
4479

C
cff-gite 已提交
4480
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)代替。
C
cff-gite 已提交
4481

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

H
HelloCrease 已提交
4484
**参数:** 
C
cff-gite 已提交
4485

H
HelloCrease 已提交
4486 4487
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4488 4489
| type     | [SensorType](#sensortype)                | 是    | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。   |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是    | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
C
cff-gite 已提交
4490

H
HelloCrease 已提交
4491
**示例:** 
C
cff-gite 已提交
4492 4493 4494 4495 4496 4497 4498 4499
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(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 已提交
4500

C
cff-gite 已提交
4501
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4502

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

C
cff-gite 已提交
4505
监听未校准磁场传感器数据变化一次。
H
h00514358 已提交
4506

C
cff-gite 已提交
4507
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)代替。
C
cff-gite 已提交
4508 4509 4510

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

H
HelloCrease 已提交
4511
**参数:** 
C
cff-gite 已提交
4512

C
cff-gite 已提交
4513 4514 4515 4516
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是    | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
4517

C
cff-gite 已提交
4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(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);
    }
  );
  ```
H
h00514358 已提交
4530

C
cff-gite 已提交
4531
### PROXIMITY<sup>(deprecated)</sup>
H
h00514358 已提交
4532

C
cff-gite 已提交
4533
once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
H
h00514358 已提交
4534

C
cff-gite 已提交
4535
监听接近光传感器数据变化一次。
H
h00514358 已提交
4536

C
cff-gite 已提交
4537
从API version 9 开始不再维护,建议使用[sensor.once.PROXIMITY](#proximity9-1)代替。
H
h00514358 已提交
4538

C
cff-gite 已提交
4539
**系统能力**:SystemCapability.Sensors.Sensor
H
h00514358 已提交
4540

C
cff-gite 已提交
4541
**参数:** 
H
h00514358 已提交
4542

C
cff-gite 已提交
4543 4544 4545 4546
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。       |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是    | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
H
h00514358 已提交
4547

C
cff-gite 已提交
4548 4549 4550 4551 4552 4553 4554
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
      console.info('Distance: ' + data.distance);
    }
  );
  ```
H
h00514358 已提交
4555

C
cff-gite 已提交
4556
### HUMIDITY<sup>(deprecated)</sup>
C
cff-gite 已提交
4557

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

C
cff-gite 已提交
4560
监听湿度传感器数据变化一次。
C
cff-gite 已提交
4561

C
cff-gite 已提交
4562
从API version 9 开始不再维护,建议使用[sensor.once.HUMIDITY](#humidity9-1)代替。
C
cff-gite 已提交
4563

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

H
HelloCrease 已提交
4566
**参数:** 
C
cff-gite 已提交
4567

H
HelloCrease 已提交
4568 4569
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4570 4571
| type     | [SensorType](#sensortype)                | 是    | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。         |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
C
cff-gite 已提交
4572

H
HelloCrease 已提交
4573
**示例:** 
C
cff-gite 已提交
4574 4575 4576 4577 4578 4579
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
  ```
C
cff-gite 已提交
4580

C
cff-gite 已提交
4581
### BAROMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4582

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

C
cff-gite 已提交
4585
监听气压计传感器数据变化一次。
H
h00514358 已提交
4586

C
cff-gite 已提交
4587
从API version 9 开始不再维护,建议使用[sensor.once.BAROMETER](#barometer9-1)代替。
C
cff-gite 已提交
4588 4589 4590

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

H
HelloCrease 已提交
4591
**参数:** 
C
cff-gite 已提交
4592

H
HelloCrease 已提交
4593 4594
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4595 4596
| type     | [SensorType](#sensortype)                | 是    | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。       |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是    | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
C
cff-gite 已提交
4597

C
cff-gite 已提交
4598 4599 4600 4601 4602 4603 4604
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
  ```
H
h00514358 已提交
4605

C
cff-gite 已提交
4606
### HALL<sup>(deprecated)</sup>
H
h00514358 已提交
4607

C
cff-gite 已提交
4608
once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
H
h00514358 已提交
4609

C
cff-gite 已提交
4610 4611
监听霍尔传感器数据变化一次。

C
cff-gite 已提交
4612
从API version 9 开始不再维护,建议使用[sensor.once.HALL](#hall9-1)代替。
H
h00514358 已提交
4613 4614 4615

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

C
cff-gite 已提交
4616
**参数:** 
H
h00514358 已提交
4617

C
cff-gite 已提交
4618 4619 4620 4621
| 参数名      | 类型                                       | 必填   | 说明                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type     | [SensorType](#sensortype)                | 是    | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
H
h00514358 已提交
4622

C
cff-gite 已提交
4623 4624 4625 4626 4627 4628 4629
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
  ```
H
h00514358 已提交
4630

C
cff-gite 已提交
4631
### AMBIENT_LIGHT<sup>(deprecated)</sup>
C
cff-gite 已提交
4632

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

C
cff-gite 已提交
4635
监听环境光传感器数据变化一次。
C
cff-gite 已提交
4636

C
cff-gite 已提交
4637
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_LIGHT](#ambient_light9-1)代替。
C
cff-gite 已提交
4638

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

H
HelloCrease 已提交
4641
**参数:** 
C
cff-gite 已提交
4642

C
cff-gite 已提交
4643 4644 4645 4646
| 参数名      | 类型                                       | 必填   | 说明                                     |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是    | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
C
cff-gite 已提交
4647

H
HelloCrease 已提交
4648
**示例:** 
C
cff-gite 已提交
4649

C
cff-gite 已提交
4650 4651 4652 4653 4654 4655
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
      console.info(' Illumination: ' + data.intensity);
    }
  );
  ```
C
cff-gite 已提交
4656

C
cff-gite 已提交
4657
### ORIENTATION<sup>(deprecated)</sup>
C
cff-gite 已提交
4658

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

C
cff-gite 已提交
4661
监听方向传感器数据变化一次。
C
cff-gite 已提交
4662

C
cff-gite 已提交
4663
从API version 9 开始不再维护,建议使用[sensor.once.ORIENTATION](#orientation9-1)代替。 
C
cff-gite 已提交
4664

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

H
HelloCrease 已提交
4667
**参数:** 
C
cff-gite 已提交
4668

H
HelloCrease 已提交
4669 4670
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4671 4672
| type     | [SensorType](#sensortype)                | 是    | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。      |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是    | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
C
cff-gite 已提交
4673

H
HelloCrease 已提交
4674
**示例:** 
C
cff-gite 已提交
4675 4676 4677 4678 4679 4680 4681 4682
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
      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 已提交
4683

C
cff-gite 已提交
4684
### ROTATION_VECTOR<sup>(deprecated)</sup>
C
cff-gite 已提交
4685

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

C
cff-gite 已提交
4688
监听旋转矢量传感器数据变化一次。
C
cff-gite 已提交
4689

C
cff-gite 已提交
4690
从API version 9 开始不再维护,建议使用[sensor.once.ROTATION_VECTOR](#rotation_vector9-1)代替。  
C
cff-gite 已提交
4691

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

H
HelloCrease 已提交
4694
**参数:** 
C
cff-gite 已提交
4695

H
HelloCrease 已提交
4696 4697
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4698 4699
| type     | [SensorType](#sensortype)                | 是    | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
C
cff-gite 已提交
4700

H
HelloCrease 已提交
4701
**示例:** 
C
cff-gite 已提交
4702 4703 4704 4705 4706 4707 4708 4709 4710
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('Scalar quantity: ' + data.w);
    }
  );
  ```
C
cff-gite 已提交
4711

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

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

C
cff-gite 已提交
4716
监听心率传感器数据变化一次。
C
cff-gite 已提交
4717

C
cff-gite 已提交
4718 4719
从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9-1)代替。

C
cff-gite 已提交
4720
**需要权限**:ohos.permission.HEART_RATE  
C
cff-gite 已提交
4721

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

H
HelloCrease 已提交
4724
**参数:** 
C
cff-gite 已提交
4725

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

C
cff-gite 已提交
4731
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4732

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

C
cff-gite 已提交
4735
监听佩戴检测传感器数据变化一次。
C
cff-gite 已提交
4736

C
cff-gite 已提交
4737
从API version 9 开始不再维护,建议使用[sensor.once.WEAR_DETECTION](#wear_detection9-1)代替。  
C
cff-gite 已提交
4738

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

H
HelloCrease 已提交
4741
**参数:** 
C
cff-gite 已提交
4742

H
HelloCrease 已提交
4743 4744
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4745 4746
| type     | [SensorType](#sensortype)                | 是    | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是    | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
C
cff-gite 已提交
4747

H
HelloCrease 已提交
4748
**示例:** 
C
cff-gite 已提交
4749 4750 4751 4752 4753 4754
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
    }
  );
  ```
C
cff-gite 已提交
4755

C
cff-gite 已提交
4756
## sensor.off<sup>(deprecated)</sup>
C
cff-gite 已提交
4757

C
cff-gite 已提交
4758
### ACCELEROMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4759

C
cff-gite 已提交
4760
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
C
cff-gite 已提交
4761 4762 4763

取消订阅传感器数据。

C
cff-gite 已提交
4764
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER](#accelerometer9-2)代替。  
C
cff-gite 已提交
4765 4766

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4767

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

H
HelloCrease 已提交
4770
**参数:** 
C
cff-gite 已提交
4771

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

H
HelloCrease 已提交
4777
**示例:** 
C
cff-gite 已提交
4778

H
HelloCrease 已提交
4779
```js
C
cff-gite 已提交
4780
function callback(data) {
C
cff-gite 已提交
4781
    console.info('x-coordinate component: ' + data.x);
C
cff-gite 已提交
4782 4783 4784
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
C
cff-gite 已提交
4785
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
C
cff-gite 已提交
4786 4787
```

C
cff-gite 已提交
4788
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4789

C
cff-gite 已提交
4790
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
4791 4792 4793

取消订阅传感器数据。

C
cff-gite 已提交
4794
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)代替。 
C
cff-gite 已提交
4795 4796

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4797

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

H
HelloCrease 已提交
4800
**参数:** 
C
cff-gite 已提交
4801

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

H
HelloCrease 已提交
4807
**示例:** 
C
cff-gite 已提交
4808

H
HelloCrease 已提交
4809
```js
C
cff-gite 已提交
4810
function callback(data) {
C
cff-gite 已提交
4811 4812 4813 4814 4815 4816
    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);
C
cff-gite 已提交
4817
}
C
cff-gite 已提交
4818
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
C
cff-gite 已提交
4819 4820
```

C
cff-gite 已提交
4821
### AMBIENT_LIGHT<sup>(deprecated)</sup>
C
cff-gite 已提交
4822

C
cff-gite 已提交
4823
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
4824 4825 4826

取消订阅传感器数据。

C
cff-gite 已提交
4827
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_LIGHT](#ambient_light9-2)代替。 
C
cff-gite 已提交
4828

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

H
HelloCrease 已提交
4831
**参数:** 
C
cff-gite 已提交
4832

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

H
HelloCrease 已提交
4838
**示例:** 
C
cff-gite 已提交
4839

H
HelloCrease 已提交
4840
```js
C
cff-gite 已提交
4841 4842
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
C
cff-gite 已提交
4843
}
C
cff-gite 已提交
4844
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
C
cff-gite 已提交
4845
```
Z
zengyawen 已提交
4846

C
cff-gite 已提交
4847
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
Z
zengyawen 已提交
4848

C
cff-gite 已提交
4849
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
Z
zengyawen 已提交
4850

C
cff-gite 已提交
4851
取消订阅传感器数据。
Z
zengyawen 已提交
4852

C
cff-gite 已提交
4853
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)代替。 
C
cff-gite 已提交
4854

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

H
HelloCrease 已提交
4857
**参数:** 
Z
zengyawen 已提交
4858

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

H
HelloCrease 已提交
4864
**示例:** 
Z
zengyawen 已提交
4865

H
HelloCrease 已提交
4866
```js
C
cff-gite 已提交
4867 4868 4869
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
C
cff-gite 已提交
4870
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
H
HelloCrease 已提交
4871
```
Z
zengyawen 已提交
4872

C
cff-gite 已提交
4873
### BAROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
4874

C
cff-gite 已提交
4875
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
Z
zengyawen 已提交
4876

C
cff-gite 已提交
4877 4878
取消订阅传感器数据。

C
cff-gite 已提交
4879
从API version 9 开始不再维护,建议使用[sensor.off.BAROMETER](#barometer9-2)代替。 
C
cff-gite 已提交
4880

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

H
HelloCrease 已提交
4883
**参数:** 
Z
zengyawen 已提交
4884

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

H
HelloCrease 已提交
4890
**示例:** 
Z
zengyawen 已提交
4891

H
HelloCrease 已提交
4892
```js
C
cff-gite 已提交
4893 4894 4895 4896
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
H
HelloCrease 已提交
4897
```
Z
zengyawen 已提交
4898

C
cff-gite 已提交
4899
### GRAVITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
4900

C
cff-gite 已提交
4901
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
4902

C
cff-gite 已提交
4903
取消订阅传感器数据。
Z
zengyawen 已提交
4904

C
cff-gite 已提交
4905
从API version 9 开始不再维护,建议使用[sensor.off.GRAVITY](#gravity9-2)代替。  
C
cff-gite 已提交
4906

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

H
HelloCrease 已提交
4909
**参数:** 
C
cff-gite 已提交
4910

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

H
HelloCrease 已提交
4916
**示例:** 
C
cff-gite 已提交
4917

H
HelloCrease 已提交
4918
```js
C
cff-gite 已提交
4919 4920 4921 4922 4923 4924
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 已提交
4925
```
Z
zengyawen 已提交
4926

C
cff-gite 已提交
4927
### GYROSCOPE<sup>(deprecated)</sup>
Z
zengyawen 已提交
4928

C
cff-gite 已提交
4929
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
Z
zengyawen 已提交
4930

C
cff-gite 已提交
4931 4932
取消订阅传感器数据。

C
cff-gite 已提交
4933
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE](#gyroscope9-2)代替。 
C
cff-gite 已提交
4934 4935

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4936

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

H
HelloCrease 已提交
4939
**参数:** 
C
cff-gite 已提交
4940

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

H
HelloCrease 已提交
4946
**示例:** 
Z
zengyawen 已提交
4947

C
cff-gite 已提交
4948 4949 4950 4951 4952 4953 4954 4955 4956 4957
```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_GYROSCOPE, callback);
```

### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
4958

C
cff-gite 已提交
4959
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
4960

C
cff-gite 已提交
4961
取消订阅传感器数据。
Z
zengyawen 已提交
4962

C
cff-gite 已提交
4963
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)代替。  
C
cff-gite 已提交
4964 4965

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4966

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

H
HelloCrease 已提交
4969
**参数:** 
Z
zengyawen 已提交
4970

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

H
HelloCrease 已提交
4976
**示例:** 
Z
zengyawen 已提交
4977

C
cff-gite 已提交
4978 4979 4980 4981 4982 4983 4984 4985
```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_GYROSCOPE_UNCALIBRATED, callback);
```
Z
zengyawen 已提交
4986

C
cff-gite 已提交
4987
### HALL<sup>(deprecated)</sup>
Z
zengyawen 已提交
4988

C
cff-gite 已提交
4989
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
Z
zengyawen 已提交
4990

C
cff-gite 已提交
4991
取消订阅传感器数据。
Z
zengyawen 已提交
4992

C
cff-gite 已提交
4993
从API version 9 开始不再维护,建议使用[sensor.off.HALL](#hall9-2)代替。 
C
cff-gite 已提交
4994

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

H
HelloCrease 已提交
4997
**参数:** 
Z
zengyawen 已提交
4998

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

H
HelloCrease 已提交
5004
**示例:** 
Z
zengyawen 已提交
5005

C
cff-gite 已提交
5006 5007 5008 5009 5010 5011
```js
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```
Z
zengyawen 已提交
5012

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

C
cff-gite 已提交
5015
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
Z
zengyawen 已提交
5016

C
cff-gite 已提交
5017
取消订阅传感器数据。
Z
zengyawen 已提交
5018

C
cff-gite 已提交
5019 5020
从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9-2)代替。

C
cff-gite 已提交
5021
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
5022

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

H
HelloCrease 已提交
5025
**参数:** 
Z
zengyawen 已提交
5026

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

C
cff-gite 已提交
5032
### HUMIDITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
5033

C
cff-gite 已提交
5034
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
Z
zengyawen 已提交
5035

C
cff-gite 已提交
5036
取消订阅传感器数据。
Z
zengyawen 已提交
5037

C
cff-gite 已提交
5038
从API version 9 开始不再维护,建议使用[sensor.off.HUMIDITY](#humidity9-2)代替。 
C
cff-gite 已提交
5039

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

H
HelloCrease 已提交
5042
**参数:** 
Z
zengyawen 已提交
5043

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

H
HelloCrease 已提交
5049
**示例:** 
Z
zengyawen 已提交
5050

C
cff-gite 已提交
5051 5052 5053 5054 5055 5056
```js
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```
Z
zengyawen 已提交
5057

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

C
cff-gite 已提交
5060
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
5061

C
cff-gite 已提交
5062
取消订阅传感器数据。
Z
zengyawen 已提交
5063

C
cff-gite 已提交
5064
从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELERATION](#linear_accelerometer9-2)代替。
C
cff-gite 已提交
5065

C
cff-gite 已提交
5066
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5067

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

H
HelloCrease 已提交
5070
**参数:** 
Z
zengyawen 已提交
5071

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

C
cff-gite 已提交
5077 5078 5079 5080 5081 5082
### MAGNETIC_FIELD<sup>(deprecated)</sup>

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

取消订阅传感器数据。

C
cff-gite 已提交
5083
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)代替。 
C
cff-gite 已提交
5084

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

H
HelloCrease 已提交
5087
**参数:** 
Z
zengyawen 已提交
5088

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

H
HelloCrease 已提交
5094
**示例:** 
Z
zengyawen 已提交
5095

C
cff-gite 已提交
5096 5097 5098 5099 5100 5101 5102 5103
```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_MAGNETIC_FIELD, callback);
```
Z
zengyawen 已提交
5104

C
cff-gite 已提交
5105
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
5106

C
cff-gite 已提交
5107
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
5108

C
cff-gite 已提交
5109
取消订阅传感器数据。
Z
zengyawen 已提交
5110

C
cff-gite 已提交
5111
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)代替。
C
cff-gite 已提交
5112

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

H
HelloCrease 已提交
5115
**参数:** 
Z
zengyawen 已提交
5116

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

H
HelloCrease 已提交
5122
**示例:** 
Z
zengyawen 已提交
5123

C
cff-gite 已提交
5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134
```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);
    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);
```
Z
zengyawen 已提交
5135

C
cff-gite 已提交
5136
### ORIENTATION<sup>(deprecated)</sup>
Z
zengyawen 已提交
5137

C
cff-gite 已提交
5138
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
Z
zengyawen 已提交
5139

C
cff-gite 已提交
5140
取消订阅传感器数据。
Z
zengyawen 已提交
5141

C
cff-gite 已提交
5142
从API version 9 开始不再维护,建议使用[sensor.off.ORIENTATION](#orientation9-2)代替。 
C
cff-gite 已提交
5143

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

H
HelloCrease 已提交
5146
**参数:** 
Z
zengyawen 已提交
5147

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

H
HelloCrease 已提交
5153
**示例:** 
Z
zengyawen 已提交
5154

C
cff-gite 已提交
5155 5156 5157 5158 5159 5160 5161 5162
```js
function callback(data) {
    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);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```
Z
zengyawen 已提交
5163

C
cff-gite 已提交
5164
### PEDOMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
5165

C
cff-gite 已提交
5166
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
5167

C
cff-gite 已提交
5168
取消订阅传感器数据。
Z
zengyawen 已提交
5169

C
cff-gite 已提交
5170
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER](#pedometer9-2)代替。 
Z
zengyawen 已提交
5171

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

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

H
HelloCrease 已提交
5176
**参数:** 
Z
zengyawen 已提交
5177

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

**示例:** 
Z
zengyawen 已提交
5184

C
cff-gite 已提交
5185 5186 5187 5188 5189 5190
```js
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```
Z
zengyawen 已提交
5191

C
cff-gite 已提交
5192
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
5193

C
cff-gite 已提交
5194
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
Z
zengyawen 已提交
5195

C
cff-gite 已提交
5196
取消订阅传感器数据。
Z
zengyawen 已提交
5197

C
cff-gite 已提交
5198
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)代替。 
C
cff-gite 已提交
5199 5200

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

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

H
HelloCrease 已提交
5204
**参数:** 
Z
zengyawen 已提交
5205

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

H
HelloCrease 已提交
5211
**示例:** 
Z
zengyawen 已提交
5212

C
cff-gite 已提交
5213 5214 5215 5216 5217 5218
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```
Z
zengyawen 已提交
5219

C
cff-gite 已提交
5220
### PROXIMITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
5221

C
cff-gite 已提交
5222
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
Z
zengyawen 已提交
5223

C
cff-gite 已提交
5224
取消订阅传感器数据。
Z
zengyawen 已提交
5225

C
cff-gite 已提交
5226
从API version 9 开始不再维护,建议使用[sensor.off.PROXIMITY](#proximity9-2)代替。 
C
cff-gite 已提交
5227

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

H
HelloCrease 已提交
5230
**参数:** 
Z
zengyawen 已提交
5231

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

H
HelloCrease 已提交
5237
**示例:** 
Z
zengyawen 已提交
5238

C
cff-gite 已提交
5239 5240 5241 5242 5243 5244
```js
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```
Z
zengyawen 已提交
5245

C
cff-gite 已提交
5246
### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
5247

C
cff-gite 已提交
5248
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
Z
zengyawen 已提交
5249

C
cff-gite 已提交
5250
取消订阅传感器数据。
Z
zengyawen 已提交
5251

C
cff-gite 已提交
5252
从API version 9 开始不再维护,建议使用[sensor.off.ROTATION_VECTOR](#rotation_vector9-2)代替。 
C
cff-gite 已提交
5253

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

H
HelloCrease 已提交
5256
**参数:** 
Z
zengyawen 已提交
5257

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

H
HelloCrease 已提交
5263
**示例:** 
Z
zengyawen 已提交
5264

C
cff-gite 已提交
5265 5266 5267 5268 5269 5270 5271 5272 5273
```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);
    console.info('Scalar quantity: ' + data.w);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```
Z
zengyawen 已提交
5274

C
cff-gite 已提交
5275
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
5276

C
cff-gite 已提交
5277
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
5278

C
cff-gite 已提交
5279
取消订阅传感器数据。
Z
zengyawen 已提交
5280

C
cff-gite 已提交
5281
从API version 9 开始不再维护,建议使用[sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)代替。
C
cff-gite 已提交
5282

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

H
HelloCrease 已提交
5285
**参数:** 
Z
zengyawen 已提交
5286

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

H
HelloCrease 已提交
5292
**示例:** 
Z
zengyawen 已提交
5293

C
cff-gite 已提交
5294 5295 5296 5297 5298 5299
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
Z
zengyawen 已提交
5300

C
cff-gite 已提交
5301
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
5302

C
cff-gite 已提交
5303
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
5304

C
cff-gite 已提交
5305 5306
取消订阅传感器数据。

C
cff-gite 已提交
5307
从API version 9 开始不再维护,建议使用[sensor.off.WEAR_DETECTION](#wear_detection9-2)代替。 
C
cff-gite 已提交
5308 5309 5310 5311 5312

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

**参数:** 

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

**示例:** 

C
cff-gite 已提交
5320
```js
C
cff-gite 已提交
5321 5322 5323 5324
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
C
cff-gite 已提交
5325 5326
```

C
cff-gite 已提交
5327
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5328

C
cff-gite 已提交
5329
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5330

C
cff-gite 已提交
5331 5332
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
5333
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9)代替。
C
cff-gite 已提交
5334 5335 5336

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

C
cff-gite 已提交
5337
**参数:** 
C
cff-gite 已提交
5338

C
cff-gite 已提交
5339 5340 5341 5342 5343
| 参数名              | 类型                                       | 必填   | 说明          |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。     |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。    |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回转换后的旋转矩阵。 |
C
cff-gite 已提交
5344 5345 5346

**示例:** 

C
cff-gite 已提交
5347
```js
C
cff-gite 已提交
5348 5349 5350 5351 5352 5353 5354 5355 5356 5357
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
    console.info("Operation successed. Data obtained: " + data);
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
C
cff-gite 已提交
5358
```
C
cff-gite 已提交
5359
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5360

C
cff-gite 已提交
5361
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5362

C
cff-gite 已提交
5363
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。
C
cff-gite 已提交
5364

C
cff-gite 已提交
5365
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)代替。
C
cff-gite 已提交
5366 5367 5368 5369 5370

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

**参数:** 

C
cff-gite 已提交
5371 5372 5373 5374
| 参数名              | 类型                                       | 必填   | 说明       |
| ---------------- | ---------------------------------------- | ---- | -------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。  |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。 |
C
cff-gite 已提交
5375

C
cff-gite 已提交
5376 5377 5378 5379 5380 5381 5382
**返回值:** 

| 类型                                 | 说明          |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |

**示例:** 
C
cff-gite 已提交
5383

C
cff-gite 已提交
5384
```js
C
cff-gite 已提交
5385 5386 5387 5388 5389 5390 5391 5392 5393
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
    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");
})
C
cff-gite 已提交
5394 5395
```

C
cff-gite 已提交
5396
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5397

C
cff-gite 已提交
5398
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
C
cff-gite 已提交
5399

C
cff-gite 已提交
5400 5401
获取地球上特定位置的地磁场。

C
cff-gite 已提交
5402
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)代替。
C
cff-gite 已提交
5403 5404 5405 5406 5407

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

**参数:** 

C
cff-gite 已提交
5408 5409 5410 5411 5412
| 参数名          | 类型                                                         | 必填 | 说明                               |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置。                         |
| timeMillis      | number                                                       | 是   | 表示获取磁偏角的时间,单位为毫秒。 |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 返回磁场信息。                     |
C
cff-gite 已提交
5413

C
cff-gite 已提交
5414
**示例:** 
C
cff-gite 已提交
5415
```js
C
cff-gite 已提交
5416 5417 5418 5419 5420 5421 5422 5423
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
C
cff-gite 已提交
5424
});
C
cff-gite 已提交
5425
```
C
cff-gite 已提交
5426
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5427

C
cff-gite 已提交
5428
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
Z
zengyawen 已提交
5429

C
cff-gite 已提交
5430
获取地球上特定位置的地磁场。
Z
zengyawen 已提交
5431

C
cff-gite 已提交
5432
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)代替。
Z
zengyawen 已提交
5433

C
cff-gite 已提交
5434
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5435

C
cff-gite 已提交
5436
**参数:** 
C
cff-gite 已提交
5437

C
cff-gite 已提交
5438 5439 5440 5441
| 参数名             | 类型                                  | 必填   | 说明                |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | 是    | 地理位置。             |
| timeMillis      | number                              | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
C
cff-gite 已提交
5442

C
cff-gite 已提交
5443 5444 5445 5446
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
C
cff-gite 已提交
5447

C
cff-gite 已提交
5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458
**示例:** 
  ```js
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
      promise.then((data) => {
          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);
      }).catch((reason) => {
          console.info('Operation failed.');
  })
  ```
C
cff-gite 已提交
5459

C
cff-gite 已提交
5460
## sensor.getAltitude<sup>(deprecated)</sup>
C
cff-gite 已提交
5461

C
cff-gite 已提交
5462
getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5463

C
cff-gite 已提交
5464
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5465

C
cff-gite 已提交
5466
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9)代替。
Z
zengyawen 已提交
5467

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

C
cff-gite 已提交
5470
**参数:** 
Z
zengyawen 已提交
5471

C
cff-gite 已提交
5472 5473 5474 5475 5476
| 参数名             | 类型                          | 必填   | 说明                   |
| --------------- | --------------------------- | ---- | -------------------- |
| seaPressure     | number                      | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number                      | 是    | 表示设备所在高度的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是    | 返回设备所在的海拔高度,单位为米。    |
Z
zengyawen 已提交
5477

C
cff-gite 已提交
5478
**示例:** 
Z
zengyawen 已提交
5479

C
cff-gite 已提交
5480 5481 5482 5483 5484 5485 5486 5487 5488 5489
  ```js
  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);
  });
  ```
Z
zengyawen 已提交
5490

C
cff-gite 已提交
5491
## sensor.getAltitude<sup>(deprecated)</sup>
Z
zengyawen 已提交
5492

C
cff-gite 已提交
5493
getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
C
cff-gite 已提交
5494

C
cff-gite 已提交
5495
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5496

C
cff-gite 已提交
5497
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)代替。
Z
zengyawen 已提交
5498

C
cff-gite 已提交
5499
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5500

C
cff-gite 已提交
5501
**参数:** 
Z
zengyawen 已提交
5502

C
cff-gite 已提交
5503 5504 5505 5506
| 参数名             | 类型     | 必填   | 说明                   |
| --------------- | ------ | ---- | -------------------- |
| seaPressure     | number | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number | 是    | 表示设备所在高度的气压值,单位为hPa。 |
Z
zengyawen 已提交
5507

C
cff-gite 已提交
5508
**返回值:** 
C
cff-gite 已提交
5509

C
cff-gite 已提交
5510 5511 5512
| 类型                    | 说明                 |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |
Z
zengyawen 已提交
5513

C
cff-gite 已提交
5514
**示例:** 
Z
zengyawen 已提交
5515

C
cff-gite 已提交
5516 5517 5518 5519 5520 5521 5522 5523
  ```js
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```
Z
zengyawen 已提交
5524

Z
zengyawen 已提交
5525

C
cff-gite 已提交
5526
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5527

C
cff-gite 已提交
5528
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5529

C
cff-gite 已提交
5530
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5531

C
cff-gite 已提交
5532
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9)代替。
Z
zengyawen 已提交
5533

C
cff-gite 已提交
5534
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5535

C
cff-gite 已提交
5536
**参数:** 
Z
zengyawen 已提交
5537

C
cff-gite 已提交
5538 5539 5540 5541
| 参数名               | 类型                          | 必填   | 说明             |
| ----------------- | --------------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt;         | 是    | 表示倾斜矩阵。        |
| callback          | AsyncCallback&lt;number&gt; | 是    | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5542

C
cff-gite 已提交
5543
**示例:** 
C
cff-gite 已提交
5544

C
cff-gite 已提交
5545 5546 5547 5548 5549 5550 5551 5552 5553 5554
  ```js
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + 
                        err.message);
          return;
      }
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
  })
  ```
Z
zengyawen 已提交
5555

C
cff-gite 已提交
5556
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5557

C
cff-gite 已提交
5558
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
Z
zengyawen 已提交
5559

C
cff-gite 已提交
5560
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5561

C
cff-gite 已提交
5562
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9-1)代替。
Z
zengyawen 已提交
5563

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

C
cff-gite 已提交
5566
**参数:** 
Z
zengyawen 已提交
5567

C
cff-gite 已提交
5568 5569 5570
| 参数名               | 类型                  | 必填   | 说明      |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | 是    | 表示倾斜矩阵。 |
Z
zengyawen 已提交
5571

C
cff-gite 已提交
5572
**返回值:** 
Z
zengyawen 已提交
5573

C
cff-gite 已提交
5574 5575 5576
| 类型                    | 说明             |
| --------------------- | -------------- |
| Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5577

C
cff-gite 已提交
5578
**示例:** 
Z
zengyawen 已提交
5579

C
cff-gite 已提交
5580 5581 5582 5583 5584 5585 5586 5587
  ```js
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('getGeomagneticDip_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```
C
cff-gite 已提交
5588

C
cff-gite 已提交
5589
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5590

C
cff-gite 已提交
5591
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5592

C
cff-gite 已提交
5593
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5594

C
cff-gite 已提交
5595
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9)代替。
Z
zengyawen 已提交
5596

C
cff-gite 已提交
5597
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5598

C
cff-gite 已提交
5599
**参数:** 
C
cff-gite 已提交
5600

C
cff-gite 已提交
5601 5602 5603 5604 5605
| 参数名                   | 类型                                       | 必填   | 说明                 |
| --------------------- | ---------------------------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | 是    | 表示当前旋转矩阵。          |
| preRotationMatrix     | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5606

C
cff-gite 已提交
5607
**示例:** 
Z
zengyawen 已提交
5608

C
cff-gite 已提交
5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620
  ```js
  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) {
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5621

Z
zengyawen 已提交
5622

C
cff-gite 已提交
5623
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5624

C
cff-gite 已提交
5625
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5626

C
cff-gite 已提交
5627
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5628

C
cff-gite 已提交
5629
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9-1)代替。
Z
zengyawen 已提交
5630

C
cff-gite 已提交
5631
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5632

C
cff-gite 已提交
5633
**参数:** 
Z
zengyawen 已提交
5634

C
cff-gite 已提交
5635 5636 5637 5638
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
5639

C
cff-gite 已提交
5640
**返回值:** 
C
cff-gite 已提交
5641

C
cff-gite 已提交
5642 5643 5644
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5645

C
cff-gite 已提交
5646
**示例:** 
Z
zengyawen 已提交
5647

C
cff-gite 已提交
5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658
  ```js
  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) => {
          console.info('getAngleModifiy_promise success');
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info("promise::catch", reason);
  })
  ```
Z
zengyawen 已提交
5659

Z
zengyawen 已提交
5660

C
cff-gite 已提交
5661
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5662

C
cff-gite 已提交
5663
createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5664

C
cff-gite 已提交
5665
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5666

C
cff-gite 已提交
5667
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9)代替。
Z
zengyawen 已提交
5668

C
cff-gite 已提交
5669
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5670

C
cff-gite 已提交
5671
**参数:** 
Z
zengyawen 已提交
5672

C
cff-gite 已提交
5673 5674 5675 5676
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
5677

C
cff-gite 已提交
5678
**示例:** 
C
cff-gite 已提交
5679

C
cff-gite 已提交
5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691
  ```js
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5692 5693


C
cff-gite 已提交
5694
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5695

C
cff-gite 已提交
5696
createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
5697

C
cff-gite 已提交
5698
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5699

C
cff-gite 已提交
5700
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)代替。
C
cff-gite 已提交
5701

C
cff-gite 已提交
5702
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5703

C
cff-gite 已提交
5704
**参数:** 
Z
zengyawen 已提交
5705

C
cff-gite 已提交
5706 5707 5708
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
5709

C
cff-gite 已提交
5710
**返回值:** 
Z
zengyawen 已提交
5711

C
cff-gite 已提交
5712 5713 5714
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
5715

C
cff-gite 已提交
5716
**示例:** 
C
cff-gite 已提交
5717

C
cff-gite 已提交
5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728
  ```js
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createRotationMatrix_promise success');
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info("promise::catch", reason);
  })	
  ```
Z
zengyawen 已提交
5729 5730


C
cff-gite 已提交
5731
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5732

C
cff-gite 已提交
5733
createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5734

C
cff-gite 已提交
5735
将旋转矢量转换为四元数。
Z
zengyawen 已提交
5736

C
cff-gite 已提交
5737
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9)代替。
C
cff-gite 已提交
5738

C
cff-gite 已提交
5739
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5740

C
cff-gite 已提交
5741
**参数:** 
Z
zengyawen 已提交
5742

C
cff-gite 已提交
5743 5744 5745 5746
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
5747

C
cff-gite 已提交
5748
**示例:** 
Z
zengyawen 已提交
5749

C
cff-gite 已提交
5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761
  ```js
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5762

C
cff-gite 已提交
5763

C
cff-gite 已提交
5764
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5765

C
cff-gite 已提交
5766
createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
5767

C
cff-gite 已提交
5768
将旋转矢量转换为四元数。
Z
zengyawen 已提交
5769

C
cff-gite 已提交
5770
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9-1)代替。
Z
zengyawen 已提交
5771

C
cff-gite 已提交
5772
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5773

C
cff-gite 已提交
5774
**参数:** 
C
cff-gite 已提交
5775

C
cff-gite 已提交
5776 5777 5778
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
5779

C
cff-gite 已提交
5780
**返回值:** 
Z
zengyawen 已提交
5781

C
cff-gite 已提交
5782 5783 5784
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
5785

C
cff-gite 已提交
5786
**示例:** 
Z
zengyawen 已提交
5787

C
cff-gite 已提交
5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798
  ```js
  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++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```
Z
zengyawen 已提交
5799

C
cff-gite 已提交
5800

C
cff-gite 已提交
5801
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
5802

C
cff-gite 已提交
5803
getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5804

C
cff-gite 已提交
5805
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
5806

C
cff-gite 已提交
5807
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9)代替。
Z
zengyawen 已提交
5808

C
cff-gite 已提交
5809
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5810

C
cff-gite 已提交
5811
**参数:** 
C
cff-gite 已提交
5812

C
cff-gite 已提交
5813 5814 5815 5816
| 参数名            | 类型                                       | 必填   | 说明                 |
| -------------- | ---------------------------------------- | ---- | ------------------ |
| rotationMatrix | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
5817

C
cff-gite 已提交
5818
**示例:** 
Z
zengyawen 已提交
5819

C
cff-gite 已提交
5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832
  ```js
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
      for (var i = 1; i < data.length; i++) {
          console.info("sensor_getDirection_callback" + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5833

Z
zengyawen 已提交
5834

C
cff-gite 已提交
5835
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
5836

C
cff-gite 已提交
5837
getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5838

C
cff-gite 已提交
5839
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
5840

C
cff-gite 已提交
5841
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9-1)代替。
Z
zengyawen 已提交
5842

C
cff-gite 已提交
5843
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5844

C
cff-gite 已提交
5845
**参数:** 
Z
zengyawen 已提交
5846

C
cff-gite 已提交
5847 5848 5849
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | 是    | 表示旋转矩阵。 |
Z
zengyawen 已提交
5850

C
cff-gite 已提交
5851
**返回值:** 
C
cff-gite 已提交
5852

C
cff-gite 已提交
5853 5854 5855
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
5856

C
cff-gite 已提交
5857
**示例:** 
Z
zengyawen 已提交
5858

C
cff-gite 已提交
5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869
  ```js
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('sensor_getAltitude_Promise success', data);
          for (var i = 1; i < data.length; i++) {
              console.info("sensor_getDirection_promise" + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```
Z
zengyawen 已提交
5870 5871


C
cff-gite 已提交
5872
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5873

C
cff-gite 已提交
5874
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
C
cff-gite 已提交
5875

C
cff-gite 已提交
5876
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
5877

C
cff-gite 已提交
5878
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)代替。
Z
zengyawen 已提交
5879

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

C
cff-gite 已提交
5882
**参数:** 
Z
zengyawen 已提交
5883

C
cff-gite 已提交
5884 5885 5886 5887 5888
| 参数名         | 类型                                       | 必填   | 说明      |
| ----------- | ---------------------------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt;                      | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt;                      | 是    | 表示地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
5889

C
cff-gite 已提交
5890
**示例:** 
Z
zengyawen 已提交
5891

C
cff-gite 已提交
5892 5893 5894 5895 5896 5897 5898 5899 5900
  ```js
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
          console.error('error code is: ' + err.code + ', message: ' + err.message);
          return;
      }
      console.info(JSON.stringify(data));
  })
  ```
Z
zengyawen 已提交
5901

C
cff-gite 已提交
5902

C
cff-gite 已提交
5903
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5904

C
cff-gite 已提交
5905
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
Z
zengyawen 已提交
5906

C
cff-gite 已提交
5907
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
5908

C
cff-gite 已提交
5909
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)代替。
Z
zengyawen 已提交
5910

C
cff-gite 已提交
5911
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5912

C
cff-gite 已提交
5913
**参数:** 
C
cff-gite 已提交
5914

C
cff-gite 已提交
5915 5916 5917 5918
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
5919

C
cff-gite 已提交
5920
**返回值:** 
Z
zengyawen 已提交
5921

C
cff-gite 已提交
5922 5923 5924
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |
C
cff-gite 已提交
5925

C
cff-gite 已提交
5926
**示例:** 
C
cff-gite 已提交
5927

C
cff-gite 已提交
5928 5929 5930 5931 5932 5933 5934 5935
  ```js
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
          console.info(JSON.stringify(data));
      }).catch((err) => {
          console.info('promise failed');
  })
  ```