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

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

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

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

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

Z
zengyawen 已提交
17 18

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

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

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

C
cff-gite 已提交
26
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

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

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

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

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

**参数:** 

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

**示例:** 

```js
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}
);
```

C
cff-gite 已提交
56
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

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

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

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

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

**参数:** 

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

**示例:** 

```js
  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}
  );
```

C
cff-gite 已提交
89
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

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

订阅环境光传感器数据。

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

**参数:** 

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

**示例:** 

```js
  sensor.on(sensor.SensorId.AMBIENT_LIGHT,function(data){
      console.info('Illumination: ' + data.intensity);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
115
###  AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

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

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

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

**参数:** 

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

**示例:**

```js
  sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE,function(data){
      console.info('Temperature: ' + data.temperature);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
141
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

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

订阅气压计传感器数据。

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

**参数:**

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

**示例:**

```js
  sensor.on(sensor.SensorId.BAROMETER,function(data){
      console.info('Atmospheric pressure: ' + data.pressure);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
167
###  GRAVITY<sup>9+</sup>
C
cff-gite 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

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

订阅重力传感器数据。

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

**参数:** 

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
195
###  GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

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

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

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

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

**参数:** 

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
225
###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

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

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

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

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

**参数:** 

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
259
###  HALL<sup>9+</sup>
C
cff-gite 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284

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

订阅心率传感器数据。

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

**参数:** 

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

**示例:**

```js
  sensor.on(sensor.SensorId.HALL,function(data){
      console.info('Status: ' + data.status);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
285
###   HEART_RATE<sup>9+</sup>
C
cff-gite 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312

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

订阅心率传感器数据。

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

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

**参数:** 

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

**示例:**

```js
sensor.on(sensor.SensorId.HEART_RATE,function(data){
    console.info('Heart rate: ' + data.heartRate);
},
    {interval: 10000000}
);
```

C
cff-gite 已提交
313
###  HUMIDITY<sup>9+</sup>
C
cff-gite 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

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

订阅湿度传感器数据。

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

**参数:** 

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

**示例:**

```js
  sensor.on(sensor.SensorId.HUMIDITY,function(data){
      console.info('Humidity: ' + data.humidity);
  },
      {interval: 10000000}
  );
```

###  LINEAR_ACCELERATION<sup>9+</sup>

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

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

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

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

**参数:** 

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

**示例:**

```js
  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);
    }
  );
```

C
cff-gite 已提交
369
###  MAGNETIC_FIELD<sup>9+</sup>
C
cff-gite 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396

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

订阅磁场传感器数据。

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

**参数:**

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
397
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

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

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

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

**参数:**

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
429
### ORIENTATION<sup>9+</sup>
C
cff-gite 已提交
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456

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

订阅定向传感器数据。

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

**参数:**

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

**示例:**

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
457
### PEDOMETER<sup>9+</sup>
C
cff-gite 已提交
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

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

订阅计步器传感器数据。

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

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

**参数:**

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

**示例:**

```js
  sensor.on(sensor.SensorId.PEDOMETER,function(data){
      console.info('Steps: ' + data.steps);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
485
### PEDOMETER_DETECTION<sup>9+</sup>
C
cff-gite 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513

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

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

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

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

**参数:**

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

**示例:**

```js
  sensor.on(sensor.SensorId.PEDOMETER_DETECTION,function(data){
      console.info('Scalar data: ' + data.scalar);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
514
### PROXIMITY<sup>9+</sup>
C
cff-gite 已提交
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

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

订阅接近传感器数据。

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

**参数:**

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

**示例:** 

```js
  sensor.on(sensor.SensorId.PROXIMITY,function(data){
      console.info('Distance: ' + data.distance);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
540
### ROTATION_VECTOR<sup>9+</sup>
C
cff-gite 已提交
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569

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

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

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

**参数:**

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

**示例:** 

```js
  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);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
570
### SIGNIFICANT_MOTION<sup>9+</sup>
C
cff-gite 已提交
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596

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

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

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

**参数:** 

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

**示例:** 

```js
  sensor.on(sensor.SensorId.SIGNIFICANT_MOTION,function(data){
      console.info('Scalar data: ' + data.scalar);
  },
      {interval: 10000000}
  );
```

C
cff-gite 已提交
597
###  WEAR_DETECTION<sup>9+</sup>
C
cff-gite 已提交
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625

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

订阅磨损检测传感器数据。

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

**参数:** 

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

**示例:** 

```js
  sensor.on(sensor.SensorId.WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
  },
      {interval: 10000000}
  );
```

## sensor.once

C
cff-gite 已提交
626
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653

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

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

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

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

**参数:** 

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

**示例:** 

```js
  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 已提交
654
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684

once(type: SensorId.ACCELEROMETER_UNCALIBRATED,callback:Callback&lt;AccelerometerUncalibratedResponse&gt;): void

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

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

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

**参数:** 

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

**示例:** 

```js
  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 已提交
685
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708

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

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

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

**参数:** 

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

**示例:** 

```js
 sensor.once(sensor.SensorId.AMBIENT_LIGHT, function(data) {
      console.info('Illumination: ' + data.intensity);
    }
  );
```

C
cff-gite 已提交
709
### AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731

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

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

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

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

**示例:** 

```js
 sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, function(data) {
      console.info('Temperature: ' + data.temperature);
    }
  );
```

C
cff-gite 已提交
732
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754

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

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

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

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

**示例:** 

```js
 sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
```

C
cff-gite 已提交
755
### GRAVITY<sup>9+</sup>
C
cff-gite 已提交
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780

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

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

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

**参数:**

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

**示例:**

```js
 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);
    }
  );
```

C
cff-gite 已提交
781
### GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808

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

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

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

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

**参数:** 

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

**示例:**

```js
 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);
    }
  );
```

C
cff-gite 已提交
809
### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

once(type: 

SensorId.GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;): void

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

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

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

**参数:** 

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

**示例:**

```js
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);
    }
);
```

C
cff-gite 已提交
842
### HALL<sup>9+</sup>
C
cff-gite 已提交
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865

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

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

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

**参数:** 

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

**示例:**

```js
sensor.once(sensor.SensorId.HALL, function(data) {
      console.info('Status: ' + data.status);
    }
);
```

C
cff-gite 已提交
866
### HEART_RATE<sup>9+</sup>
C
cff-gite 已提交
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 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 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 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 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727

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

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

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

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

**参数:** 

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

**示例:**

```js
sensor.once(sensor.SensorId.HEART_BEAT_RATE, function(data) {
      console.info('Heart rate: ' + data.heartRate);
    }
);
```

### HUMIDITY<sup>9+</sup>

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

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

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

**参数:** 

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

**示例:**

```js
sensor.once(sensor.SensorId.HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
);
```

### LINEAR_ACCELERATION<sup>9+</sup>

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

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

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

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

**参数:** 

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

**示例:**

```js
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);
  }
);
```

### MAGNETIC_FIELD<sup>9+</sup>

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

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

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

**参数:**

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

**示例:**

```js
  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);
    }
  );
```

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

once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED,callback:Callback&lt;MagneticFieldUncalibratedResponse&gt;): void

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

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

**参数:**

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

**示例:**

```js
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);
    }
);
```

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

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

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

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

**参数:** 

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

**示例:**

```js
  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);
    }
  );
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
sensor.once(sensor.SensorId.PEDOMETER, function(data) {
    console.info('Steps: ' + data.steps);
  }
);
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function(data) {
    console.info('Scalar data: ' + data.scalar);
  }
);
```

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

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

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

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

**参数:**

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

**示例:**

```js
  sensor.once(sensor.SensorId.PROXIMITY, function(data) {
      console.info('Distance: ' + data.distance);
    }
  );
```

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

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

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

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

**参数:**

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

**示例:** 

```js
  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);
    }
  );
```

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

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

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

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

**参数:**

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

**示例:** 

```js
  sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
```

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

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

订阅一次磨损检测传感器数据。

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

**参数:**

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

**示例:** 

```js
  sensor.once(sensor.SensorId.WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
    }
  );
```

## sensor.off

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

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

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

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

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

**参数:**

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

**示例:**

```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.SensorId.ACCELEROMETER, callback);
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的未校准加速度计传感器类型为ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |

**示例:**

```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.SensorId.ACCELEROMETER_UNCALIBRATED, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                            | 必填 | 说明                                                         |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                           | 是   | 要取消订阅的环境光传感器类型为AMBIENT_LIGHT。                |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 取消注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的环境温度传感器类型为AMBIENT_TEMPERATURE。        |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |

**示例:**

```js
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorId.AMBIENT_TEMPERATURE, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                   | 是   | 要取消订阅的气压计传感器类型为BAROMETER。                    |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |

**示例:**

```js
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorId.BAROMETER, callback);
```

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

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

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

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

**参数:** 

| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                               | 是   | 要取消订阅的重力传感器类型为GRAVITY。                        |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |

**示例:**

```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.SensorId.GRAVITY, callback);
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                   | 是   | 要取消订阅的陀螺仪传感器类型为GYROSCOPE。                    |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |

**示例:**

```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.SensorId.GYROSCOPE, callback);
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的未校准陀螺仪传感器类型为GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |

**示例:**

```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.SensorId.GYROSCOPE_UNCALIBRATED, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                         | 是   | 要取消订阅的霍尔传感器类型为HALL。                           |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 取消注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorId.HALL, callback);
```

### 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](#sensorid)                                   | 是   | 要取消订阅的心率传感器类型为HEART_RATE。                     |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 取消注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |

**示例:**

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

### HUMIDITY<sup>9+</sup> 

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

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

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

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                 | 是   | 要取消订阅的湿度传感器类型为HUMIDITY。                       |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorId.HUMIDITY, callback);
```

### LINEAR_ACCELEROMETER<sup>9+</sup> 

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

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

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

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

**参数:**

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

**示例:**

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

### MAGNETIC_FIELD<sup>9+</sup> 

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的磁场传感器类型为MAGNETIC_FIELD。                 |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |

**示例:**

```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.SensorId.MAGNETIC_FIELD, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的未校准磁场传感器类型为MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |

**示例:**

```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.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                       | 是   | 要取消订阅的方向传感器类型为ORIENTATION。                    |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |

**示例:**

```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.SensorId.ORIENTATION, callback);
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                   | 是   | 要取消订阅的计步传感器类型为PEDOMETER。                      |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorId.PEDOMETER, callback);
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的计步检测传感器类型为PEDOMETER_DETECTION。        |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                   | 是   | 要取消订阅的接近光传感器类型为PROXIMITY。                    |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorId.PROXIMITY, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的旋转矢量传感器类型为ROTATION_VECTOR。            |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |

**示例:**

```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.SensorId.ROTATION_VECTOR, callback);
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的大幅动作传感器类型为SIGNIFICANT_MOTION。         |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |

**示例:**

```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback);
```

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

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

取消订阅磨损检测传感器数据。

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid)                                        | 是   | 要取消订阅的佩戴检测传感器类型为WEAR_DETECTION。             |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |

**示例:**

```js
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorId.WEAR_DETECTION, accCallback);
```

## sensor.on

### ACCELEROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
1728

C
cff-gite 已提交
1729
on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
Z
zengyawen 已提交
1730 1731 1732

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

C
cff-gite 已提交
1733
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer9) 
C
cff-gite 已提交
1734

L
li-yaoyao777 已提交
1735
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1736 1737 1738

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

H
HelloCrease 已提交
1739
**参数:** 
C
cff-gite 已提交
1740

H
HelloCrease 已提交
1741 1742 1743 1744 1745
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。 |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是    | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
1746

H
HelloCrease 已提交
1747
**示例:** 
C
cff-gite 已提交
1748

H
HelloCrease 已提交
1749
  ```js
C
cff-gite 已提交
1750
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
1751
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
1752 1753
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
1754 1755
  },
      {interval: 10000000}
Z
zengyawen 已提交
1756 1757
  );
  ```
Z
zengyawen 已提交
1758

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

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

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

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

L
li-yaoyao777 已提交
1767
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1768 1769 1770

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

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

H
h00514358 已提交
1778
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
1779 1780 1781 1782 1783

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

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

L
li-yaoyao777 已提交
1784
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805

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

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

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

C
cff-gite 已提交
1806
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
1807

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

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

C
cff-gite 已提交
1812
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer_uncalibrated9) 
C
cff-gite 已提交
1813

L
li-yaoyao777 已提交
1814
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
1815 1816 1817

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

H
HelloCrease 已提交
1818
**参数:** 
C
cff-gite 已提交
1819

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

H
HelloCrease 已提交
1826
**示例:** 
H
HelloCrease 已提交
1827
  ```js
C
cff-gite 已提交
1828
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
1829 1830 1831 1832 1833 1834
      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);
1835 1836
  },
      {interval: 10000000}
Z
zengyawen 已提交
1837 1838
  );
  ```
Z
zengyawen 已提交
1839

C
cff-gite 已提交
1840
### GRAVITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
1841

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

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

C
cff-gite 已提交
1846 1847
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gravity9) 

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

H
HelloCrease 已提交
1850
**参数:** 
C
cff-gite 已提交
1851

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

H
HelloCrease 已提交
1858
**示例:** 
H
HelloCrease 已提交
1859
  ```js
C
cff-gite 已提交
1860
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
1861
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
1862 1863
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
1864 1865
  },
      {interval: 10000000}
Z
zengyawen 已提交
1866 1867
  );
  ```
Z
zengyawen 已提交
1868

C
cff-gite 已提交
1869
### GYROSCOPE<sup>(deprecated)</sup>
Z
zengyawen 已提交
1870

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

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

C
cff-gite 已提交
1875 1876
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope9) 

L
li-yaoyao777 已提交
1877
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
1878 1879 1880

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

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

H
HelloCrease 已提交
1888
**示例:** 
H
HelloCrease 已提交
1889
  ```js
C
cff-gite 已提交
1890
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
1891
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
1892 1893
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
1894 1895
  },
      {interval: 10000000}
Z
zengyawen 已提交
1896 1897
  );
  ```
Z
zengyawen 已提交
1898

C
cff-gite 已提交
1899
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
1900

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

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

C
cff-gite 已提交
1905 1906
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope_uncalibrated9) 

L
li-yaoyao777 已提交
1907
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
1908 1909 1910

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

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

H
HelloCrease 已提交
1918
**示例:** 
H
HelloCrease 已提交
1919
  ```js
C
cff-gite 已提交
1920
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
1921
      console.info('X-coordinate component: ' + data.x);
Z
zengyawen 已提交
1922 1923
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
1924
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
1925 1926
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
1927 1928
  },
      {interval: 10000000}
Z
zengyawen 已提交
1929 1930
  );
  ```
Z
zengyawen 已提交
1931

C
cff-gite 已提交
1932
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
1933

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

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

C
cff-gite 已提交
1938 1939
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#significant_motion9) 

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

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

H
HelloCrease 已提交
1949
**示例:** 
H
HelloCrease 已提交
1950
  ```js
C
cff-gite 已提交
1951
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
1952
      console.info('Scalar data: ' + data.scalar);
1953 1954
  },
      {interval: 10000000}
Z
zengyawen 已提交
1955 1956
  );
  ```
Z
zengyawen 已提交
1957

C
cff-gite 已提交
1958
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
1959

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

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

C
cff-gite 已提交
1964 1965
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer_detection9) 

C
cff-gite 已提交
1966
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
1967 1968 1969

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

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

H
HelloCrease 已提交
1977
**示例:** 
H
HelloCrease 已提交
1978
  ```js
C
cff-gite 已提交
1979
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
1980
      console.info('Scalar data: ' + data.scalar);
1981 1982
  },
      {interval: 10000000}
Z
zengyawen 已提交
1983 1984
  );
  ```
Z
zengyawen 已提交
1985

C
cff-gite 已提交
1986
### PEDOMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
1987

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

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

C
cff-gite 已提交
1992 1993
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer9) 

C
cff-gite 已提交
1994
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
1995 1996 1997

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

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

H
HelloCrease 已提交
2005
**示例:** 
H
HelloCrease 已提交
2006
  ```js
C
cff-gite 已提交
2007
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
2008
      console.info('Steps: ' + data.steps);
2009 2010
  },
      {interval: 10000000}
Z
zengyawen 已提交
2011 2012
  );
  ```
Z
zengyawen 已提交
2013

C
cff-gite 已提交
2014
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
Z
zengyawen 已提交
2015

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

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

C
cff-gite 已提交
2020 2021
从API Version9开始该接口不再维护,请使用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_temperature9) 

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

H
HelloCrease 已提交
2024
**参数:** 
C
cff-gite 已提交
2025

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

H
HelloCrease 已提交
2032
**示例:** 
C
cff-gite 已提交
2033

H
HelloCrease 已提交
2034
  ```js
C
cff-gite 已提交
2035
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
2036
      console.info('Temperature: ' + data.temperature);
2037 2038
  },
      {interval: 10000000}
Z
zengyawen 已提交
2039 2040
  );
  ```
Z
zengyawen 已提交
2041

C
cff-gite 已提交
2042
### MAGNETIC_FIELD<sup>(deprecated)</sup>
Z
zengyawen 已提交
2043

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

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

C
cff-gite 已提交
2048 2049
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field9) 

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

H
HelloCrease 已提交
2052
**参数:** 
C
cff-gite 已提交
2053

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

H
HelloCrease 已提交
2060
**示例:** 
H
HelloCrease 已提交
2061
  ```js
C
cff-gite 已提交
2062
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
2063 2064 2065
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
2066 2067
  },
      {interval: 10000000}
Z
zengyawen 已提交
2068 2069
  );
  ```
Z
zengyawen 已提交
2070

C
cff-gite 已提交
2071
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
2072

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

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

C
cff-gite 已提交
2077 2078
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field_uncalibrated9) 

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

H
HelloCrease 已提交
2081
**参数:** 
C
cff-gite 已提交
2082

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

H
HelloCrease 已提交
2089
**示例:** 
H
HelloCrease 已提交
2090
  ```js
C
cff-gite 已提交
2091
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
2092 2093 2094 2095
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
Z
zengyawen 已提交
2096 2097
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
2098 2099
  },
      {interval: 10000000}
Z
zengyawen 已提交
2100 2101
  );
  ```
Z
zengyawen 已提交
2102

C
cff-gite 已提交
2103
### PROXIMITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
2104

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

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

C
cff-gite 已提交
2109 2110
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#proximity9) 

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

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

H
HelloCrease 已提交
2120
**示例:** 
H
HelloCrease 已提交
2121
  ```js
C
cff-gite 已提交
2122
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
2123
      console.info('Distance: ' + data.distance);
2124 2125
  },
      {interval: 10000000}
Z
zengyawen 已提交
2126 2127
  );
  ```
Z
zengyawen 已提交
2128

C
cff-gite 已提交
2129
### HUMIDITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
2130

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

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

C
cff-gite 已提交
2135 2136
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#humidity9) 

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

H
HelloCrease 已提交
2139
**参数:** 
C
cff-gite 已提交
2140

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

H
HelloCrease 已提交
2147
**示例:** 
C
cff-gite 已提交
2148

H
HelloCrease 已提交
2149
  ```js
C
cff-gite 已提交
2150
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
2151
      console.info('Humidity: ' + data.humidity);
2152 2153
  },
      {interval: 10000000}
Z
zengyawen 已提交
2154 2155
  );
  ```
Z
zengyawen 已提交
2156

C
cff-gite 已提交
2157
### BAROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
2158

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

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

C
cff-gite 已提交
2163 2164
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#barometer9) 

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

H
HelloCrease 已提交
2167
**参数:** 
C
cff-gite 已提交
2168

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

H
HelloCrease 已提交
2175
**示例:** 
C
cff-gite 已提交
2176

H
HelloCrease 已提交
2177
  ```js
C
cff-gite 已提交
2178
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
2179
      console.info('Atmospheric pressure: ' + data.pressure);
2180 2181
  },
      {interval: 10000000}
Z
zengyawen 已提交
2182 2183
  );
  ```
Z
zengyawen 已提交
2184

C
cff-gite 已提交
2185
### HALL<sup>(deprecated)</sup>
Z
zengyawen 已提交
2186

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

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

C
cff-gite 已提交
2191 2192
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#hall9) 

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

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

H
HelloCrease 已提交
2202
**示例:** 
H
HelloCrease 已提交
2203
  ```js
C
cff-gite 已提交
2204
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
2205
      console.info('Status: ' + data.status);
2206 2207
  },
      {interval: 10000000}
Z
zengyawen 已提交
2208 2209
  );
  ```
Z
zengyawen 已提交
2210

C
cff-gite 已提交
2211
### AMBIENT_LIGHT<sup>(deprecated)</sup>
Z
zengyawen 已提交
2212

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

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

C
cff-gite 已提交
2217 2218
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_light9) 

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

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

H
HelloCrease 已提交
2228
**示例:** 
C
cff-gite 已提交
2229

H
HelloCrease 已提交
2230
  ```js
C
cff-gite 已提交
2231
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
2232 2233 2234
      console.info(' Illumination: ' + data.intensity);
  },
      {interval: 10000000}
Z
zengyawen 已提交
2235 2236
  );
  ```
Z
zengyawen 已提交
2237

C
cff-gite 已提交
2238
### ORIENTATION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2239

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

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

C
cff-gite 已提交
2244 2245
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#orientation9) 

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

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

H
HelloCrease 已提交
2255
**示例:** 
H
HelloCrease 已提交
2256
  ```js
C
cff-gite 已提交
2257
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
C
cff-gite 已提交
2258 2259 2260
      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);
2261 2262
  },
      {interval: 10000000}
Z
zengyawen 已提交
2263 2264
  );
  ```
Z
zengyawen 已提交
2265

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

C
cff-gite 已提交
2268
on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;, options?: Options): void
C
cff-gite 已提交
2269 2270 2271

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

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

C
cff-gite 已提交
2274
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
2275 2276 2277

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

H
HelloCrease 已提交
2278
**参数:** 
C
cff-gite 已提交
2279

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

H
h00514358 已提交
2285
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311

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

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

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

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

**参数:**

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

**示例:**

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

C
cff-gite 已提交
2312
### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
2313

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

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

C
cff-gite 已提交
2318 2319
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#rotation_vector9) 

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

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

H
HelloCrease 已提交
2329
**示例:** 
H
HelloCrease 已提交
2330
  ```js
C
cff-gite 已提交
2331
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
Z
zengyawen 已提交
2332 2333 2334
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
2335
      console.info('Scalar quantity: ' + data.w);
2336 2337
  },
      {interval: 10000000}
Z
zengyawen 已提交
2338 2339
  );
  ```
Z
zengyawen 已提交
2340

C
cff-gite 已提交
2341
### WEAR_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2342

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

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

C
cff-gite 已提交
2347 2348
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#wear_detection9) 

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

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

H
HelloCrease 已提交
2358
**示例:** 
H
HelloCrease 已提交
2359
  ```js
C
cff-gite 已提交
2360
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
Z
zengyawen 已提交
2361
      console.info('Wear status: ' + data.value);
2362 2363
  },
      {interval: 10000000}
Z
zengyawen 已提交
2364 2365
  );
  ```
Z
zengyawen 已提交
2366

H
HelloCrease 已提交
2367
## sensor.once
Z
zengyawen 已提交
2368

C
cff-gite 已提交
2369
### ACCELEROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
2370

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

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

C
cff-gite 已提交
2375
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer9-1) 
C
cff-gite 已提交
2376

L
li-yaoyao777 已提交
2377
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
2378 2379 2380

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

H
HelloCrease 已提交
2381
**参数:** 
C
cff-gite 已提交
2382

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

H
HelloCrease 已提交
2388
**示例:** 
H
HelloCrease 已提交
2389
  ```js
C
cff-gite 已提交
2390
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
2391 2392 2393
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
2394
    }
Z
zengyawen 已提交
2395 2396
  );
  ```
Z
zengyawen 已提交
2397

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

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

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

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

L
li-yaoyao777 已提交
2406
**需要权限**:ohos.permission.ACCELERATION
C
cff-gite 已提交
2407 2408 2409

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

H
HelloCrease 已提交
2410
**参数:** 
C
cff-gite 已提交
2411

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

H
h00514358 已提交
2417
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
2418 2419 2420

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

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

L
li-yaoyao777 已提交
2423
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442

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

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

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

C
cff-gite 已提交
2443
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
2444

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

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

C
cff-gite 已提交
2449 2450
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer_uncalibrated9-1) 

L
li-yaoyao777 已提交
2451
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
2452 2453 2454

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

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

H
HelloCrease 已提交
2461
**示例:** 
Z
zengyawen 已提交
2462
  ```
C
cff-gite 已提交
2463
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
2464 2465 2466 2467 2468 2469
      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 已提交
2470
    }
Z
zengyawen 已提交
2471 2472
  );
  ```
Z
zengyawen 已提交
2473

C
cff-gite 已提交
2474
### GRAVITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
2475

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

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

C
cff-gite 已提交
2480 2481
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gravity9-1) 

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

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

H
HelloCrease 已提交
2490
**示例:** 
H
HelloCrease 已提交
2491
  ```js
C
cff-gite 已提交
2492
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
Z
zengyawen 已提交
2493 2494 2495
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
2496
    }
Z
zengyawen 已提交
2497 2498
  );
  ```
Z
zengyawen 已提交
2499

C
cff-gite 已提交
2500
### GYROSCOPE<sup>(deprecated)</sup>
Z
zengyawen 已提交
2501

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

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

C
cff-gite 已提交
2506 2507
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope9-1) 

L
li-yaoyao777 已提交
2508
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
2509 2510 2511

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

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

H
HelloCrease 已提交
2518
**示例:** 
H
HelloCrease 已提交
2519
  ```js
C
cff-gite 已提交
2520
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
Z
zengyawen 已提交
2521 2522 2523
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
2524
    }
Z
zengyawen 已提交
2525 2526
  );
  ```
Z
zengyawen 已提交
2527

C
cff-gite 已提交
2528
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
2529

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

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

C
cff-gite 已提交
2534 2535
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope_uncalibrated9-1) 

L
li-yaoyao777 已提交
2536
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
2537 2538 2539

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

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

H
HelloCrease 已提交
2546
**示例:** 
H
HelloCrease 已提交
2547
  ```js
C
cff-gite 已提交
2548
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
2549 2550 2551 2552 2553 2554
      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 已提交
2555
    }
Z
zengyawen 已提交
2556 2557
  );
  ```
Z
zengyawen 已提交
2558

C
cff-gite 已提交
2559
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2560

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

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

C
cff-gite 已提交
2565 2566
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#significant_motion9-1) 

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

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

H
HelloCrease 已提交
2575
**示例:** 
H
HelloCrease 已提交
2576
  ```js
C
cff-gite 已提交
2577
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
Z
zengyawen 已提交
2578
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
2579
    }
Z
zengyawen 已提交
2580 2581
  );
  ```
Z
zengyawen 已提交
2582

C
cff-gite 已提交
2583
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2584

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

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

C
cff-gite 已提交
2589 2590
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer_detection9-1) 

C
cff-gite 已提交
2591
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
2592 2593 2594

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

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

H
HelloCrease 已提交
2601
**示例:** 
H
HelloCrease 已提交
2602
  ```js
C
cff-gite 已提交
2603
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
Z
zengyawen 已提交
2604
      console.info('Scalar data: ' + data.scalar);
Z
zengyawen 已提交
2605
    }
Z
zengyawen 已提交
2606 2607
  );
  ```
Z
zengyawen 已提交
2608

C
cff-gite 已提交
2609
### PEDOMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
2610

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

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

C
cff-gite 已提交
2615 2616
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer9-1) 

C
cff-gite 已提交
2617
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
2618 2619 2620

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

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

H
HelloCrease 已提交
2627
**示例:** 
H
HelloCrease 已提交
2628
  ```js
C
cff-gite 已提交
2629
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
Z
zengyawen 已提交
2630
      console.info('Steps: ' + data.steps);
Z
zengyawen 已提交
2631
    }
Z
zengyawen 已提交
2632 2633
  );
  ```
Z
zengyawen 已提交
2634

C
cff-gite 已提交
2635
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
Z
zengyawen 已提交
2636

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

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

C
cff-gite 已提交
2641 2642
从API Version9开始该接口不再维护,请用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_temperature9-1) 

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

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

H
HelloCrease 已提交
2651
**示例:** 
H
HelloCrease 已提交
2652
  ```js
C
cff-gite 已提交
2653
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
Z
zengyawen 已提交
2654
      console.info('Temperature: ' + data.temperature);
Z
zengyawen 已提交
2655
    }
Z
zengyawen 已提交
2656 2657
  );
  ```
Z
zengyawen 已提交
2658

C
cff-gite 已提交
2659
### MAGNETIC_FIELD<sup>(deprecated)</sup>
Z
zengyawen 已提交
2660

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

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

C
cff-gite 已提交
2665 2666
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field9-1) 

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

H
HelloCrease 已提交
2669
**参数:** 
C
cff-gite 已提交
2670

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

H
HelloCrease 已提交
2676
**示例:** 
H
HelloCrease 已提交
2677
  ```js
C
cff-gite 已提交
2678
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
Z
zengyawen 已提交
2679 2680 2681
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
2682
    }
Z
zengyawen 已提交
2683 2684
  );
  ```
Z
zengyawen 已提交
2685

C
cff-gite 已提交
2686
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
2687

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

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

C
cff-gite 已提交
2692 2693
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field_uncalibrated9-1) 

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

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

H
HelloCrease 已提交
2702
**示例:** 
H
HelloCrease 已提交
2703
  ```js
C
cff-gite 已提交
2704
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
Z
zengyawen 已提交
2705 2706 2707 2708 2709 2710
      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 已提交
2711
    }
Z
zengyawen 已提交
2712 2713
  );
  ```
Z
zengyawen 已提交
2714

C
cff-gite 已提交
2715
### PROXIMITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
2716

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

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

C
cff-gite 已提交
2721 2722
从API Version9开始该接口不再维护,请用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#proximity9-1) 

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

H
HelloCrease 已提交
2725
**参数:** 
C
cff-gite 已提交
2726

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

H
HelloCrease 已提交
2732
**示例:** 
H
HelloCrease 已提交
2733
  ```js
L
li-yaoyao777 已提交
2734
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
Z
zengyawen 已提交
2735
      console.info('Distance: ' + data.distance);
Z
zengyawen 已提交
2736
    }
Z
zengyawen 已提交
2737 2738
  );
  ```
Z
zengyawen 已提交
2739

C
cff-gite 已提交
2740
### HUMIDITY<sup>(deprecated)</sup>
Z
zengyawen 已提交
2741

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

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

C
cff-gite 已提交
2746 2747
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#humidity9-1) 

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

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

H
HelloCrease 已提交
2756
**示例:** 
H
HelloCrease 已提交
2757
  ```js
C
cff-gite 已提交
2758
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
Z
zengyawen 已提交
2759
      console.info('Humidity: ' + data.humidity);
Z
zengyawen 已提交
2760
    }
Z
zengyawen 已提交
2761 2762
  );
  ```
Z
zengyawen 已提交
2763

C
cff-gite 已提交
2764
### BAROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
2765

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

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

C
cff-gite 已提交
2770 2771
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#barometer9-1) 

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

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

H
HelloCrease 已提交
2780
**示例:** 
H
HelloCrease 已提交
2781
  ```js
C
cff-gite 已提交
2782
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
Z
zengyawen 已提交
2783
      console.info('Atmospheric pressure: ' + data.pressure);
Z
zengyawen 已提交
2784
    }
Z
zengyawen 已提交
2785 2786
  );
  ```
Z
zengyawen 已提交
2787

C
cff-gite 已提交
2788
### HALL<sup>(deprecated)</sup>
Z
zengyawen 已提交
2789

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

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

C
cff-gite 已提交
2794 2795
从API Version9开始该接口不再维护,请用  [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#hall9-1) 

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

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

H
HelloCrease 已提交
2804
**示例:** 
H
HelloCrease 已提交
2805
  ```js
C
cff-gite 已提交
2806
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
Z
zengyawen 已提交
2807
      console.info('Status: ' + data.status);
Z
zengyawen 已提交
2808
    }
Z
zengyawen 已提交
2809 2810
  );
  ```
Z
zengyawen 已提交
2811

C
cff-gite 已提交
2812
### AMBIENT_LIGHT<sup>(deprecated)</sup>
Z
zengyawen 已提交
2813

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

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

C
cff-gite 已提交
2818 2819
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_light9-1) 

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

H
HelloCrease 已提交
2822
**参数:** 
C
cff-gite 已提交
2823

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

H
HelloCrease 已提交
2829
**示例:** 
C
cff-gite 已提交
2830

H
HelloCrease 已提交
2831
  ```js
C
cff-gite 已提交
2832
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
2833
      console.info(' Illumination: ' + data.intensity);
Z
zengyawen 已提交
2834
    }
Z
zengyawen 已提交
2835 2836
  );
  ```
Z
zengyawen 已提交
2837

C
cff-gite 已提交
2838
### ORIENTATION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2839

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

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

C
cff-gite 已提交
2844 2845
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#orientation9-1) 

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

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

H
HelloCrease 已提交
2854
**示例:** 
H
HelloCrease 已提交
2855
  ```js
C
cff-gite 已提交
2856
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
C
cff-gite 已提交
2857 2858 2859
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
Z
zengyawen 已提交
2860
    }
Z
zengyawen 已提交
2861 2862
  );
  ```
Z
zengyawen 已提交
2863

C
cff-gite 已提交
2864
### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
2865

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

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

C
cff-gite 已提交
2870 2871
从API Version9开始该接口不再维护,请用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#rotation_vector9-1) 

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

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

H
HelloCrease 已提交
2880
**示例:** 
H
HelloCrease 已提交
2881
  ```js
C
cff-gite 已提交
2882
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
Z
zengyawen 已提交
2883 2884 2885
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
2886
      console.info('Scalar quantity: ' + data.w);
Z
zengyawen 已提交
2887
    }
Z
zengyawen 已提交
2888 2889
  );
  ```
Z
zengyawen 已提交
2890

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

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

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

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

C
cff-gite 已提交
2899
**需要权限**:ohos.permission.HEART_RATE  
C
cff-gite 已提交
2900 2901 2902

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

H
HelloCrease 已提交
2903
**参数:** 
C
cff-gite 已提交
2904

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

H
h00514358 已提交
2910
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
2911 2912 2913

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

H
h00514358 已提交
2914
订阅一次心率传感器数据。
H
h00514358 已提交
2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933

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

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

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

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

C
cff-gite 已提交
2934
### WEAR_DETECTION<sup>(deprecated)</sup>
Z
zengyawen 已提交
2935

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

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

C
cff-gite 已提交
2940 2941
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#wear_detection9-1) 

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

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

H
HelloCrease 已提交
2950
**示例:** 
H
HelloCrease 已提交
2951
  ```js
C
cff-gite 已提交
2952
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
Z
zengyawen 已提交
2953
      console.info("Wear status: "+ data.value);
Z
zengyawen 已提交
2954
    }
Z
zengyawen 已提交
2955 2956
  );
  ```
Z
zengyawen 已提交
2957

H
HelloCrease 已提交
2958 2959
## sensor.off

C
cff-gite 已提交
2960
### ACCELEROMETER<sup>(deprecated)</sup>
Z
zengyawen 已提交
2961

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

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

C
cff-gite 已提交
2966 2967
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer9-2) 

L
li-yaoyao777 已提交
2968
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
2969 2970 2971

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

H
HelloCrease 已提交
2972
**参数:** 
C
cff-gite 已提交
2973

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

H
HelloCrease 已提交
2979
**示例:** 
C
cff-gite 已提交
2980

H
HelloCrease 已提交
2981
```js
C
cff-gite 已提交
2982 2983 2984 2985 2986 2987 2988 2989
function callback(data) {
    console.info('x-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
```

C
cff-gite 已提交
2990
### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
2991

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

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

C
cff-gite 已提交
2996 2997
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#accelerometer_uncalibrated9-2) 

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

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

H
HelloCrease 已提交
3002
**参数:** 
C
cff-gite 已提交
3003

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

H
HelloCrease 已提交
3009
**示例:** 
C
cff-gite 已提交
3010

H
HelloCrease 已提交
3011
```js
C
cff-gite 已提交
3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
```

C
cff-gite 已提交
3023
### AMBIENT_LIGHT<sup>(deprecated)</sup>
C
cff-gite 已提交
3024

C
cff-gite 已提交
3025
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
3026 3027 3028

取消订阅传感器数据。

C
cff-gite 已提交
3029 3030
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_light9-2) 

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

H
HelloCrease 已提交
3033
**参数:** 
C
cff-gite 已提交
3034

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

H
HelloCrease 已提交
3040
**示例:** 
C
cff-gite 已提交
3041

H
HelloCrease 已提交
3042
```js
C
cff-gite 已提交
3043 3044 3045 3046 3047 3048
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

C
cff-gite 已提交
3049
### AMBIENT_TEMPERATURE<sup>(deprecated)</sup>
C
cff-gite 已提交
3050

C
cff-gite 已提交
3051
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
C
cff-gite 已提交
3052 3053 3054

取消订阅传感器数据。

C
cff-gite 已提交
3055 3056
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#ambient_temperature9-2) 

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

H
HelloCrease 已提交
3059
**参数:** 
C
cff-gite 已提交
3060

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

H
HelloCrease 已提交
3066
**示例:** 
C
cff-gite 已提交
3067

H
HelloCrease 已提交
3068
```js
C
cff-gite 已提交
3069 3070 3071 3072 3073 3074
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

C
cff-gite 已提交
3075
### BAROMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
3076

C
cff-gite 已提交
3077
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
C
cff-gite 已提交
3078 3079 3080

取消订阅传感器数据。

C
cff-gite 已提交
3081 3082
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#barometer9-2) 

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

H
HelloCrease 已提交
3085
**参数:** 
C
cff-gite 已提交
3086

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

H
HelloCrease 已提交
3092
**示例:** 
C
cff-gite 已提交
3093

H
HelloCrease 已提交
3094
```js
C
cff-gite 已提交
3095 3096 3097 3098 3099 3100
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

C
cff-gite 已提交
3101
### GRAVITY<sup>(deprecated)</sup>
C
cff-gite 已提交
3102

C
cff-gite 已提交
3103
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
C
cff-gite 已提交
3104 3105 3106

取消订阅传感器数据。

C
cff-gite 已提交
3107 3108
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gravity9-2) 

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

H
HelloCrease 已提交
3111
**参数:** 
C
cff-gite 已提交
3112

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

H
HelloCrease 已提交
3118
**示例:** 
C
cff-gite 已提交
3119

H
HelloCrease 已提交
3120
```js
C
cff-gite 已提交
3121 3122 3123 3124 3125 3126 3127 3128
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);
```

C
cff-gite 已提交
3129
### GYROSCOPE<sup>(deprecated)</sup>
C
cff-gite 已提交
3130

C
cff-gite 已提交
3131
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
C
cff-gite 已提交
3132 3133 3134

取消订阅传感器数据。

C
cff-gite 已提交
3135 3136
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope9-2) 

L
li-yaoyao777 已提交
3137
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3138 3139 3140

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

H
HelloCrease 已提交
3141
**参数:** 
C
cff-gite 已提交
3142

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

H
HelloCrease 已提交
3148
**示例:** 
C
cff-gite 已提交
3149

H
HelloCrease 已提交
3150
```js
C
cff-gite 已提交
3151 3152 3153 3154 3155 3156 3157 3158
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);
```

C
cff-gite 已提交
3159
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
3160

H
HelloCrease 已提交
3161
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
3162 3163 3164

取消订阅传感器数据。

C
cff-gite 已提交
3165 3166
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#gyroscope_uncalibrated9-2) 

L
li-yaoyao777 已提交
3167
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3168 3169 3170

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

H
HelloCrease 已提交
3171
**参数:** 
C
cff-gite 已提交
3172

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

H
HelloCrease 已提交
3178
**示例:** 
C
cff-gite 已提交
3179

H
HelloCrease 已提交
3180
```js
C
cff-gite 已提交
3181 3182 3183 3184 3185 3186 3187 3188
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);
```

C
cff-gite 已提交
3189
### HALL<sup>(deprecated)</sup>
C
cff-gite 已提交
3190

C
cff-gite 已提交
3191
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
C
cff-gite 已提交
3192 3193 3194

取消订阅传感器数据。

C
cff-gite 已提交
3195 3196
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#hall9-2) 

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

H
HelloCrease 已提交
3199
**参数:** 
C
cff-gite 已提交
3200

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

H
HelloCrease 已提交
3206
**示例:** 
C
cff-gite 已提交
3207

H
HelloCrease 已提交
3208
```js
C
cff-gite 已提交
3209 3210 3211 3212 3213 3214
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

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

C
cff-gite 已提交
3217
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
C
cff-gite 已提交
3218 3219 3220

取消订阅传感器数据。

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

C
cff-gite 已提交
3223
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
3224 3225 3226

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

H
HelloCrease 已提交
3227
**参数:** 
C
cff-gite 已提交
3228

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

H
h00514358 已提交
3234
### HEART_BEAT_RATE<sup>9+</sup>
H
h00514358 已提交
3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259

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

取消订阅传感器数据。

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

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

**参数:**

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

**示例:**

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

C
cff-gite 已提交
3260
### HUMIDITY<sup>(deprecated)</sup>
C
cff-gite 已提交
3261

C
cff-gite 已提交
3262
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
C
cff-gite 已提交
3263 3264 3265

取消订阅传感器数据。

C
cff-gite 已提交
3266 3267
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#humidity9-2) 

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

H
HelloCrease 已提交
3270
**参数:** 
C
cff-gite 已提交
3271

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

H
HelloCrease 已提交
3277
**示例:** 
C
cff-gite 已提交
3278

H
HelloCrease 已提交
3279
```js
C
cff-gite 已提交
3280 3281 3282 3283 3284 3285
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

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

C
cff-gite 已提交
3288
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
C
cff-gite 已提交
3289 3290 3291

取消订阅传感器数据。

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

L
li-yaoyao777 已提交
3294
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3295 3296 3297

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

H
HelloCrease 已提交
3298
**参数:** 
C
cff-gite 已提交
3299

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

H
h00514358 已提交
3305
### LINEAR_ACCELEROMETER<sup>9+</sup>
H
h00514358 已提交
3306 3307 3308 3309 3310

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

取消订阅传感器数据。

L
li-yaoyao777 已提交
3311
**需要权限**:ohos.permission.ACCELEROMETER
H
h00514358 已提交
3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332

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

**参数:**

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

**示例:**

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

C
cff-gite 已提交
3333
### MAGNETIC_FIELD<sup>(deprecated)</sup>
C
cff-gite 已提交
3334

C
cff-gite 已提交
3335
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
C
cff-gite 已提交
3336 3337 3338

取消订阅传感器数据。

C
cff-gite 已提交
3339 3340
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field9-2) 

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

H
HelloCrease 已提交
3343
**参数:** 
C
cff-gite 已提交
3344

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

H
HelloCrease 已提交
3350
**示例:** 
C
cff-gite 已提交
3351

H
HelloCrease 已提交
3352
```js
C
cff-gite 已提交
3353 3354 3355 3356 3357 3358 3359 3360
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);
```

C
cff-gite 已提交
3361
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
3362

C
cff-gite 已提交
3363
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
3364 3365 3366

取消订阅传感器数据。

C
cff-gite 已提交
3367 3368
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#magnetic_field_uncalibrated9-2) 

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

H
HelloCrease 已提交
3371
**参数:** 
C
cff-gite 已提交
3372

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

H
HelloCrease 已提交
3378
**示例:** 
C
cff-gite 已提交
3379

H
HelloCrease 已提交
3380
```js
C
cff-gite 已提交
3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391
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);
```

C
cff-gite 已提交
3392
### ORIENTATION<sup>(deprecated)</sup>
C
cff-gite 已提交
3393

C
cff-gite 已提交
3394
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
C
cff-gite 已提交
3395 3396 3397

取消订阅传感器数据。

C
cff-gite 已提交
3398 3399
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#orientation9-2) 

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

H
HelloCrease 已提交
3402
**参数:** 
C
cff-gite 已提交
3403

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

H
HelloCrease 已提交
3409
**示例:** 
C
cff-gite 已提交
3410

H
HelloCrease 已提交
3411
```js
C
cff-gite 已提交
3412
function callback(data) {
C
cff-gite 已提交
3413 3414 3415
    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 已提交
3416 3417 3418 3419
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```

C
cff-gite 已提交
3420
### PEDOMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
3421

C
cff-gite 已提交
3422
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
C
cff-gite 已提交
3423 3424 3425

取消订阅传感器数据。

C
cff-gite 已提交
3426 3427
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer9-2) 

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

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

H
HelloCrease 已提交
3432
**参数:** 
C
cff-gite 已提交
3433

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

H
HelloCrease 已提交
3439
**示例:** 
C
cff-gite 已提交
3440

H
HelloCrease 已提交
3441
```js
C
cff-gite 已提交
3442 3443 3444 3445 3446 3447
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

C
cff-gite 已提交
3448
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
3449

C
cff-gite 已提交
3450
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
C
cff-gite 已提交
3451 3452 3453

取消订阅传感器数据。

C
cff-gite 已提交
3454 3455
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#pedometer_detection9-2) 

C
cff-gite 已提交
3456 3457 3458 3459
**需要权限**:ohos.permission.ACTIVITY_MOTION

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

H
HelloCrease 已提交
3460
**参数:** 
C
cff-gite 已提交
3461

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

H
HelloCrease 已提交
3467
**示例:** 
C
cff-gite 已提交
3468

H
HelloCrease 已提交
3469
```js
C
cff-gite 已提交
3470 3471 3472 3473 3474 3475
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

C
cff-gite 已提交
3476
### PROXIMITY<sup>(deprecated)</sup>
C
cff-gite 已提交
3477

C
cff-gite 已提交
3478
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
C
cff-gite 已提交
3479 3480 3481

取消订阅传感器数据。

C
cff-gite 已提交
3482 3483
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#proximity9-2) 

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

H
HelloCrease 已提交
3486
**参数:** 
C
cff-gite 已提交
3487

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

H
HelloCrease 已提交
3493
**示例:** 
C
cff-gite 已提交
3494

H
HelloCrease 已提交
3495
```js
C
cff-gite 已提交
3496 3497 3498 3499 3500 3501
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```

C
cff-gite 已提交
3502
### ROTATION_VECTOR<sup>(deprecated)</sup>
C
cff-gite 已提交
3503

C
cff-gite 已提交
3504
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
C
cff-gite 已提交
3505 3506 3507

取消订阅传感器数据。

C
cff-gite 已提交
3508 3509
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#rotation_vector9-2) 

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

H
HelloCrease 已提交
3512
**参数:** 
C
cff-gite 已提交
3513

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

H
HelloCrease 已提交
3519
**示例:** 
C
cff-gite 已提交
3520

H
HelloCrease 已提交
3521
```js
C
cff-gite 已提交
3522 3523 3524 3525
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3526
    console.info('Scalar quantity: ' + data.w);
C
cff-gite 已提交
3527 3528 3529 3530
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```

C
cff-gite 已提交
3531
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
C
cff-gite 已提交
3532

C
cff-gite 已提交
3533
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
C
cff-gite 已提交
3534 3535 3536

取消订阅传感器数据。

C
cff-gite 已提交
3537 3538
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#significant_motion9-2) 

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

H
HelloCrease 已提交
3541
**参数:** 
C
cff-gite 已提交
3542

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

H
HelloCrease 已提交
3548
**示例:** 
C
cff-gite 已提交
3549

H
HelloCrease 已提交
3550
```js
C
cff-gite 已提交
3551 3552 3553 3554 3555 3556
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```

C
cff-gite 已提交
3557
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
3558

C
cff-gite 已提交
3559
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
3560 3561 3562

取消订阅传感器数据。

C
cff-gite 已提交
3563 3564
从API Version9开始该接口不再维护,请使用 [zh-cn/application-dev/reference/apis/js-apis-sensor.md · OpenHarmony/docs - Gitee.com](https://gitee.com/openharmony/docs/blob/e6186d7257de339c5ae79e5e1dd23d56139f7ddc/zh-cn/application-dev/reference/apis/js-apis-sensor.md#wear_detection9-2) 

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

H
HelloCrease 已提交
3567
**参数:** 
C
cff-gite 已提交
3568

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

H
HelloCrease 已提交
3574
**示例:** 
C
cff-gite 已提交
3575

H
HelloCrease 已提交
3576
```js
C
cff-gite 已提交
3577 3578 3579 3580 3581
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
Z
zengyawen 已提交
3582

Z
zengyawen 已提交
3583 3584 3585 3586 3587 3588
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
3591
**参数:** 
Z
zengyawen 已提交
3592

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

H
HelloCrease 已提交
3599
**示例:** 
Z
zengyawen 已提交
3600

H
HelloCrease 已提交
3601
```js
C
cff-gite 已提交
3602
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
H
HelloCrease 已提交
3603 3604 3605 3606
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
H
HelloCrease 已提交
3607
    console.info("Operation successed. Data obtained: " + data);
H
HelloCrease 已提交
3608 3609 3610 3611 3612
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
Z
zengyawen 已提交
3613 3614 3615 3616 3617 3618
## sensor.transformCoordinateSystem

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

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

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

H
HelloCrease 已提交
3621
**参数:** 
Z
zengyawen 已提交
3622

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

H
HelloCrease 已提交
3628
**返回值:** 
Z
zengyawen 已提交
3629

H
HelloCrease 已提交
3630 3631 3632
| 类型                                 | 说明          |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回转换后的旋转矩阵。 |
Z
zengyawen 已提交
3633

H
HelloCrease 已提交
3634
**示例:** 
Z
zengyawen 已提交
3635

H
HelloCrease 已提交
3636
```js
C
cff-gite 已提交
3637
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
H
HelloCrease 已提交
3638 3639 3640 3641 3642 3643 3644 3645 3646
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
```
Z
zengyawen 已提交
3647

Z
zengyawen 已提交
3648
## sensor.getGeomagneticField
Z
zengyawen 已提交
3649

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

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

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

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

H
HelloCrease 已提交
3663
**示例:** 
H
HelloCrease 已提交
3664
```js
C
cff-gite 已提交
3665
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
H
HelloCrease 已提交
3666 3667 3668 3669
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
C
cff-gite 已提交
3670
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
H
HelloCrease 已提交
3671 3672 3673 3674
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});
```
Z
zengyawen 已提交
3675 3676 3677 3678 3679 3680
## sensor.getGeomagneticField

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

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

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

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

H
HelloCrease 已提交
3689 3690 3691 3692
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
Z
zengyawen 已提交
3693

H
HelloCrease 已提交
3694
**示例:** 
H
HelloCrease 已提交
3695
  ```js
C
cff-gite 已提交
3696
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
Z
zengyawen 已提交
3697
      promise.then((data) => {
Z
zengyawen 已提交
3698 3699 3700
          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
Z
zengyawen 已提交
3701
      }).catch((reason) => {
Z
zengyawen 已提交
3702 3703
          console.info('Operation failed.');
  })
Z
zengyawen 已提交
3704 3705
  ```

Z
zengyawen 已提交
3706 3707 3708 3709 3710 3711
## sensor.getAltitude

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

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

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

H
HelloCrease 已提交
3714
**参数:** 
Z
zengyawen 已提交
3715

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

H
HelloCrease 已提交
3722
**示例:** 
Z
zengyawen 已提交
3723

H
HelloCrease 已提交
3724
  ```js
Z
zengyawen 已提交
3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740
  sensor.getAltitude(0, 200, function(err, data)  {
      if (err) {
          console.error(
  "Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
          console.info("Successed to get getAltitude interface get data: " + data);
  });
  ```

## sensor.getAltitude

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

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

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

H
HelloCrease 已提交
3743
**参数:** 
Z
zengyawen 已提交
3744

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

H
HelloCrease 已提交
3750
**返回值:** 
Z
zengyawen 已提交
3751

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

H
HelloCrease 已提交
3756
**示例:** 
Z
zengyawen 已提交
3757

H
HelloCrease 已提交
3758
  ```js
Z
zengyawen 已提交
3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```


## sensor.getGeomagneticDip

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

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

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

H
HelloCrease 已提交
3776
**参数:** 
Z
zengyawen 已提交
3777

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

H
HelloCrease 已提交
3783
**示例:** 
Z
zengyawen 已提交
3784

H
HelloCrease 已提交
3785
  ```js
Z
zengyawen 已提交
3786 3787
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
C
cff-gite 已提交
3788
          console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + 
Z
zengyawen 已提交
3789 3790 3791
                        err.message);
          return;
      }
H
HelloCrease 已提交
3792
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
Z
zengyawen 已提交
3793 3794 3795 3796 3797 3798 3799 3800 3801
  })
  ```

## sensor.getGeomagneticDip

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

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

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

H
HelloCrease 已提交
3804
**参数:** 
Z
zengyawen 已提交
3805

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

H
HelloCrease 已提交
3810
**返回值:** 
Z
zengyawen 已提交
3811

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

H
HelloCrease 已提交
3816
**示例:** 
Z
zengyawen 已提交
3817

H
HelloCrease 已提交
3818
  ```js
Z
zengyawen 已提交
3819 3820
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
C
cff-gite 已提交
3821
          console.info('getGeomagneticDip_promise successed', data);
Z
zengyawen 已提交
3822 3823 3824 3825 3826 3827 3828
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

H
HelloCrease 已提交
3829
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
3830 3831 3832

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

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

H
HelloCrease 已提交
3835
**参数:** 
Z
zengyawen 已提交
3836

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

H
HelloCrease 已提交
3843
**示例:** 
Z
zengyawen 已提交
3844

H
HelloCrease 已提交
3845
  ```js
Z
zengyawen 已提交
3846 3847
  sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
3848
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
3849 3850 3851 3852
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
3853
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864
      }
  })
  ```


## sensor. getAngleModify

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

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

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

H
HelloCrease 已提交
3867
**参数:** 
Z
zengyawen 已提交
3868

H
HelloCrease 已提交
3869 3870 3871 3872
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
3873

H
HelloCrease 已提交
3874
**返回值:** 
Z
zengyawen 已提交
3875

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

H
HelloCrease 已提交
3880
**示例:** 
Z
zengyawen 已提交
3881

H
HelloCrease 已提交
3882
  ```js
Z
zengyawen 已提交
3883 3884
  const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
      promise.then((data) => {
H
HelloCrease 已提交
3885
          console.info('getAngleModifiy_promise success');
Z
zengyawen 已提交
3886
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
3887
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
3888 3889
          }
      }).catch((reason) => {
H
HelloCrease 已提交
3890
          console.info("promise::catch", reason);
Z
zengyawen 已提交
3891 3892 3893 3894 3895 3896 3897 3898 3899 3900
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
3903
**参数:** 
Z
zengyawen 已提交
3904

H
HelloCrease 已提交
3905 3906 3907 3908
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
3909

H
HelloCrease 已提交
3910
**示例:** 
Z
zengyawen 已提交
3911

H
HelloCrease 已提交
3912
  ```js
Z
zengyawen 已提交
3913 3914
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
H
HelloCrease 已提交
3915
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
3916 3917 3918
                        err.message);
          return;
      }
C
cff-gite 已提交
3919
      for (var i=0; i < data.length; i++) {
L
li-yaoyao777 已提交
3920
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931
      }
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
3934
**参数:** 
Z
zengyawen 已提交
3935

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

H
HelloCrease 已提交
3940
**返回值:** 
Z
zengyawen 已提交
3941

H
HelloCrease 已提交
3942 3943 3944
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
3945

H
HelloCrease 已提交
3946
**示例:** 
Z
zengyawen 已提交
3947

H
HelloCrease 已提交
3948
  ```js
Z
zengyawen 已提交
3949 3950
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
H
HelloCrease 已提交
3951
          console.info('createRotationMatrix_promise success');
C
cff-gite 已提交
3952
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
3953
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
3954 3955
          }
      }).catch((reason) => {
H
HelloCrease 已提交
3956
          console.info("promise::catch", reason);
Z
zengyawen 已提交
3957 3958 3959 3960 3961 3962 3963 3964 3965 3966
  })	
  ```


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
3969
**参数:** 
Z
zengyawen 已提交
3970

H
HelloCrease 已提交
3971 3972 3973 3974
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
3975

H
HelloCrease 已提交
3976
**示例:** 
Z
zengyawen 已提交
3977

H
HelloCrease 已提交
3978
  ```js
Z
zengyawen 已提交
3979 3980
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
3981
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
Z
zengyawen 已提交
3982 3983 3984 3985
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
3986
          console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997
      }
  })
  ```


## sensor.createQuaternion

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

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

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

H
HelloCrease 已提交
4000
**参数:** 
Z
zengyawen 已提交
4001

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

H
HelloCrease 已提交
4006
**返回值:** 
Z
zengyawen 已提交
4007

H
HelloCrease 已提交
4008 4009 4010
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
4011

H
HelloCrease 已提交
4012
**示例:** 
Z
zengyawen 已提交
4013

H
HelloCrease 已提交
4014
  ```js
Z
zengyawen 已提交
4015 4016 4017 4018
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
H
HelloCrease 已提交
4019
              console.info("data[" + i + "]: " + data[i]);
Z
zengyawen 已提交
4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.getDirection

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

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

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

H
HelloCrease 已提交
4035
**参数:** 
Z
zengyawen 已提交
4036

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

H
HelloCrease 已提交
4042
**示例:** 
Z
zengyawen 已提交
4043

H
HelloCrease 已提交
4044
  ```js
Z
zengyawen 已提交
4045 4046
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
H
HelloCrease 已提交
4047
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
Z
zengyawen 已提交
4048 4049 4050
                        err.message);
          return;
      }
H
HelloCrease 已提交
4051
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
Z
zengyawen 已提交
4052
      for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
4053
          console.info("sensor_getDirection_callback" + data[i]);
Z
zengyawen 已提交
4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064
      }
  })
  ```


## sensor.getDirection

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

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

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

H
HelloCrease 已提交
4067
**参数:** 
Z
zengyawen 已提交
4068

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

H
HelloCrease 已提交
4073
**返回值:** 
Z
zengyawen 已提交
4074

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

H
HelloCrease 已提交
4079
**示例:** 
Z
zengyawen 已提交
4080

H
HelloCrease 已提交
4081
  ```js
Z
zengyawen 已提交
4082 4083
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
H
HelloCrease 已提交
4084
          console.info('sensor_getAltitude_Promise success', data);
Z
zengyawen 已提交
4085
          for (var i = 1; i < data.length; i++) {
H
HelloCrease 已提交
4086
              console.info("sensor_getDirection_promise" + data[i]);
Z
zengyawen 已提交
4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
4102
**参数:** 
Z
zengyawen 已提交
4103

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

H
HelloCrease 已提交
4110
**示例:** 
Z
zengyawen 已提交
4111

H
HelloCrease 已提交
4112
  ```js
Z
zengyawen 已提交
4113 4114
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
L
li-yaoyao777 已提交
4115
          console.error('error code is: ' + err.code + ', message: ' + err.message);
Z
zengyawen 已提交
4116 4117
          return;
      }
L
li-yaoyao777 已提交
4118
      console.info(JSON.stringify(data));
Z
zengyawen 已提交
4119 4120 4121 4122 4123 4124 4125 4126 4127 4128
  })
  ```


## sensor.createRotationMatrix

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

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

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

H
HelloCrease 已提交
4131
**参数:** 
Z
zengyawen 已提交
4132

H
HelloCrease 已提交
4133 4134 4135 4136
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
4137

H
HelloCrease 已提交
4138
**返回值:** 
Z
zengyawen 已提交
4139

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

H
HelloCrease 已提交
4144
**示例:** 
Z
zengyawen 已提交
4145

H
HelloCrease 已提交
4146
  ```js
Z
zengyawen 已提交
4147 4148
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
L
li-yaoyao777 已提交
4149
          console.info(JSON.stringify(data));
Z
zengyawen 已提交
4150
      }).catch((err) => {
H
HelloCrease 已提交
4151
          console.info('promise failed');
Z
zengyawen 已提交
4152 4153 4154
  })
  ```

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

C
cff-gite 已提交
4157
 getSensorLists(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
C
cff-gite 已提交
4158 4159 4160 4161 4162 4163 4164

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

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

**参数:** 

C
cff-gite 已提交
4165 4166 4167
| 参数名   | 类型                                           | 必填 | 说明             |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
4168 4169 4170

**示例:** 

C
cff-gite 已提交
4171
```js
C
cff-gite 已提交
4172
sensor.getSensorLists((error, data) => {
C
cff-gite 已提交
4173
    if (error) {
C
cff-gite 已提交
4174
        console.error('getSensorLists failed');
C
cff-gite 已提交
4175
    } else {
C
cff-gite 已提交
4176
        console.info("getSensorLists callback in" + data.length);
C
cff-gite 已提交
4177
        for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
4178
            console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
4179
        }
C
cff-gite 已提交
4180 4181
    }
});
C
cff-gite 已提交
4182 4183
```

C
cff-gite 已提交
4184
## sensor.getSensorLists<sup>9+</sup>
C
cff-gite 已提交
4185 4186 4187 4188 4189 4190 4191 4192 4193

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

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

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

**返回值:** 

C
cff-gite 已提交
4194 4195 4196
| 参数名  | 类型                                     | 必填 | 说明             |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 返回传感器列表。 |
C
cff-gite 已提交
4197 4198 4199

**示例:** 

C
cff-gite 已提交
4200
```js
C
cff-gite 已提交
4201 4202
sensor.getSensorLists().then((data) => {
    console.info("getSensorLists promise in" + data.length);
C
cff-gite 已提交
4203
    for (var i = 0; i < data.length; i++) {
C
cff-gite 已提交
4204
        console.info("getSensorLists " + JSON.stringify(data[i]));
C
cff-gite 已提交
4205 4206
     }
}, (error)=>{
C
cff-gite 已提交
4207
    console.error('getSensorLists failed');
C
cff-gite 已提交
4208
});
C
cff-gite 已提交
4209 4210
```

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

C
cff-gite 已提交
4213
getSingleSensor(type: SensorType, callback: AsyncCallback&lt;Sensor&gt;): void
C
cff-gite 已提交
4214 4215 4216 4217 4218 4219 4220

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

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

**参数:** 

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

C
cff-gite 已提交
4226
**示例:**
C
cff-gite 已提交
4227

C
cff-gite 已提交
4228
```js
C
cff-gite 已提交
4229 4230
 sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) => {
     if (error) {
C
cff-gite 已提交
4231
         console.error('getSingleSensor failed');
C
cff-gite 已提交
4232 4233 4234 4235
     } else {
         console.info("getSingleSensor " + JSON.stringify(data));
     }
});
C
cff-gite 已提交
4236 4237
```

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

C
cff-gite 已提交
4240
 getSingleSensor(type: SensorType): Promise&lt;Sensor&gt;
C
cff-gite 已提交
4241 4242 4243 4244 4245 4246 4247

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

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

**参数:** 

C
cff-gite 已提交
4248 4249 4250
| 参数名 | 类型       | 必填 | 说明         |
| ------ | ---------- | ---- | ------------ |
| type   | SensorType | 是   | 传感器类型。 |
C
cff-gite 已提交
4251 4252 4253

**返回值:** 

C
cff-gite 已提交
4254 4255 4256
| 参数名  | 类型                              | 必填 | 说明             |
| ------- | --------------------------------- | ---- | ---------------- |
| promise | Promise&lt;[Sensor](#sensor9)&gt; | 是   | 返回传感器信息。 |
C
cff-gite 已提交
4257 4258 4259

**示例:**

C
cff-gite 已提交
4260
```js
C
cff-gite 已提交
4261 4262 4263 4264 4265
sensor.getSingleSensor(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER).then((data) => {
    console.info("getSingleSensor " + JSON.stringify(data));
}, (error)=>{
    console.error('getSingleSensor failed');
});
C
cff-gite 已提交
4266 4267
```

Z
zengyawen 已提交
4268
## SensorType
Z
zengyawen 已提交
4269 4270 4271

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

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

Z
zengyawen 已提交
4274

C
cff-gite 已提交
4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299
| 名称                                                      | 默认值 | 说明                   |
| --------------------------------------------------------- | ------ | ---------------------- |
| SENSOR_TYPE_ID_ACCELEROMETER                              | 1      | 加速度传感器。         |
| SENSOR_TYPE_ID_GYROSCOPE                                  | 2      | 陀螺仪传感器。         |
| SENSOR_TYPE_ID_AMBIENT_LIGHT                              | 5      | 环境光传感器。         |
| SENSOR_TYPE_ID_MAGNETIC_FIELD                             | 6      | 磁场传感器。           |
| SENSOR_TYPE_ID_BAROMETER                                  | 8      | 气压计传感器。         |
| SENSOR_TYPE_ID_HALL                                       | 10     | 霍尔传感器。           |
| SENSOR_TYPE_ID_PROXIMITY                                  | 12     | 接近光传感器。         |
| SENSOR_TYPE_ID_HUMIDITY                                   | 13     | 湿度传感器。           |
| SENSOR_TYPE_ID_ORIENTATION                                | 256    | 方向传感器。           |
| SENSOR_TYPE_ID_GRAVITY                                    | 257    | 重力传感器。           |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION<sup>(deprecated)</sup> | 258    | 线性加速度传感器。     |
| SENSOR_TYPE_ID_LINEAR_ACCELEROMETER<sup>9+</sup>          | 258    | 线性加速度传感器。     |
| SENSOR_TYPE_ID_ROTATION_VECTOR                            | 259    | 旋转矢量传感器。       |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE                        | 260    | 环境温度传感器。       |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED                | 261    | 未校准磁场传感器。     |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED                     | 263    | 未校准陀螺仪传感器。   |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION                         | 264    | 有效运动传感器。       |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION                        | 265    | 计步检测传感器。       |
| SENSOR_TYPE_ID_PEDOMETER                                  | 266    | 计步传感器。           |
| SENSOR_TYPE_ID_HEART_RATE<sup>(deprecated)</sup>          | 278    | 心率传感器。           |
| SENSOR_TYPE_ID_HEART_BEAT_RATE<sup>9+</sup>               | 278    | 心率传感器。           |
| SENSOR_TYPE_ID_WEAR_DETECTION                             | 280    | 佩戴检测传感器。       |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED                 | 281    | 未校准加速度计传感器。 |
Z
zengyawen 已提交
4300 4301


Z
zengyawen 已提交
4302 4303 4304 4305
## Response

传感器数据的时间戳。

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

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

C
cff-gite 已提交
4312
## Sensor<sup>9+</sup>
C
cff-gite 已提交
4313 4314 4315 4316 4317

指示传感器信息。

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

C
cff-gite 已提交
4318 4319 4320 4321 4322 4323 4324 4325 4326 4327
| 名称            | 参数类型 | 说明                   |
| --------------- | -------- | ---------------------- |
| sensorName      | string   | 传感器名称。           |
| venderName      | string   | 传感器供应商。         |
| firmwareVersion | string   | 传感器固件版本。       |
| hardwareVersion | string   | 传感器硬件版本。       |
| sensorTypeId    | number   | 传感器类型id。         |
| maxRange        | number   | 传感器的最大测量范围。 |
| precision       | number   | 传感器精度。           |
| power           | number   | 传感器电源。           |
C
cff-gite 已提交
4328

Z
zengyawen 已提交
4329
## AccelerometerResponse
Z
zengyawen 已提交
4330

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

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

Z
zengyawen 已提交
4335

H
HelloCrease 已提交
4336 4337 4338 4339 4340
| 名称   | 参数类型   | 可读   | 可写   | 说明                     |
| ---- | ------ | ---- | ---- | ---------------------- |
| x    | number | 是    | 是    | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
4341 4342 4343


## LinearAccelerometerResponse
Z
zengyawen 已提交
4344

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

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

Z
zengyawen 已提交
4349

H
HelloCrease 已提交
4350 4351 4352 4353 4354
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
4355 4356 4357


## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
4358

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

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

Z
zengyawen 已提交
4363

H
HelloCrease 已提交
4364 4365 4366 4367 4368 4369 4370 4371
| 名称    | 参数类型   | 可读   | 可写   | 说明                           |
| ----- | ------ | ---- | ---- | ---------------------------- |
| x     | number | 是    | 是    | 施加在设备x轴未校准的加速度,单位 : m/s2。    |
| y     | number | 是    | 是    | 施加在设备y轴未校准的加速度,单位 : m/s2。    |
| z     | number | 是    | 是    | 施加在设备z轴未校准的加速度,单位 : m/s2。    |
| biasX | number | 是    | 是    | 施加在设备x轴未校准的加速度偏量,单位 : m/s2。  |
| biasY | number | 是    | 是    | 施加在设备上y轴未校准的加速度偏量,单位 : m/s2。 |
| biasZ | number | 是    | 是    | 施加在设备z轴未校准的加速度偏量,单位 : m/s2。  |
Z
zengyawen 已提交
4372 4373 4374


## GravityResponse
Z
zengyawen 已提交
4375

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

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

Z
zengyawen 已提交
4380

H
HelloCrease 已提交
4381 4382 4383 4384 4385
| 名称   | 参数类型   | 可读   | 可写   | 说明                       |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | 是    | 是    | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number | 是    | 是    | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number | 是    | 是    | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
4386 4387 4388


## OrientationResponse
Z
zengyawen 已提交
4389

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

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

Z
zengyawen 已提交
4394

H
HelloCrease 已提交
4395 4396
| 名称    | 参数类型   | 可读   | 可写   | 说明                |
| ----- | ------ | ---- | ---- | ----------------- |
4397
| alpha | number | 是    | 是    | 设备围绕Z轴的旋转角度,单位:度。 |
H
HelloCrease 已提交
4398 4399
| beta  | number | 是    | 是    | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是    | 是    | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
4400 4401 4402


## RotationVectorResponse
Z
zengyawen 已提交
4403

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

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

Z
zengyawen 已提交
4408

H
HelloCrease 已提交
4409 4410 4411 4412 4413 4414
| 名称   | 参数类型   | 可读   | 可写   | 说明        |
| ---- | ------ | ---- | ---- | --------- |
| x    | number | 是    | 是    | 旋转矢量x轴分量。 |
| y    | number | 是    | 是    | 旋转矢量y轴分量。 |
| z    | number | 是    | 是    | 旋转矢量z轴分量。 |
| w    | number | 是    | 是    | 标量。       |
Z
zengyawen 已提交
4415 4416 4417


## GyroscopeResponse
Z
zengyawen 已提交
4418

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

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

Z
zengyawen 已提交
4423

H
HelloCrease 已提交
4424 4425 4426 4427 4428
| 名称   | 参数类型   | 可读   | 可写   | 说明                  |
| ---- | ------ | ---- | ---- | ------------------- |
| x    | number | 是    | 是    | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number | 是    | 是    | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number | 是    | 是    | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
4429 4430 4431


## GyroscopeUncalibratedResponse
Z
zengyawen 已提交
4432

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

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

Z
zengyawen 已提交
4437

H
HelloCrease 已提交
4438 4439 4440 4441 4442 4443 4444 4445
| 名称    | 参数类型   | 可读   | 可写   | 说明                       |
| ----- | ------ | ---- | ---- | ------------------------ |
| 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 已提交
4446 4447 4448


## SignificantMotionResponse
Z
zengyawen 已提交
4449

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

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

Z
zengyawen 已提交
4454

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


## ProximityResponse
Z
zengyawen 已提交
4461

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

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

Z
zengyawen 已提交
4466

H
HelloCrease 已提交
4467 4468 4469
| 名称       | 参数类型   | 可读   | 可写   | 说明                           |
| -------- | ------ | ---- | ---- | ---------------------------- |
| distance | number | 是    | 是    | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
4470 4471 4472


## LightResponse
Z
zengyawen 已提交
4473

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

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

Z
zengyawen 已提交
4478

H
HelloCrease 已提交
4479 4480 4481
| 名称        | 参数类型   | 可读   | 可写   | 说明          |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | 是    | 是    | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
4482 4483 4484


## HallResponse
Z
zengyawen 已提交
4485

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

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

Z
zengyawen 已提交
4490

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


## MagneticFieldResponse
Z
zengyawen 已提交
4497

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

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

Z
zengyawen 已提交
4502

C
cff-gite 已提交
4503 4504 4505 4506 4507
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
Z
zengyawen 已提交
4508 4509 4510


## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
4511

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

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

Z
zengyawen 已提交
4516

H
HelloCrease 已提交
4517 4518 4519 4520 4521 4522 4523 4524
| 名称    | 参数类型   | 可读   | 可写   | 说明                     |
| ----- | ------ | ---- | ---- | ---------------------- |
| 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 已提交
4525 4526 4527


## PedometerResponse
Z
zengyawen 已提交
4528

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

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

Z
zengyawen 已提交
4533

H
HelloCrease 已提交
4534 4535 4536
| 名称    | 参数类型   | 可读   | 可写   | 说明       |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | 是    | 是    | 用户的行走步数。 |
Z
zengyawen 已提交
4537 4538 4539


## HumidityResponse
Z
zengyawen 已提交
4540

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

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

Z
zengyawen 已提交
4545

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


C
cff-gite 已提交
4551
## PedometerDetectionResponse
Z
zengyawen 已提交
4552

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

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

Z
zengyawen 已提交
4557

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


## AmbientTemperatureResponse
Z
zengyawen 已提交
4564

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

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

Z
zengyawen 已提交
4569

H
HelloCrease 已提交
4570 4571 4572
| 名称          | 参数类型   | 可读   | 可写   | 说明            |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | 是    | 是    | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
4573 4574 4575


## BarometerResponse
Z
zengyawen 已提交
4576

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

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

Z
zengyawen 已提交
4581

H
HelloCrease 已提交
4582 4583 4584
| 名称       | 参数类型   | 可读   | 可写   | 说明           |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | 是    | 是    | 压力值(单位:帕斯卡)。 |
Z
zengyawen 已提交
4585 4586 4587


## HeartRateResponse
Z
zengyawen 已提交
4588

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

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

Z
zengyawen 已提交
4593

H
HelloCrease 已提交
4594 4595 4596
| 名称        | 参数类型   | 可读   | 可写   | 说明                    |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | 是    | 是    | 心率值。测量用户的心率数值,单位:bpm。 |
Z
zengyawen 已提交
4597 4598 4599


## WearDetectionResponse
Z
zengyawen 已提交
4600

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

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

Z
zengyawen 已提交
4605

H
HelloCrease 已提交
4606 4607 4608
| 名称    | 参数类型   | 可读   | 可写   | 说明                        |
| ----- | ------ | ---- | ---- | ------------------------- |
| value | number | 是    | 是    | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
Z
zengyawen 已提交
4609 4610 4611 4612


## Options

Z
zengyawen 已提交
4613
设置传感器上报频率。
Z
zengyawen 已提交
4614

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

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

Z
zengyawen 已提交
4621 4622
## RotationMatrixResponse

C
cff-gite 已提交
4623 4624 4625
设置旋转矩阵响应对象。

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

H
HelloCrease 已提交
4627 4628 4629 4630
| 名称          | 参数类型                | 可读   | 可写   | 说明    |
| ----------- | ------------------- | ---- | ---- | ----- |
| rotation    | Array&lt;number&gt; | 是    | 是    | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是    | 是    | 倾斜矩阵。 |
Z
zengyawen 已提交
4631 4632 4633 4634


## CoordinatesOptions

C
cff-gite 已提交
4635 4636 4637
设置坐标选项对象。

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

H
HelloCrease 已提交
4639 4640 4641 4642
| 名称   | 参数类型   | 可读   | 可写   | 说明     |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | 是    | 是    | x坐标方向。 |
| y    | number | 是    | 是    | y坐标方向。 |
Z
zengyawen 已提交
4643

Z
zengyawen 已提交
4644 4645 4646

## GeomagneticResponse

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

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

H
HelloCrease 已提交
4651 4652 4653 4654 4655 4656 4657 4658 4659
| 名称              | 参数类型   | 可读   | 可写   | 说明                        |
| --------------- | ------ | ---- | ---- | ------------------------- |
| x               | number | 是    | 是    | 地磁场的北分量。                  |
| y               | number | 是    | 是    | 地磁场的东分量。                  |
| z               | number | 是    | 是    | 地磁场的垂直分量。                 |
| geomagneticDip  | number | 是    | 是    | 地磁倾角,即地球磁场线与水平面的夹角。       |
| deflectionAngle | number | 是    | 是    | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number | 是    | 是    | 地磁场的水平强度。                 |
| totalIntensity  | number | 是    | 是    | 地磁场的总强度。                  |
Z
zengyawen 已提交
4660 4661 4662

## LocationOptions

C
cff-gite 已提交
4663 4664 4665 4666
指示地理位置。

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

H
HelloCrease 已提交
4667 4668 4669 4670 4671
| 名称        | 参数类型   | 可读   | 可写   | 说明    |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | 是    | 是    | 纬度。   |
| longitude | number | 是    | 是    | 经度。   |
| altitude  | number | 是    | 是    | 海拔高度。 |