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

H
h00514358 已提交
3
sensor模块提供了获取传感器数据的能力,包括获取传感器属性列表,订阅传感器数据,以及一些通用的传感器算法。
C
cff-gite 已提交
4

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

Z
zengyawen 已提交
8 9

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

H
HelloCrease 已提交
11
```js
Z
zengyawen 已提交
12 13 14
import sensor from '@ohos.sensor';
```

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

C
cff-gite 已提交
17
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
18 19 20

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

H
h00514358 已提交
21
订阅加速度传感器数据。
C
cff-gite 已提交
22

H
h00514358 已提交
23
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
24 25 26 27 28

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

**参数:** 

C
cff-gite 已提交
29 30 31
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。              |
H
h00514358 已提交
32
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerResponse。 |
C
cff-gite 已提交
33
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                         |
C
cff-gite 已提交
34

C
cff-gite 已提交
35 36
**错误码**

C
cff-gite 已提交
37
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
38 39 40 41 42

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

C
cff-gite 已提交
43 44 45
**示例:** 

```js
C
cff-gite 已提交
46
try {
H
h00514358 已提交
47
    sensor.on(sensor.SensorId.ACCELEROMETER, function (data) {
C
cff-gite 已提交
48 49 50
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
H
h00514358 已提交
51 52 53
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
54
}
C
cff-gite 已提交
55 56
```

C
cff-gite 已提交
57
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
58

C
cff-gite 已提交
59
on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;,options?: Options): void
C
cff-gite 已提交
60

H
h00514358 已提交
61
订阅未校准加速度传感器数据。
C
cff-gite 已提交
62 63 64 65 66 67 68 69 70

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
71
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
H
h00514358 已提交
72
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerUncalibratedResponse。 |
C
cff-gite 已提交
73
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
74

C
cff-gite 已提交
75 76
**错误码**

C
cff-gite 已提交
77
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
78 79 80 81 82

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

C
cff-gite 已提交
83 84 85
**示例:** 

```js
C
cff-gite 已提交
86
try {
H
h00514358 已提交
87
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) {
C
cff-gite 已提交
88 89 90 91 92 93
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
H
h00514358 已提交
94 95 96
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
97
}
C
cff-gite 已提交
98 99
```

C
cff-gite 已提交
100
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
101 102 103 104 105 106 107 108 109

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

订阅环境光传感器数据。

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

**参数:** 

C
cff-gite 已提交
110 111 112
| 参数名   | 类型                                            | 必填 | 说明                                                |
| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。      |
H
h00514358 已提交
113
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LightResponse。 |
C
cff-gite 已提交
114
| options  | [Options](#options)                             | 否   | 设置上报频率,默认值为200000000ns。                 |
C
cff-gite 已提交
115

C
cff-gite 已提交
116 117
**错误码**

C
cff-gite 已提交
118
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
119 120 121 122 123

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

C
cff-gite 已提交
124 125 126
**示例:** 

```js
C
cff-gite 已提交
127
try {
H
h00514358 已提交
128 129 130 131 132
    sensor.on(sensor.SensorId.AMBIENT_LIGHT, function (data) {
        console.info('The ambient light intensity: ' + data.intensity);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
133
}
C
cff-gite 已提交
134 135
```

C
cff-gite 已提交
136
###  AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
137 138 139

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

H
h00514358 已提交
140
订阅温度传感器数据。
C
cff-gite 已提交
141 142 143 144 145 146 147

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
148
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
H
h00514358 已提交
149
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AmbientTemperatureResponse。 |
C
cff-gite 已提交
150
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
151

C
cff-gite 已提交
152 153
**错误码**

C
cff-gite 已提交
154
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
155 156 157 158 159

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

C
cff-gite 已提交
160 161 162
**示例:**

```js
C
cff-gite 已提交
163
try {
H
h00514358 已提交
164 165 166 167 168
    sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) {
        console.info('Temperature: ' + data.temperature);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
169
}
C
cff-gite 已提交
170 171
```

C
cff-gite 已提交
172
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
173 174 175 176 177 178 179 180 181

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

订阅气压计传感器数据。

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

**参数:**

C
cff-gite 已提交
182 183 184
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。              |
H
h00514358 已提交
185
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为BarometerResponse。 |
C
cff-gite 已提交
186
| options  | [Options](#options)                                     | 否   | 设置上报频率,默认值为200000000ns。                     |
C
cff-gite 已提交
187

C
cff-gite 已提交
188 189
**错误码**

C
cff-gite 已提交
190
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
191 192 193 194 195

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

C
cff-gite 已提交
196 197 198
**示例:**

```js
C
cff-gite 已提交
199
try {
H
h00514358 已提交
200 201 202 203 204
    sensor.on(sensor.SensorId.BAROMETER, function (data) {
        console.info('Atmospheric pressure: ' + data.pressure);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
205
}
C
cff-gite 已提交
206 207
```

C
cff-gite 已提交
208
###  GRAVITY<sup>9+</sup>
C
cff-gite 已提交
209 210 211 212 213 214 215 216 217

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

订阅重力传感器数据。

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

**参数:** 

C
cff-gite 已提交
218 219 220
| 参数名   | 类型                                                | 必填 | 说明                                                  |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。              |
H
h00514358 已提交
221
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GravityResponse。 |
C
cff-gite 已提交
222
| options  | [Options](#options)                                 | 否   | 设置上报频率,默认值为200000000ns。                   |
C
cff-gite 已提交
223

C
cff-gite 已提交
224 225
**错误码**

C
cff-gite 已提交
226
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
227 228 229 230 231

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

C
cff-gite 已提交
232 233 234
**示例:**

```js
C
cff-gite 已提交
235
try {
H
h00514358 已提交
236 237 238 239 240 241 242
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
243
}
C
cff-gite 已提交
244 245
```

C
cff-gite 已提交
246
###  GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
247 248 249 250 251

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

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

C
cff-gite 已提交
252
**需要权限**:ohos.permission.GYROSCOPE 
C
cff-gite 已提交
253 254 255 256 257

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

**参数:** 

C
cff-gite 已提交
258 259 260
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。              |
H
h00514358 已提交
261
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeResponse。 |
C
cff-gite 已提交
262
| options  | [Options](#options)                                     | 否   | 设置上报频率,默认值为200000000ns。                     |
C
cff-gite 已提交
263

C
cff-gite 已提交
264 265
**错误码**

C
cff-gite 已提交
266
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
267 268 269 270 271

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

C
cff-gite 已提交
272 273 274
**示例:**

```js
C
cff-gite 已提交
275
try {
H
h00514358 已提交
276 277 278 279 280 281 282
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
283
}
C
cff-gite 已提交
284 285
```

C
cff-gite 已提交
286
###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
287 288 289 290

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

H
h00514358 已提交
291
订阅未校准陀螺仪传感器数据
C
cff-gite 已提交
292

C
cff-gite 已提交
293
**需要权限**:ohos.permission.GYROSCOPE 
C
cff-gite 已提交
294 295 296 297 298 299 300

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
301
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
H
h00514358 已提交
302
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
303
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
304

C
cff-gite 已提交
305 306
**错误码**

C
cff-gite 已提交
307
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
308 309 310 311 312

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

C
cff-gite 已提交
313 314 315
**示例:**

```js
C
cff-gite 已提交
316
try {
H
h00514358 已提交
317 318 319 320 321 322 323 324 325 326
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
327
}
C
cff-gite 已提交
328 329
```

C
cff-gite 已提交
330
###  HALL<sup>9+</sup>
C
cff-gite 已提交
331 332 333

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

C
cff-gite 已提交
334
订阅霍尔传感器数据。
C
cff-gite 已提交
335 336 337 338 339

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

**参数:** 

C
cff-gite 已提交
340 341 342
| 参数名   | 类型                                          | 必填 | 说明                                               |
| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。              |
H
h00514358 已提交
343
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HallResponse。 |
C
cff-gite 已提交
344
| options  | [Options](#options)                           | 否   | 设置上报频率,默认值为200000000ns。                |
C
cff-gite 已提交
345

C
cff-gite 已提交
346 347
**错误码**

C
cff-gite 已提交
348
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
349 350 351 352 353

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

C
cff-gite 已提交
354 355 356
**示例:**

```js
C
cff-gite 已提交
357
try {
H
h00514358 已提交
358 359 360 361 362
    sensor.on(sensor.SensorId.HALL, function (data) {
        console.info('Hall status: ' + data.status);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
363
}
C
cff-gite 已提交
364 365
```

C
cff-gite 已提交
366 367 368 369 370 371 372 373 374 375 376 377
###   HEART_RATE<sup>9+</sup>

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

订阅心率传感器数据。

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

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

**参数:** 

C
cff-gite 已提交
378 379 380
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。             |
H
h00514358 已提交
381
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HeartRateResponse。 |
C
cff-gite 已提交
382
| options  | [Options](#options)                                     | 否   | 设置上报频率,默认值为200000000ns。                     |
C
cff-gite 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395

**错误码**

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

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

**示例:**

```js
try {
H
h00514358 已提交
396
    sensor.on(sensor.SensorId.HEART_RATE, function (data) {
C
cff-gite 已提交
397
        console.info('Heart rate: ' + data.heartRate);
H
h00514358 已提交
398 399 400
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
401 402 403
}
```

C
cff-gite 已提交
404
###  HUMIDITY<sup>9+</sup>
C
cff-gite 已提交
405 406 407 408 409 410 411 412 413

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

订阅湿度传感器数据。

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

**参数:** 

C
cff-gite 已提交
414 415 416
| 参数名   | 类型                                                  | 必填 | 说明                                                   |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。              |
H
h00514358 已提交
417
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HumidityResponse。 |
C
cff-gite 已提交
418
| options  | [Options](#options)                                   | 否   | 设置上报频率,默认值为200000000ns。                    |
C
cff-gite 已提交
419

C
cff-gite 已提交
420 421
**错误码**

C
cff-gite 已提交
422
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
423 424 425 426 427

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

C
cff-gite 已提交
428 429 430
**示例:**

```js
C
cff-gite 已提交
431
try {
H
h00514358 已提交
432 433 434 435 436
    sensor.on(sensor.SensorId.HUMIDITY, function (data) {
        console.info('Humidity: ' + data.humidity);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
437
}
C
cff-gite 已提交
438 439
```

C
cff-gite 已提交
440
###   LINEAR_ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
441 442 443 444 445 446 447 448 449 450 451 452 453 454

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

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

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
455
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。        |
H
h00514358 已提交
456
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LinearAccelerometerResponse。 |
C
cff-gite 已提交
457
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470

**错误码**

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

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

**示例:**

```js
try {
H
h00514358 已提交
471 472 473 474 475 476 477
    sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
478 479 480
}
```

C
cff-gite 已提交
481
###  MAGNETIC_FIELD<sup>9+</sup>
C
cff-gite 已提交
482 483 484

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

H
h00514358 已提交
485
订阅地磁传感器数据。
C
cff-gite 已提交
486 487 488 489 490

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

**参数:**

C
cff-gite 已提交
491 492 493
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。             |
H
h00514358 已提交
494
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldResponse。 |
C
cff-gite 已提交
495
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                         |
C
cff-gite 已提交
496

C
cff-gite 已提交
497 498
**错误码**

C
cff-gite 已提交
499
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
500 501 502 503 504

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

C
cff-gite 已提交
505 506 507
**示例:**

```js
C
cff-gite 已提交
508
try {
H
h00514358 已提交
509 510 511 512 513 514 515
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
516
}
C
cff-gite 已提交
517 518
```

C
cff-gite 已提交
519
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
520

C
cff-gite 已提交
521
on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
C
cff-gite 已提交
522

H
h00514358 已提交
523
订阅未校准地磁传感器数据
C
cff-gite 已提交
524 525 526 527 528 529 530

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
531
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
H
h00514358 已提交
532
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
533
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
534

C
cff-gite 已提交
535 536
**错误码**

C
cff-gite 已提交
537
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
538 539 540 541 542

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

C
cff-gite 已提交
543 544 545
**示例:**

```js
C
cff-gite 已提交
546
try {
H
h00514358 已提交
547 548 549 550 551 552 553 554 555 556
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
557
}
C
cff-gite 已提交
558 559
```

C
cff-gite 已提交
560
### ORIENTATION<sup>9+</sup>
C
cff-gite 已提交
561 562 563

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

H
h00514358 已提交
564
订阅方向传感器数据。
C
cff-gite 已提交
565 566 567

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

C
cff-gite 已提交
568 569
**错误码**

C
cff-gite 已提交
570
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
571 572 573 574 575

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

C
cff-gite 已提交
576 577
**参数:**

C
cff-gite 已提交
578 579 580
| 参数名   | 类型                                                        | 必填 | 说明                                                      |
| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。              |
H
h00514358 已提交
581
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为OrientationResponse。 |
C
cff-gite 已提交
582
| options  | [Options](#options)                                         | 否   | 设置上报频率,默认值为200000000ns。                       |
C
cff-gite 已提交
583 584 585 586

**示例:**

```js
C
cff-gite 已提交
587
try {
H
h00514358 已提交
588 589 590 591 592 593 594
    sensor.on(sensor.SensorId.ORIENTATION, function (data) {
        console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
        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);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
595
}
C
cff-gite 已提交
596 597
```

C
cff-gite 已提交
598
### PEDOMETER<sup>9+</sup>
C
cff-gite 已提交
599 600 601 602 603 604 605 606 607

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

订阅计步器传感器数据。

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

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

C
cff-gite 已提交
608 609
**错误码**

C
cff-gite 已提交
610
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
611 612 613 614 615

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

C
cff-gite 已提交
616 617
**参数:**

C
cff-gite 已提交
618 619 620
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。              |
H
h00514358 已提交
621
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerResponse。 |
C
cff-gite 已提交
622
| options  | [Options](#options)                                     | 否   | 设置上报频率,默认值为200000000ns。                     |
C
cff-gite 已提交
623 624 625 626

**示例:**

```js
C
cff-gite 已提交
627
try {
H
h00514358 已提交
628 629 630 631 632
    sensor.on(sensor.SensorId.PEDOMETER, function (data) {
        console.info('Step count: ' + data.steps);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
633
}
C
cff-gite 已提交
634 635
```

C
cff-gite 已提交
636
### PEDOMETER_DETECTION<sup>9+</sup>
C
cff-gite 已提交
637 638 639 640

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

H
h00514358 已提交
641
订阅计步检测器传感器数据。
C
cff-gite 已提交
642 643 644 645 646 647 648 649 650

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
651
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
H
h00514358 已提交
652
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerDetectionResponse。 |
C
cff-gite 已提交
653
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
654

C
cff-gite 已提交
655 656
**错误码**

C
cff-gite 已提交
657
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
658 659 660 661 662

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

C
cff-gite 已提交
663 664 665
**示例:**

```js
C
cff-gite 已提交
666
try {
H
h00514358 已提交
667 668 669 670 671
    sensor.on(sensor.SensorId.PEDOMETER_DETECTION, function (data) {
        console.info('Pedometer scalar: ' + data.scalar);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
672
}
C
cff-gite 已提交
673 674
```

C
cff-gite 已提交
675
### PROXIMITY<sup>9+</sup>
C
cff-gite 已提交
676 677 678

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

H
h00514358 已提交
679
订阅接近光传感器数据。
C
cff-gite 已提交
680 681 682 683 684

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

**参数:**

C
cff-gite 已提交
685 686 687
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。              |
H
h00514358 已提交
688
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为ProximityResponse。 |
C
cff-gite 已提交
689
| options  | [Options](#options)                                     | 否   | 设置上报频率,默认值为200000000ns。                     |
C
cff-gite 已提交
690

C
cff-gite 已提交
691 692
**错误码**

C
cff-gite 已提交
693
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
694 695 696 697 698

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

C
cff-gite 已提交
699 700 701
**示例:** 

```js
C
cff-gite 已提交
702
try {
H
h00514358 已提交
703 704 705 706 707
    sensor.on(sensor.SensorId.PROXIMITY, function (data) {
        console.info('Distance: ' + data.distance);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
708
}
C
cff-gite 已提交
709 710
```

C
cff-gite 已提交
711
### ROTATION_VECTOR<sup>9+</sup>
C
cff-gite 已提交
712 713 714 715 716 717 718 719 720 721 722 723

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
724
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
H
h00514358 已提交
725
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为RotationVectorResponse。 |
C
cff-gite 已提交
726
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
727

C
cff-gite 已提交
728 729
**错误码**

C
cff-gite 已提交
730
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
731 732 733 734 735

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

C
cff-gite 已提交
736 737 738
**示例:** 

```js
C
cff-gite 已提交
739
try {
H
h00514358 已提交
740 741 742 743 744 745 746 747
    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 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
748
}
C
cff-gite 已提交
749 750
```

C
cff-gite 已提交
751
### SIGNIFICANT_MOTION<sup>9+</sup>
C
cff-gite 已提交
752 753 754 755

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

H
h00514358 已提交
756
订阅大幅动作检测传感器数据。
C
cff-gite 已提交
757 758 759 760 761 762 763

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
764
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
H
h00514358 已提交
765
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为SignificantMotionResponse。 |
C
cff-gite 已提交
766
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                          |
C
cff-gite 已提交
767

C
cff-gite 已提交
768 769
**错误码**

C
cff-gite 已提交
770
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
771 772 773 774 775

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

C
cff-gite 已提交
776 777 778
**示例:** 

```js
C
cff-gite 已提交
779
try {
H
h00514358 已提交
780 781 782 783 784
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, function (data) {
        console.info('Scalar data: ' + data.scalar);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
785
}
C
cff-gite 已提交
786 787
```

C
cff-gite 已提交
788
###  WEAR_DETECTION<sup>9+</sup>
C
cff-gite 已提交
789 790 791 792

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

C
cff-gite 已提交
793
订阅佩戴检测传感器数据。
C
cff-gite 已提交
794 795 796 797 798

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

**参数:** 

C
cff-gite 已提交
799 800 801
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。             |
H
h00514358 已提交
802
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为WearDetectionResponse。 |
C
cff-gite 已提交
803
| options  | [Options](#options)                                          | 否   | 设置上报频率,默认值为200000000ns。                         |
C
cff-gite 已提交
804

C
cff-gite 已提交
805 806
**错误码**

C
cff-gite 已提交
807
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
808 809 810 811 812

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

C
cff-gite 已提交
813 814 815
**示例:** 

```js
C
cff-gite 已提交
816
try {
H
h00514358 已提交
817 818 819 820 821
    sensor.on(sensor.SensorId.WEAR_DETECTION, function (data) {
        console.info('Wear status: ' + data.value);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
822
}
C
cff-gite 已提交
823 824
```

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

C
cff-gite 已提交
827
### ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
828 829 830

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

H
h00514358 已提交
831
获取一次加速度传感器数据。
C
cff-gite 已提交
832 833 834 835 836 837 838

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

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

**参数:** 

C
cff-gite 已提交
839 840 841
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。              |
H
h00514358 已提交
842
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerResponse。 |
C
cff-gite 已提交
843

C
cff-gite 已提交
844 845
**错误码**

C
cff-gite 已提交
846
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
847 848 849 850 851

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

C
cff-gite 已提交
852 853 854
**示例:** 

```js
C
cff-gite 已提交
855
try {
H
h00514358 已提交
856 857 858 859 860 861 862
    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);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
863
}
C
cff-gite 已提交
864 865
```

C
cff-gite 已提交
866
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
867

C
cff-gite 已提交
868
once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
869

H
h00514358 已提交
870
获取一次未校准加速度传感器数据。
C
cff-gite 已提交
871 872 873 874 875 876 877 878 879

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
880
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
H
h00514358 已提交
881
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerUncalibratedResponse。 |
C
cff-gite 已提交
882

C
cff-gite 已提交
883 884
**错误码**

C
cff-gite 已提交
885
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
886 887 888 889 890

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

C
cff-gite 已提交
891 892 893
**示例:** 

```js
C
cff-gite 已提交
894
try {
H
h00514358 已提交
895 896 897 898 899 900 901 902 903 904
    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);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
905
}
C
cff-gite 已提交
906 907
```

C
cff-gite 已提交
908
### AMBIENT_LIGHT<sup>9+</sup>
C
cff-gite 已提交
909 910 911

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

H
h00514358 已提交
912
获取一次环境光传感器数据。
C
cff-gite 已提交
913 914 915 916 917

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

**参数:** 

C
cff-gite 已提交
918 919 920
| 参数名   | 类型                                            | 必填 | 说明                                                |
| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。      |
H
h00514358 已提交
921
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LightResponse。 |
C
cff-gite 已提交
922

C
cff-gite 已提交
923 924
**错误码**

C
cff-gite 已提交
925
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
926 927 928 929 930

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

C
cff-gite 已提交
931 932 933
**示例:** 

```js
C
cff-gite 已提交
934
try {
H
h00514358 已提交
935 936 937 938 939
    sensor.once(sensor.SensorId.AMBIENT_LIGHT, function (data) {
        console.info('The ambient light intensity: ' + data.intensity);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
940
}
C
cff-gite 已提交
941 942
```

C
cff-gite 已提交
943
### AMBIENT_TEMPERATURE<sup>9+</sup>
C
cff-gite 已提交
944 945 946

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

H
h00514358 已提交
947
获取一次温度传感器数据。
C
cff-gite 已提交
948 949

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

C
cff-gite 已提交
951 952 953 954
**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
955
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
H
h00514358 已提交
956
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AmbientTemperatureResponse。 |
C
cff-gite 已提交
957

C
cff-gite 已提交
958 959
**错误码**

C
cff-gite 已提交
960
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
961 962 963 964 965

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

C
cff-gite 已提交
966 967 968
**示例:** 

```js
C
cff-gite 已提交
969
try {
H
h00514358 已提交
970 971 972 973 974
    sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, function (data) {
        console.info('Temperature: ' + data.temperature);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
975
}
C
cff-gite 已提交
976 977
```

C
cff-gite 已提交
978
### BAROMETER<sup>9+</sup>
C
cff-gite 已提交
979 980 981

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

H
h00514358 已提交
982
获取一次气压计传感器数据。
C
cff-gite 已提交
983 984

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

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

C
cff-gite 已提交
988 989 990
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。              |
H
h00514358 已提交
991
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为BarometerResponse。 |
C
cff-gite 已提交
992

C
cff-gite 已提交
993 994
**错误码**

C
cff-gite 已提交
995
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
996 997 998 999 1000

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

C
cff-gite 已提交
1001 1002 1003
**示例:** 

```js
C
cff-gite 已提交
1004
try {
H
h00514358 已提交
1005 1006 1007 1008 1009
    sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function (data) {
        console.info('Atmospheric pressure: ' + data.pressure);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1010
}
C
cff-gite 已提交
1011 1012
```

C
cff-gite 已提交
1013
### GRAVITY<sup>9+</sup>
C
cff-gite 已提交
1014 1015 1016

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

H
h00514358 已提交
1017
获取一次重力传感器数据。
C
cff-gite 已提交
1018 1019 1020 1021 1022

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

**参数:**

C
cff-gite 已提交
1023 1024 1025
| 参数名   | 类型                                                | 必填 | 说明                                                  |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。              |
H
h00514358 已提交
1026
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GravityResponse。 |
C
cff-gite 已提交
1027

C
cff-gite 已提交
1028 1029
**错误码**

C
cff-gite 已提交
1030
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1031 1032 1033 1034 1035

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

C
cff-gite 已提交
1036 1037 1038
**示例:**

```js
C
cff-gite 已提交
1039
try {
H
h00514358 已提交
1040 1041 1042 1043 1044 1045 1046
    sensor.once(sensor.SensorId.GRAVITY, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1047
}
C
cff-gite 已提交
1048 1049
```

C
cff-gite 已提交
1050
### GYROSCOPE<sup>9+</sup>
C
cff-gite 已提交
1051 1052 1053

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

H
h00514358 已提交
1054
获取一次陀螺仪传感器数据。
C
cff-gite 已提交
1055 1056 1057 1058 1059 1060 1061

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

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

**参数:** 

C
cff-gite 已提交
1062 1063 1064
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。              |
H
h00514358 已提交
1065
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeResponse。 |
C
cff-gite 已提交
1066

C
cff-gite 已提交
1067 1068
**错误码**

C
cff-gite 已提交
1069
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1070 1071 1072 1073 1074

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

C
cff-gite 已提交
1075 1076 1077
**示例:**

```js
C
cff-gite 已提交
1078
try {
H
h00514358 已提交
1079 1080 1081 1082 1083 1084 1085
    sensor.once(sensor.SensorId.GYROSCOPE, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1086
}
C
cff-gite 已提交
1087 1088
```

C
cff-gite 已提交
1089
### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
C
cff-gite 已提交
1090

C
cff-gite 已提交
1091
once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1092

H
h00514358 已提交
1093
获取一次未校准陀螺仪传感器数据。
C
cff-gite 已提交
1094 1095 1096 1097 1098 1099 1100 1101 1102

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1103
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
H
h00514358 已提交
1104
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
1105

C
cff-gite 已提交
1106 1107
**错误码**

C
cff-gite 已提交
1108
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1109 1110 1111 1112 1113

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

C
cff-gite 已提交
1114 1115 1116
**示例:**

```js
C
cff-gite 已提交
1117
try {
H
h00514358 已提交
1118
    sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) {
C
cff-gite 已提交
1119 1120 1121 1122 1123 1124
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
H
h00514358 已提交
1125 1126 1127
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1128
}
C
cff-gite 已提交
1129 1130
```

C
cff-gite 已提交
1131
### HALL<sup>9+</sup>
C
cff-gite 已提交
1132 1133 1134

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

H
h00514358 已提交
1135
获取霍尔传感器数据。
C
cff-gite 已提交
1136 1137 1138 1139 1140

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

**参数:** 

C
cff-gite 已提交
1141 1142 1143
| 参数名   | 类型                                          | 必填 | 说明                                               |
| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。              |
H
h00514358 已提交
1144
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HallResponse。 |
C
cff-gite 已提交
1145

C
cff-gite 已提交
1146 1147
**错误码**

C
cff-gite 已提交
1148
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1149 1150 1151 1152 1153

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

C
cff-gite 已提交
1154 1155 1156
**示例:**

```js
C
cff-gite 已提交
1157
try {
H
h00514358 已提交
1158
    sensor.once(sensor.SensorId.HALL, function (data) {
C
cff-gite 已提交
1159
        console.info('Status: ' + data.status);
H
h00514358 已提交
1160 1161 1162
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1163
}
C
cff-gite 已提交
1164 1165
```

C
cff-gite 已提交
1166 1167 1168 1169
### HEART_RATE<sup>9+</sup>

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

H
h00514358 已提交
1170
获取一次心率传感器数据。
C
cff-gite 已提交
1171 1172 1173 1174 1175 1176 1177

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

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

**参数:** 

C
cff-gite 已提交
1178 1179 1180
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。             |
H
h00514358 已提交
1181
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HeartRateResponse。 |
C
cff-gite 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194

**错误码**

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

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

**示例:**

```js
try {
C
cff-gite 已提交
1195
    sensor.once(sensor.SensorId.HEART_RATE, function (data) {
C
cff-gite 已提交
1196
        console.info('Heart rate: ' + data.heartRate);
H
h00514358 已提交
1197 1198 1199
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1200 1201 1202
}
```

C
cff-gite 已提交
1203 1204 1205 1206
### HUMIDITY<sup>9+</sup>

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

H
h00514358 已提交
1207
获取一次湿度传感器数据。
C
cff-gite 已提交
1208 1209 1210 1211 1212

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

**参数:** 

C
cff-gite 已提交
1213 1214 1215
| 参数名   | 类型                                                  | 必填 | 说明                                                   |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。              |
H
h00514358 已提交
1216
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HumidityResponse。 |
C
cff-gite 已提交
1217

C
cff-gite 已提交
1218 1219
**错误码**

C
cff-gite 已提交
1220
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1221 1222 1223 1224 1225

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

C
cff-gite 已提交
1226 1227 1228
**示例:**

```js
C
cff-gite 已提交
1229
try {
H
h00514358 已提交
1230
    sensor.once(sensor.SensorId.HUMIDITY, function (data) {
C
cff-gite 已提交
1231
        console.info('Humidity: ' + data.humidity);
H
h00514358 已提交
1232 1233 1234
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1235
}
C
cff-gite 已提交
1236 1237
```

C
cff-gite 已提交
1238
### LINEAR_ACCELEROMETER<sup>9+</sup>
C
cff-gite 已提交
1239 1240 1241

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

H
h00514358 已提交
1242
获取一次线性加速度传感器数据。
C
cff-gite 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1252
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。        |
H
h00514358 已提交
1253
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LinearAccelerometerResponse。 |
C
cff-gite 已提交
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266

**错误码**

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

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

**示例:**

```js
try {
H
h00514358 已提交
1267
    sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, function (data) {
C
cff-gite 已提交
1268 1269 1270
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
H
h00514358 已提交
1271 1272 1273
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1274 1275 1276
}
```

C
cff-gite 已提交
1277 1278 1279 1280
### MAGNETIC_FIELD<sup>9+</sup>

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

H
h00514358 已提交
1281
获取一次磁场传感器数据。
C
cff-gite 已提交
1282 1283 1284 1285 1286

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

**参数:**

C
cff-gite 已提交
1287 1288 1289
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。             |
H
h00514358 已提交
1290
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldResponse。 |
C
cff-gite 已提交
1291

C
cff-gite 已提交
1292 1293
**错误码**

C
cff-gite 已提交
1294
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1295 1296 1297 1298 1299

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

C
cff-gite 已提交
1300 1301 1302
**示例:**

```js
C
cff-gite 已提交
1303
try {
H
h00514358 已提交
1304 1305 1306 1307 1308 1309 1310
    sensor.once(sensor.SensorId.MAGNETIC_FIELD, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1311
}
C
cff-gite 已提交
1312 1313 1314 1315
```

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

C
cff-gite 已提交
1316
once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
1317

H
h00514358 已提交
1318
获取一次未经校准的磁场传感器数据。
C
cff-gite 已提交
1319 1320 1321 1322 1323 1324 1325

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1326
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
H
h00514358 已提交
1327
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
1328

C
cff-gite 已提交
1329 1330
**错误码**

C
cff-gite 已提交
1331
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1332 1333 1334 1335 1336

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

C
cff-gite 已提交
1337 1338 1339
**示例:**

```js
C
cff-gite 已提交
1340
try {
H
h00514358 已提交
1341
    sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) {
C
cff-gite 已提交
1342 1343 1344 1345 1346 1347
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
H
h00514358 已提交
1348 1349 1350
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1351
}
C
cff-gite 已提交
1352 1353 1354 1355 1356 1357
```

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

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

H
h00514358 已提交
1358
获取一次方向传感器数据。
C
cff-gite 已提交
1359 1360 1361 1362 1363

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

**参数:** 

C
cff-gite 已提交
1364 1365 1366
| 参数名   | 类型                                                        | 必填 | 说明                                                      |
| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。              |
H
h00514358 已提交
1367
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为OrientationResponse。 |
C
cff-gite 已提交
1368

C
cff-gite 已提交
1369 1370
**错误码**

C
cff-gite 已提交
1371
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1372 1373 1374 1375 1376

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

C
cff-gite 已提交
1377 1378 1379
**示例:**

```js
C
cff-gite 已提交
1380
try {
H
h00514358 已提交
1381 1382 1383 1384 1385 1386 1387
    sensor.once(sensor.SensorId.ORIENTATION, function (data) {
        console.info('The device rotates at an angle around the X axis: ' + data.beta);
        console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
        console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1388
}
C
cff-gite 已提交
1389 1390 1391 1392 1393 1394
```

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

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

H
h00514358 已提交
1395
获取一次计步器传感器数据。
C
cff-gite 已提交
1396 1397 1398 1399 1400 1401 1402

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

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

**参数:**

C
cff-gite 已提交
1403 1404 1405
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。              |
H
h00514358 已提交
1406
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerResponse。 |
C
cff-gite 已提交
1407

C
cff-gite 已提交
1408 1409
**错误码**

C
cff-gite 已提交
1410
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1411 1412 1413 1414 1415

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

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

```js
C
cff-gite 已提交
1419
try {
H
h00514358 已提交
1420 1421 1422 1423 1424
    sensor.once(sensor.SensorId.PEDOMETER, function (data) {
        console.info('Step count: ' + data.steps);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1425
}
C
cff-gite 已提交
1426 1427 1428 1429 1430
```

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

once(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;): void
H
update  
h00514358 已提交
1431

H
h00514358 已提交
1432
获取一次计步检测器传感器数据。
C
cff-gite 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1442
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
H
h00514358 已提交
1443
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerDetectionResponse。 |
C
cff-gite 已提交
1444

C
cff-gite 已提交
1445 1446
**错误码**

C
cff-gite 已提交
1447
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1448 1449 1450 1451 1452

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

C
cff-gite 已提交
1453 1454 1455
**示例:**

```js
C
cff-gite 已提交
1456
try {
H
h00514358 已提交
1457
    sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function (data) {
C
cff-gite 已提交
1458
        console.info('Scalar data: ' + data.scalar);
H
h00514358 已提交
1459 1460 1461
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1462
}
C
cff-gite 已提交
1463 1464 1465 1466 1467 1468
```

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

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

H
h00514358 已提交
1469
获取一次接近光传感器数据。
C
cff-gite 已提交
1470 1471 1472 1473 1474

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

**参数:**

C
cff-gite 已提交
1475 1476 1477
| 参数名   | 类型                                                    | 必填 | 说明                                                    |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。              |
H
h00514358 已提交
1478
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为ProximityResponse。 |
C
cff-gite 已提交
1479

C
cff-gite 已提交
1480 1481
**错误码**

C
cff-gite 已提交
1482
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1483 1484 1485 1486 1487

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

C
cff-gite 已提交
1488 1489 1490
**示例:**

```js
C
cff-gite 已提交
1491
try {
H
h00514358 已提交
1492 1493 1494 1495 1496
    sensor.once(sensor.SensorId.PROXIMITY, function (data) {
        console.info('Distance: ' + data.distance);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1497
}
C
cff-gite 已提交
1498 1499 1500 1501 1502 1503
```

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

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

H
h00514358 已提交
1504
获取一次旋转矢量传感器数据。
C
cff-gite 已提交
1505 1506 1507 1508 1509 1510 1511

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1512
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
H
h00514358 已提交
1513
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为RotationVectorResponse。 |
C
cff-gite 已提交
1514

C
cff-gite 已提交
1515 1516
**错误码**

C
cff-gite 已提交
1517
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1518 1519 1520 1521 1522

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

C
cff-gite 已提交
1523 1524 1525
**示例:** 

```js
C
cff-gite 已提交
1526
try {
H
h00514358 已提交
1527 1528 1529 1530 1531 1532 1533 1534
    sensor.once(sensor.SensorId.ROTATION_VECTOR, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('Scalar quantity: ' + data.w);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1535
}
C
cff-gite 已提交
1536 1537 1538 1539 1540 1541
```

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

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

H
h00514358 已提交
1542
获取一次大幅动作检测传感器数据。
C
cff-gite 已提交
1543 1544 1545 1546 1547 1548 1549

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1550
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
H
h00514358 已提交
1551
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为SignificantMotionResponse。 |
C
cff-gite 已提交
1552

C
cff-gite 已提交
1553 1554
**错误码**

C
cff-gite 已提交
1555
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1556 1557 1558 1559 1560

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

C
cff-gite 已提交
1561 1562 1563
**示例:** 

```js
C
cff-gite 已提交
1564
try {
H
h00514358 已提交
1565 1566 1567 1568 1569
    sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function (data) {
        console.info('Scalar data: ' + data.scalar);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1570
}
C
cff-gite 已提交
1571 1572 1573 1574 1575 1576
```

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

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

H
h00514358 已提交
1577
获取一次佩戴检测传感器数据。
C
cff-gite 已提交
1578 1579 1580 1581 1582

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

**参数:**

C
cff-gite 已提交
1583 1584 1585
| 参数名   | 类型                                                         | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。             |
H
h00514358 已提交
1586
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为WearDetectionResponse。 |
C
cff-gite 已提交
1587

C
cff-gite 已提交
1588 1589
**错误码**

C
cff-gite 已提交
1590
以下错误码的详细介绍请参见 [ohos.sensor(传感器)错误码](../errorcodes/errorcode-sensor.md)
C
cff-gite 已提交
1591 1592 1593 1594 1595

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

C
cff-gite 已提交
1596 1597 1598
**示例:** 

```js
C
cff-gite 已提交
1599
try {
H
h00514358 已提交
1600 1601 1602 1603 1604
    sensor.once(sensor.SensorId.WEAR_DETECTION, function (data) {
        console.info("Wear status: " + data.value);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1605
}
C
cff-gite 已提交
1606 1607
```

C
cff-gite 已提交
1608
## sensor.off<sup>9+</sup>
C
cff-gite 已提交
1609 1610 1611 1612 1613

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

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

H
h00514358 已提交
1614
取消订阅加速度传感器数据。
C
cff-gite 已提交
1615 1616 1617 1618 1619 1620 1621 1622 1623

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1624
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。               |
H
h00514358 已提交
1625
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1626 1627 1628 1629

**示例:**

```js
H
h00514358 已提交
1630 1631 1632 1633 1634 1635
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1636
try {
H
h00514358 已提交
1637 1638 1639 1640 1641 1642 1643 1644
    sensor.on(sensor.SensorId.ACCELEROMETER, callback1);
    sensor.on(sensor.SensorId.ACCELEROMETER, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
    // 取消SensorId.ACCELEROMETER类型的所有回调
    sensor.off(sensor.SensorId.ACCELEROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1645 1646 1647 1648 1649
}
```

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

C
cff-gite 已提交
1650
off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
1651

H
h00514358 已提交
1652
取消订阅未校准加速度传感器数据。
C
cff-gite 已提交
1653 1654 1655 1656 1657 1658 1659 1660 1661

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1662
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。  |
H
update  
h00514358 已提交
1663
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1664 1665 1666 1667

**示例:**

```js
H
h00514358 已提交
1668 1669 1670 1671 1672 1673
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1674
try {
H
h00514358 已提交
1675 1676 1677 1678 1679 1680 1681 1682
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
    // 取消注册SensorId.ACCELEROMETER_UNCALIBRATED类型的所有回调
    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
}
```

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

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

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

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

**参数:**

| 参数名   | 类型                                            | 必填 | 说明                                                         |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1698
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。               |
C
cff-gite 已提交
1699
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1700 1701 1702 1703

**示例:**

```js
H
h00514358 已提交
1704 1705 1706 1707 1708
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
C
cff-gite 已提交
1709
}
H
h00514358 已提交
1710 1711 1712 1713 1714 1715 1716 1717 1718
try {
    sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1);
    sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
    // 取消注册SensorId.AMBIENT_LIGHT的所有回调
    sensor.off(sensor.SensorId.AMBIENT_LIGHT);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1719
}
C
cff-gite 已提交
1720 1721 1722 1723 1724 1725
```

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

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

H
h00514358 已提交
1726
取消订阅温度传感器数据。
C
cff-gite 已提交
1727 1728 1729 1730 1731 1732 1733

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1734
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。         |
C
cff-gite 已提交
1735
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1736 1737 1738 1739

**示例:**

```js
H
h00514358 已提交
1740 1741 1742 1743 1744 1745
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1746
try {
H
h00514358 已提交
1747 1748 1749 1750 1751 1752 1753 1754
    sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
    sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
    // 取消注册SensorId.AMBIENT_TEMPERATURE的所有回调
    sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
}
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1770
| type     | [SensorId](#sensorid9).BAROMETER                        | 是   | 传感器类型,该值固定为SensorId.BAROMETER。                   |
C
cff-gite 已提交
1771
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1772 1773 1774 1775

**示例:**

```js
H
h00514358 已提交
1776 1777 1778 1779 1780 1781
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1782
try {
H
h00514358 已提交
1783 1784 1785 1786 1787 1788 1789 1790
    sensor.on(sensor.SensorId.BAROMETER, callback1);
    sensor.on(sensor.SensorId.BAROMETER, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.BAROMETER, callback1);
    // 取消注册SensorId.BAROMETER的所有回调
    sensor.off(sensor.SensorId.BAROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
}
```

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

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

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

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

**参数:** 

| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1806
| type     | [SensorId](#sensorid9).GRAVITY                      | 是   | 传感器类型,该值固定为SensorId.GRAVITY。                     |
C
cff-gite 已提交
1807
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1808 1809 1810 1811

**示例:**

```js
H
h00514358 已提交
1812 1813 1814 1815 1816 1817
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1818
try {
H
h00514358 已提交
1819 1820 1821 1822 1823 1824 1825 1826
    sensor.on(sensor.SensorId.GRAVITY, callback1);
    sensor.on(sensor.SensorId.GRAVITY, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.GRAVITY, callback1);
    // 取消注册SensorId.GRAVITY的所有回调
    sensor.off(sensor.SensorId.GRAVITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
}
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1844
| type     | [SensorId](#sensorid9).GYROSCOPE                        | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。                   |
C
cff-gite 已提交
1845
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1846 1847 1848 1849

**示例:**

```js
H
h00514358 已提交
1850 1851 1852 1853 1854 1855
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1856
try {
H
h00514358 已提交
1857 1858 1859 1860 1861 1862 1863 1864
    sensor.on(sensor.SensorId.GYROSCOPE, callback1);
    sensor.on(sensor.SensorId.GYROSCOPE, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.GYROSCOPE, callback1);
    // 取消注册SensorId.GYROSCOPE的所有回调
    sensor.off(sensor.SensorId.GYROSCOPE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1865 1866 1867 1868 1869
}
```

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

C
cff-gite 已提交
1870
off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
C
cff-gite 已提交
1871

H
h00514358 已提交
1872
 取消订阅未校准陀螺仪传感器数据。
C
cff-gite 已提交
1873 1874 1875 1876 1877 1878 1879 1880 1881

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1882
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。      |
C
cff-gite 已提交
1883
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1884 1885 1886 1887

**示例:**

```js
H
h00514358 已提交
1888 1889 1890 1891 1892 1893
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1894
try {
H
h00514358 已提交
1895 1896 1897 1898 1899 1900 1901 1902
    sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
    // 取消注册SensorId.GYROSCOPE_UNCALIBRATED的所有回调
    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
}
```

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

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

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

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

**参数:**

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1918
| type     | [SensorId](#sensorid9).HALL                   | 是   | 传感器类型,该值固定为SensorId.HALL。                        |
C
cff-gite 已提交
1919
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1920 1921 1922 1923

**示例:**

```js
H
h00514358 已提交
1924 1925 1926 1927 1928 1929
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1930
try {
H
h00514358 已提交
1931 1932 1933 1934 1935 1936 1937 1938
    sensor.on(sensor.SensorId.HALL, callback1);
    sensor.on(sensor.SensorId.HALL, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.HALL, callback1);
    // 取消注册SensorId.HALL的所有回调
    sensor.off(sensor.SensorId.HALL);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1939 1940 1941
}
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1956
| type     | [SensorId](#sensorid9).HEART_RATE                       | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。                  |
C
cff-gite 已提交
1957
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1958 1959 1960 1961

**示例:**

```js
H
h00514358 已提交
1962 1963 1964 1965 1966 1967
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1968
try {
H
h00514358 已提交
1969 1970 1971 1972 1973 1974 1975 1976
    sensor.on(sensor.SensorId.HEART_RATE, callback1);
    sensor.on(sensor.SensorId.HEART_RATE, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.HEART_RATE, callback1);
    // 取消注册SensorId.HEART_RATE的所有回调
    sensor.off(sensor.SensorId.HEART_RATE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
1977 1978 1979
}
```

C
cff-gite 已提交
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991
### HUMIDITY<sup>9+</sup> 

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

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

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

**参数:**

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
1992
| type     | [SensorId](#sensorid9).HUMIDITY                       | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。                    |
C
cff-gite 已提交
1993
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
1994 1995 1996 1997

**示例:**

```js
H
h00514358 已提交
1998 1999 2000 2001 2002 2003
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2004
try {
H
h00514358 已提交
2005 2006 2007 2008 2009 2010 2011 2012
    sensor.on(sensor.SensorId.HUMIDITY, callback1);
    sensor.on(sensor.SensorId.HUMIDITY, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.HUMIDITY, callback1);
    // 取消注册SensorId.HUMIDITY的所有回调
    sensor.off(sensor.SensorId.HUMIDITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2013 2014 2015
}
```

C
cff-gite 已提交
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
### LINEAR_ACCELEROMETER<sup>9+</sup> 

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2030
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELERATION。         |
C
cff-gite 已提交
2031
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2032 2033 2034 2035

**示例:**

```js
H
h00514358 已提交
2036 2037 2038 2039 2040 2041
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2042
try {
H
h00514358 已提交
2043 2044 2045 2046 2047 2048 2049 2050
    sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
    sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
    // 取消注册SensorId.LINEAR_ACCELEROMETER的所有回调
    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2051 2052 2053
}
```

C
cff-gite 已提交
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
### MAGNETIC_FIELD<sup>9+</sup> 

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2066
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。              |
C
cff-gite 已提交
2067
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2068 2069 2070 2071

**示例:**

```js
H
h00514358 已提交
2072 2073 2074 2075 2076 2077
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2078
try {
H
h00514358 已提交
2079 2080 2081 2082 2083 2084 2085 2086
    sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1);
    sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
    // 取消注册SensorId.MAGNETIC_FIELD的所有回调
    sensor.off(sensor.SensorId.MAGNETIC_FIELD);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2087 2088 2089 2090 2091
}
```

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

C
cff-gite 已提交
2092
off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
C
cff-gite 已提交
2093 2094 2095 2096 2097 2098 2099 2100 2101

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2102
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。 |
C
cff-gite 已提交
2103
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2104 2105 2106 2107

**示例:**

```js
H
h00514358 已提交
2108 2109 2110 2111 2112 2113
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2114
try {
H
h00514358 已提交
2115 2116 2117 2118 2119 2120 2121 2122
    sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
    // 取消注册SensorId.MAGNETIC_FIELD_UNCALIBRATED的所有回调
    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
}
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2138
| type     | [SensorId](#sensorid9).ORIENTATION                          | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。                 |
C
cff-gite 已提交
2139
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2140 2141 2142 2143

**示例:**

```js
H
h00514358 已提交
2144 2145 2146 2147 2148 2149
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2150
try {
H
h00514358 已提交
2151 2152 2153 2154 2155 2156 2157 2158
    sensor.on(sensor.SensorId.ORIENTATION, callback1);
    sensor.on(sensor.SensorId.ORIENTATION, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.ORIENTATION, callback1);
    // 取消注册SensorId.ORIENTATION的所有回调
    sensor.off(sensor.SensorId.ORIENTATION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
}
```

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

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

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

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2176
| type     | [SensorId](#sensorid9).PEDOMETER                        | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。                   |
C
cff-gite 已提交
2177
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2178 2179 2180 2181

**示例:**

```js
H
h00514358 已提交
2182 2183 2184 2185 2186 2187
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2188
try {
H
h00514358 已提交
2189 2190 2191 2192 2193 2194 2195 2196
    sensor.on(sensor.SensorId.PEDOMETER, callback1);
    sensor.on(sensor.SensorId.PEDOMETER, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.PEDOMETER, callback1);
    // 取消注册SensorId.PEDOMETER的所有回调
    sensor.off(sensor.SensorId.PEDOMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2197 2198 2199 2200 2201 2202 2203
}
```

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

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

H
h00514358 已提交
2204
取消订阅计步检测器传感器数据。
C
cff-gite 已提交
2205 2206 2207 2208 2209 2210 2211 2212 2213

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2214
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。         |
C
cff-gite 已提交
2215
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2216 2217 2218 2219

**示例:**

```js
H
h00514358 已提交
2220 2221 2222 2223 2224 2225
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2226
try {
H
h00514358 已提交
2227 2228 2229 2230 2231 2232 2233 2234
    sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1);
    sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
    // 取消注册SensorId.PEDOMETER_DETECTION的所有回调
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2235 2236 2237 2238 2239 2240 2241
}
```

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

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

H
h00514358 已提交
2242
取消订阅接近光传感器数据。
C
cff-gite 已提交
2243 2244 2245 2246 2247 2248 2249

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2250
| type     | [SensorId](#sensorid9).PROXIMITY                        | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。                   |
C
cff-gite 已提交
2251
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2252 2253 2254 2255

**示例:**

```js
H
h00514358 已提交
2256 2257 2258 2259 2260 2261
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2262
try {
H
h00514358 已提交
2263 2264 2265 2266 2267 2268 2269 2270
    sensor.on(sensor.SensorId.PROXIMITY, callback1);
    sensor.on(sensor.SensorId.PROXIMITY, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.PROXIMITY, callback1);
    // 取消注册SensorId.PROXIMITY的所有回调
    sensor.off(sensor.SensorId.PROXIMITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285
}
```

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

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

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

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2286
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。             |
C
cff-gite 已提交
2287
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2288 2289 2290 2291

**示例:**

```js
H
h00514358 已提交
2292 2293 2294 2295 2296 2297
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2298
try {
H
h00514358 已提交
2299 2300 2301 2302 2303 2304 2305 2306
    sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1);
    sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
    // 取消注册SensorId.ROTATION_VECTOR的所有回调
    sensor.off(sensor.SensorId.ROTATION_VECTOR);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2307 2308 2309 2310 2311 2312 2313
}
```

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

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

H
h00514358 已提交
2314
取消大幅动作检测传感器数据。
C
cff-gite 已提交
2315 2316 2317 2318 2319 2320 2321

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2322
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。          |
C
cff-gite 已提交
2323
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2324 2325 2326 2327

**示例:**

```js
H
h00514358 已提交
2328 2329 2330 2331 2332 2333
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2334
try {
H
h00514358 已提交
2335 2336 2337 2338 2339 2340 2341 2342
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
    // 取消注册SensorId.SIGNIFICANT_MOTION的所有回调
    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2343 2344 2345 2346 2347 2348 2349
}
```

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

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

C
cff-gite 已提交
2350
取消订阅佩戴检测传感器数据。
C
cff-gite 已提交
2351 2352 2353 2354 2355 2356 2357

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
C
cff-gite 已提交
2358
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。              |
C
cff-gite 已提交
2359
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 否   | 需要取消订阅的回调函数,若无此参数,则取消订阅当前类型的所有回调函数。 |
C
cff-gite 已提交
2360 2361 2362 2363

**示例:**

```js
H
h00514358 已提交
2364 2365 2366 2367 2368 2369
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2370
try {
H
h00514358 已提交
2371 2372 2373 2374 2375 2376 2377 2378
    sensor.on(sensor.SensorId.WEAR_DETECTION, callback1);
    sensor.on(sensor.SensorId.WEAR_DETECTION, callback2);
    // 仅取消callback1的注册
    sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
    // 取消注册SensorId.WEAR_DETECTION的所有回调
    sensor.off(sensor.SensorId.WEAR_DETECTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
C
cff-gite 已提交
2379 2380 2381
}
```

C
cff-gite 已提交
2382 2383 2384 2385
## sensor.getGeomagneticInfo<sup>9+</sup> 

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

H
h00514358 已提交
2386
获取某时刻地球上特定位置的地磁场信息。
C
cff-gite 已提交
2387 2388 2389 2390 2391 2392 2393

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

**参数:** 

| 参数名          | 类型                                                         | 必填 | 说明                               |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
H
h00514358 已提交
2394 2395 2396
| locationOptions | [LocationOptions](#locationoptions)                          | 是   | 地理位置,包括经度、纬度和海拔高度。                         |
| timeMillis      | number                                                       | 是   | 获取磁偏角的时间,unix时间戳,单位毫秒。 |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 是   | 回调函数,返回地磁场信息。                     |
C
cff-gite 已提交
2397

C
cff-gite 已提交
2398 2399 2400 2401 2402 2403 2404 2405
**错误码**

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

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

C
cff-gite 已提交
2406 2407 2408 2409
**示例:** 

```js
try {
H
h00514358 已提交
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421
    sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, function (err, data) {
        if (err) {
            console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info("GeomagneticInfo x" + data.x);
        console.info("GeomagneticInfo y" + data.y);
        console.info("GeomagneticInfo z" + data.z);
        console.info("GeomagneticInfo geomagneticDip" + data.geomagneticDip);
        console.info("GeomagneticInfo deflectionAngle" + data.deflectionAngle);
        console.info("GeomagneticInfo levelIntensity" + data.levelIntensity);
        console.info("GeomagneticInfo totalIntensity" + data.totalIntensity);
C
cff-gite 已提交
2422 2423
    });
} catch (err) {
H
h00514358 已提交
2424
    console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2425 2426 2427 2428 2429 2430 2431
}
```

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

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

H
h00514358 已提交
2432
获取某时刻地球上特定位置的地磁场信息。
C
cff-gite 已提交
2433 2434 2435 2436 2437 2438 2439

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

**参数:** 

| 参数名          | 类型                                | 必填 | 说明                               |
| --------------- | ----------------------------------- | ---- | ---------------------------------- |
H
h00514358 已提交
2440 2441
| locationOptions | [LocationOptions](#locationoptions) | 是   | 地理位置,包括经度、纬度和海拔高度。                         |
| timeMillis      | number                              | 是   | 获取磁偏角的时间,unix时间戳,单位毫秒。 |
C
cff-gite 已提交
2442 2443 2444 2445 2446

**返回值:** 

| 类型                                                       | 说明           |
| ---------------------------------------------------------- | -------------- |
H
h00514358 已提交
2447
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise对象,返回地磁场信息。 |
C
cff-gite 已提交
2448

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

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

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

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

```js
try {
H
h00514358 已提交
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472
    const promise = sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000);
    promise.then((data) => {
        console.info("GeomagneticInfo x" + data.x);
        console.info("GeomagneticInfo y" + data.y);
        console.info("GeomagneticInfo z" + data.z);
        console.info("GeomagneticInfo geomagneticDip" + data.geomagneticDip);
        console.info("GeomagneticInfo deflectionAngle" + data.deflectionAngle);
        console.info("GeomagneticInfo levelIntensity" + data.levelIntensity);
        console.info("GeomagneticInfo totalIntensity" + data.totalIntensity);
    }, (err)=>{
        console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2473
} catch (err) {
H
h00514358 已提交
2474
    console.error('Get geomagneticInfo. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2475 2476 2477
}
```

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

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

H
h00514358 已提交
2482
根据气压值获取海拔高度。
C
cff-gite 已提交
2483 2484 2485 2486 2487 2488 2489

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

**参数:** 

| 参数名          | 类型                        | 必填 | 说明                                  |
| --------------- | --------------------------- | ---- | ------------------------------------- |
H
h00514358 已提交
2490 2491 2492
| seaPressure     | number                      | 是   | 海平面气压值,单位为hPa。         |
| currentPressure | number                      | 是   | 指定的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是   | 回调函数,返回指定的气压值对应的海拔高度,单位为米。    |
C
cff-gite 已提交
2493

C
cff-gite 已提交
2494 2495 2496 2497 2498 2499 2500 2501
**错误码**

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

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

C
cff-gite 已提交
2502 2503 2504 2505
**示例:**

```js
try {
H
h00514358 已提交
2506 2507 2508 2509 2510 2511 2512 2513 2514
    let seaPressure = 1013.2;
    let currentPressure = 1500.0;
    sensor.getDeviceAltitude(seaPressure, currentPressure, function (err, data) {
        if (err) {
            console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('altitude: ' + data);
    });
C
cff-gite 已提交
2515
} catch (err) {
H
h00514358 已提交
2516
    console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2517 2518 2519
}
```

C
cff-gite 已提交
2520
## sensor.getDeviceAltitude<sup>9+</sup> 
C
cff-gite 已提交
2521 2522 2523

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

H
h00514358 已提交
2524
根据气压值获取海拔高度。
C
cff-gite 已提交
2525 2526 2527 2528 2529 2530 2531

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

**参数:** 

| 参数名          | 类型   | 必填 | 说明                                  |
| --------------- | ------ | ---- | ------------------------------------- |
H
h00514358 已提交
2532 2533
| seaPressure     | number | 是   | 海平面气压值,单位为hPa。         |
| currentPressure | number | 是   | 指定的气压值,单位为hPa。 |
C
cff-gite 已提交
2534 2535 2536 2537 2538

**返回值:** 

| 类型                  | 说明                                 |
| --------------------- | ------------------------------------ |
H
h00514358 已提交
2539
| Promise&lt;number&gt; | Promise对象,返回指定的气压值对应的海拔高度,单位为米。 |
C
cff-gite 已提交
2540

C
cff-gite 已提交
2541 2542 2543 2544 2545 2546 2547 2548
**错误码**

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

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

C
cff-gite 已提交
2549 2550 2551 2552
**示例:** 

```js
try {
H
h00514358 已提交
2553 2554 2555 2556 2557 2558 2559 2560
    let seaPressure = 1013.2;
    let currentPressure = 1500.0;
    const promise = sensor.getDeviceAltitude(seaPressure, currentPressure);
    promise.then((data) => {
        console.info('sensor_getDeviceAltitude_Promise success', data);
    }, (err) => {
        console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2561
} catch (err) {
H
h00514358 已提交
2562
    console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2563 2564 2565
}
```

C
cff-gite 已提交
2566
## sensor.getInclination<sup>9+</sup> 
C
cff-gite 已提交
2567 2568 2569

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

H
h00514358 已提交
2570
根据倾斜矩阵计算地磁倾角。
C
cff-gite 已提交
2571 2572 2573 2574 2575 2576 2577

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

**参数:**

| 参数名            | 类型                        | 必填 | 说明                         |
| ----------------- | --------------------------- | ---- | ---------------------------- |
H
h00514358 已提交
2578 2579
| inclinationMatrix | Array&lt;number&gt;         | 是   | 倾斜矩阵。               |
| callback          | AsyncCallback&lt;number&gt; | 是   | 回调函数,返回地磁倾角,单位为弧度。 |
C
cff-gite 已提交
2580

C
cff-gite 已提交
2581 2582 2583 2584 2585 2586 2587 2588
**错误码**

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

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

C
cff-gite 已提交
2589 2590 2591 2592
**示例:** 

```js
try {
H
h00514358 已提交
2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605
    // inclinationMatrix可以为3*3,或者4*4
    let inclinationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ]
    sensor.getInclination(inclinationMatrix, function (err, data) {
        if (err) {
            console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('Inclination: ' + data);
    })
C
cff-gite 已提交
2606
} catch (err) {
H
h00514358 已提交
2607
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2608 2609 2610
}
```

C
cff-gite 已提交
2611
## sensor.getInclination<sup>9+</sup> 
C
cff-gite 已提交
2612 2613 2614

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

H
h00514358 已提交
2615
根据倾斜矩阵计算地磁倾角。
C
cff-gite 已提交
2616 2617 2618 2619 2620 2621 2622

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

**参数:**

| 参数名            | 类型                | 必填 | 说明           |
| ----------------- | ------------------- | ---- | -------------- |
H
h00514358 已提交
2623
| inclinationMatrix | Array&lt;number&gt; | 是   | 倾斜矩阵。 |
C
cff-gite 已提交
2624 2625 2626 2627 2628

**返回值:** 

| 类型                  | 说明                         |
| --------------------- | ---------------------------- |
H
h00514358 已提交
2629
| Promise&lt;number&gt; | Promise对象,返回地磁倾斜角,单位为弧度。 |
C
cff-gite 已提交
2630

C
cff-gite 已提交
2631 2632 2633 2634 2635 2636 2637 2638
**错误码**

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

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

C
cff-gite 已提交
2639 2640 2641 2642
**示例:** 

```js
try {
H
h00514358 已提交
2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654
    // inclinationMatrix可以为3*3,或者4*4
    let inclinationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ]
    const promise = sensor.getInclination(inclinationMatrix);
    promise.then((data) => {
        console.info('Inclination: ' + data);
    }, (err) => {
        console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2655
} catch (err) {
H
h00514358 已提交
2656
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2657 2658 2659
}
```

C
cff-gite 已提交
2660
## sensor.getAngleVariation<sup>9+</sup>
C
cff-gite 已提交
2661 2662 2663 2664

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

H
h00514358 已提交
2665
计算两个旋转矩阵之间的角度变化。
C
cff-gite 已提交
2666 2667 2668 2669 2670 2671 2672

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

**参数:**

| 参数名                | 类型                                     | 必填 | 说明                              |
| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
H
h00514358 已提交
2673 2674 2675
| currentRotationMatrix | Array&lt;number&gt;                      | 是   | 当前旋转矩阵。                |
| preRotationMatrix     | Array&lt;number&gt;                      | 是   | 相对旋转矩阵。                    |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,返回绕z、x、y轴方向的旋转角度。 |
C
cff-gite 已提交
2676

C
cff-gite 已提交
2677 2678 2679 2680 2681 2682 2683 2684
**错误码**

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

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

C
cff-gite 已提交
2685 2686 2687 2688
**示例:** 

```js
try {
H
h00514358 已提交
2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711
    // 旋转矩阵可以为3*3,或者4*4
    let currentRotationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ];
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, function (err, data) {
        if (err) {
            console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        if (data.length < 3) {
            console.error("Get angle variation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    })
C
cff-gite 已提交
2712
} catch (err) {
H
h00514358 已提交
2713
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2714 2715 2716
}
```

C
cff-gite 已提交
2717
## sensor.getAngleVariation<sup>9+</sup>
C
cff-gite 已提交
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728

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

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

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

**参数:**

| 参数名                | 类型                | 必填 | 说明               |
| --------------------- | ------------------- | ---- | ------------------ |
H
h00514358 已提交
2729 2730
| currentRotationMatrix | Array&lt;number&gt; | 是   | 当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是   | 相对旋转矩阵                  |
C
cff-gite 已提交
2731 2732 2733 2734 2735

**返回值:** 

| 类型                               | 说明                              |
| ---------------------------------- | --------------------------------- |
H
h00514358 已提交
2736
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回绕z、x、y轴方向的旋转角度。 |
C
cff-gite 已提交
2737

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

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

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

C
cff-gite 已提交
2746 2747 2748 2749
**示例:** 

```js
try {
H
h00514358 已提交
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771
    // 旋转矩阵可以为3*3,或者4*4
    let currentRotationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ];
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix);
    promise.then((data) => {
        if (data.length < 3) {
            console.error("Get angle variation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    }, (err) => {
        console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2772
} catch (err) {
H
h00514358 已提交
2773
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2774 2775 2776
}
```

C
cff-gite 已提交
2777
## sensor.getRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2778 2779 2780

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

H
h00514358 已提交
2781
根据旋转矢量获取旋转矩阵。
C
cff-gite 已提交
2782 2783 2784 2785 2786 2787 2788

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

**参数:** 

| 参数名         | 类型                                     | 必填 | 说明           |
| -------------- | ---------------------------------------- | ---- | -------------- |
H
h00514358 已提交
2789 2790
| rotationVector | Array&lt;number&gt;                      | 是   | 旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,返回3*3旋转矩阵。 |
C
cff-gite 已提交
2791

C
cff-gite 已提交
2792 2793 2794 2795 2796 2797 2798 2799
**错误码**

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

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

C
cff-gite 已提交
2800 2801 2802 2803
**示例:** 

```js
try {
H
h00514358 已提交
2804 2805 2806 2807 2808 2809 2810 2811 2812 2813
    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
    sensor.getRotationMatrix(rotationVector, function (err, data) {
        if (err) {
            console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    })
C
cff-gite 已提交
2814
} catch (err) {
H
h00514358 已提交
2815
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2816 2817 2818
}
```

C
cff-gite 已提交
2819
## sensor.getRotationMatrix<sup>9+</sup>
C
cff-gite 已提交
2820 2821 2822

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

H
h00514358 已提交
2823
根据旋转矢量获取旋转矩阵。
C
cff-gite 已提交
2824 2825 2826 2827 2828 2829 2830

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
H
h00514358 已提交
2831
| rotationVector | Array&lt;number&gt; | 是   | 旋转矢量。 |
C
cff-gite 已提交
2832 2833 2834 2835 2836

**返回值:**

| 类型                               | 说明           |
| ---------------------------------- | -------------- |
H
h00514358 已提交
2837
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回旋转矩阵。 |
C
cff-gite 已提交
2838

C
cff-gite 已提交
2839 2840 2841 2842 2843 2844 2845 2846
**错误码**

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

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

C
cff-gite 已提交
2847 2848 2849 2850
**示例:** 

```js
try {
H
h00514358 已提交
2851 2852 2853 2854 2855 2856 2857 2858 2859
    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
    const promise = sensor.getRotationMatrix(rotationVector);
    promise.then((data) => {
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    }, (err) => {
        console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2860
} catch (err) {
H
h00514358 已提交
2861
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2862 2863 2864
}
```

C
cff-gite 已提交
2865
## sensor.transformRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
2866 2867 2868 2869

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

H
h00514358 已提交
2870
根据指定坐标系映射旋转矩阵。
C
cff-gite 已提交
2871 2872 2873 2874 2875 2876 2877

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

**参数:** 

| 参数名           | 类型                                      | 必填 | 说明                   |
| ---------------- | ----------------------------------------- | ---- | ---------------------- |
H
h00514358 已提交
2878 2879 2880
| inRotationVector | Array&lt;number&gt;                       | 是   | 旋转矩阵。         |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 指定坐标系方向。       |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | 是   | 回调函数,返回映射后的旋转矩阵。 |
C
cff-gite 已提交
2881

H
h00514358 已提交
2882
**错误码**
C
cff-gite 已提交
2883 2884 2885 2886 2887 2888 2889

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

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

C
cff-gite 已提交
2890 2891 2892 2893
**示例:** 

```js
try {
H
h00514358 已提交
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
    let rotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, function (err, data) {
        if (err) {
            console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + '] = ' + data[i]);
C
cff-gite 已提交
2906 2907
        }
    })
C
cff-gite 已提交
2908
} catch (err) {
H
h00514358 已提交
2909
    console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2910 2911 2912
}
```

C
cff-gite 已提交
2913
## sensor.transformRotationMatrix<sup>9+</sup>
C
cff-gite 已提交
2914 2915 2916

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

H
h00514358 已提交
2917
根据指定坐标系映射旋转矩阵。
C
cff-gite 已提交
2918 2919 2920 2921 2922 2923 2924

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

**参数:**

| 参数名           | 类型                                      | 必填 | 说明             |
| ---------------- | ----------------------------------------- | ---- | ---------------- |
H
h00514358 已提交
2925 2926
| inRotationVector | Array&lt;number&gt;                       | 是   | 旋转矩阵。   |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是   | 指定坐标系方向。 |
C
cff-gite 已提交
2927 2928 2929 2930 2931

**返回值:**

| 类型                               | 说明                   |
| ---------------------------------- | ---------------------- |
H
h00514358 已提交
2932
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回转换后的旋转矩阵。 |
C
cff-gite 已提交
2933

C
cff-gite 已提交
2934 2935 2936 2937 2938 2939 2940 2941
**错误码**

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

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

C
cff-gite 已提交
2942 2943 2944 2945
**示例:**

```js
try {
H
h00514358 已提交
2946 2947 2948 2949 2950 2951
    let rotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    const promise = sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 });
C
cff-gite 已提交
2952
    promise.then((data) => {
H
h00514358 已提交
2953 2954
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2955
        }
H
h00514358 已提交
2956 2957 2958
    }, (err) => {
        console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2959
} catch (err) {
H
h00514358 已提交
2960
    console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2961 2962 2963 2964 2965 2966 2967
}
```

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

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

H
h00514358 已提交
2968
根据旋转向量计算归一化四元数。
C
cff-gite 已提交
2969 2970 2971 2972 2973 2974 2975

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

**参数:** 

| 参数名         | 类型                                     | 必填 | 说明           |
| -------------- | ---------------------------------------- | ---- | -------------- |
H
h00514358 已提交
2976 2977
| rotationVector | Array&lt;number&gt;                      | 是   | 旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,返回归一化四元数。   |
C
cff-gite 已提交
2978

C
cff-gite 已提交
2979 2980 2981 2982 2983 2984 2985 2986
**错误码**

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

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

C
cff-gite 已提交
2987 2988 2989 2990
**示例:**

```js
try {
H
h00514358 已提交
2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
    sensor.getQuaternion(rotationVector, function (err, data) {
        if (err) {
            console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    })
C
cff-gite 已提交
3001
} catch (err) {
H
h00514358 已提交
3002
    console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3003 3004 3005 3006 3007 3008 3009
}
```

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

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

H
h00514358 已提交
3010
根据旋转向量计算归一化四元数。
C
cff-gite 已提交
3011 3012 3013 3014 3015 3016 3017

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
H
h00514358 已提交
3018
| rotationVector | Array&lt;number&gt; | 是   | 旋转矢量。 |
C
cff-gite 已提交
3019 3020 3021 3022 3023

**返回值:**

| 类型                               | 说明         |
| ---------------------------------- | ------------ |
H
h00514358 已提交
3024
| Promise&lt;Array&lt;number&gt;&gt; | Promise,对象返归一化回四元数。 |
C
cff-gite 已提交
3025

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

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

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

C
cff-gite 已提交
3034 3035 3036 3037
**示例:** 

```js
try {
H
h00514358 已提交
3038 3039 3040 3041 3042 3043 3044 3045 3046
    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
    const promise = sensor.getQuaternion(rotationVector);
    promise.then((data) => {
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    }, (err) => {
        console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
3047
} catch (err) {
H
h00514358 已提交
3048
    console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3049 3050 3051 3052 3053 3054 3055
}
```

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

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

H
h00514358 已提交
3056
根据旋转矩阵计算设备方向。
C
cff-gite 已提交
3057 3058 3059 3060 3061 3062 3063

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

**参数:**

| 参数名         | 类型                                     | 必填 | 说明                              |
| -------------- | ---------------------------------------- | ---- | --------------------------------- |
H
h00514358 已提交
3064 3065
| rotationMatrix | Array&lt;number&gt;                      | 是   | 旋转矩阵。                    |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是   | 回调函数,返回围绕z、x、y轴方向的旋转角度。 |
C
cff-gite 已提交
3066

C
cff-gite 已提交
3067 3068 3069 3070 3071 3072 3073 3074
**错误码**

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

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

C
cff-gite 已提交
3075 3076 3077 3078
**示例:** 

```js
try {
H
h00514358 已提交
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.getOrientation(preRotationMatrix, function (err, data) {
        if (err) {
            console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        if (data.length < 3) {
            console.error("Get orientation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    })
C
cff-gite 已提交
3096
} catch (err) {
H
h00514358 已提交
3097
    console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112
}
```

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

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

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

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

**参数:**

| 参数名         | 类型                | 必填 | 说明           |
| -------------- | ------------------- | ---- | -------------- |
H
h00514358 已提交
3113
| rotationMatrix | Array&lt;number&gt; | 是   | 旋转矩阵。 |
C
cff-gite 已提交
3114 3115 3116 3117 3118

**返回值:**

| 类型                               | 说明                              |
| ---------------------------------- | --------------------------------- |
H
h00514358 已提交
3119
| Promise&lt;Array&lt;number&gt;&gt; | Promise对象,返回围绕z、x、y轴方向的旋转角度。 |
C
cff-gite 已提交
3120

C
cff-gite 已提交
3121 3122 3123 3124 3125 3126 3127 3128
**错误码**

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

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

C
cff-gite 已提交
3129 3130 3131 3132
**示例:** 

```js
try {
H
h00514358 已提交
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    const promise = sensor.getOrientation(preRotationMatrix);
    promise.then((data) => {
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    }, (err) => {
C
cff-gite 已提交
3144
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
H
h00514358 已提交
3145 3146 3147
    });
} catch (err) {
    console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3148 3149 3150
}
```

C
cff-gite 已提交
3151
## sensor.getRotationMatrix<sup>9+</sup> 
C
cff-gite 已提交
3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162

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

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

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

**参数:** 

| 参数名      | 类型                                                         | 必填 | 说明           |
| ----------- | ------------------------------------------------------------ | ---- | -------------- |
H
h00514358 已提交
3163 3164 3165
| gravity     | Array&lt;number&gt;                                          | 是   | 重力矢量。 |
| geomagnetic | Array&lt;number&gt;                                          | 是   | 地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是   | 回调函数,返回旋转矩阵。 |
C
cff-gite 已提交
3166

C
cff-gite 已提交
3167 3168 3169 3170 3171 3172 3173 3174
**错误码**

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

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

C
cff-gite 已提交
3175 3176 3177 3178
**示例:**

```js
try {
H
h00514358 已提交
3179 3180 3181 3182 3183 3184 3185 3186 3187
    let gravity = [-0.27775216, 0.5351276, 9.788099];
    let geomagnetic = [210.87253, -78.6096, -111.44444];
    sensor.getRotationMatrix(gravity, geomagnetic, function (err, data) => {
        if (err) {
            console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('RotationMatrix' + JSON.stringify(data));
    })
C
cff-gite 已提交
3188
} catch (err) {
H
h00514358 已提交
3189
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3190 3191 3192
}
```

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

C
cff-gite 已提交
3195
getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
C
cff-gite 已提交
3196 3197 3198 3199 3200 3201 3202 3203 3204

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

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

**参数:** 

| 参数名      | 类型                | 必填 | 说明           |
| ----------- | ------------------- | ---- | -------------- |
H
h00514358 已提交
3205 3206
| gravity     | Array&lt;number&gt; | 是   | 重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是   | 地磁矢量。 |
C
cff-gite 已提交
3207 3208 3209 3210 3211

**返回值:** 

| 类型                                                         | 说明           |
| ------------------------------------------------------------ | -------------- |
H
h00514358 已提交
3212
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise对象,返回旋转矩阵。 |
C
cff-gite 已提交
3213

C
cff-gite 已提交
3214 3215 3216 3217 3218 3219 3220 3221
**错误码**

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

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

C
cff-gite 已提交
3222 3223 3224 3225
**示例:** 

```js
try {
H
h00514358 已提交
3226 3227 3228 3229 3230 3231 3232 3233
    let gravity = [-0.27775216, 0.5351276, 9.788099];
    let geomagnetic = [210.87253, -78.6096, -111.44444];
    const promise = sensor.getRotationMatrix(gravity, geomagnetic);
    promise.then((data) => {
        console.info('RotationMatrix' + JSON.stringify(data));
    }, (err) => {
        console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
3234
} catch (err) {
H
h00514358 已提交
3235
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3236 3237 3238
}
```

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

H
h00514358 已提交
3241
getSensorList(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
C
cff-gite 已提交
3242

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

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

C
cff-gite 已提交
3247
**参数:** 
C
cff-gite 已提交
3248

C
cff-gite 已提交
3249 3250
| 参数名   | 类型                                           | 必填 | 说明             |
| -------- | ---------------------------------------------- | ---- | ---------------- |
H
h00514358 已提交
3251
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | 是   | 回调函数,返回传感器属性列表。 |
Z
zengyawen 已提交
3252

C
cff-gite 已提交
3253 3254 3255 3256 3257 3258 3259 3260
**错误码**

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

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

C
cff-gite 已提交
3261
**示例:** 
Z
zengyawen 已提交
3262

C
cff-gite 已提交
3263
```js
C
cff-gite 已提交
3264
try {
H
h00514358 已提交
3265 3266 3267 3268 3269
    sensor.getSensorList((err, data) => {
        if (err) {
            console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
C
cff-gite 已提交
3270
        for (var i = 0; i < data.length; i++) {
H
h00514358 已提交
3271
            console.info('data[' + i + ']: ' + JSON.stringify(data[i]));
C
cff-gite 已提交
3272
        }
C
cff-gite 已提交
3273 3274
    });
} catch (err) {
H
h00514358 已提交
3275
    console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3276
}
C
cff-gite 已提交
3277
```
Z
zengyawen 已提交
3278

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

C
cff-gite 已提交
3281 3282 3283
 getSensorList(): Promise< Array&lt;Sensor&gt;>

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

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

C
cff-gite 已提交
3287
**返回值:** 
C
cff-gite 已提交
3288

C
cff-gite 已提交
3289 3290
| 参数名  | 类型                                     | 必填 | 说明             |
| ------- | ---------------------------------------- | ---- | ---------------- |
H
h00514358 已提交
3291
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | 是   | Promise对象,返回传感器属性列表。 |
Z
zengyawen 已提交
3292

C
cff-gite 已提交
3293 3294 3295 3296 3297 3298 3299 3300
**错误码**

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

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

H
HelloCrease 已提交
3301
**示例:** 
C
cff-gite 已提交
3302

C
cff-gite 已提交
3303
```js
C
cff-gite 已提交
3304 3305 3306
try {
    sensor.getSensorList().then((data) => {
        for (var i = 0; i < data.length; i++) {
H
h00514358 已提交
3307
            console.info('data[' + i + ']: ' + JSON.stringify(data[i]));
C
cff-gite 已提交
3308
        }
H
h00514358 已提交
3309 3310
    }, (err) => {
        console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3311 3312
    });
} catch (err) {
H
h00514358 已提交
3313
    console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3314
}
C
cff-gite 已提交
3315
```
Z
zengyawen 已提交
3316

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

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

H
h00514358 已提交
3321
获取指定传感器类型的属性信息。
C
cff-gite 已提交
3322 3323 3324

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

H
HelloCrease 已提交
3325
**参数:** 
C
cff-gite 已提交
3326

C
cff-gite 已提交
3327 3328
| 参数名   | 类型                                    | 必填 | 说明             |
| -------- | --------------------------------------- | ---- | ---------------- |
H
h00514358 已提交
3329 3330
| type     | [SensorId](#sensorid9)                  | 是   | 指定传感器类型。     |
| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | 是   | 回调函数,返回指定传感器的属性信息。 |
H
h00514358 已提交
3331

C
cff-gite 已提交
3332 3333 3334 3335 3336 3337 3338 3339
**错误码**

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

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

C
cff-gite 已提交
3340
**示例:**
H
h00514358 已提交
3341

C
cff-gite 已提交
3342
```js
C
cff-gite 已提交
3343
try {
C
cff-gite 已提交
3344
    sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err, data) => {
H
h00514358 已提交
3345 3346 3347 3348 3349
        if (err) {
            console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('Sensor: ' + JSON.stringify(data));
C
cff-gite 已提交
3350 3351
    });
} catch (err) {
H
h00514358 已提交
3352
    console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3353
}
C
cff-gite 已提交
3354
```
H
h00514358 已提交
3355

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

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

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

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

C
cff-gite 已提交
3364
**参数:** 
H
h00514358 已提交
3365

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

C
cff-gite 已提交
3370
**返回值:** 
Z
zengyawen 已提交
3371

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

C
cff-gite 已提交
3376 3377 3378 3379 3380 3381 3382 3383
**错误码**

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

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

C
cff-gite 已提交
3384
**示例:**
C
cff-gite 已提交
3385

C
cff-gite 已提交
3386
```js
C
cff-gite 已提交
3387
try {
C
cff-gite 已提交
3388
    sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data) => {
H
h00514358 已提交
3389 3390 3391
        console.info('Sensor: ' + JSON.stringify(data));
    }, (err) => {
        console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3392 3393
    });
} catch (err) {
H
h00514358 已提交
3394
    console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3395
}
C
cff-gite 已提交
3396
```
C
cff-gite 已提交
3397

C
cff-gite 已提交
3398
## SensorId<sup>9+</sup>
C
cff-gite 已提交
3399

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

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

C
cff-gite 已提交
3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426
| 名称                        | 值   | 说明                   |
| --------------------------- | ---- | ---------------------- |
| ACCELEROMETER               | 1    | 加速度传感器。         |
| GYROSCOPE                   | 2    | 陀螺仪传感器。         |
| AMBIENT_LIGHT               | 5    | 环境光传感器。         |
| MAGNETIC_FIELD              | 6    | 磁场传感器。           |
| BAROMETER                   | 8    | 气压计传感器。         |
| HALL                        | 10   | 霍尔传感器。           |
| PROXIMITY                   | 12   | 接近光传感器。         |
| HUMIDITY                    | 13   | 湿度传感器。           |
| ORIENTATION                 | 256  | 方向传感器。           |
| GRAVITY                     | 257  | 重力传感器。           |
| LINEAR_ACCELEROMETER        | 258  | 线性加速度传感器。     |
| ROTATION_VECTOR             | 259  | 旋转矢量传感器。       |
| AMBIENT_TEMPERATURE         | 260  | 环境温度传感器。       |
| MAGNETIC_FIELD_UNCALIBRATED | 261  | 未校准磁场传感器。     |
| GYROSCOPE_UNCALIBRATED      | 263  | 未校准陀螺仪传感器。   |
| SIGNIFICANT_MOTION          | 264  | 有效运动传感器。       |
| PEDOMETER_DETECTION         | 265  | 计步检测传感器。       |
| PEDOMETER                   | 266  | 计步传感器。           |
| HEART_RATE                  | 278  | 心率传感器。           |
| WEAR_DETECTION              | 280  | 佩戴检测传感器。       |
| ACCELEROMETER_UNCALIBRATED  | 281  | 未校准加速度计传感器。 |
Z
zengyawen 已提交
3427

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

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

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

C
cff-gite 已提交
3434

C
cff-gite 已提交
3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457
| 名称                                       | 值   | 说明                   |
| ------------------------------------------ | ---- | ---------------------- |
| SENSOR_TYPE_ID_ACCELEROMETER               | 1    | 加速度传感器。         |
| SENSOR_TYPE_ID_GYROSCOPE                   | 2    | 陀螺仪传感器。         |
| SENSOR_TYPE_ID_AMBIENT_LIGHT               | 5    | 环境光传感器。         |
| SENSOR_TYPE_ID_MAGNETIC_FIELD              | 6    | 磁场传感器。           |
| SENSOR_TYPE_ID_BAROMETER                   | 8    | 气压计传感器。         |
| SENSOR_TYPE_ID_HALL                        | 10   | 霍尔传感器。           |
| SENSOR_TYPE_ID_PROXIMITY                   | 12   | 接近光传感器。         |
| SENSOR_TYPE_ID_HUMIDITY                    | 13   | 湿度传感器。           |
| SENSOR_TYPE_ID_ORIENTATION                 | 256  | 方向传感器。           |
| SENSOR_TYPE_ID_GRAVITY                     | 257  | 重力传感器。           |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION         | 258  | 线性加速度传感器。     |
| SENSOR_TYPE_ID_ROTATION_VECTOR             | 259  | 旋转矢量传感器。       |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE         | 260  | 环境温度传感器。       |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | 未校准磁场传感器。     |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED      | 263  | 未校准陀螺仪传感器。   |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION          | 264  | 有效运动传感器。       |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION         | 265  | 计步检测传感器。       |
| SENSOR_TYPE_ID_PEDOMETER                   | 266  | 计步传感器。           |
| SENSOR_TYPE_ID_HEART_RATE                  | 278  | 心率传感器。           |
| SENSOR_TYPE_ID_WEAR_DETECTION              | 280  | 佩戴检测传感器。       |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED  | 281  | 未校准加速度计传感器。 |
C
cff-gite 已提交
3458

C
cff-gite 已提交
3459

C
cff-gite 已提交
3460
## Response
Z
zengyawen 已提交
3461

C
cff-gite 已提交
3462
传感器数据的时间戳。
Z
zengyawen 已提交
3463

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

C
cff-gite 已提交
3466 3467 3468
| 名称      | 类型   | 可读 | 可写 | 说明                     |
| --------- | ------ | ---- | ---- | ------------------------ |
| timestamp | number | 是   | 是   | 传感器数据上报的时间戳。 |
Z
zengyawen 已提交
3469

C
cff-gite 已提交
3470
## Sensor<sup>9+</sup>
Z
zengyawen 已提交
3471

C
cff-gite 已提交
3472
指示传感器信息。
C
cff-gite 已提交
3473

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

C
cff-gite 已提交
3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487
| 名称            | 类型 | 可读 | 可写 | 说明                   |
| --------------- | -------- | ---------------------- | ---------------------- | ---------------------- |
| sensorName      | string   | 是  | 是  | 传感器名称。           |
| venderName      | string   | 是  | 是  | 传感器供应商。         |
| firmwareVersion | string   | 是  | 是  | 传感器固件版本。       |
| hardwareVersion | string   | 是  | 是  | 传感器硬件版本。       |
| sensorId        | number   | 是  | 是  | 传感器类型id。         |
| maxRange        | number   | 是  | 是  | 传感器测量范围的最大值。 |
| minSamplePeriod | number   | 是  | 是  | 允许的最小采样周期。   |
| maxSamplePeriod | number   | 是  | 是  | 允许的最大采样周期。   |
| precision       | number   | 是  | 是  | 传感器精度。           |
| power           | number   | 是  | 是  | 传感器功率。           |
C
cff-gite 已提交
3488

C
cff-gite 已提交
3489
## AccelerometerResponse
C
cff-gite 已提交
3490

C
cff-gite 已提交
3491
加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3492

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


C
cff-gite 已提交
3496 3497 3498 3499 3500
| 名称 | 类型   | 可读 | 可写 | 说明                                 |
| ---- | ------ | ---- | ---- | ------------------------------------ |
| x    | number | 是   | 是   | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number | 是   | 是   | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number | 是   | 是   | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3501 3502


C
cff-gite 已提交
3503
## LinearAccelerometerResponse
C
cff-gite 已提交
3504

C
cff-gite 已提交
3505
线性加速度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3506

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

C
cff-gite 已提交
3509

C
cff-gite 已提交
3510 3511 3512 3513 3514
| 名称 | 类型   | 可读 | 可写 | 说明                                     |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| x    | number | 是   | 是   | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number | 是   | 是   | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number | 是   | 是   | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3515

Z
zengyawen 已提交
3516

C
cff-gite 已提交
3517
## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
3518

C
cff-gite 已提交
3519
未校准加速度计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3520

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

C
cff-gite 已提交
3523

C
cff-gite 已提交
3524 3525 3526 3527 3528 3529 3530 3531
| 名称  | 类型   | 可读 | 可写 | 说明                                             |
| ----- | ------ | ---- | ---- | ------------------------------------------------ |
| x     | number | 是   | 是   | 施加在设备x轴未校准的加速度,单位 : m/s2。       |
| y     | number | 是   | 是   | 施加在设备y轴未校准的加速度,单位 : m/s2。       |
| z     | number | 是   | 是   | 施加在设备z轴未校准的加速度,单位 : m/s2。       |
| biasX | number | 是   | 是   | 施加在设备x轴未校准的加速度偏量,单位 : m/s2。   |
| biasY | number | 是   | 是   | 施加在设备上y轴未校准的加速度偏量,单位 : m/s2。 |
| biasZ | number | 是   | 是   | 施加在设备z轴未校准的加速度偏量,单位 : m/s2。   |
C
cff-gite 已提交
3532

C
cff-gite 已提交
3533

C
cff-gite 已提交
3534
## GravityResponse
Z
zengyawen 已提交
3535

C
cff-gite 已提交
3536
重力传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3537

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


C
cff-gite 已提交
3541 3542 3543 3544 3545
| 名称 | 类型   | 可读 | 可写 | 说明                                     |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| x    | number | 是   | 是   | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number | 是   | 是   | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number | 是   | 是   | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3546

C
cff-gite 已提交
3547

C
cff-gite 已提交
3548
## OrientationResponse
C
cff-gite 已提交
3549

C
cff-gite 已提交
3550
方向传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3551

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

Z
zengyawen 已提交
3554

C
cff-gite 已提交
3555 3556 3557 3558 3559
| 名称  | 类型   | 可读 | 可写 | 说明                              |
| ----- | ------ | ---- | ---- | --------------------------------- |
| alpha | number | 是   | 是   | 设备围绕Z轴的旋转角度,单位:度。 |
| beta  | number | 是   | 是   | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number | 是   | 是   | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
3560 3561


C
cff-gite 已提交
3562
## RotationVectorResponse
Z
zengyawen 已提交
3563

C
cff-gite 已提交
3564
旋转矢量传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3565

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

C
cff-gite 已提交
3568

C
cff-gite 已提交
3569 3570 3571 3572 3573 3574
| 名称 | 类型   | 可读 | 可写 | 说明              |
| ---- | ------ | ---- | ---- | ----------------- |
| x    | number | 是   | 是   | 旋转矢量x轴分量。 |
| y    | number | 是   | 是   | 旋转矢量y轴分量。 |
| z    | number | 是   | 是   | 旋转矢量z轴分量。 |
| w    | number | 是   | 是   | 标量。            |
C
cff-gite 已提交
3575

C
cff-gite 已提交
3576

C
cff-gite 已提交
3577
## GyroscopeResponse
Z
zengyawen 已提交
3578

C
cff-gite 已提交
3579
陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3580

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


C
cff-gite 已提交
3584 3585 3586 3587 3588
| 名称 | 类型   | 可读 | 可写 | 说明                             |
| ---- | ------ | ---- | ---- | -------------------------------- |
| x    | number | 是   | 是   | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number | 是   | 是   | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number | 是   | 是   | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
3589

C
cff-gite 已提交
3590

C
cff-gite 已提交
3591
## GyroscopeUncalibratedResponse
C
cff-gite 已提交
3592

C
cff-gite 已提交
3593
未校准陀螺仪传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3594

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

C
cff-gite 已提交
3597

C
cff-gite 已提交
3598 3599 3600 3601 3602 3603 3604 3605
| 名称  | 类型   | 可读 | 可写 | 说明                                       |
| ----- | ------ | ---- | ---- | ------------------------------------------ |
| 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 已提交
3606 3607


C
cff-gite 已提交
3608
## SignificantMotionResponse
Z
zengyawen 已提交
3609

C
cff-gite 已提交
3610
有效运动传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3611

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

C
cff-gite 已提交
3614

C
cff-gite 已提交
3615 3616 3617
| 名称   | 类型   | 可读 | 可写 | 说明                                                         |
| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| scalar | number | 是   | 是   | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 |
C
cff-gite 已提交
3618

Z
zengyawen 已提交
3619

C
cff-gite 已提交
3620
## ProximityResponse
C
cff-gite 已提交
3621

C
cff-gite 已提交
3622
接近光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3623

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


C
cff-gite 已提交
3627 3628 3629
| 名称     | 类型   | 可读 | 可写 | 说明                                                   |
| -------- | ------ | ---- | ---- | ------------------------------------------------------ |
| distance | number | 是   | 是   | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
3630

C
cff-gite 已提交
3631

C
cff-gite 已提交
3632
## LightResponse
C
cff-gite 已提交
3633

C
cff-gite 已提交
3634
环境光传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3635

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

Z
zengyawen 已提交
3638

C
cff-gite 已提交
3639 3640 3641
| 名称      | 类型   | 可读 | 可写 | 说明                   |
| --------- | ------ | ---- | ---- | ---------------------- |
| intensity | number | 是   | 是   | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
3642 3643


C
cff-gite 已提交
3644
## HallResponse
Z
zengyawen 已提交
3645

C
cff-gite 已提交
3646
霍尔传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3647

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

C
cff-gite 已提交
3650

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

Z
zengyawen 已提交
3655

C
cff-gite 已提交
3656
## MagneticFieldResponse
Z
zengyawen 已提交
3657

C
cff-gite 已提交
3658
磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3659

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

C
cff-gite 已提交
3662

C
cff-gite 已提交
3663 3664 3665 3666 3667
| 名称 | 类型   | 可读 | 可写 | 说明                         |
| ---- | ------ | ---- | ---- | ---------------------------- |
| x    | number | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
C
cff-gite 已提交
3668

C
cff-gite 已提交
3669

C
cff-gite 已提交
3670
## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
3671

C
cff-gite 已提交
3672
未校准磁场传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3673

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


C
cff-gite 已提交
3677 3678 3679 3680 3681 3682 3683 3684
| 名称  | 类型   | 可读 | 可写 | 说明                                   |
| ----- | ------ | ---- | ---- | -------------------------------------- |
| 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 已提交
3685 3686


C
cff-gite 已提交
3687
## PedometerResponse
C
cff-gite 已提交
3688

C
cff-gite 已提交
3689
计步传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3690

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

Z
zengyawen 已提交
3693

C
cff-gite 已提交
3694 3695 3696
| 名称  | 类型   | 可读 | 可写 | 说明             |
| ----- | ------ | ---- | ---- | ---------------- |
| steps | number | 是   | 是   | 用户的行走步数。 |
C
cff-gite 已提交
3697

Z
zengyawen 已提交
3698

C
cff-gite 已提交
3699
## HumidityResponse
Z
zengyawen 已提交
3700

C
cff-gite 已提交
3701
湿度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3702

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

C
cff-gite 已提交
3705

C
cff-gite 已提交
3706 3707 3708
| 名称     | 类型   | 可读 | 可写 | 说明                                                      |
| -------- | ------ | ---- | ---- | --------------------------------------------------------- |
| humidity | number | 是   | 是   | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |
C
cff-gite 已提交
3709

C
cff-gite 已提交
3710

C
cff-gite 已提交
3711
## PedometerDetectionResponse
Z
zengyawen 已提交
3712

C
cff-gite 已提交
3713
计步检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3714

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


C
cff-gite 已提交
3718 3719 3720
| 名称   | 类型   | 可读 | 可写 | 说明                                                         |
| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| scalar | number | 是   | 是   | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |
Z
zengyawen 已提交
3721

C
cff-gite 已提交
3722

C
cff-gite 已提交
3723
## AmbientTemperatureResponse
C
cff-gite 已提交
3724

C
cff-gite 已提交
3725
温度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3726

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

C
cff-gite 已提交
3729

C
cff-gite 已提交
3730 3731 3732
| 名称        | 类型   | 可读 | 可写 | 说明                       |
| ----------- | ------ | ---- | ---- | -------------------------- |
| temperature | number | 是   | 是   | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
3733 3734


C
cff-gite 已提交
3735
## BarometerResponse
Z
zengyawen 已提交
3736

C
cff-gite 已提交
3737
气压计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3738

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

C
cff-gite 已提交
3741

C
cff-gite 已提交
3742 3743 3744
| 名称     | 类型   | 可读 | 可写 | 说明                     |
| -------- | ------ | ---- | ---- | ------------------------ |
| pressure | number | 是   | 是   | 压力值(单位:帕斯卡)。 |
C
cff-gite 已提交
3745

Z
zengyawen 已提交
3746

C
cff-gite 已提交
3747
## HeartRateResponse
Z
zengyawen 已提交
3748

C
cff-gite 已提交
3749
心率传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3750

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


C
cff-gite 已提交
3754 3755 3756
| 名称      | 类型   | 可读 | 可写 | 说明                                    |
| --------- | ------ | ---- | ---- | --------------------------------------- |
| heartRate | number | 是   | 是   | 心率值。测量用户的心率数值,单位:bpm。 |
H
h00514358 已提交
3757

C
cff-gite 已提交
3758

C
cff-gite 已提交
3759
## WearDetectionResponse
C
cff-gite 已提交
3760

C
cff-gite 已提交
3761
佩戴检测传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3762

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

H
h00514358 已提交
3765

C
cff-gite 已提交
3766 3767 3768
| 名称  | 类型   | 可读 | 可写 | 说明                                             |
| ----- | ------ | ---- | ---- | ------------------------------------------------ |
| value | number | 是   | 是   | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
H
h00514358 已提交
3769 3770


C
cff-gite 已提交
3771
## Options
H
h00514358 已提交
3772

C
cff-gite 已提交
3773
设置传感器上报频率。
H
h00514358 已提交
3774

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

C
cff-gite 已提交
3777
| 名称     | 类型   | 可读 | 可写 | 说明                                        |
C
cff-gite 已提交
3778 3779
| -------- | ------ | ---- | ---- | ------------------------------------------- |
| interval | number | 是   | 是   | 表示传感器的上报频率,默认值为200000000ns。 |
H
h00514358 已提交
3780

C
cff-gite 已提交
3781
## RotationMatrixResponse
H
h00514358 已提交
3782

C
cff-gite 已提交
3783
设置旋转矩阵响应对象。
H
h00514358 已提交
3784

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

C
cff-gite 已提交
3787
| 名称        | 类型                | 可读 | 可写 | 说明       |
C
cff-gite 已提交
3788 3789 3790
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | 是   | 是   | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是   | 是   | 倾斜矩阵。 |
Z
zengyawen 已提交
3791 3792


C
cff-gite 已提交
3793
## CoordinatesOptions
C
cff-gite 已提交
3794

C
cff-gite 已提交
3795
设置坐标选项对象。
C
cff-gite 已提交
3796

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

C
cff-gite 已提交
3799 3800 3801 3802
| 名称 | 类型   | 可读 | 可写 | 说明        |
| ---- | ------ | ---- | ---- | ----------- |
| x    | number | 是   | 是   | x坐标方向。 |
| y    | number | 是   | 是   | y坐标方向。 |
Z
zengyawen 已提交
3803

Z
zengyawen 已提交
3804

C
cff-gite 已提交
3805
## GeomagneticResponse
Z
zengyawen 已提交
3806

C
cff-gite 已提交
3807
设置地磁响应对象,继承于[Response](#response)
Z
zengyawen 已提交
3808

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

C
cff-gite 已提交
3811 3812 3813 3814 3815 3816 3817 3818 3819
| 名称            | 类型   | 可读 | 可写 | 说明                                               |
| --------------- | ------ | ---- | ---- | -------------------------------------------------- |
| x               | number | 是   | 是   | 地磁场的北分量。                                   |
| y               | number | 是   | 是   | 地磁场的东分量。                                   |
| z               | number | 是   | 是   | 地磁场的垂直分量。                                 |
| geomagneticDip  | number | 是   | 是   | 地磁倾角,即地球磁场线与水平面的夹角。             |
| deflectionAngle | number | 是   | 是   | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number | 是   | 是   | 地磁场的水平强度。                                 |
| totalIntensity  | number | 是   | 是   | 地磁场的总强度。                                   |
C
cff-gite 已提交
3820

C
cff-gite 已提交
3821
## LocationOptions
C
cff-gite 已提交
3822

C
cff-gite 已提交
3823
指示地理位置。
C
cff-gite 已提交
3824

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

C
cff-gite 已提交
3827 3828 3829 3830 3831
| 名称      | 类型   | 可读 | 可写 | 说明       |
| --------- | ------ | ---- | ---- | ---------- |
| latitude  | number | 是   | 是   | 纬度。     |
| longitude | number | 是   | 是   | 经度。     |
| altitude  | number | 是   | 是   | 海拔高度。 |
Z
zengyawen 已提交
3832

C
cff-gite 已提交
3833
## sensor.on<sup>(deprecated)</sup>
Z
zengyawen 已提交
3834

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

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

C
cff-gite 已提交
3839
监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
3840

C
cff-gite 已提交
3841
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER](#accelerometer9)代替。
C
cff-gite 已提交
3842

L
li-yaoyao777 已提交
3843
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3844 3845 3846

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

H
HelloCrease 已提交
3847
**参数:** 
C
cff-gite 已提交
3848

C
cff-gite 已提交
3849 3850 3851 3852 3853
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER       | 是   | 要订阅的加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。     |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
3854

H
HelloCrease 已提交
3855
**示例:** 
C
cff-gite 已提交
3856

H
HelloCrease 已提交
3857
  ```js
C
cff-gite 已提交
3858
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
3859 3860 3861
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3862 3863
  },
      {interval: 10000000}
Z
zengyawen 已提交
3864 3865
  );
  ```
Z
zengyawen 已提交
3866

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

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

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

C
cff-gite 已提交
3873
从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)代替。 
C
cff-gite 已提交
3874

C
cff-gite 已提交
3875
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3876 3877 3878

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

H
HelloCrease 已提交
3879
**参数:** 
C
cff-gite 已提交
3880

C
cff-gite 已提交
3881 3882 3883 3884 3885
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 要订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 注册线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
3886

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

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

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

C
cff-gite 已提交
3893
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)代替。
C
cff-gite 已提交
3894

L
li-yaoyao777 已提交
3895
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3896 3897 3898

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

H
HelloCrease 已提交
3899
**参数:** 
C
cff-gite 已提交
3900

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

H
HelloCrease 已提交
3907
**示例:** 
C
cff-gite 已提交
3908 3909
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
3910 3911 3912 3913 3914 3915
      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 已提交
3916 3917
  },
      {interval: 10000000}
Z
zengyawen 已提交
3918 3919
  );
  ```
Z
zengyawen 已提交
3920

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

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

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

C
cff-gite 已提交
3927
从API version 9 开始不再维护,建议使用[sensor.on.GRAVITY](#gravity9)代替。
C
cff-gite 已提交
3928

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

H
HelloCrease 已提交
3931
**参数:** 
C
cff-gite 已提交
3932

C
cff-gite 已提交
3933 3934 3935 3936 3937
| 参数名   | 类型                                                | 必填 | 说明                                                        |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | 是   | 要订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。            |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
| options  | [Options](#options)                                 | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
3938

H
HelloCrease 已提交
3939
**示例:** 
H
HelloCrease 已提交
3940
  ```js
C
cff-gite 已提交
3941
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
Z
zengyawen 已提交
3942 3943 3944
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3945 3946
  },
      {interval: 10000000}
Z
zengyawen 已提交
3947 3948
  );
  ```
Z
zengyawen 已提交
3949

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

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

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

C
cff-gite 已提交
3956
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE](#gyroscope9)代替。
C
cff-gite 已提交
3957

L
li-yaoyao777 已提交
3958
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3959 3960 3961

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

H
HelloCrease 已提交
3962
**参数:** 
C
cff-gite 已提交
3963

C
cff-gite 已提交
3964 3965 3966 3967 3968
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | 是   | 要订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。         |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
3969

H
HelloCrease 已提交
3970
**示例:** 
H
HelloCrease 已提交
3971
  ```js
C
cff-gite 已提交
3972
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
Z
zengyawen 已提交
3973 3974 3975
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3976 3977
  },
      {interval: 10000000}
Z
zengyawen 已提交
3978 3979
  );
  ```
Z
zengyawen 已提交
3980

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

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

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

C
cff-gite 已提交
3987
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)代替。
C
cff-gite 已提交
3988

L
li-yaoyao777 已提交
3989
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3990 3991 3992

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

H
HelloCrease 已提交
3993
**参数:** 
C
cff-gite 已提交
3994

C
cff-gite 已提交
3995 3996 3997 3998 3999
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率。                                 |
Z
zengyawen 已提交
4000

H
HelloCrease 已提交
4001
**示例:** 
H
HelloCrease 已提交
4002
  ```js
C
cff-gite 已提交
4003
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
Z
zengyawen 已提交
4004 4005 4006 4007 4008 4009
      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 已提交
4010 4011
  },
      {interval: 10000000}
Z
zengyawen 已提交
4012 4013
  );
  ```
Z
zengyawen 已提交
4014

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

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

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

C
cff-gite 已提交
4021
从API version 9 开始不再维护,建议使用[sensor.on.SIGNIFICANT_MOTION](#significant_motion9) 代替。
C
cff-gite 已提交
4022

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

H
HelloCrease 已提交
4025
**参数:** 
C
cff-gite 已提交
4026

C
cff-gite 已提交
4027 4028 4029 4030 4031
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | 是   | 要订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4032

H
HelloCrease 已提交
4033
**示例:** 
H
HelloCrease 已提交
4034
  ```js
C
cff-gite 已提交
4035
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
4036
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
4037 4038
  },
      {interval: 10000000}
Z
zengyawen 已提交
4039 4040
  );
  ```
Z
zengyawen 已提交
4041

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

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

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

C
cff-gite 已提交
4048
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)代替。 
C
cff-gite 已提交
4049

C
cff-gite 已提交
4050
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
4051 4052 4053

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

H
HelloCrease 已提交
4054
**参数:** 
C
cff-gite 已提交
4055

C
cff-gite 已提交
4056 4057 4058 4059 4060
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 要订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4061

H
HelloCrease 已提交
4062
**示例:** 
H
HelloCrease 已提交
4063
  ```js
C
cff-gite 已提交
4064
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
4065
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
4066 4067
  },
      {interval: 10000000}
Z
zengyawen 已提交
4068 4069
  );
  ```
Z
zengyawen 已提交
4070

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

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

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

C
cff-gite 已提交
4077
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER](#pedometer9)代替。
C
cff-gite 已提交
4078

C
cff-gite 已提交
4079
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
4080 4081 4082

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

H
HelloCrease 已提交
4083
**参数:** 
C
cff-gite 已提交
4084

C
cff-gite 已提交
4085 4086 4087 4088 4089
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | 是   | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。           |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4090

H
HelloCrease 已提交
4091
**示例:** 
H
HelloCrease 已提交
4092
  ```js
C
cff-gite 已提交
4093
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
4094
      console.info('Steps: ' + data.steps);
C
cff-gite 已提交
4095 4096
  },
      {interval: 10000000}
Z
zengyawen 已提交
4097 4098
  );
  ```
Z
zengyawen 已提交
4099

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

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

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

C
cff-gite 已提交
4106
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)代替。
C
cff-gite 已提交
4107

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

H
HelloCrease 已提交
4110
**参数:** 
C
cff-gite 已提交
4111

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

H
HelloCrease 已提交
4118
**示例:** 
C
cff-gite 已提交
4119

H
HelloCrease 已提交
4120
  ```js
C
cff-gite 已提交
4121
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
4122
      console.info('Temperature: ' + data.temperature);
C
cff-gite 已提交
4123 4124
  },
      {interval: 10000000}
Z
zengyawen 已提交
4125 4126
  );
  ```
Z
zengyawen 已提交
4127

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

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

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

C
cff-gite 已提交
4134
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD](#magnetic_field9)代替。  
C
cff-gite 已提交
4135

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

H
HelloCrease 已提交
4138
**参数:** 
C
cff-gite 已提交
4139

C
cff-gite 已提交
4140 4141 4142 4143 4144
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | 是   | 要订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。      |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4145

H
HelloCrease 已提交
4146
**示例:** 
C
cff-gite 已提交
4147

H
HelloCrease 已提交
4148
  ```js
C
cff-gite 已提交
4149
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
4150 4151 4152
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
4153 4154
  },
      {interval: 10000000}
Z
zengyawen 已提交
4155 4156
  );
  ```
Z
zengyawen 已提交
4157

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

C
cff-gite 已提交
4160
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
4161

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

C
cff-gite 已提交
4164
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)代替。 
C
cff-gite 已提交
4165

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

H
HelloCrease 已提交
4168
**参数:** 
C
cff-gite 已提交
4169

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

H
HelloCrease 已提交
4176
**示例:** 
H
HelloCrease 已提交
4177
  ```js
C
cff-gite 已提交
4178
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
Z
zengyawen 已提交
4179 4180 4181 4182 4183 4184
      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 已提交
4185 4186
  },
      {interval: 10000000}
Z
zengyawen 已提交
4187 4188
  );
  ```
Z
zengyawen 已提交
4189

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

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

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

C
cff-gite 已提交
4196
从API version 9 开始不再维护,建议使用[sensor.on.PROXIMITY](#proximity9)代替。 
C
cff-gite 已提交
4197

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

H
HelloCrease 已提交
4200
**参数:** 
C
cff-gite 已提交
4201

C
cff-gite 已提交
4202 4203 4204 4205 4206
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | 是   | 要订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。         |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4207

H
HelloCrease 已提交
4208
**示例:** 
H
HelloCrease 已提交
4209
  ```js
C
cff-gite 已提交
4210
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
4211
      console.info('Distance: ' + data.distance);
C
cff-gite 已提交
4212 4213
  },
      {interval: 10000000}
Z
zengyawen 已提交
4214 4215
  );
  ```
Z
zengyawen 已提交
4216

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

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

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

C
cff-gite 已提交
4223
从API version 9 开始不再维护,建议使用[sensor.on.HUMIDITY](#humidity9)代替。  
C
cff-gite 已提交
4224

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

H
HelloCrease 已提交
4227
**参数:** 
C
cff-gite 已提交
4228

C
cff-gite 已提交
4229 4230 4231 4232 4233
| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | 是   | 要订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。            |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
| options  | [Options](#options)                                   | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4234

H
HelloCrease 已提交
4235
**示例:** 
C
cff-gite 已提交
4236

H
HelloCrease 已提交
4237
  ```js
C
cff-gite 已提交
4238
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
4239
      console.info('Humidity: ' + data.humidity);
C
cff-gite 已提交
4240 4241
  },
      {interval: 10000000}
Z
zengyawen 已提交
4242 4243
  );
  ```
Z
zengyawen 已提交
4244

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

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

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

C
cff-gite 已提交
4251
从API version 9 开始不再维护,建议使用[sensor.on.BAROMETER](#barometer9)代替。
C
cff-gite 已提交
4252

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

H
HelloCrease 已提交
4255
**参数:** 
C
cff-gite 已提交
4256

C
cff-gite 已提交
4257 4258 4259 4260 4261
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | 是   | 要订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。         |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
| options  | [Options](#options)                                     | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4262

H
HelloCrease 已提交
4263
**示例:** 
C
cff-gite 已提交
4264

H
HelloCrease 已提交
4265
  ```js
C
cff-gite 已提交
4266
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
4267
      console.info('Atmospheric pressure: ' + data.pressure);
C
cff-gite 已提交
4268 4269
  },
      {interval: 10000000}
Z
zengyawen 已提交
4270 4271
  );
  ```
Z
zengyawen 已提交
4272

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

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

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

C
cff-gite 已提交
4279
从API version 9 开始不再维护,建议使用[sensor.on.HALL](#hall9)代替。
C
cff-gite 已提交
4280

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

H
HelloCrease 已提交
4283
**参数:** 
C
cff-gite 已提交
4284

C
cff-gite 已提交
4285 4286 4287 4288 4289
| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | 是   | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。                |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
| options  | [Options](#options)                           | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4290

H
HelloCrease 已提交
4291
**示例:** 
H
HelloCrease 已提交
4292
  ```js
C
cff-gite 已提交
4293
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
4294
      console.info('Status: ' + data.status);
C
cff-gite 已提交
4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305
  },
      {interval: 10000000}
  );
  ```

### AMBIENT_LIGHT<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4306
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_LIGHT](#ambient_light9)代替。
C
cff-gite 已提交
4307 4308 4309 4310 4311

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

**参数:** 

C
cff-gite 已提交
4312 4313 4314 4315 4316
| 参数名   | 类型                                                   | 必填 | 说明                                                        |
| -------- | ------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | 是   | 要订阅的环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。    |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt;        | 是   | 注册环境光传感器的回调函数,上报的数据类型为LightResponse。 |
| options  | [Options](#options)                                    | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。           |
C
cff-gite 已提交
4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333

**示例:** 

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

### ORIENTATION<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4334
从API version 9 开始不再维护,建议使用[sensor.on.ORIENTATION](#orientation9)代替。
C
cff-gite 已提交
4335 4336 4337 4338 4339

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

**参数:** 

C
cff-gite 已提交
4340 4341 4342 4343 4344
| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | 是   | 要订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION           |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
| options  | [Options](#options)                                         | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
C
cff-gite 已提交
4345 4346 4347 4348 4349 4350 4351 4352 4353

**示例:** 
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4354 4355
  );
  ```
Z
zengyawen 已提交
4356

C
cff-gite 已提交
4357 4358 4359 4360 4361 4362
### HEART_RATE<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4363 4364
从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9)代替。

C
cff-gite 已提交
4365 4366 4367 4368 4369 4370 4371 4372
**需要权限**:ohos.permission.HEALTH_DATA 

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

**参数:** 

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

### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
4377

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

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

C
cff-gite 已提交
4382
从API version 9 开始不再维护,建议使用[sensor.on.ROTATION_VECTOR](#rotation_vector9)代替。
C
cff-gite 已提交
4383

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

H
HelloCrease 已提交
4386
**参数:** 
C
cff-gite 已提交
4387

C
cff-gite 已提交
4388 4389 4390 4391 4392
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | 是   | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4393

H
HelloCrease 已提交
4394
**示例:** 
H
HelloCrease 已提交
4395
  ```js
C
cff-gite 已提交
4396 4397 4398 4399 4400 4401 4402
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('Scalar quantity: ' + data.w);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4403 4404
  );
  ```
Z
zengyawen 已提交
4405

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

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

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

C
cff-gite 已提交
4412
从API version 9 开始不再维护,建议使用[sensor.on.WEAR_DETECTION](#wear_detection9)代替。
C
cff-gite 已提交
4413

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

H
HelloCrease 已提交
4416
**参数:** 
C
cff-gite 已提交
4417

C
cff-gite 已提交
4418 4419 4420 4421 4422
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | 是   | 要订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。  |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
| options  | [Options](#options)                                          | 否   | 可选参数列表,设置上报频率,默认值为200000000ns。            |
Z
zengyawen 已提交
4423

H
HelloCrease 已提交
4424
**示例:** 
H
HelloCrease 已提交
4425
  ```js
C
cff-gite 已提交
4426 4427 4428 4429
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4430 4431
  );
  ```
Z
zengyawen 已提交
4432

C
cff-gite 已提交
4433
## sensor.once<sup>(deprecated)</sup>
Z
zengyawen 已提交
4434

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

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

C
cff-gite 已提交
4439 4440
监听加速度传感器的数据变化一次。

C
cff-gite 已提交
4441
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER](#accelerometer9-1)代替。
C
cff-gite 已提交
4442 4443

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4444

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

H
HelloCrease 已提交
4447
**参数:** 
C
cff-gite 已提交
4448

C
cff-gite 已提交
4449 4450 4451 4452
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER       | 是   | 加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER。             |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 注册一次加速度传感器的回调函数,上报的数据类型为AccelerometerResponse。 |
Z
zengyawen 已提交
4453

H
HelloCrease 已提交
4454
**示例:** 
H
HelloCrease 已提交
4455
  ```js
C
cff-gite 已提交
4456
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
4457 4458 4459
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
4460
    }
Z
zengyawen 已提交
4461 4462
  );
  ```
Z
zengyawen 已提交
4463

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

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

C
cff-gite 已提交
4468
监听线性加速度传感器数据变化一次。
Z
zengyawen 已提交
4469

C
cff-gite 已提交
4470
从API version 9 开始不再维护,建议使用[sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)代替。
C
cff-gite 已提交
4471

C
cff-gite 已提交
4472
**需要权限**:ohos.permission.ACCELERATION
C
cff-gite 已提交
4473 4474 4475

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

H
HelloCrease 已提交
4476
**参数:** 
C
cff-gite 已提交
4477

C
cff-gite 已提交
4478 4479 4480 4481
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。   |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 注册一次线性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
Z
zengyawen 已提交
4482

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

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

C
cff-gite 已提交
4487
监听未校准加速度传感器的数据变化一次。
Z
zengyawen 已提交
4488

C
cff-gite 已提交
4489
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)代替。
C
cff-gite 已提交
4490 4491

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4492

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

H
HelloCrease 已提交
4495
**参数:** 
C
cff-gite 已提交
4496

C
cff-gite 已提交
4497 4498 4499 4500
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 是   | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
Z
zengyawen 已提交
4501

H
HelloCrease 已提交
4502
**示例:** 
C
cff-gite 已提交
4503 4504 4505 4506 4507 4508 4509 4510
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
Z
zengyawen 已提交
4511
    }
Z
zengyawen 已提交
4512 4513
  );
  ```
Z
zengyawen 已提交
4514

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

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

C
cff-gite 已提交
4519
监听重力传感器的数据变化一次。
C
cff-gite 已提交
4520

C
cff-gite 已提交
4521
从API version 9 开始不再维护,建议使用[sensor.once.GRAVITY](#gravity9-1)代替。
C
cff-gite 已提交
4522

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

H
HelloCrease 已提交
4525
**参数:** 
C
cff-gite 已提交
4526

C
cff-gite 已提交
4527 4528 4529 4530
| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | 是   | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。                     |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
Z
zengyawen 已提交
4531

H
HelloCrease 已提交
4532
**示例:** 
C
cff-gite 已提交
4533 4534 4535 4536 4537 4538 4539 4540
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
C
cff-gite 已提交
4541

C
cff-gite 已提交
4542
### GYROSCOPE<sup>(deprecated)</sup>
C
cff-gite 已提交
4543

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

C
cff-gite 已提交
4546
监听陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4547

C
cff-gite 已提交
4548
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE](#gyroscope9-1)代替。
C
cff-gite 已提交
4549

C
cff-gite 已提交
4550
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4551

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

H
HelloCrease 已提交
4554
**参数:** 
C
cff-gite 已提交
4555

C
cff-gite 已提交
4556 4557 4558 4559
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | 是   | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。                 |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
C
cff-gite 已提交
4560

H
HelloCrease 已提交
4561
**示例:** 
C
cff-gite 已提交
4562 4563 4564 4565 4566 4567 4568 4569
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
C
cff-gite 已提交
4570

C
cff-gite 已提交
4571
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4572

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

C
cff-gite 已提交
4575
监听未校准陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4576

C
cff-gite 已提交
4577
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)代替。
C
cff-gite 已提交
4578

C
cff-gite 已提交
4579
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4580

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

H
HelloCrease 已提交
4583
**参数:** 
C
cff-gite 已提交
4584

C
cff-gite 已提交
4585 4586 4587 4588
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
4589

H
HelloCrease 已提交
4590
**示例:** 
C
cff-gite 已提交
4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
    }
  );
  ```
C
cff-gite 已提交
4602

C
cff-gite 已提交
4603
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4604

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

C
cff-gite 已提交
4607
监听有效运动传感器的数据变化一次。
C
cff-gite 已提交
4608

C
cff-gite 已提交
4609
从API version 9 开始不再维护,建议使用[sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)代替。
C
cff-gite 已提交
4610

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

H
HelloCrease 已提交
4613
**参数:** 
C
cff-gite 已提交
4614

C
cff-gite 已提交
4615 4616 4617 4618
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | 是   | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。      |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
C
cff-gite 已提交
4619

H
HelloCrease 已提交
4620
**示例:** 
C
cff-gite 已提交
4621 4622 4623 4624 4625 4626
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4627

C
cff-gite 已提交
4628
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4629

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

C
cff-gite 已提交
4632
监听计步检测传感器数据变化一次。
C
cff-gite 已提交
4633

C
cff-gite 已提交
4634
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)代替。
C
cff-gite 已提交
4635

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

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

H
HelloCrease 已提交
4640
**参数:** 
C
cff-gite 已提交
4641

C
cff-gite 已提交
4642 4643 4644 4645
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。     |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
C
cff-gite 已提交
4646

H
HelloCrease 已提交
4647
**示例:** 
C
cff-gite 已提交
4648 4649 4650 4651 4652 4653
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4654

C
cff-gite 已提交
4655
### PEDOMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4656

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

C
cff-gite 已提交
4659
监听计步器传感器数据变化一次。
C
cff-gite 已提交
4660

C
cff-gite 已提交
4661
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER](#pedometer9-1)代替。
C
cff-gite 已提交
4662

C
cff-gite 已提交
4663
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
4664 4665 4666

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

H
HelloCrease 已提交
4667
**参数:** 
C
cff-gite 已提交
4668

C
cff-gite 已提交
4669 4670 4671 4672
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | 是   | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。                   |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
C
cff-gite 已提交
4673

H
HelloCrease 已提交
4674
**示例:** 
C
cff-gite 已提交
4675 4676 4677 4678 4679 4680
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
      console.info('Steps: ' + data.steps);
    }
  );
  ```
C
cff-gite 已提交
4681

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

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

C
cff-gite 已提交
4686
监听环境温度传感器数据变化一次。
C
cff-gite 已提交
4687

C
cff-gite 已提交
4688
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)代替。
C
cff-gite 已提交
4689 4690 4691

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

H
HelloCrease 已提交
4692
**参数:** 
C
cff-gite 已提交
4693

C
cff-gite 已提交
4694 4695 4696 4697
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 是   | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。     |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
C
cff-gite 已提交
4698

H
HelloCrease 已提交
4699
**示例:** 
C
cff-gite 已提交
4700 4701 4702 4703 4704 4705
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
      console.info('Temperature: ' + data.temperature);
    }
  );
  ```
C
cff-gite 已提交
4706

C
cff-gite 已提交
4707
### MAGNETIC_FIELD<sup>(deprecated)</sup>
C
cff-gite 已提交
4708

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

C
cff-gite 已提交
4711
监听磁场传感器数据变化一次。
C
cff-gite 已提交
4712

C
cff-gite 已提交
4713
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)代替。
C
cff-gite 已提交
4714

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

H
HelloCrease 已提交
4717
**参数:** 
C
cff-gite 已提交
4718

C
cff-gite 已提交
4719 4720 4721 4722
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | 是   | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。              |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
C
cff-gite 已提交
4723

H
HelloCrease 已提交
4724
**示例:** 
C
cff-gite 已提交
4725 4726 4727 4728 4729 4730 4731 4732
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
C
cff-gite 已提交
4733

C
cff-gite 已提交
4734
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4735

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

C
cff-gite 已提交
4738
监听未校准磁场传感器数据变化一次。
H
h00514358 已提交
4739

C
cff-gite 已提交
4740
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)代替。
C
cff-gite 已提交
4741 4742 4743

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

H
HelloCrease 已提交
4744
**参数:** 
C
cff-gite 已提交
4745

C
cff-gite 已提交
4746 4747 4748 4749
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 是   | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
4750

C
cff-gite 已提交
4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
    }
  );
  ```
H
h00514358 已提交
4763

C
cff-gite 已提交
4764
### PROXIMITY<sup>(deprecated)</sup>
H
h00514358 已提交
4765

C
cff-gite 已提交
4766
once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
H
h00514358 已提交
4767

C
cff-gite 已提交
4768
监听接近光传感器数据变化一次。
H
h00514358 已提交
4769

C
cff-gite 已提交
4770
从API version 9 开始不再维护,建议使用[sensor.once.PROXIMITY](#proximity9-1)代替。
H
h00514358 已提交
4771

C
cff-gite 已提交
4772
**系统能力**:SystemCapability.Sensors.Sensor
H
h00514358 已提交
4773

C
cff-gite 已提交
4774
**参数:** 
H
h00514358 已提交
4775

C
cff-gite 已提交
4776 4777 4778 4779
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | 是   | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。                 |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
H
h00514358 已提交
4780

C
cff-gite 已提交
4781 4782 4783 4784 4785 4786 4787
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
      console.info('Distance: ' + data.distance);
    }
  );
  ```
H
h00514358 已提交
4788

C
cff-gite 已提交
4789
### HUMIDITY<sup>(deprecated)</sup>
C
cff-gite 已提交
4790

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

C
cff-gite 已提交
4793
监听湿度传感器数据变化一次。
C
cff-gite 已提交
4794

C
cff-gite 已提交
4795
从API version 9 开始不再维护,建议使用[sensor.once.HUMIDITY](#humidity9-1)代替。
C
cff-gite 已提交
4796

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

H
HelloCrease 已提交
4799
**参数:** 
C
cff-gite 已提交
4800

C
cff-gite 已提交
4801 4802 4803 4804
| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | 是   | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。                    |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
C
cff-gite 已提交
4805

H
HelloCrease 已提交
4806
**示例:** 
C
cff-gite 已提交
4807 4808 4809 4810 4811 4812
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
  ```
C
cff-gite 已提交
4813

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

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

C
cff-gite 已提交
4818
监听气压计传感器数据变化一次。
H
h00514358 已提交
4819

C
cff-gite 已提交
4820
从API version 9 开始不再维护,建议使用[sensor.once.BAROMETER](#barometer9-1)代替。
C
cff-gite 已提交
4821 4822 4823

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

H
HelloCrease 已提交
4824
**参数:** 
C
cff-gite 已提交
4825

C
cff-gite 已提交
4826 4827 4828 4829
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | 是   | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。                 |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
C
cff-gite 已提交
4830

C
cff-gite 已提交
4831 4832 4833 4834 4835 4836 4837
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
  ```
H
h00514358 已提交
4838

C
cff-gite 已提交
4839
### HALL<sup>(deprecated)</sup>
H
h00514358 已提交
4840

C
cff-gite 已提交
4841
once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
H
h00514358 已提交
4842

C
cff-gite 已提交
4843 4844
监听霍尔传感器数据变化一次。

C
cff-gite 已提交
4845
从API version 9 开始不再维护,建议使用[sensor.once.HALL](#hall9-1)代替。
H
h00514358 已提交
4846 4847 4848

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

C
cff-gite 已提交
4849
**参数:** 
H
h00514358 已提交
4850

C
cff-gite 已提交
4851 4852 4853 4854
| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | 是   | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。                        |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
H
h00514358 已提交
4855

C
cff-gite 已提交
4856 4857 4858 4859 4860 4861 4862
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
  ```
H
h00514358 已提交
4863

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

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

C
cff-gite 已提交
4868
监听环境光传感器数据变化一次。
C
cff-gite 已提交
4869

C
cff-gite 已提交
4870
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_LIGHT](#ambient_light9-1)代替。
C
cff-gite 已提交
4871

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

H
HelloCrease 已提交
4874
**参数:** 
C
cff-gite 已提交
4875

C
cff-gite 已提交
4876 4877 4878 4879
| 参数名   | 类型                                                   | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | 是   | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。             |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt;        | 是   | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
C
cff-gite 已提交
4880

H
HelloCrease 已提交
4881
**示例:** 
C
cff-gite 已提交
4882

C
cff-gite 已提交
4883 4884 4885 4886 4887 4888
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
      console.info(' Illumination: ' + data.intensity);
    }
  );
  ```
C
cff-gite 已提交
4889

C
cff-gite 已提交
4890
### ORIENTATION<sup>(deprecated)</sup>
C
cff-gite 已提交
4891

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

C
cff-gite 已提交
4894
监听方向传感器数据变化一次。
C
cff-gite 已提交
4895

C
cff-gite 已提交
4896
从API version 9 开始不再维护,建议使用[sensor.once.ORIENTATION](#orientation9-1)代替。 
C
cff-gite 已提交
4897

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

H
HelloCrease 已提交
4900
**参数:** 
C
cff-gite 已提交
4901

C
cff-gite 已提交
4902 4903 4904 4905
| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | 是   | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。                 |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
C
cff-gite 已提交
4906

H
HelloCrease 已提交
4907
**示例:** 
C
cff-gite 已提交
4908 4909 4910 4911 4912 4913 4914 4915
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
    }
  );
  ```
C
cff-gite 已提交
4916

C
cff-gite 已提交
4917
### ROTATION_VECTOR<sup>(deprecated)</sup>
C
cff-gite 已提交
4918

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

C
cff-gite 已提交
4921
监听旋转矢量传感器数据变化一次。
C
cff-gite 已提交
4922

C
cff-gite 已提交
4923
从API version 9 开始不再维护,建议使用[sensor.once.ROTATION_VECTOR](#rotation_vector9-1)代替。  
C
cff-gite 已提交
4924

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

H
HelloCrease 已提交
4927
**参数:** 
C
cff-gite 已提交
4928

C
cff-gite 已提交
4929 4930 4931 4932
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | 是   | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。         |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
C
cff-gite 已提交
4933

H
HelloCrease 已提交
4934
**示例:** 
C
cff-gite 已提交
4935 4936 4937 4938 4939 4940 4941 4942 4943
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('Scalar quantity: ' + data.w);
    }
  );
  ```
C
cff-gite 已提交
4944

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

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

C
cff-gite 已提交
4949
监听心率传感器数据变化一次。
C
cff-gite 已提交
4950

C
cff-gite 已提交
4951
从API version 9 开始不再维护,建议使用[sensor.once.HEART_RATE](#heart_rate9-1)代替。
C
cff-gite 已提交
4952

C
cff-gite 已提交
4953
**需要权限**:ohos.permission.HEART_RATE  
C
cff-gite 已提交
4954

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

H
HelloCrease 已提交
4957
**参数:** 
C
cff-gite 已提交
4958

C
cff-gite 已提交
4959 4960 4961 4962
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HEART_RATE     | 是   | 心率传感器类型为SENSOR_TYPE_ID_HEART_RATE。                  |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 注册一次心率传感器的回调函数,上报的数据类型为HeartRateResponse。 |
C
cff-gite 已提交
4963

C
cff-gite 已提交
4964
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4965

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

C
cff-gite 已提交
4968
监听佩戴检测传感器数据变化一次。
C
cff-gite 已提交
4969

C
cff-gite 已提交
4970
从API version 9 开始不再维护,建议使用[sensor.once.WEAR_DETECTION](#wear_detection9-1)代替。  
C
cff-gite 已提交
4971

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

H
HelloCrease 已提交
4974
**参数:** 
C
cff-gite 已提交
4975

C
cff-gite 已提交
4976 4977 4978 4979
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | 是   | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。          |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
C
cff-gite 已提交
4980

H
HelloCrease 已提交
4981
**示例:** 
C
cff-gite 已提交
4982 4983 4984 4985 4986 4987
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
    }
  );
  ```
C
cff-gite 已提交
4988

C
cff-gite 已提交
4989
## sensor.off<sup>(deprecated)</sup>
C
cff-gite 已提交
4990

C
cff-gite 已提交
4991
### ACCELEROMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4992

C
cff-gite 已提交
4993
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
C
cff-gite 已提交
4994 4995 4996

取消订阅传感器数据。

C
cff-gite 已提交
4997
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER](#accelerometer9-2)代替。  
C
cff-gite 已提交
4998 4999

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5000

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

H
HelloCrease 已提交
5003
**参数:** 
C
cff-gite 已提交
5004

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

H
HelloCrease 已提交
5010
**示例:** 
C
cff-gite 已提交
5011

H
HelloCrease 已提交
5012
```js
C
cff-gite 已提交
5013
function callback(data) {
C
cff-gite 已提交
5014
    console.info('x-coordinate component: ' + data.x);
C
cff-gite 已提交
5015 5016 5017
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
C
cff-gite 已提交
5018
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
C
cff-gite 已提交
5019 5020
```

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

C
cff-gite 已提交
5023
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
5024 5025 5026

取消订阅传感器数据。

C
cff-gite 已提交
5027
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)代替。 
C
cff-gite 已提交
5028 5029

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5030

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

H
HelloCrease 已提交
5033
**参数:** 
C
cff-gite 已提交
5034

C
cff-gite 已提交
5035 5036 5037 5038
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 是   | 要取消订阅的未校准加速度计传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 否   | 取消注册未校准加速度计传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
C
cff-gite 已提交
5039

H
HelloCrease 已提交
5040
**示例:** 
C
cff-gite 已提交
5041

H
HelloCrease 已提交
5042
```js
C
cff-gite 已提交
5043
function callback(data) {
C
cff-gite 已提交
5044 5045 5046 5047 5048 5049
    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 已提交
5050
}
C
cff-gite 已提交
5051
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
C
cff-gite 已提交
5052 5053
```

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

C
cff-gite 已提交
5056
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
5057 5058 5059

取消订阅传感器数据。

C
cff-gite 已提交
5060
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_LIGHT](#ambient_light9-2)代替。 
C
cff-gite 已提交
5061

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

H
HelloCrease 已提交
5064
**参数:** 
C
cff-gite 已提交
5065

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

H
HelloCrease 已提交
5071
**示例:** 
C
cff-gite 已提交
5072

H
HelloCrease 已提交
5073
```js
C
cff-gite 已提交
5074 5075
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
C
cff-gite 已提交
5076
}
C
cff-gite 已提交
5077
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
C
cff-gite 已提交
5078
```
Z
zengyawen 已提交
5079

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

C
cff-gite 已提交
5082
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
Z
zengyawen 已提交
5083

C
cff-gite 已提交
5084
取消订阅传感器数据。
Z
zengyawen 已提交
5085

C
cff-gite 已提交
5086
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)代替。 
C
cff-gite 已提交
5087

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

H
HelloCrease 已提交
5090
**参数:** 
Z
zengyawen 已提交
5091

C
cff-gite 已提交
5092 5093 5094 5095
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 是   | 要取消订阅的环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 否   | 取消注册环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
Z
zengyawen 已提交
5096

H
HelloCrease 已提交
5097
**示例:** 
Z
zengyawen 已提交
5098

H
HelloCrease 已提交
5099
```js
C
cff-gite 已提交
5100 5101 5102
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
C
cff-gite 已提交
5103
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
H
HelloCrease 已提交
5104
```
Z
zengyawen 已提交
5105

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

C
cff-gite 已提交
5108
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
Z
zengyawen 已提交
5109

C
cff-gite 已提交
5110 5111
取消订阅传感器数据。

C
cff-gite 已提交
5112
从API version 9 开始不再维护,建议使用[sensor.off.BAROMETER](#barometer9-2)代替。 
C
cff-gite 已提交
5113

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

H
HelloCrease 已提交
5116
**参数:** 
Z
zengyawen 已提交
5117

C
cff-gite 已提交
5118 5119 5120 5121
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | 是   | 要取消订阅的气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。     |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 否   | 取消注册气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
Z
zengyawen 已提交
5122

H
HelloCrease 已提交
5123
**示例:** 
Z
zengyawen 已提交
5124

H
HelloCrease 已提交
5125
```js
C
cff-gite 已提交
5126 5127 5128 5129
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
H
HelloCrease 已提交
5130
```
Z
zengyawen 已提交
5131

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

C
cff-gite 已提交
5134
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
5135

C
cff-gite 已提交
5136
取消订阅传感器数据。
Z
zengyawen 已提交
5137

C
cff-gite 已提交
5138
从API version 9 开始不再维护,建议使用[sensor.off.GRAVITY](#gravity9-2)代替。  
C
cff-gite 已提交
5139

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

H
HelloCrease 已提交
5142
**参数:** 
C
cff-gite 已提交
5143

C
cff-gite 已提交
5144 5145 5146 5147
| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | 是   | 要取消订阅的重力传感器类型为SENSOR_TYPE_ID_GRAVITY。         |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 否   | 取消注册注册重力传感器的回调函数,上报的数据类型为GravityResponse。 |
Z
zengyawen 已提交
5148

H
HelloCrease 已提交
5149
**示例:** 
C
cff-gite 已提交
5150

H
HelloCrease 已提交
5151
```js
C
cff-gite 已提交
5152 5153 5154 5155 5156 5157
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
H
HelloCrease 已提交
5158
```
Z
zengyawen 已提交
5159

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

C
cff-gite 已提交
5162
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
Z
zengyawen 已提交
5163

C
cff-gite 已提交
5164 5165
取消订阅传感器数据。

C
cff-gite 已提交
5166
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE](#gyroscope9-2)代替。 
C
cff-gite 已提交
5167 5168

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
5169

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

H
HelloCrease 已提交
5172
**参数:** 
C
cff-gite 已提交
5173

C
cff-gite 已提交
5174 5175 5176 5177
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | 是   | 要取消订阅的陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。     |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 否   | 取消注册陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
Z
zengyawen 已提交
5178

H
HelloCrease 已提交
5179
**示例:** 
Z
zengyawen 已提交
5180

C
cff-gite 已提交
5181 5182 5183 5184 5185 5186 5187 5188 5189 5190
```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
```

### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
Z
zengyawen 已提交
5191

C
cff-gite 已提交
5192
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
5193

C
cff-gite 已提交
5194
取消订阅传感器数据。
Z
zengyawen 已提交
5195

C
cff-gite 已提交
5196
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)代替。  
C
cff-gite 已提交
5197 5198

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
5199

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

H
HelloCrease 已提交
5202
**参数:** 
Z
zengyawen 已提交
5203

C
cff-gite 已提交
5204 5205 5206 5207
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 是   | 要取消订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 否   | 取消注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
Z
zengyawen 已提交
5208

H
HelloCrease 已提交
5209
**示例:** 
Z
zengyawen 已提交
5210

C
cff-gite 已提交
5211 5212 5213 5214 5215 5216 5217 5218
```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
```
Z
zengyawen 已提交
5219

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

C
cff-gite 已提交
5222
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
Z
zengyawen 已提交
5223

C
cff-gite 已提交
5224
取消订阅传感器数据。
Z
zengyawen 已提交
5225

C
cff-gite 已提交
5226
从API version 9 开始不再维护,建议使用[sensor.off.HALL](#hall9-2)代替。 
C
cff-gite 已提交
5227

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

H
HelloCrease 已提交
5230
**参数:** 
Z
zengyawen 已提交
5231

C
cff-gite 已提交
5232 5233 5234 5235
| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | 是   | 要取消订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。            |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 否   | 取消注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
Z
zengyawen 已提交
5236

H
HelloCrease 已提交
5237
**示例:** 
Z
zengyawen 已提交
5238

C
cff-gite 已提交
5239 5240 5241 5242 5243 5244
```js
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```
Z
zengyawen 已提交
5245

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

C
cff-gite 已提交
5248
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
Z
zengyawen 已提交
5249

C
cff-gite 已提交
5250
取消订阅传感器数据。
Z
zengyawen 已提交
5251

C
cff-gite 已提交
5252
从API version 9 开始不再维护,建议使用[sensor.off.HEART_RATE](#heart_rate9-2)代替。
C
cff-gite 已提交
5253

C
cff-gite 已提交
5254
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
5255

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

H
HelloCrease 已提交
5258
**参数:** 
Z
zengyawen 已提交
5259

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

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

C
cff-gite 已提交
5267
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
Z
zengyawen 已提交
5268

C
cff-gite 已提交
5269
取消订阅传感器数据。
Z
zengyawen 已提交
5270

C
cff-gite 已提交
5271
从API version 9 开始不再维护,建议使用[sensor.off.HUMIDITY](#humidity9-2)代替。 
C
cff-gite 已提交
5272

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

H
HelloCrease 已提交
5275
**参数:** 
Z
zengyawen 已提交
5276

C
cff-gite 已提交
5277 5278 5279 5280
| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | 是   | 要取消订阅的湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。        |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 否   | 取消注册湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
Z
zengyawen 已提交
5281

H
HelloCrease 已提交
5282
**示例:** 
Z
zengyawen 已提交
5283

C
cff-gite 已提交
5284 5285 5286 5287 5288 5289
```js
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```
Z
zengyawen 已提交
5290

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

C
cff-gite 已提交
5293
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
5294

C
cff-gite 已提交
5295
取消订阅传感器数据。
Z
zengyawen 已提交
5296

C
cff-gite 已提交
5297
从API version 9 开始不再维护,建议使用[sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)代替。
C
cff-gite 已提交
5298

C
cff-gite 已提交
5299
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5300

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

H
HelloCrease 已提交
5303
**参数:** 
Z
zengyawen 已提交
5304

C
cff-gite 已提交
5305 5306 5307 5308
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | 是   | 要取消订阅的线性加速度传感器类型为SENSOR_TYPE_ID_LINEAR_ACCELERATION。 |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 否   | 取消注册性加速度传感器的回调函数,上报的数据类型为LinearAccelerometerResponse。 |
Z
zengyawen 已提交
5309

C
cff-gite 已提交
5310 5311 5312 5313 5314 5315
### MAGNETIC_FIELD<sup>(deprecated)</sup>

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

取消订阅传感器数据。

C
cff-gite 已提交
5316
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)代替。 
C
cff-gite 已提交
5317

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

H
HelloCrease 已提交
5320
**参数:** 
Z
zengyawen 已提交
5321

C
cff-gite 已提交
5322 5323 5324 5325
| 参数名           | 类型                                                         | 必填 | 说明                                                         |
| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type             | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | 是   | 要取消订阅的磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。  |
| callbackcallback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 否   | 取消注册磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
Z
zengyawen 已提交
5326

H
HelloCrease 已提交
5327
**示例:** 
Z
zengyawen 已提交
5328

C
cff-gite 已提交
5329 5330 5331 5332 5333 5334 5335 5336
```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
```
Z
zengyawen 已提交
5337

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

C
cff-gite 已提交
5340
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
5341

C
cff-gite 已提交
5342
取消订阅传感器数据。
Z
zengyawen 已提交
5343

C
cff-gite 已提交
5344
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)代替。
C
cff-gite 已提交
5345

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

H
HelloCrease 已提交
5348
**参数:** 
Z
zengyawen 已提交
5349

C
cff-gite 已提交
5350 5351 5352 5353
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 是   | 要取消订阅的未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 否   | 取消注册未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
Z
zengyawen 已提交
5354

H
HelloCrease 已提交
5355
**示例:** 
Z
zengyawen 已提交
5356

C
cff-gite 已提交
5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367
```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
```
Z
zengyawen 已提交
5368

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

C
cff-gite 已提交
5371
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
Z
zengyawen 已提交
5372

C
cff-gite 已提交
5373
取消订阅传感器数据。
Z
zengyawen 已提交
5374

C
cff-gite 已提交
5375
从API version 9 开始不再维护,建议使用[sensor.off.ORIENTATION](#orientation9-2)代替。 
C
cff-gite 已提交
5376

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

H
HelloCrease 已提交
5379
**参数:** 
Z
zengyawen 已提交
5380

C
cff-gite 已提交
5381 5382 5383 5384
| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | 是   | 要取消订阅的方向传感器类型为SENSOR_TYPE_ID_ORIENTATION       |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 否   | 取消注册方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
Z
zengyawen 已提交
5385

H
HelloCrease 已提交
5386
**示例:** 
Z
zengyawen 已提交
5387

C
cff-gite 已提交
5388 5389 5390 5391 5392 5393 5394 5395
```js
function callback(data) {
    console.info('The device rotates at an angle around the X axis: ' + data.beta);
    console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
    console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```
Z
zengyawen 已提交
5396

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

C
cff-gite 已提交
5399
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
5400

C
cff-gite 已提交
5401
取消订阅传感器数据。
Z
zengyawen 已提交
5402

C
cff-gite 已提交
5403
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER](#pedometer9-2)代替。 
Z
zengyawen 已提交
5404

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

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

H
HelloCrease 已提交
5409
**参数:** 
Z
zengyawen 已提交
5410

C
cff-gite 已提交
5411 5412 5413 5414
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | 是   | 要取消订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。       |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 否   | 取消注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
C
cff-gite 已提交
5415 5416

**示例:** 
Z
zengyawen 已提交
5417

C
cff-gite 已提交
5418 5419 5420 5421 5422 5423
```js
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```
Z
zengyawen 已提交
5424

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

C
cff-gite 已提交
5427
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
Z
zengyawen 已提交
5428

C
cff-gite 已提交
5429
取消订阅传感器数据。
Z
zengyawen 已提交
5430

C
cff-gite 已提交
5431
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)代替。 
C
cff-gite 已提交
5432 5433

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

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

H
HelloCrease 已提交
5437
**参数:** 
Z
zengyawen 已提交
5438

C
cff-gite 已提交
5439 5440 5441 5442
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | 是   | 要取消订阅的计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 否   | 取消注册计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
Z
zengyawen 已提交
5443

H
HelloCrease 已提交
5444
**示例:** 
Z
zengyawen 已提交
5445

C
cff-gite 已提交
5446 5447 5448 5449 5450 5451
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```
Z
zengyawen 已提交
5452

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

C
cff-gite 已提交
5455
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
Z
zengyawen 已提交
5456

C
cff-gite 已提交
5457
取消订阅传感器数据。
Z
zengyawen 已提交
5458

C
cff-gite 已提交
5459
从API version 9 开始不再维护,建议使用[sensor.off.PROXIMITY](#proximity9-2)代替。 
C
cff-gite 已提交
5460

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

H
HelloCrease 已提交
5463
**参数:** 
Z
zengyawen 已提交
5464

C
cff-gite 已提交
5465 5466 5467 5468
| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | 是   | 要取消订阅的接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。     |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 否   | 取消注册接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
Z
zengyawen 已提交
5469

H
HelloCrease 已提交
5470
**示例:** 
Z
zengyawen 已提交
5471

C
cff-gite 已提交
5472 5473 5474 5475 5476 5477
```js
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```
Z
zengyawen 已提交
5478

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

C
cff-gite 已提交
5481
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
Z
zengyawen 已提交
5482

C
cff-gite 已提交
5483
取消订阅传感器数据。
Z
zengyawen 已提交
5484

C
cff-gite 已提交
5485
从API version 9 开始不再维护,建议使用[sensor.off.ROTATION_VECTOR](#rotation_vector9-2)代替。 
C
cff-gite 已提交
5486

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

H
HelloCrease 已提交
5489
**参数:** 
Z
zengyawen 已提交
5490

C
cff-gite 已提交
5491 5492 5493 5494
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | 是   | 要取消订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 否   | 取消注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
Z
zengyawen 已提交
5495

H
HelloCrease 已提交
5496
**示例:** 
Z
zengyawen 已提交
5497

C
cff-gite 已提交
5498 5499 5500 5501 5502 5503 5504 5505 5506
```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('Scalar quantity: ' + data.w);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```
Z
zengyawen 已提交
5507

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

C
cff-gite 已提交
5510
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
5511

C
cff-gite 已提交
5512
取消订阅传感器数据。
Z
zengyawen 已提交
5513

C
cff-gite 已提交
5514
从API version 9 开始不再维护,建议使用[sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)代替。
C
cff-gite 已提交
5515

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

H
HelloCrease 已提交
5518
**参数:** 
Z
zengyawen 已提交
5519

C
cff-gite 已提交
5520 5521 5522 5523
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | 是   | 要取消订阅的大幅动作传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 否   | 取消注册有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
Z
zengyawen 已提交
5524

H
HelloCrease 已提交
5525
**示例:** 
Z
zengyawen 已提交
5526

C
cff-gite 已提交
5527 5528 5529 5530 5531 5532
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
Z
zengyawen 已提交
5533

C
cff-gite 已提交
5534
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
5535

C
cff-gite 已提交
5536
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
5537

C
cff-gite 已提交
5538 5539
取消订阅传感器数据。

C
cff-gite 已提交
5540
从API version 9 开始不再维护,建议使用[sensor.off.WEAR_DETECTION](#wear_detection9-2)代替。 
C
cff-gite 已提交
5541 5542 5543 5544 5545

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

**参数:** 

C
cff-gite 已提交
5546 5547 5548 5549
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | 是   | 要取消订阅的佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 否   | 取消注册佩戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
C
cff-gite 已提交
5550 5551 5552

**示例:** 

C
cff-gite 已提交
5553
```js
C
cff-gite 已提交
5554 5555 5556 5557
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
C
cff-gite 已提交
5558 5559
```

C
cff-gite 已提交
5560
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5561

C
cff-gite 已提交
5562
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5563

C
cff-gite 已提交
5564 5565
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
5566
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9)代替。
C
cff-gite 已提交
5567 5568 5569

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

C
cff-gite 已提交
5570
**参数:** 
C
cff-gite 已提交
5571

C
cff-gite 已提交
5572 5573 5574 5575 5576
| 参数名              | 类型                                       | 必填   | 说明          |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。     |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。    |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回转换后的旋转矩阵。 |
C
cff-gite 已提交
5577 5578 5579

**示例:** 

C
cff-gite 已提交
5580
```js
C
cff-gite 已提交
5581 5582 5583 5584 5585 5586 5587 5588 5589 5590
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
    console.info("Operation successed. Data obtained: " + data);
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
C
cff-gite 已提交
5591
```
C
cff-gite 已提交
5592
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5593

C
cff-gite 已提交
5594
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5595

C
cff-gite 已提交
5596
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。
C
cff-gite 已提交
5597

C
cff-gite 已提交
5598
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)代替。
C
cff-gite 已提交
5599 5600 5601 5602 5603

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

**参数:** 

C
cff-gite 已提交
5604 5605 5606 5607
| 参数名              | 类型                                       | 必填   | 说明       |
| ---------------- | ---------------------------------------- | ---- | -------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。  |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。 |
C
cff-gite 已提交
5608

C
cff-gite 已提交
5609 5610 5611 5612 5613 5614 5615
**返回值:** 

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

**示例:** 
C
cff-gite 已提交
5616

C
cff-gite 已提交
5617
```js
C
cff-gite 已提交
5618 5619 5620 5621 5622 5623 5624 5625 5626
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
C
cff-gite 已提交
5627 5628
```

C
cff-gite 已提交
5629
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5630

C
cff-gite 已提交
5631
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
C
cff-gite 已提交
5632

C
cff-gite 已提交
5633 5634
获取地球上特定位置的地磁场。

C
cff-gite 已提交
5635
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)代替。
C
cff-gite 已提交
5636 5637 5638 5639 5640

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

**参数:** 

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

C
cff-gite 已提交
5647
**示例:** 
C
cff-gite 已提交
5648
```js
C
cff-gite 已提交
5649 5650 5651 5652 5653 5654 5655 5656
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
    console.info('sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
C
cff-gite 已提交
5657
});
C
cff-gite 已提交
5658
```
C
cff-gite 已提交
5659
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5660

C
cff-gite 已提交
5661
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
Z
zengyawen 已提交
5662

C
cff-gite 已提交
5663
获取地球上特定位置的地磁场。
Z
zengyawen 已提交
5664

C
cff-gite 已提交
5665
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)代替。
Z
zengyawen 已提交
5666

C
cff-gite 已提交
5667
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5668

C
cff-gite 已提交
5669
**参数:** 
C
cff-gite 已提交
5670

C
cff-gite 已提交
5671 5672 5673 5674
| 参数名             | 类型                                  | 必填   | 说明                |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | 是    | 地理位置。             |
| timeMillis      | number                              | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
C
cff-gite 已提交
5675

C
cff-gite 已提交
5676 5677 5678 5679
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
C
cff-gite 已提交
5680

C
cff-gite 已提交
5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691
**示例:** 
  ```js
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
      promise.then((data) => {
          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
      }).catch((reason) => {
          console.info('Operation failed.');
  })
  ```
C
cff-gite 已提交
5692

C
cff-gite 已提交
5693
## sensor.getAltitude<sup>(deprecated)</sup>
C
cff-gite 已提交
5694

C
cff-gite 已提交
5695
getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5696

C
cff-gite 已提交
5697
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5698

C
cff-gite 已提交
5699
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9)代替。
Z
zengyawen 已提交
5700

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

C
cff-gite 已提交
5703
**参数:** 
Z
zengyawen 已提交
5704

C
cff-gite 已提交
5705 5706 5707 5708 5709
| 参数名             | 类型                          | 必填   | 说明                   |
| --------------- | --------------------------- | ---- | -------------------- |
| seaPressure     | number                      | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number                      | 是    | 表示设备所在高度的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是    | 返回设备所在的海拔高度,单位为米。    |
Z
zengyawen 已提交
5710

C
cff-gite 已提交
5711
**示例:** 
Z
zengyawen 已提交
5712

C
cff-gite 已提交
5713 5714 5715 5716 5717 5718 5719 5720 5721 5722
  ```js
  sensor.getAltitude(0, 200, function(err, data)  {
      if (err) {
          console.error(
  "Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
          console.info("Successed to get getAltitude interface get data: " + data);
  });
  ```
Z
zengyawen 已提交
5723

C
cff-gite 已提交
5724
## sensor.getAltitude<sup>(deprecated)</sup>
Z
zengyawen 已提交
5725

C
cff-gite 已提交
5726
getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
C
cff-gite 已提交
5727

C
cff-gite 已提交
5728
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5729

C
cff-gite 已提交
5730
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)代替。
Z
zengyawen 已提交
5731

C
cff-gite 已提交
5732
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5733

C
cff-gite 已提交
5734
**参数:** 
Z
zengyawen 已提交
5735

C
cff-gite 已提交
5736 5737 5738 5739
| 参数名             | 类型     | 必填   | 说明                   |
| --------------- | ------ | ---- | -------------------- |
| seaPressure     | number | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number | 是    | 表示设备所在高度的气压值,单位为hPa。 |
Z
zengyawen 已提交
5740

C
cff-gite 已提交
5741
**返回值:** 
C
cff-gite 已提交
5742

C
cff-gite 已提交
5743 5744 5745
| 类型                    | 说明                 |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |
Z
zengyawen 已提交
5746

C
cff-gite 已提交
5747
**示例:** 
Z
zengyawen 已提交
5748

C
cff-gite 已提交
5749 5750 5751 5752 5753 5754 5755 5756
  ```js
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```
Z
zengyawen 已提交
5757

Z
zengyawen 已提交
5758

C
cff-gite 已提交
5759
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5760

C
cff-gite 已提交
5761
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5762

C
cff-gite 已提交
5763
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5764

C
cff-gite 已提交
5765
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9)代替。
Z
zengyawen 已提交
5766

C
cff-gite 已提交
5767
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5768

C
cff-gite 已提交
5769
**参数:** 
Z
zengyawen 已提交
5770

C
cff-gite 已提交
5771 5772 5773 5774
| 参数名               | 类型                          | 必填   | 说明             |
| ----------------- | --------------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt;         | 是    | 表示倾斜矩阵。        |
| callback          | AsyncCallback&lt;number&gt; | 是    | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5775

C
cff-gite 已提交
5776
**示例:** 
C
cff-gite 已提交
5777

C
cff-gite 已提交
5778 5779 5780 5781 5782 5783 5784 5785 5786 5787
  ```js
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is:' + err.code + ', message: ' + 
                        err.message);
          return;
      }
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
  })
  ```
Z
zengyawen 已提交
5788

C
cff-gite 已提交
5789
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5790

C
cff-gite 已提交
5791
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
Z
zengyawen 已提交
5792

C
cff-gite 已提交
5793
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5794

C
cff-gite 已提交
5795
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9-1)代替。
Z
zengyawen 已提交
5796

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

C
cff-gite 已提交
5799
**参数:** 
Z
zengyawen 已提交
5800

C
cff-gite 已提交
5801 5802 5803
| 参数名               | 类型                  | 必填   | 说明      |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | 是    | 表示倾斜矩阵。 |
Z
zengyawen 已提交
5804

C
cff-gite 已提交
5805
**返回值:** 
Z
zengyawen 已提交
5806

C
cff-gite 已提交
5807 5808 5809
| 类型                    | 说明             |
| --------------------- | -------------- |
| Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5810

C
cff-gite 已提交
5811
**示例:** 
Z
zengyawen 已提交
5812

C
cff-gite 已提交
5813 5814 5815 5816 5817 5818 5819 5820
  ```js
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('getGeomagneticDip_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```
C
cff-gite 已提交
5821

C
cff-gite 已提交
5822
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5823

C
cff-gite 已提交
5824
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5825

C
cff-gite 已提交
5826
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5827

C
cff-gite 已提交
5828
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9)代替。
Z
zengyawen 已提交
5829

C
cff-gite 已提交
5830
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5831

C
cff-gite 已提交
5832
**参数:** 
C
cff-gite 已提交
5833

C
cff-gite 已提交
5834 5835 5836 5837 5838
| 参数名                   | 类型                                       | 必填   | 说明                 |
| --------------------- | ---------------------------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | 是    | 表示当前旋转矩阵。          |
| preRotationMatrix     | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5839

C
cff-gite 已提交
5840
**示例:** 
Z
zengyawen 已提交
5841

C
cff-gite 已提交
5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853
  ```js
  sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
      if (err) {
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5854

Z
zengyawen 已提交
5855

C
cff-gite 已提交
5856
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5857

C
cff-gite 已提交
5858
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5859

C
cff-gite 已提交
5860
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5861

C
cff-gite 已提交
5862
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9-1)代替。
Z
zengyawen 已提交
5863

C
cff-gite 已提交
5864
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5865

C
cff-gite 已提交
5866
**参数:** 
Z
zengyawen 已提交
5867

C
cff-gite 已提交
5868 5869 5870 5871
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
5872

C
cff-gite 已提交
5873
**返回值:** 
C
cff-gite 已提交
5874

C
cff-gite 已提交
5875 5876 5877
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5878

C
cff-gite 已提交
5879
**示例:** 
Z
zengyawen 已提交
5880

C
cff-gite 已提交
5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891
  ```js
  const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
      promise.then((data) => {
          console.info('getAngleModifiy_promise success');
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info("promise::catch", reason);
  })
  ```
Z
zengyawen 已提交
5892

Z
zengyawen 已提交
5893

C
cff-gite 已提交
5894
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5895

C
cff-gite 已提交
5896
createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5897

C
cff-gite 已提交
5898
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5899

C
cff-gite 已提交
5900
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9)代替。
Z
zengyawen 已提交
5901

C
cff-gite 已提交
5902
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5903

C
cff-gite 已提交
5904
**参数:** 
Z
zengyawen 已提交
5905

C
cff-gite 已提交
5906 5907 5908 5909
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
5910

C
cff-gite 已提交
5911
**示例:** 
C
cff-gite 已提交
5912

C
cff-gite 已提交
5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924
  ```js
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5925 5926


C
cff-gite 已提交
5927
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5928

C
cff-gite 已提交
5929
createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
5930

C
cff-gite 已提交
5931
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5932

C
cff-gite 已提交
5933
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)代替。
C
cff-gite 已提交
5934

C
cff-gite 已提交
5935
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5936

C
cff-gite 已提交
5937
**参数:** 
Z
zengyawen 已提交
5938

C
cff-gite 已提交
5939 5940 5941
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
5942

C
cff-gite 已提交
5943
**返回值:** 
Z
zengyawen 已提交
5944

C
cff-gite 已提交
5945 5946 5947
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
5948

C
cff-gite 已提交
5949
**示例:** 
C
cff-gite 已提交
5950

C
cff-gite 已提交
5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961
  ```js
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createRotationMatrix_promise success');
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info("promise::catch", reason);
  })	
  ```
Z
zengyawen 已提交
5962 5963


C
cff-gite 已提交
5964
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5965

C
cff-gite 已提交
5966
createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5967

C
cff-gite 已提交
5968
将旋转矢量转换为四元数。
Z
zengyawen 已提交
5969

C
cff-gite 已提交
5970
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9)代替。
C
cff-gite 已提交
5971

C
cff-gite 已提交
5972
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5973

C
cff-gite 已提交
5974
**参数:** 
Z
zengyawen 已提交
5975

C
cff-gite 已提交
5976 5977 5978 5979
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
5980

C
cff-gite 已提交
5981
**示例:** 
Z
zengyawen 已提交
5982

C
cff-gite 已提交
5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994
  ```js
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
          console.info("data[" + i + "]: " + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
5995

C
cff-gite 已提交
5996

C
cff-gite 已提交
5997
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5998

C
cff-gite 已提交
5999
createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
6000

C
cff-gite 已提交
6001
将旋转矢量转换为四元数。
Z
zengyawen 已提交
6002

C
cff-gite 已提交
6003
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9-1)代替。
Z
zengyawen 已提交
6004

C
cff-gite 已提交
6005
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6006

C
cff-gite 已提交
6007
**参数:** 
C
cff-gite 已提交
6008

C
cff-gite 已提交
6009 6010 6011
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
6012

C
cff-gite 已提交
6013
**返回值:** 
Z
zengyawen 已提交
6014

C
cff-gite 已提交
6015 6016 6017
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
6018

C
cff-gite 已提交
6019
**示例:** 
Z
zengyawen 已提交
6020

C
cff-gite 已提交
6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031
  ```js
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```
Z
zengyawen 已提交
6032

C
cff-gite 已提交
6033

C
cff-gite 已提交
6034
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
6035

C
cff-gite 已提交
6036
getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
6037

C
cff-gite 已提交
6038
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
6039

C
cff-gite 已提交
6040
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9)代替。
Z
zengyawen 已提交
6041

C
cff-gite 已提交
6042
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6043

C
cff-gite 已提交
6044
**参数:** 
C
cff-gite 已提交
6045

C
cff-gite 已提交
6046 6047 6048 6049
| 参数名            | 类型                                       | 必填   | 说明                 |
| -------------- | ---------------------------------------- | ---- | ------------------ |
| rotationMatrix | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
6050

C
cff-gite 已提交
6051
**示例:** 
Z
zengyawen 已提交
6052

C
cff-gite 已提交
6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065
  ```js
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
      for (var i = 1; i < data.length; i++) {
          console.info("sensor_getDirection_callback" + data[i]);
      }
  })
  ```
Z
zengyawen 已提交
6066

Z
zengyawen 已提交
6067

C
cff-gite 已提交
6068
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
6069

C
cff-gite 已提交
6070
getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
6071

C
cff-gite 已提交
6072
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
6073

C
cff-gite 已提交
6074
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9-1)代替。
Z
zengyawen 已提交
6075

C
cff-gite 已提交
6076
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6077

C
cff-gite 已提交
6078
**参数:** 
Z
zengyawen 已提交
6079

C
cff-gite 已提交
6080 6081 6082
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | 是    | 表示旋转矩阵。 |
Z
zengyawen 已提交
6083

C
cff-gite 已提交
6084
**返回值:** 
C
cff-gite 已提交
6085

C
cff-gite 已提交
6086 6087 6088
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
6089

C
cff-gite 已提交
6090
**示例:** 
Z
zengyawen 已提交
6091

C
cff-gite 已提交
6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102
  ```js
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('sensor_getAltitude_Promise success', data);
          for (var i = 1; i < data.length; i++) {
              console.info("sensor_getDirection_promise" + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```
Z
zengyawen 已提交
6103 6104


C
cff-gite 已提交
6105
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
6106

C
cff-gite 已提交
6107
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
C
cff-gite 已提交
6108

C
cff-gite 已提交
6109
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
6110

C
cff-gite 已提交
6111
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)代替。
Z
zengyawen 已提交
6112

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

C
cff-gite 已提交
6115
**参数:** 
Z
zengyawen 已提交
6116

C
cff-gite 已提交
6117 6118 6119 6120 6121
| 参数名         | 类型                                       | 必填   | 说明      |
| ----------- | ---------------------------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt;                      | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt;                      | 是    | 表示地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
6122

C
cff-gite 已提交
6123
**示例:** 
Z
zengyawen 已提交
6124

C
cff-gite 已提交
6125 6126 6127 6128 6129 6130 6131 6132 6133
  ```js
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
          console.error('error code is: ' + err.code + ', message: ' + err.message);
          return;
      }
      console.info(JSON.stringify(data));
  })
  ```
Z
zengyawen 已提交
6134

C
cff-gite 已提交
6135

C
cff-gite 已提交
6136
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
6137

C
cff-gite 已提交
6138
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
Z
zengyawen 已提交
6139

C
cff-gite 已提交
6140
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
6141

C
cff-gite 已提交
6142
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)代替。
Z
zengyawen 已提交
6143

C
cff-gite 已提交
6144
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6145

C
cff-gite 已提交
6146
**参数:** 
C
cff-gite 已提交
6147

C
cff-gite 已提交
6148 6149 6150 6151
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
6152

C
cff-gite 已提交
6153
**返回值:** 
Z
zengyawen 已提交
6154

C
cff-gite 已提交
6155 6156 6157
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |
C
cff-gite 已提交
6158

C
cff-gite 已提交
6159
**示例:** 
C
cff-gite 已提交
6160

C
cff-gite 已提交
6161 6162 6163 6164 6165 6166 6167 6168
  ```js
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
          console.info(JSON.stringify(data));
      }).catch((err) => {
          console.info('promise failed');
  })
  ```