js-apis-sensor.md 251.1 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 29 30

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
31 32 33
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。                 |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerResponse。 |
| 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 

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
71 72 73
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AccelerometerUncalibratedResponse。 |
| 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 110 111

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

订阅环境光传感器数据。

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

**参数:** 

| 参数名   | 类型                                            | 必填 | 说明                                                        |
| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
H
h00514358 已提交
112 113 114
| type     | [SensorId](#sensorid9)                          | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。                   |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LightResponse。 |
| 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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
148 149 150
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。            |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为AmbientTemperatureResponse。 |
| 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 182 183

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

订阅气压计传感器数据。

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
184 185 186
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.BAROMETER。                        |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为BarometerResponse。 |
| 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 218 219

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

订阅重力传感器数据。

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

**参数:** 

| 参数名   | 类型                                                | 必填 | 说明                                                        |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
H
h00514358 已提交
220 221 222
| type     | [SensorId](#sensorid9)                              | 是   | 传感器类型,该值固定为SensorId.GRAVITY。                           |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GravityResponse。 |
| 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 258 259

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
260 261 262
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。                        |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeResponse。 |
| 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  

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
301 302 303
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。     |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为GyroscopeUncalibratedResponse。 |
| 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 340 341

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

**参数:** 

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
342 343 344
| type     | [SensorId](#sensorid9)                        | 是   | 传感器类型,该值固定为SensorId.HALL。                               |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HallResponse。 |
| 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 378 379
###   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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
380 381 382
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。                         |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HeartRateResponse。 |
| 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 414 415

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

订阅湿度传感器数据。

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

**参数:** 

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
416 417 418
| type     | [SensorId](#sensorid9)                                | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。                           |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为HumidityResponse。 |
| 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 

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
455 456 457
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。         |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为LinearAccelerometerResponse。 |
| 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 491 492

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
493 494 495
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。                     |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldResponse。 |
| 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 

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
531 532 533
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。  |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为MagneticFieldUncalibratedResponse。 |
| 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 578 579
**参数:**

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
580 581 582
| type     | [SensorId](#sensorid9)                                      | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。                        |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为OrientationResponse。 |
| 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 618 619
**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
620 621 622
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。                          |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerResponse。 |
| 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 

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
651 652 653
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.PEDOMETER_DETECTION。            |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为PedometerDetectionResponse。 |
| 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 685 686

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
687 688 689
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.PROXIMITY。                        |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为ProximityResponse。 |
| 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 

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
724 725 726
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.ROTATION_VECTOR。                |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为RotationVectorResponse。 |
| 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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
764 765 766
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.SIGNIFICANT_MOTION。             |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为SignificantMotionResponse。 |
| 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 799 800

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
801 802 803
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.WEAR_DETECTION。                 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是   | 回调函数,异步上报的传感器数据固定为WearDetectionResponse。 |
| 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 839 840

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

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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
841 842
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER。                            |
| 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

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
880 881
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.ACCELEROMETER_UNCALIBRATED。         |
| 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 918 919

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

**参数:** 

| 参数名   | 类型                                            | 必填 | 说明                                                         |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
920 921
| type     | [SensorId](#sensorid9)                          | 是   | 传感器类型,该值固定为SensorId.AMBIENT_LIGHT。                            |
| 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
**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
955 956
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.AMBIENT_TEMPERATURE。                    |
| 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 988 989
**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
990 991
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.BAROMETER。                                |
| 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 1023 1024

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

**参数:**

| 参数名   | 类型                                                | 必填 | 说明                                                         |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1025 1026
| type     | [SensorId](#sensorid9)                              | 是   | 传感器类型,该值固定为SensorId.GRAVITY。                                    |
| 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 1062 1063

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

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1064 1065
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE。                                |
| 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 

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1103 1104
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.GYROSCOPE_UNCALIBRATED。             |
| 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 1141 1142

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

**参数:** 

| 参数名   | 类型                                          | 必填 | 说明                                                         |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1143 1144
| type     | [SensorId](#sensorid9)                        | 是   | 传感器类型,该值固定为SensorId.HALL。                                       |
| 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 1178 1179

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

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

**参数:** 

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1180 1181
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.HEART_RATE。                                 |
| 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 {
H
h00514358 已提交
1195
    sensor.once(sensor.SensorId.HEART_BEAT_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 1213 1214

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

**参数:** 

| 参数名   | 类型                                                  | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1215 1216
| type     | [SensorId](#sensorid9)                                | 是   | 传感器类型,该值固定为SensorId.HUMIDITY。                                   |
| 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 

**参数:** 

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1252 1253
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.LINEAR_ACCELEROMETER。                 |
| 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 1287 1288

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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1289 1290
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD。                             |
| 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

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1326 1327
| type     | [SensorId](#sensorid9)                                       | 是   | 传感器类型,该值固定为SensorId.MAGNETIC_FIELD_UNCALIBRATED。          |
| 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 1364 1365

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

**参数:** 

| 参数名   | 类型                                                        | 必填 | 说明                                                         |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1366 1367
| type     | [SensorId](#sensorid9)                                      | 是   | 传感器类型,该值固定为SensorId.ORIENTATION。                                |
| 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 1403 1404

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

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

**参数:**

| 参数名   | 类型                                                    | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
H
h00514358 已提交
1405 1406
| type     | [SensorId](#sensorid9)                                  | 是   | 传感器类型,该值固定为SensorId.PEDOMETER。                                  |
| 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
h00514358 已提交
1431
获取一次计步检测器传感器数据。
C
cff-gite 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440

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

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

**参数:**

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

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

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

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

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

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

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

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

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

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

**参数:**

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

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

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

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

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

```js
C
cff-gite 已提交
1490
try {
H
h00514358 已提交
1491 1492 1493 1494 1495
    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 已提交
1496
}
C
cff-gite 已提交
1497 1498 1499 1500 1501 1502
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
C
cff-gite 已提交
1525
try {
H
h00514358 已提交
1526 1527 1528 1529 1530 1531 1532 1533
    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 已提交
1534
}
C
cff-gite 已提交
1535 1536 1537 1538 1539 1540
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
C
cff-gite 已提交
1563
try {
H
h00514358 已提交
1564 1565 1566 1567 1568
    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 已提交
1569
}
C
cff-gite 已提交
1570 1571 1572 1573 1574 1575
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
C
cff-gite 已提交
1598
try {
H
h00514358 已提交
1599 1600 1601 1602 1603
    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 已提交
1604
}
C
cff-gite 已提交
1605 1606
```

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

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1629 1630 1631 1632 1633 1634
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1635
try {
H
h00514358 已提交
1636 1637 1638 1639 1640 1641 1642 1643
    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 已提交
1644 1645 1646 1647 1648
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1667 1668 1669 1670 1671 1672
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1673
try {
H
h00514358 已提交
1674 1675 1676 1677 1678 1679 1680 1681
    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 已提交
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1703 1704 1705 1706 1707
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
C
cff-gite 已提交
1708
}
H
h00514358 已提交
1709 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);
}V
C
cff-gite 已提交
1719 1720 1721 1722 1723 1724
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1739 1740 1741 1742 1743 1744
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1745
try {
H
h00514358 已提交
1746 1747 1748 1749 1750 1751 1752 1753
    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 已提交
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1775 1776 1777 1778 1779 1780
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1781
try {
H
h00514358 已提交
1782 1783 1784 1785 1786 1787 1788 1789
    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 已提交
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
}
```

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

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

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

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

**参数:** 

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

**示例:**

```js
H
h00514358 已提交
1811 1812 1813 1814 1815 1816
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1817
try {
H
h00514358 已提交
1818 1819 1820 1821 1822 1823 1824 1825
    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 已提交
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1849 1850 1851 1852 1853 1854
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1855
try {
H
h00514358 已提交
1856 1857 1858 1859 1860 1861 1862 1863
    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 已提交
1864 1865 1866 1867 1868
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1887 1888 1889 1890 1891 1892
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1893
try {
H
h00514358 已提交
1894 1895 1896 1897 1898 1899 1900 1901
    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 已提交
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1923 1924 1925 1926 1927 1928
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1929
try {
H
h00514358 已提交
1930 1931 1932 1933 1934 1935 1936 1937
    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 已提交
1938 1939 1940
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1961 1962 1963 1964 1965 1966
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
1967
try {
H
h00514358 已提交
1968 1969 1970 1971 1972 1973 1974 1975
    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 已提交
1976 1977 1978
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
1997 1998 1999 2000 2001 2002
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2003
try {
H
h00514358 已提交
2004 2005 2006 2007 2008 2009 2010 2011
    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 已提交
2012 2013 2014
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2035 2036 2037 2038 2039 2040
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2041
try {
H
h00514358 已提交
2042 2043 2044 2045 2046 2047 2048 2049
    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 已提交
2050 2051 2052
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2071 2072 2073 2074 2075 2076
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2077
try {
H
h00514358 已提交
2078 2079 2080 2081 2082 2083 2084 2085
    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 已提交
2086 2087 2088 2089 2090
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2107 2108 2109 2110 2111 2112
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2113
try {
H
h00514358 已提交
2114 2115 2116 2117 2118 2119 2120 2121
    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 已提交
2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2143 2144 2145 2146 2147 2148
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2149
try {
H
h00514358 已提交
2150 2151 2152 2153 2154 2155 2156 2157
    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 已提交
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2181 2182 2183 2184 2185 2186
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2187
try {
H
h00514358 已提交
2188 2189 2190 2191 2192 2193 2194 2195
    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 已提交
2196 2197 2198 2199 2200 2201 2202
}
```

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

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2219 2220 2221 2222 2223 2224
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2225
try {
H
h00514358 已提交
2226 2227 2228 2229 2230 2231 2232 2233
    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 已提交
2234 2235 2236 2237 2238 2239 2240
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2255 2256 2257 2258 2259 2260
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2261
try {
H
h00514358 已提交
2262 2263 2264 2265 2266 2267 2268 2269
    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 已提交
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2291 2292 2293 2294 2295 2296
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2297
try {
H
h00514358 已提交
2298 2299 2300 2301 2302 2303 2304 2305
    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 已提交
2306 2307 2308 2309 2310 2311 2312
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2327 2328 2329 2330 2331 2332
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2333
try {
H
h00514358 已提交
2334 2335 2336 2337 2338 2339 2340 2341
    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 已提交
2342 2343 2344 2345 2346 2347 2348
}
```

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

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

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

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

**参数:**

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

**示例:**

```js
H
h00514358 已提交
2363 2364 2365 2366 2367 2368
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
C
cff-gite 已提交
2369
try {
H
h00514358 已提交
2370 2371 2372 2373 2374 2375 2376 2377
    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 已提交
2378 2379 2380
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420
    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 已提交
2421 2422
    });
} catch (err) {
H
h00514358 已提交
2423
    console.error('Get geomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2424 2425 2426 2427 2428 2429 2430
}
```

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

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

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

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

**参数:** 

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

**返回值:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471
    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 已提交
2472
} catch (err) {
H
h00514358 已提交
2473
    console.error('Get geomagneticInfo. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2474 2475 2476
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2505 2506 2507 2508 2509 2510 2511 2512 2513
    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 已提交
2514
} catch (err) {
H
h00514358 已提交
2515
    console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2516 2517 2518
}
```

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

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

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

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

**参数:** 

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

**返回值:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2552 2553 2554 2555 2556 2557 2558 2559
    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 已提交
2560
} catch (err) {
H
h00514358 已提交
2561
    console.error('Get altitude failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2562 2563 2564
}
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604
    // 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 已提交
2605
} catch (err) {
H
h00514358 已提交
2606
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2607 2608 2609
}
```

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

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

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

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

**参数:**

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

**返回值:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653
    // 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 已提交
2654
} catch (err) {
H
h00514358 已提交
2655
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2656 2657 2658
}
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710
    // 旋转矩阵可以为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 已提交
2711
} catch (err) {
H
h00514358 已提交
2712
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2713 2714 2715
}
```

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

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

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

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

**参数:**

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

**返回值:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770
    // 旋转矩阵可以为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 已提交
2771
} catch (err) {
H
h00514358 已提交
2772
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2773 2774 2775
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2803 2804 2805 2806 2807 2808 2809 2810 2811 2812
    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 已提交
2813
} catch (err) {
H
h00514358 已提交
2814
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2815 2816 2817
}
```

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

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

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

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

**参数:**

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

**返回值:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
2850 2851 2852 2853 2854 2855 2856 2857 2858
    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 已提交
2859
} catch (err) {
H
h00514358 已提交
2860
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2861 2862 2863
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904
    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 已提交
2905 2906
        }
    })
C
cff-gite 已提交
2907
} catch (err) {
H
h00514358 已提交
2908
    console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2909 2910 2911
}
```

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

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

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

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

**参数:**

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

**返回值:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
2945 2946 2947 2948 2949 2950
    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 已提交
2951
    promise.then((data) => {
H
h00514358 已提交
2952 2953
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
C
cff-gite 已提交
2954
        }
H
h00514358 已提交
2955 2956 2957
    }, (err) => {
        console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
    });
C
cff-gite 已提交
2958
} catch (err) {
H
h00514358 已提交
2959
    console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
2960 2961 2962 2963 2964 2965 2966
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
2990 2991 2992 2993 2994 2995 2996 2997 2998 2999
    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 已提交
3000
} catch (err) {
H
h00514358 已提交
3001
    console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3002 3003 3004 3005 3006 3007 3008
}
```

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

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

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

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

**参数:**

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

**返回值:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
3037 3038 3039 3040 3041 3042 3043 3044 3045
    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 已提交
3046
} catch (err) {
H
h00514358 已提交
3047
    console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3048 3049 3050 3051 3052 3053 3054
}
```

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

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

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

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

**参数:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094
    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 已提交
3095
} catch (err) {
H
h00514358 已提交
3096
    console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111
}
```

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

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

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

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

**参数:**

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

**返回值:**

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

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

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

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

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

```js
try {
H
h00514358 已提交
3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142
    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 已提交
3143
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
H
h00514358 已提交
3144 3145 3146
    });
} catch (err) {
    console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3147 3148 3149
}
```

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

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

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

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

**参数:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
3178 3179 3180 3181 3182 3183 3184 3185 3186
    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 已提交
3187
} catch (err) {
H
h00514358 已提交
3188
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3189 3190 3191
}
```

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

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

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

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

**参数:** 

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

**返回值:** 

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

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

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

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

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

```js
try {
H
h00514358 已提交
3225 3226 3227 3228 3229 3230 3231 3232
    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 已提交
3233
} catch (err) {
H
h00514358 已提交
3234
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3235 3236 3237
}
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

C
cff-gite 已提交
3385
```js
C
cff-gite 已提交
3386 3387
try {
    sensor.getSingleSensor(sensor.SensorId.SENSOR_TYPE_ID_ACCELEROMETER).then((data) => {
H
h00514358 已提交
3388 3389 3390
        console.info('Sensor: ' + JSON.stringify(data));
    }, (err) => {
        console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3391 3392
    });
} catch (err) {
H
h00514358 已提交
3393
    console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
C
cff-gite 已提交
3394
}
C
cff-gite 已提交
3395
```
C
cff-gite 已提交
3396

C
cff-gite 已提交
3397
## SensorId<sup>9+</sup>
C
cff-gite 已提交
3398

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

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

C
cff-gite 已提交
3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425
| 名称                        | 默认值 | 说明                   |
| --------------------------- | ------ | ---------------------- |
| 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 已提交
3426

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

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

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

C
cff-gite 已提交
3433

C
cff-gite 已提交
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456
| 名称                                       | 默认值 | 说明                   |
| ------------------------------------------ | ------ | ---------------------- |
| 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 已提交
3457

C
cff-gite 已提交
3458

C
cff-gite 已提交
3459
## Response
Z
zengyawen 已提交
3460

C
cff-gite 已提交
3461
传感器数据的时间戳。
Z
zengyawen 已提交
3462

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

C
cff-gite 已提交
3465 3466 3467
| 名称      | 参数类型 | 可读 | 可写 | 说明                     |
| --------- | -------- | ---- | ---- | ------------------------ |
| timestamp | number   | 是   | 是   | 传感器数据上报的时间戳。 |
Z
zengyawen 已提交
3468

C
cff-gite 已提交
3469
## Sensor<sup>9+</sup>
Z
zengyawen 已提交
3470

C
cff-gite 已提交
3471
指示传感器信息。
C
cff-gite 已提交
3472

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

C
cff-gite 已提交
3475 3476
| 名称            | 参数类型 | 说明                   |
| --------------- | -------- | ---------------------- |
C
cff-gite 已提交
3477
| sensorName      | string   | 传感器名称。           |
C
cff-gite 已提交
3478 3479 3480 3481
| venderName      | string   | 传感器供应商。         |
| firmwareVersion | string   | 传感器固件版本。       |
| hardwareVersion | string   | 传感器硬件版本。       |
| sensorId        | number   | 传感器类型id。         |
H
h00514358 已提交
3482
| maxRange        | number   | 传感器测量范围的最大值。 |
C
cff-gite 已提交
3483 3484 3485
| minSamplePeriod | number   | 允许的最小采样周期。   |
| maxSamplePeriod | number   | 允许的最大采样周期。   |
| precision       | number   | 传感器精度。           |
H
h00514358 已提交
3486
| power           | number   | 传感器功率。           |
C
cff-gite 已提交
3487

C
cff-gite 已提交
3488
## AccelerometerResponse
C
cff-gite 已提交
3489

C
cff-gite 已提交
3490
加速度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3491

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


C
cff-gite 已提交
3495 3496 3497 3498 3499
| 名称 | 参数类型 | 可读 | 可写 | 说明                                 |
| ---- | -------- | ---- | ---- | ------------------------------------ |
| x    | number   | 是   | 是   | 施加在设备x轴的加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3500 3501


C
cff-gite 已提交
3502
## LinearAccelerometerResponse
C
cff-gite 已提交
3503

C
cff-gite 已提交
3504
线性加速度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3505

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

C
cff-gite 已提交
3508

C
cff-gite 已提交
3509 3510 3511 3512 3513
| 名称 | 参数类型 | 可读 | 可写 | 说明                                     |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | 是   | 是   | 施加在设备x轴的线性加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的线性加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的线性加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3514

Z
zengyawen 已提交
3515

C
cff-gite 已提交
3516
## AccelerometerUncalibratedResponse
Z
zengyawen 已提交
3517

C
cff-gite 已提交
3518
未校准加速度计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3519

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

C
cff-gite 已提交
3522

C
cff-gite 已提交
3523 3524 3525 3526 3527 3528 3529 3530
| 名称  | 参数类型 | 可读 | 可写 | 说明                                             |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| 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 已提交
3531

C
cff-gite 已提交
3532

C
cff-gite 已提交
3533
## GravityResponse
Z
zengyawen 已提交
3534

C
cff-gite 已提交
3535
重力传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3536

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


C
cff-gite 已提交
3540 3541 3542 3543 3544
| 名称 | 参数类型 | 可读 | 可写 | 说明                                     |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | 是   | 是   | 施加在设备x轴的重力加速度,单位 : m/s2。 |
| y    | number   | 是   | 是   | 施加在设备y轴的重力加速度,单位 : m/s2。 |
| z    | number   | 是   | 是   | 施加在设备z轴的重力加速度,单位 : m/s2。 |
Z
zengyawen 已提交
3545

C
cff-gite 已提交
3546

C
cff-gite 已提交
3547
## OrientationResponse
C
cff-gite 已提交
3548

C
cff-gite 已提交
3549
方向传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3550

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

Z
zengyawen 已提交
3553

C
cff-gite 已提交
3554 3555 3556 3557 3558
| 名称  | 参数类型 | 可读 | 可写 | 说明                              |
| ----- | -------- | ---- | ---- | --------------------------------- |
| alpha | number   | 是   | 是   | 设备围绕Z轴的旋转角度,单位:度。 |
| beta  | number   | 是   | 是   | 设备围绕X轴的旋转角度,单位:度。 |
| gamma | number   | 是   | 是   | 设备围绕Y轴的旋转角度,单位:度。 |
Z
zengyawen 已提交
3559 3560


C
cff-gite 已提交
3561
## RotationVectorResponse
Z
zengyawen 已提交
3562

C
cff-gite 已提交
3563
旋转矢量传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3564

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

C
cff-gite 已提交
3567

C
cff-gite 已提交
3568 3569 3570 3571 3572 3573
| 名称 | 参数类型 | 可读 | 可写 | 说明              |
| ---- | -------- | ---- | ---- | ----------------- |
| x    | number   | 是   | 是   | 旋转矢量x轴分量。 |
| y    | number   | 是   | 是   | 旋转矢量y轴分量。 |
| z    | number   | 是   | 是   | 旋转矢量z轴分量。 |
| w    | number   | 是   | 是   | 标量。            |
C
cff-gite 已提交
3574

C
cff-gite 已提交
3575

C
cff-gite 已提交
3576
## GyroscopeResponse
Z
zengyawen 已提交
3577

C
cff-gite 已提交
3578
陀螺仪传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3579

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


C
cff-gite 已提交
3583 3584 3585 3586 3587
| 名称 | 参数类型 | 可读 | 可写 | 说明                             |
| ---- | -------- | ---- | ---- | -------------------------------- |
| x    | number   | 是   | 是   | 设备x轴的旋转角速度,单位rad/s。 |
| y    | number   | 是   | 是   | 设备y轴的旋转角速度,单位rad/s。 |
| z    | number   | 是   | 是   | 设备z轴的旋转角速度,单位rad/s。 |
Z
zengyawen 已提交
3588

C
cff-gite 已提交
3589

C
cff-gite 已提交
3590
## GyroscopeUncalibratedResponse
C
cff-gite 已提交
3591

C
cff-gite 已提交
3592
未校准陀螺仪传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3593

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

C
cff-gite 已提交
3596

C
cff-gite 已提交
3597 3598 3599 3600 3601 3602 3603 3604
| 名称  | 参数类型 | 可读 | 可写 | 说明                                       |
| ----- | -------- | ---- | ---- | ------------------------------------------ |
| 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 已提交
3605 3606


C
cff-gite 已提交
3607
## SignificantMotionResponse
Z
zengyawen 已提交
3608

C
cff-gite 已提交
3609
有效运动传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3610

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

C
cff-gite 已提交
3613

C
cff-gite 已提交
3614 3615 3616
| 名称   | 参数类型 | 可读 | 可写 | 说明                                                         |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | 是   | 是   | 表示剧烈运动程度。测量三个物理轴(x、y&nbsp;&nbsp;z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动。 |
C
cff-gite 已提交
3617

Z
zengyawen 已提交
3618

C
cff-gite 已提交
3619
## ProximityResponse
C
cff-gite 已提交
3620

C
cff-gite 已提交
3621
接近光传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3622

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


C
cff-gite 已提交
3626 3627 3628
| 名称     | 参数类型 | 可读 | 可写 | 说明                                                   |
| -------- | -------- | ---- | ---- | ------------------------------------------------------ |
| distance | number   | 是   | 是   | 可见物体与设备显示器的接近程度。0表示接近,1表示远离。 |
Z
zengyawen 已提交
3629

C
cff-gite 已提交
3630

C
cff-gite 已提交
3631
## LightResponse
C
cff-gite 已提交
3632

C
cff-gite 已提交
3633
环境光传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3634

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

Z
zengyawen 已提交
3637

C
cff-gite 已提交
3638 3639 3640
| 名称      | 参数类型 | 可读 | 可写 | 说明                   |
| --------- | -------- | ---- | ---- | ---------------------- |
| intensity | number   | 是   | 是   | 光强(单位:勒克斯)。 |
Z
zengyawen 已提交
3641 3642


C
cff-gite 已提交
3643
## HallResponse
Z
zengyawen 已提交
3644

C
cff-gite 已提交
3645
霍尔传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3646

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

C
cff-gite 已提交
3649

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

Z
zengyawen 已提交
3654

C
cff-gite 已提交
3655
## MagneticFieldResponse
Z
zengyawen 已提交
3656

C
cff-gite 已提交
3657
磁场传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3658

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

C
cff-gite 已提交
3661

C
cff-gite 已提交
3662 3663 3664 3665 3666
| 名称 | 参数类型 | 可读 | 可写 | 说明                         |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | 是   | 是   | x轴环境磁场强度,单位 : μT。 |
| y    | number   | 是   | 是   | y轴环境磁场强度,单位 : μT。 |
| z    | number   | 是   | 是   | z轴环境磁场强度,单位 : μT。 |
C
cff-gite 已提交
3667

C
cff-gite 已提交
3668

C
cff-gite 已提交
3669
## MagneticFieldUncalibratedResponse
Z
zengyawen 已提交
3670

C
cff-gite 已提交
3671
未校准磁场传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3672

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


C
cff-gite 已提交
3676 3677 3678 3679 3680 3681 3682 3683
| 名称  | 参数类型 | 可读 | 可写 | 说明                                   |
| ----- | -------- | ---- | ---- | -------------------------------------- |
| 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 已提交
3684 3685


C
cff-gite 已提交
3686
## PedometerResponse
C
cff-gite 已提交
3687

C
cff-gite 已提交
3688
计步传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3689

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

Z
zengyawen 已提交
3692

C
cff-gite 已提交
3693 3694 3695
| 名称  | 参数类型 | 可读 | 可写 | 说明             |
| ----- | -------- | ---- | ---- | ---------------- |
| steps | number   | 是   | 是   | 用户的行走步数。 |
C
cff-gite 已提交
3696

Z
zengyawen 已提交
3697

C
cff-gite 已提交
3698
## HumidityResponse
Z
zengyawen 已提交
3699

C
cff-gite 已提交
3700
湿度传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3701

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

C
cff-gite 已提交
3704

C
cff-gite 已提交
3705 3706 3707
| 名称     | 参数类型 | 可读 | 可写 | 说明                                                      |
| -------- | -------- | ---- | ---- | --------------------------------------------------------- |
| humidity | number   | 是   | 是   | 湿度值。测量环境的相对湿度,以百分比&nbsp;(%)&nbsp;表示。 |
C
cff-gite 已提交
3708

C
cff-gite 已提交
3709

C
cff-gite 已提交
3710
## PedometerDetectionResponse
Z
zengyawen 已提交
3711

C
cff-gite 已提交
3712
计步检测传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3713

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


C
cff-gite 已提交
3717 3718 3719
| 名称   | 参数类型 | 可读 | 可写 | 说明                                                         |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | 是   | 是   | 计步器检测。检测用户的计步动作,如果取值为1则代表用户产生了计步行走的动作,取值为0则代表用户没有发生运动。 |
Z
zengyawen 已提交
3720

C
cff-gite 已提交
3721

C
cff-gite 已提交
3722
## AmbientTemperatureResponse
C
cff-gite 已提交
3723

C
cff-gite 已提交
3724
温度传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3725

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

C
cff-gite 已提交
3728

C
cff-gite 已提交
3729 3730 3731
| 名称        | 参数类型 | 可读 | 可写 | 说明                       |
| ----------- | -------- | ---- | ---- | -------------------------- |
| temperature | number   | 是   | 是   | 环境温度(单位:摄氏度)。 |
Z
zengyawen 已提交
3732 3733


C
cff-gite 已提交
3734
## BarometerResponse
Z
zengyawen 已提交
3735

C
cff-gite 已提交
3736
气压计传感器数据,继承于[Response](#response)
Z
zengyawen 已提交
3737

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

C
cff-gite 已提交
3740

C
cff-gite 已提交
3741 3742 3743
| 名称     | 参数类型 | 可读 | 可写 | 说明                     |
| -------- | -------- | ---- | ---- | ------------------------ |
| pressure | number   | 是   | 是   | 压力值(单位:帕斯卡)。 |
C
cff-gite 已提交
3744

Z
zengyawen 已提交
3745

C
cff-gite 已提交
3746
## HeartRateResponse
Z
zengyawen 已提交
3747

C
cff-gite 已提交
3748
心率传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3749

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


C
cff-gite 已提交
3753 3754 3755
| 名称      | 参数类型 | 可读 | 可写 | 说明                                    |
| --------- | -------- | ---- | ---- | --------------------------------------- |
| heartRate | number   | 是   | 是   | 心率值。测量用户的心率数值,单位:bpm。 |
H
h00514358 已提交
3756

C
cff-gite 已提交
3757

C
cff-gite 已提交
3758
## WearDetectionResponse
C
cff-gite 已提交
3759

C
cff-gite 已提交
3760
佩戴检测传感器数据,继承于[Response](#response)
C
cff-gite 已提交
3761

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

H
h00514358 已提交
3764

C
cff-gite 已提交
3765 3766 3767
| 名称  | 参数类型 | 可读 | 可写 | 说明                                             |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| value | number   | 是   | 是   | 表示设备是否被穿戴(1表示已穿戴,0表示未穿戴)。 |
H
h00514358 已提交
3768 3769


C
cff-gite 已提交
3770
## Options
H
h00514358 已提交
3771

C
cff-gite 已提交
3772
设置传感器上报频率。
H
h00514358 已提交
3773

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

C
cff-gite 已提交
3776 3777 3778
| 名称     | 参数类型 | 说明                                        |
| -------- | -------- | ------------------------------------------- |
| interval | number   | 表示传感器的上报频率,默认值为200000000ns。 |
H
h00514358 已提交
3779

C
cff-gite 已提交
3780
## RotationMatrixResponse
H
h00514358 已提交
3781

C
cff-gite 已提交
3782
设置旋转矩阵响应对象。
H
h00514358 已提交
3783

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

C
cff-gite 已提交
3786 3787 3788 3789
| 名称        | 参数类型            | 可读 | 可写 | 说明       |
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | 是   | 是   | 旋转矩阵。 |
| inclination | Array&lt;number&gt; | 是   | 是   | 倾斜矩阵。 |
Z
zengyawen 已提交
3790 3791


C
cff-gite 已提交
3792
## CoordinatesOptions
C
cff-gite 已提交
3793

C
cff-gite 已提交
3794
设置坐标选项对象。
C
cff-gite 已提交
3795

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

C
cff-gite 已提交
3798 3799 3800 3801
| 名称 | 参数类型 | 可读 | 可写 | 说明        |
| ---- | -------- | ---- | ---- | ----------- |
| x    | number   | 是   | 是   | x坐标方向。 |
| y    | number   | 是   | 是   | y坐标方向。 |
Z
zengyawen 已提交
3802

Z
zengyawen 已提交
3803

C
cff-gite 已提交
3804
## GeomagneticResponse
Z
zengyawen 已提交
3805

C
cff-gite 已提交
3806
设置地磁响应对象,继承于[Response](#response)
Z
zengyawen 已提交
3807

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

C
cff-gite 已提交
3810 3811 3812 3813 3814 3815 3816 3817 3818
| 名称            | 参数类型 | 可读 | 可写 | 说明                                               |
| --------------- | -------- | ---- | ---- | -------------------------------------------------- |
| x               | number   | 是   | 是   | 地磁场的北分量。                                   |
| y               | number   | 是   | 是   | 地磁场的东分量。                                   |
| z               | number   | 是   | 是   | 地磁场的垂直分量。                                 |
| geomagneticDip  | number   | 是   | 是   | 地磁倾角,即地球磁场线与水平面的夹角。             |
| deflectionAngle | number   | 是   | 是   | 地磁偏角,即地磁北方向与正北方向在水平面上的角度。 |
| levelIntensity  | number   | 是   | 是   | 地磁场的水平强度。                                 |
| totalIntensity  | number   | 是   | 是   | 地磁场的总强度。                                   |
C
cff-gite 已提交
3819

C
cff-gite 已提交
3820
## LocationOptions
C
cff-gite 已提交
3821

C
cff-gite 已提交
3822
指示地理位置。
C
cff-gite 已提交
3823

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

C
cff-gite 已提交
3826 3827 3828 3829 3830
| 名称      | 参数类型 | 可读 | 可写 | 说明       |
| --------- | -------- | ---- | ---- | ---------- |
| latitude  | number   | 是   | 是   | 纬度。     |
| longitude | number   | 是   | 是   | 经度。     |
| altitude  | number   | 是   | 是   | 海拔高度。 |
Z
zengyawen 已提交
3831

C
cff-gite 已提交
3832
## sensor.on<sup>(deprecated)</sup>
Z
zengyawen 已提交
3833

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

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

C
cff-gite 已提交
3838
监听加速度传感器的数据变化。如果多次调用该接口,仅最后一次调用生效。
Z
zengyawen 已提交
3839

C
cff-gite 已提交
3840
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER](#accelerometer9)代替。
C
cff-gite 已提交
3841

L
li-yaoyao777 已提交
3842
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3843 3844 3845

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

H
HelloCrease 已提交
3846
**参数:** 
C
cff-gite 已提交
3847

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

H
HelloCrease 已提交
3854
**示例:** 
C
cff-gite 已提交
3855

H
HelloCrease 已提交
3856
  ```js
C
cff-gite 已提交
3857
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
3858 3859 3860
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3861 3862
  },
      {interval: 10000000}
Z
zengyawen 已提交
3863 3864
  );
  ```
Z
zengyawen 已提交
3865

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

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

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

C
cff-gite 已提交
3872
从API version 9 开始不再维护,建议使用[sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)代替。 
C
cff-gite 已提交
3873

C
cff-gite 已提交
3874
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3875 3876 3877

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

H
HelloCrease 已提交
3878
**参数:** 
C
cff-gite 已提交
3879

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

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

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

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

C
cff-gite 已提交
3892
从API version 9 开始不再维护,建议使用[sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)代替。
C
cff-gite 已提交
3893

L
li-yaoyao777 已提交
3894
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
3895 3896 3897

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

H
HelloCrease 已提交
3898
**参数:** 
C
cff-gite 已提交
3899

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

H
HelloCrease 已提交
3906
**示例:** 
C
cff-gite 已提交
3907 3908
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
Z
zengyawen 已提交
3909 3910 3911 3912 3913 3914
      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 已提交
3915 3916
  },
      {interval: 10000000}
Z
zengyawen 已提交
3917 3918
  );
  ```
Z
zengyawen 已提交
3919

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

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

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

C
cff-gite 已提交
3926
从API version 9 开始不再维护,建议使用[sensor.on.GRAVITY](#gravity9)代替。
C
cff-gite 已提交
3927

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

H
HelloCrease 已提交
3930
**参数:** 
C
cff-gite 已提交
3931

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

H
HelloCrease 已提交
3938
**示例:** 
H
HelloCrease 已提交
3939
  ```js
C
cff-gite 已提交
3940
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
Z
zengyawen 已提交
3941 3942 3943
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3944 3945
  },
      {interval: 10000000}
Z
zengyawen 已提交
3946 3947
  );
  ```
Z
zengyawen 已提交
3948

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

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

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

C
cff-gite 已提交
3955
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE](#gyroscope9)代替。
C
cff-gite 已提交
3956

L
li-yaoyao777 已提交
3957
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3958 3959 3960

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

H
HelloCrease 已提交
3961
**参数:** 
C
cff-gite 已提交
3962

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

H
HelloCrease 已提交
3969
**示例:** 
H
HelloCrease 已提交
3970
  ```js
C
cff-gite 已提交
3971
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
Z
zengyawen 已提交
3972 3973 3974
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
3975 3976
  },
      {interval: 10000000}
Z
zengyawen 已提交
3977 3978
  );
  ```
Z
zengyawen 已提交
3979

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

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

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

C
cff-gite 已提交
3986
从API version 9 开始不再维护,建议使用[sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)代替。
C
cff-gite 已提交
3987

L
li-yaoyao777 已提交
3988
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
3989 3990 3991

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

H
HelloCrease 已提交
3992
**参数:** 
C
cff-gite 已提交
3993

H
HelloCrease 已提交
3994 3995
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
3996 3997 3998
| type     | [SensorType](#sensortype)                | 是    | 要订阅的未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率。                           |
Z
zengyawen 已提交
3999

H
HelloCrease 已提交
4000
**示例:** 
H
HelloCrease 已提交
4001
  ```js
C
cff-gite 已提交
4002
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
Z
zengyawen 已提交
4003 4004 4005 4006 4007 4008
      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 已提交
4009 4010
  },
      {interval: 10000000}
Z
zengyawen 已提交
4011 4012
  );
  ```
Z
zengyawen 已提交
4013

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

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

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

C
cff-gite 已提交
4020
从API version 9 开始不再维护,建议使用[sensor.on.SIGNIFICANT_MOTION](#significant_motion9) 代替。
C
cff-gite 已提交
4021

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

H
HelloCrease 已提交
4024
**参数:** 
C
cff-gite 已提交
4025

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

H
HelloCrease 已提交
4032
**示例:** 
H
HelloCrease 已提交
4033
  ```js
C
cff-gite 已提交
4034
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
Z
zengyawen 已提交
4035
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
4036 4037
  },
      {interval: 10000000}
Z
zengyawen 已提交
4038 4039
  );
  ```
Z
zengyawen 已提交
4040

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

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

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

C
cff-gite 已提交
4047
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)代替。 
C
cff-gite 已提交
4048

C
cff-gite 已提交
4049
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
4050 4051 4052

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

H
HelloCrease 已提交
4053
**参数:** 
C
cff-gite 已提交
4054

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

H
HelloCrease 已提交
4061
**示例:** 
H
HelloCrease 已提交
4062
  ```js
C
cff-gite 已提交
4063
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
Z
zengyawen 已提交
4064
      console.info('Scalar data: ' + data.scalar);
C
cff-gite 已提交
4065 4066
  },
      {interval: 10000000}
Z
zengyawen 已提交
4067 4068
  );
  ```
Z
zengyawen 已提交
4069

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

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

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

C
cff-gite 已提交
4076
从API version 9 开始不再维护,建议使用[sensor.on.PEDOMETER](#pedometer9)代替。
C
cff-gite 已提交
4077

C
cff-gite 已提交
4078
**需要权限**:ohos.permission.ACTIVITY_MOTION 
C
cff-gite 已提交
4079 4080 4081

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

H
HelloCrease 已提交
4082
**参数:** 
C
cff-gite 已提交
4083

C
cff-gite 已提交
4084 4085 4086 4087 4088
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。   |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。          |
Z
zengyawen 已提交
4089

H
HelloCrease 已提交
4090
**示例:** 
H
HelloCrease 已提交
4091
  ```js
C
cff-gite 已提交
4092
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
Z
zengyawen 已提交
4093
      console.info('Steps: ' + data.steps);
C
cff-gite 已提交
4094 4095
  },
      {interval: 10000000}
Z
zengyawen 已提交
4096 4097
  );
  ```
Z
zengyawen 已提交
4098

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

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

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

C
cff-gite 已提交
4105
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)代替。
C
cff-gite 已提交
4106

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

H
HelloCrease 已提交
4109
**参数:** 
C
cff-gite 已提交
4110

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

H
HelloCrease 已提交
4117
**示例:** 
C
cff-gite 已提交
4118

H
HelloCrease 已提交
4119
  ```js
C
cff-gite 已提交
4120
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
Z
zengyawen 已提交
4121
      console.info('Temperature: ' + data.temperature);
C
cff-gite 已提交
4122 4123
  },
      {interval: 10000000}
Z
zengyawen 已提交
4124 4125
  );
  ```
Z
zengyawen 已提交
4126

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

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

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

C
cff-gite 已提交
4133
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD](#magnetic_field9)代替。  
C
cff-gite 已提交
4134

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

H
HelloCrease 已提交
4137
**参数:** 
C
cff-gite 已提交
4138

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

H
HelloCrease 已提交
4145
**示例:** 
C
cff-gite 已提交
4146

H
HelloCrease 已提交
4147
  ```js
C
cff-gite 已提交
4148
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
Z
zengyawen 已提交
4149 4150 4151
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
C
cff-gite 已提交
4152 4153
  },
      {interval: 10000000}
Z
zengyawen 已提交
4154 4155
  );
  ```
Z
zengyawen 已提交
4156

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

C
cff-gite 已提交
4159
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
4160

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

C
cff-gite 已提交
4163
从API version 9 开始不再维护,建议使用[sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)代替。 
C
cff-gite 已提交
4164

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

H
HelloCrease 已提交
4167
**参数:** 
C
cff-gite 已提交
4168

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

H
HelloCrease 已提交
4175
**示例:** 
H
HelloCrease 已提交
4176
  ```js
C
cff-gite 已提交
4177
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
Z
zengyawen 已提交
4178 4179 4180 4181 4182 4183
      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 已提交
4184 4185
  },
      {interval: 10000000}
Z
zengyawen 已提交
4186 4187
  );
  ```
Z
zengyawen 已提交
4188

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

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

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

C
cff-gite 已提交
4195
从API version 9 开始不再维护,建议使用[sensor.on.PROXIMITY](#proximity9)代替。 
C
cff-gite 已提交
4196

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

H
HelloCrease 已提交
4199
**参数:** 
C
cff-gite 已提交
4200

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

H
HelloCrease 已提交
4207
**示例:** 
H
HelloCrease 已提交
4208
  ```js
C
cff-gite 已提交
4209
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
Z
zengyawen 已提交
4210
      console.info('Distance: ' + data.distance);
C
cff-gite 已提交
4211 4212
  },
      {interval: 10000000}
Z
zengyawen 已提交
4213 4214
  );
  ```
Z
zengyawen 已提交
4215

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

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

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

C
cff-gite 已提交
4222
从API version 9 开始不再维护,建议使用[sensor.on.HUMIDITY](#humidity9)代替。  
C
cff-gite 已提交
4223

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

H
HelloCrease 已提交
4226
**参数:** 
C
cff-gite 已提交
4227

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

H
HelloCrease 已提交
4234
**示例:** 
C
cff-gite 已提交
4235

H
HelloCrease 已提交
4236
  ```js
C
cff-gite 已提交
4237
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
Z
zengyawen 已提交
4238
      console.info('Humidity: ' + data.humidity);
C
cff-gite 已提交
4239 4240
  },
      {interval: 10000000}
Z
zengyawen 已提交
4241 4242
  );
  ```
Z
zengyawen 已提交
4243

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

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

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

C
cff-gite 已提交
4250
从API version 9 开始不再维护,建议使用[sensor.on.BAROMETER](#barometer9)代替。
C
cff-gite 已提交
4251

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

H
HelloCrease 已提交
4254
**参数:** 
C
cff-gite 已提交
4255

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

H
HelloCrease 已提交
4262
**示例:** 
C
cff-gite 已提交
4263

H
HelloCrease 已提交
4264
  ```js
C
cff-gite 已提交
4265
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
Z
zengyawen 已提交
4266
      console.info('Atmospheric pressure: ' + data.pressure);
C
cff-gite 已提交
4267 4268
  },
      {interval: 10000000}
Z
zengyawen 已提交
4269 4270
  );
  ```
Z
zengyawen 已提交
4271

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

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

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

C
cff-gite 已提交
4278
从API version 9 开始不再维护,建议使用[sensor.on.HALL](#hall9)代替。
C
cff-gite 已提交
4279

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

H
HelloCrease 已提交
4282
**参数:** 
C
cff-gite 已提交
4283

C
cff-gite 已提交
4284 4285 4286 4287 4288
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册霍尔传感器的回调函数,上报的数据类型为&nbsp;HallResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
4289

H
HelloCrease 已提交
4290
**示例:** 
H
HelloCrease 已提交
4291
  ```js
C
cff-gite 已提交
4292
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
Z
zengyawen 已提交
4293
      console.info('Status: ' + data.status);
C
cff-gite 已提交
4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304
  },
      {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 已提交
4305
从API version 9 开始不再维护,建议使用[sensor.on.AMBIENT_LIGHT](#ambient_light9)代替。
C
cff-gite 已提交
4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332

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

**参数:** 

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

**示例:** 

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

### ORIENTATION<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4333
从API version 9 开始不再维护,建议使用[sensor.on.ORIENTATION](#orientation9)代替。
C
cff-gite 已提交
4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352

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

**参数:** 

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

**示例:** 
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4353 4354
  );
  ```
Z
zengyawen 已提交
4355

C
cff-gite 已提交
4356 4357 4358 4359 4360 4361
### HEART_RATE<sup>(deprecated)</sup>

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

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

C
cff-gite 已提交
4362 4363
从API version 9 开始不再维护,建议使用[sensor.on.HEART_RATE](#heart_rate9)代替。

C
cff-gite 已提交
4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375
**需要权限**:ohos.permission.HEALTH_DATA 

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

**参数:** 

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

### ROTATION_VECTOR<sup>(deprecated)</sup>
Z
zengyawen 已提交
4376

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

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

C
cff-gite 已提交
4381
从API version 9 开始不再维护,建议使用[sensor.on.ROTATION_VECTOR](#rotation_vector9)代替。
C
cff-gite 已提交
4382

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

H
HelloCrease 已提交
4385
**参数:** 
C
cff-gite 已提交
4386

C
cff-gite 已提交
4387 4388 4389 4390 4391
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 要订阅的旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
| options  | [Options](#options)                      | 否    | 可选参数列表,设置上报频率,默认值为200000000ns。           |
Z
zengyawen 已提交
4392

H
HelloCrease 已提交
4393
**示例:** 
H
HelloCrease 已提交
4394
  ```js
C
cff-gite 已提交
4395 4396 4397 4398 4399 4400 4401
  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 已提交
4402 4403
  );
  ```
Z
zengyawen 已提交
4404

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

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

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

C
cff-gite 已提交
4411
从API version 9 开始不再维护,建议使用[sensor.on.WEAR_DETECTION](#wear_detection9)代替。
C
cff-gite 已提交
4412

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

H
HelloCrease 已提交
4415
**参数:** 
C
cff-gite 已提交
4416

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

H
HelloCrease 已提交
4423
**示例:** 
H
HelloCrease 已提交
4424
  ```js
C
cff-gite 已提交
4425 4426 4427 4428
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
  },
      {interval: 10000000}
Z
zengyawen 已提交
4429 4430
  );
  ```
Z
zengyawen 已提交
4431

C
cff-gite 已提交
4432
## sensor.once<sup>(deprecated)</sup>
Z
zengyawen 已提交
4433

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

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

C
cff-gite 已提交
4438 4439
监听加速度传感器的数据变化一次。

C
cff-gite 已提交
4440
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER](#accelerometer9-1)代替。
C
cff-gite 已提交
4441 4442

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4443

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

H
HelloCrease 已提交
4446
**参数:** 
C
cff-gite 已提交
4447

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

H
HelloCrease 已提交
4453
**示例:** 
H
HelloCrease 已提交
4454
  ```js
C
cff-gite 已提交
4455
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
Z
zengyawen 已提交
4456 4457 4458
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
Z
zengyawen 已提交
4459
    }
Z
zengyawen 已提交
4460 4461
  );
  ```
Z
zengyawen 已提交
4462

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

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

C
cff-gite 已提交
4467
监听线性加速度传感器数据变化一次。
Z
zengyawen 已提交
4468

C
cff-gite 已提交
4469
从API version 9 开始不再维护,建议使用[sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)代替。
C
cff-gite 已提交
4470

C
cff-gite 已提交
4471
**需要权限**:ohos.permission.ACCELERATION
C
cff-gite 已提交
4472 4473 4474

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

H
HelloCrease 已提交
4475
**参数:** 
C
cff-gite 已提交
4476

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

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

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

C
cff-gite 已提交
4486
监听未校准加速度传感器的数据变化一次。
Z
zengyawen 已提交
4487

C
cff-gite 已提交
4488
从API version 9 开始不再维护,建议使用[sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)代替。
C
cff-gite 已提交
4489 4490

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4491

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

H
HelloCrease 已提交
4494
**参数:** 
C
cff-gite 已提交
4495

H
HelloCrease 已提交
4496 4497
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4498 4499
| type     | [SensorType](#sensortype)                | 是    | 未校准加速度传感器类型为SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED。 |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | 是    | 注册一次未校准加速度传感器的回调函数,上报的数据类型为AccelerometerUncalibratedResponse。 |
Z
zengyawen 已提交
4500

H
HelloCrease 已提交
4501
**示例:** 
C
cff-gite 已提交
4502 4503 4504 4505 4506 4507 4508 4509
  ```
  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 已提交
4510
    }
Z
zengyawen 已提交
4511 4512
  );
  ```
Z
zengyawen 已提交
4513

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

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

C
cff-gite 已提交
4518
监听重力传感器的数据变化一次。
C
cff-gite 已提交
4519

C
cff-gite 已提交
4520
从API version 9 开始不再维护,建议使用[sensor.once.GRAVITY](#gravity9-1)代替。
C
cff-gite 已提交
4521

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

H
HelloCrease 已提交
4524
**参数:** 
C
cff-gite 已提交
4525

C
cff-gite 已提交
4526 4527 4528 4529
| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 重力传感器类型为SENSOR_TYPE_ID_GRAVITY。         |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | 是    | 注册一次重力传感器的回调函数,上报的数据类型为GravityResponse。 |
Z
zengyawen 已提交
4530

H
HelloCrease 已提交
4531
**示例:** 
C
cff-gite 已提交
4532 4533 4534 4535 4536 4537 4538 4539
  ```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 已提交
4540

C
cff-gite 已提交
4541
### GYROSCOPE<sup>(deprecated)</sup>
C
cff-gite 已提交
4542

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

C
cff-gite 已提交
4545
监听陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4546

C
cff-gite 已提交
4547
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE](#gyroscope9-1)代替。
C
cff-gite 已提交
4548

C
cff-gite 已提交
4549
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4550

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

H
HelloCrease 已提交
4553
**参数:** 
C
cff-gite 已提交
4554

H
HelloCrease 已提交
4555 4556
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4557 4558
| type     | [SensorType](#sensortype)                | 是    | 陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE。       |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | 是    | 注册一次陀螺仪传感器的回调函数,上报的数据类型为GyroscopeResponse。 |
C
cff-gite 已提交
4559

H
HelloCrease 已提交
4560
**示例:** 
C
cff-gite 已提交
4561 4562 4563 4564 4565 4566 4567 4568
  ```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 已提交
4569

C
cff-gite 已提交
4570
### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4571

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

C
cff-gite 已提交
4574
监听未校准陀螺仪传感器的数据变化一次。
C
cff-gite 已提交
4575

C
cff-gite 已提交
4576
从API version 9 开始不再维护,建议使用[sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)代替。
C
cff-gite 已提交
4577

C
cff-gite 已提交
4578
**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
4579

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

H
HelloCrease 已提交
4582
**参数:** 
C
cff-gite 已提交
4583

H
HelloCrease 已提交
4584 4585
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4586 4587
| type     | [SensorType](#sensortype)                | 是    | 未校准陀螺仪传感器类型为SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED。 |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | 是    | 注册一次未校准陀螺仪传感器的回调函数,上报的数据类型为GyroscopeUncalibratedResponse。 |
C
cff-gite 已提交
4588

H
HelloCrease 已提交
4589
**示例:** 
C
cff-gite 已提交
4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600
  ```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 已提交
4601

C
cff-gite 已提交
4602
### SIGNIFICANT_MOTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4603

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

C
cff-gite 已提交
4606
监听有效运动传感器的数据变化一次。
C
cff-gite 已提交
4607

C
cff-gite 已提交
4608
从API version 9 开始不再维护,建议使用[sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)代替。
C
cff-gite 已提交
4609

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

H
HelloCrease 已提交
4612
**参数:** 
C
cff-gite 已提交
4613

H
HelloCrease 已提交
4614 4615
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4616 4617
| type     | [SensorType](#sensortype)                | 是    | 有效运动传感器类型为SENSOR_TYPE_ID_SIGNIFICANT_MOTION。 |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | 是    | 注册一次有效运动传感器的回调函数,上报的数据类型为SignificantMotionResponse。 |
C
cff-gite 已提交
4618

H
HelloCrease 已提交
4619
**示例:** 
C
cff-gite 已提交
4620 4621 4622 4623 4624 4625
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4626

C
cff-gite 已提交
4627
### PEDOMETER_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4628

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

C
cff-gite 已提交
4631
监听计步检测传感器数据变化一次。
C
cff-gite 已提交
4632

C
cff-gite 已提交
4633
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)代替。
C
cff-gite 已提交
4634

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

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

H
HelloCrease 已提交
4639
**参数:** 
C
cff-gite 已提交
4640

H
HelloCrease 已提交
4641 4642
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4643 4644
| type     | [SensorType](#sensortype)                | 是    | 计步检测传感器类型为SENSOR_TYPE_ID_PEDOMETER_DETECTION。 |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | 是    | 注册一次计步检测传感器的回调函数,上报的数据类型为PedometerDetectionResponse。 |
C
cff-gite 已提交
4645

H
HelloCrease 已提交
4646
**示例:** 
C
cff-gite 已提交
4647 4648 4649 4650 4651 4652
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
C
cff-gite 已提交
4653

C
cff-gite 已提交
4654
### PEDOMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4655

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

C
cff-gite 已提交
4658
监听计步器传感器数据变化一次。
C
cff-gite 已提交
4659

C
cff-gite 已提交
4660
从API version 9 开始不再维护,建议使用[sensor.once.PEDOMETER](#pedometer9-1)代替。
C
cff-gite 已提交
4661

C
cff-gite 已提交
4662
**需要权限**:ohos.permission.ACTIVITY_MOTION
C
cff-gite 已提交
4663 4664 4665

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

H
HelloCrease 已提交
4666
**参数:** 
C
cff-gite 已提交
4667

H
HelloCrease 已提交
4668 4669
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4670 4671
| type     | [SensorType](#sensortype)                | 是    | 计步传感器类型为SENSOR_TYPE_ID_PEDOMETER。        |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | 是    | 注册一次计步传感器的回调函数,上报的数据类型为PedometerResponse。 |
C
cff-gite 已提交
4672

H
HelloCrease 已提交
4673
**示例:** 
C
cff-gite 已提交
4674 4675 4676 4677 4678 4679
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
      console.info('Steps: ' + data.steps);
    }
  );
  ```
C
cff-gite 已提交
4680

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

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

C
cff-gite 已提交
4685
监听环境温度传感器数据变化一次。
C
cff-gite 已提交
4686

C
cff-gite 已提交
4687
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)代替。
C
cff-gite 已提交
4688 4689 4690

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

H
HelloCrease 已提交
4691
**参数:** 
C
cff-gite 已提交
4692

H
HelloCrease 已提交
4693 4694
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4695 4696
| type     | [SensorType](#sensortype)                | 是    | 环境温度传感器类型为SENSOR_TYPE_ID_AMBIENT_TEMPERATURE。 |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | 是    | 注册一次环境温度传感器的回调函数,上报的数据类型为AmbientTemperatureResponse。 |
C
cff-gite 已提交
4697

H
HelloCrease 已提交
4698
**示例:** 
C
cff-gite 已提交
4699 4700 4701 4702 4703 4704
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
      console.info('Temperature: ' + data.temperature);
    }
  );
  ```
C
cff-gite 已提交
4705

C
cff-gite 已提交
4706
### MAGNETIC_FIELD<sup>(deprecated)</sup>
C
cff-gite 已提交
4707

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

C
cff-gite 已提交
4710
监听磁场传感器数据变化一次。
C
cff-gite 已提交
4711

C
cff-gite 已提交
4712
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)代替。
C
cff-gite 已提交
4713

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

H
HelloCrease 已提交
4716
**参数:** 
C
cff-gite 已提交
4717

H
HelloCrease 已提交
4718 4719
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4720 4721
| type     | [SensorType](#sensortype)                | 是    | 磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD。   |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | 是    | 注册一次磁场传感器的回调函数,上报的数据类型为MagneticFieldResponse。 |
C
cff-gite 已提交
4722

H
HelloCrease 已提交
4723
**示例:** 
C
cff-gite 已提交
4724 4725 4726 4727 4728 4729 4730 4731
  ```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 已提交
4732

C
cff-gite 已提交
4733
### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup>
C
cff-gite 已提交
4734

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

C
cff-gite 已提交
4737
监听未校准磁场传感器数据变化一次。
H
h00514358 已提交
4738

C
cff-gite 已提交
4739
从API version 9 开始不再维护,建议使用[sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)代替。
C
cff-gite 已提交
4740 4741 4742

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

H
HelloCrease 已提交
4743
**参数:** 
C
cff-gite 已提交
4744

C
cff-gite 已提交
4745 4746 4747 4748
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 未校准磁场传感器类型为SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED。 |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | 是    | 注册一次未校准磁场传感器的回调函数,上报的数据类型为MagneticFieldUncalibratedResponse。 |
C
cff-gite 已提交
4749

C
cff-gite 已提交
4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761
**示例:** 
  ```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 已提交
4762

C
cff-gite 已提交
4763
### PROXIMITY<sup>(deprecated)</sup>
H
h00514358 已提交
4764

C
cff-gite 已提交
4765
once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
H
h00514358 已提交
4766

C
cff-gite 已提交
4767
监听接近光传感器数据变化一次。
H
h00514358 已提交
4768

C
cff-gite 已提交
4769
从API version 9 开始不再维护,建议使用[sensor.once.PROXIMITY](#proximity9-1)代替。
H
h00514358 已提交
4770

C
cff-gite 已提交
4771
**系统能力**:SystemCapability.Sensors.Sensor
H
h00514358 已提交
4772

C
cff-gite 已提交
4773
**参数:** 
H
h00514358 已提交
4774

C
cff-gite 已提交
4775 4776 4777 4778
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 接近光传感器类型为SENSOR_TYPE_ID_PROXIMITY。       |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | 是    | 注册一次接近光传感器的回调函数,上报的数据类型为ProximityResponse。 |
H
h00514358 已提交
4779

C
cff-gite 已提交
4780 4781 4782 4783 4784 4785 4786
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
      console.info('Distance: ' + data.distance);
    }
  );
  ```
H
h00514358 已提交
4787

C
cff-gite 已提交
4788
### HUMIDITY<sup>(deprecated)</sup>
C
cff-gite 已提交
4789

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

C
cff-gite 已提交
4792
监听湿度传感器数据变化一次。
C
cff-gite 已提交
4793

C
cff-gite 已提交
4794
从API version 9 开始不再维护,建议使用[sensor.once.HUMIDITY](#humidity9-1)代替。
C
cff-gite 已提交
4795

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

H
HelloCrease 已提交
4798
**参数:** 
C
cff-gite 已提交
4799

H
HelloCrease 已提交
4800 4801
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4802 4803
| type     | [SensorType](#sensortype)                | 是    | 湿度传感器类型为SENSOR_TYPE_ID_HUMIDITY。         |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | 是    | 注册一次湿度传感器的回调函数,上报的数据类型为HumidityResponse。 |
C
cff-gite 已提交
4804

H
HelloCrease 已提交
4805
**示例:** 
C
cff-gite 已提交
4806 4807 4808 4809 4810 4811
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
  ```
C
cff-gite 已提交
4812

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

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

C
cff-gite 已提交
4817
监听气压计传感器数据变化一次。
H
h00514358 已提交
4818

C
cff-gite 已提交
4819
从API version 9 开始不再维护,建议使用[sensor.once.BAROMETER](#barometer9-1)代替。
C
cff-gite 已提交
4820 4821 4822

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

H
HelloCrease 已提交
4823
**参数:** 
C
cff-gite 已提交
4824

H
HelloCrease 已提交
4825 4826
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4827 4828
| type     | [SensorType](#sensortype)                | 是    | 气压计传感器类型为SENSOR_TYPE_ID_BAROMETER。       |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | 是    | 注册一次气压计传感器的回调函数,上报的数据类型为BarometerResponse。 |
C
cff-gite 已提交
4829

C
cff-gite 已提交
4830 4831 4832 4833 4834 4835 4836
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
  ```
H
h00514358 已提交
4837

C
cff-gite 已提交
4838
### HALL<sup>(deprecated)</sup>
H
h00514358 已提交
4839

C
cff-gite 已提交
4840
once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void
H
h00514358 已提交
4841

C
cff-gite 已提交
4842 4843
监听霍尔传感器数据变化一次。

C
cff-gite 已提交
4844
从API version 9 开始不再维护,建议使用[sensor.once.HALL](#hall9-1)代替。
H
h00514358 已提交
4845 4846 4847

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

C
cff-gite 已提交
4848
**参数:** 
H
h00514358 已提交
4849

C
cff-gite 已提交
4850 4851 4852 4853
| 参数名      | 类型                                       | 必填   | 说明                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type     | [SensorType](#sensortype)                | 是    | 霍尔传感器类型为SENSOR_TYPE_ID_HALL。         |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | 是    | 注册一次霍尔传感器的回调函数,上报的数据类型为HallResponse。 |
H
h00514358 已提交
4854

C
cff-gite 已提交
4855 4856 4857 4858 4859 4860 4861
**示例:** 
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
  ```
H
h00514358 已提交
4862

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

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

C
cff-gite 已提交
4867
监听环境光传感器数据变化一次。
C
cff-gite 已提交
4868

C
cff-gite 已提交
4869
从API version 9 开始不再维护,建议使用[sensor.once.AMBIENT_LIGHT](#ambient_light9-1)代替。
C
cff-gite 已提交
4870

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

H
HelloCrease 已提交
4873
**参数:** 
C
cff-gite 已提交
4874

C
cff-gite 已提交
4875 4876 4877 4878
| 参数名      | 类型                                       | 必填   | 说明                                     |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | 是    | 环境光传感器类型为SENSOR_TYPE_ID_AMBIENT_LIGHT。 |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | 是    | 注册一次环境光传感器的回调函数,上报的数据类型为LightResponse。 |
C
cff-gite 已提交
4879

H
HelloCrease 已提交
4880
**示例:** 
C
cff-gite 已提交
4881

C
cff-gite 已提交
4882 4883 4884 4885 4886 4887
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
      console.info(' Illumination: ' + data.intensity);
    }
  );
  ```
C
cff-gite 已提交
4888

C
cff-gite 已提交
4889
### ORIENTATION<sup>(deprecated)</sup>
C
cff-gite 已提交
4890

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

C
cff-gite 已提交
4893
监听方向传感器数据变化一次。
C
cff-gite 已提交
4894

C
cff-gite 已提交
4895
从API version 9 开始不再维护,建议使用[sensor.once.ORIENTATION](#orientation9-1)代替。 
C
cff-gite 已提交
4896

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

H
HelloCrease 已提交
4899
**参数:** 
C
cff-gite 已提交
4900

H
HelloCrease 已提交
4901 4902
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4903 4904
| type     | [SensorType](#sensortype)                | 是    | 方向传感器类型为SENSOR_TYPE_ID_ORIENTATION。      |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | 是    | 注册一次方向传感器的回调函数,上报的数据类型为OrientationResponse。 |
C
cff-gite 已提交
4905

H
HelloCrease 已提交
4906
**示例:** 
C
cff-gite 已提交
4907 4908 4909 4910 4911 4912 4913 4914
  ```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 已提交
4915

C
cff-gite 已提交
4916
### ROTATION_VECTOR<sup>(deprecated)</sup>
C
cff-gite 已提交
4917

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

C
cff-gite 已提交
4920
监听旋转矢量传感器数据变化一次。
C
cff-gite 已提交
4921

C
cff-gite 已提交
4922
从API version 9 开始不再维护,建议使用[sensor.once.ROTATION_VECTOR](#rotation_vector9-1)代替。  
C
cff-gite 已提交
4923

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

H
HelloCrease 已提交
4926
**参数:** 
C
cff-gite 已提交
4927

H
HelloCrease 已提交
4928 4929
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4930 4931
| type     | [SensorType](#sensortype)                | 是    | 旋转矢量传感器类型为SENSOR_TYPE_ID_ROTATION_VECTOR。 |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | 是    | 注册一次旋转矢量传感器的回调函数,上报的数据类型为RotationVectorResponse。 |
C
cff-gite 已提交
4932

H
HelloCrease 已提交
4933
**示例:** 
C
cff-gite 已提交
4934 4935 4936 4937 4938 4939 4940 4941 4942
  ```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 已提交
4943

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

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

C
cff-gite 已提交
4948
监听心率传感器数据变化一次。
C
cff-gite 已提交
4949

C
cff-gite 已提交
4950
从API version 9 开始不再维护,建议使用[sensor.once.HEART_RATE](#heart_rate9-1)代替。
C
cff-gite 已提交
4951

C
cff-gite 已提交
4952
**需要权限**:ohos.permission.HEART_RATE  
C
cff-gite 已提交
4953

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

H
HelloCrease 已提交
4956
**参数:** 
C
cff-gite 已提交
4957

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

C
cff-gite 已提交
4963
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
4964

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

C
cff-gite 已提交
4967
监听佩戴检测传感器数据变化一次。
C
cff-gite 已提交
4968

C
cff-gite 已提交
4969
从API version 9 开始不再维护,建议使用[sensor.once.WEAR_DETECTION](#wear_detection9-1)代替。  
C
cff-gite 已提交
4970

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

H
HelloCrease 已提交
4973
**参数:** 
C
cff-gite 已提交
4974

H
HelloCrease 已提交
4975 4976
| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
C
cff-gite 已提交
4977 4978
| type     | [SensorType](#sensortype)                | 是    | 佩戴检测传感器类型为SENSOR_TYPE_ID_WEAR_DETECTION。 |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | 是    | 注册一次穿戴检测传感器的回调函数,上报的数据类型为WearDetectionResponse。 |
C
cff-gite 已提交
4979

H
HelloCrease 已提交
4980
**示例:** 
C
cff-gite 已提交
4981 4982 4983 4984 4985 4986
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
    }
  );
  ```
C
cff-gite 已提交
4987

C
cff-gite 已提交
4988
## sensor.off<sup>(deprecated)</sup>
C
cff-gite 已提交
4989

C
cff-gite 已提交
4990
### ACCELEROMETER<sup>(deprecated)</sup>
C
cff-gite 已提交
4991

C
cff-gite 已提交
4992
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
C
cff-gite 已提交
4993 4994 4995

取消订阅传感器数据。

C
cff-gite 已提交
4996
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER](#accelerometer9-2)代替。  
C
cff-gite 已提交
4997 4998

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
4999

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

H
HelloCrease 已提交
5002
**参数:** 
C
cff-gite 已提交
5003

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

H
HelloCrease 已提交
5009
**示例:** 
C
cff-gite 已提交
5010

H
HelloCrease 已提交
5011
```js
C
cff-gite 已提交
5012
function callback(data) {
C
cff-gite 已提交
5013
    console.info('x-coordinate component: ' + data.x);
C
cff-gite 已提交
5014 5015 5016
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
C
cff-gite 已提交
5017
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
C
cff-gite 已提交
5018 5019
```

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

C
cff-gite 已提交
5022
off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
C
cff-gite 已提交
5023 5024 5025

取消订阅传感器数据。

C
cff-gite 已提交
5026
从API version 9 开始不再维护,建议使用[sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)代替。 
C
cff-gite 已提交
5027 5028

**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5029

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

H
HelloCrease 已提交
5032
**参数:** 
C
cff-gite 已提交
5033

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

H
HelloCrease 已提交
5039
**示例:** 
C
cff-gite 已提交
5040

H
HelloCrease 已提交
5041
```js
C
cff-gite 已提交
5042
function callback(data) {
C
cff-gite 已提交
5043 5044 5045 5046 5047 5048
    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 已提交
5049
}
C
cff-gite 已提交
5050
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
C
cff-gite 已提交
5051 5052
```

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

C
cff-gite 已提交
5055
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
C
cff-gite 已提交
5056 5057 5058

取消订阅传感器数据。

C
cff-gite 已提交
5059
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_LIGHT](#ambient_light9-2)代替。 
C
cff-gite 已提交
5060

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

H
HelloCrease 已提交
5063
**参数:** 
C
cff-gite 已提交
5064

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

H
HelloCrease 已提交
5070
**示例:** 
C
cff-gite 已提交
5071

H
HelloCrease 已提交
5072
```js
C
cff-gite 已提交
5073 5074
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
C
cff-gite 已提交
5075
}
C
cff-gite 已提交
5076
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
C
cff-gite 已提交
5077
```
Z
zengyawen 已提交
5078

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

C
cff-gite 已提交
5081
off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
Z
zengyawen 已提交
5082

C
cff-gite 已提交
5083
取消订阅传感器数据。
Z
zengyawen 已提交
5084

C
cff-gite 已提交
5085
从API version 9 开始不再维护,建议使用[sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)代替。 
C
cff-gite 已提交
5086

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

H
HelloCrease 已提交
5089
**参数:** 
Z
zengyawen 已提交
5090

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

H
HelloCrease 已提交
5096
**示例:** 
Z
zengyawen 已提交
5097

H
HelloCrease 已提交
5098
```js
C
cff-gite 已提交
5099 5100 5101
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
C
cff-gite 已提交
5102
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
H
HelloCrease 已提交
5103
```
Z
zengyawen 已提交
5104

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

C
cff-gite 已提交
5107
off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
Z
zengyawen 已提交
5108

C
cff-gite 已提交
5109 5110
取消订阅传感器数据。

C
cff-gite 已提交
5111
从API version 9 开始不再维护,建议使用[sensor.off.BAROMETER](#barometer9-2)代替。 
C
cff-gite 已提交
5112

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

H
HelloCrease 已提交
5115
**参数:** 
Z
zengyawen 已提交
5116

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

H
HelloCrease 已提交
5122
**示例:** 
Z
zengyawen 已提交
5123

H
HelloCrease 已提交
5124
```js
C
cff-gite 已提交
5125 5126 5127 5128
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
H
HelloCrease 已提交
5129
```
Z
zengyawen 已提交
5130

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

C
cff-gite 已提交
5133
off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
5134

C
cff-gite 已提交
5135
取消订阅传感器数据。
Z
zengyawen 已提交
5136

C
cff-gite 已提交
5137
从API version 9 开始不再维护,建议使用[sensor.off.GRAVITY](#gravity9-2)代替。  
C
cff-gite 已提交
5138

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

H
HelloCrease 已提交
5141
**参数:** 
C
cff-gite 已提交
5142

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

H
HelloCrease 已提交
5148
**示例:** 
C
cff-gite 已提交
5149

H
HelloCrease 已提交
5150
```js
C
cff-gite 已提交
5151 5152 5153 5154 5155 5156
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 已提交
5157
```
Z
zengyawen 已提交
5158

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

C
cff-gite 已提交
5161
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
Z
zengyawen 已提交
5162

C
cff-gite 已提交
5163 5164
取消订阅传感器数据。

C
cff-gite 已提交
5165
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE](#gyroscope9-2)代替。 
C
cff-gite 已提交
5166 5167

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
5168

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

H
HelloCrease 已提交
5171
**参数:** 
C
cff-gite 已提交
5172

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

H
HelloCrease 已提交
5178
**示例:** 
Z
zengyawen 已提交
5179

C
cff-gite 已提交
5180 5181 5182 5183 5184 5185 5186 5187 5188 5189
```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 已提交
5190

C
cff-gite 已提交
5191
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
5192

C
cff-gite 已提交
5193
取消订阅传感器数据。
Z
zengyawen 已提交
5194

C
cff-gite 已提交
5195
从API version 9 开始不再维护,建议使用[sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)代替。  
C
cff-gite 已提交
5196 5197

**需要权限**:ohos.permission.GYROSCOPE
C
cff-gite 已提交
5198

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

H
HelloCrease 已提交
5201
**参数:** 
Z
zengyawen 已提交
5202

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

H
HelloCrease 已提交
5208
**示例:** 
Z
zengyawen 已提交
5209

C
cff-gite 已提交
5210 5211 5212 5213 5214 5215 5216 5217
```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 已提交
5218

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

C
cff-gite 已提交
5221
off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback&lt;HallResponse&gt;): void
Z
zengyawen 已提交
5222

C
cff-gite 已提交
5223
取消订阅传感器数据。
Z
zengyawen 已提交
5224

C
cff-gite 已提交
5225
从API version 9 开始不再维护,建议使用[sensor.off.HALL](#hall9-2)代替。 
C
cff-gite 已提交
5226

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

H
HelloCrease 已提交
5229
**参数:** 
Z
zengyawen 已提交
5230

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

H
HelloCrease 已提交
5236
**示例:** 
Z
zengyawen 已提交
5237

C
cff-gite 已提交
5238 5239 5240 5241 5242 5243
```js
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```
Z
zengyawen 已提交
5244

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

C
cff-gite 已提交
5247
off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
Z
zengyawen 已提交
5248

C
cff-gite 已提交
5249
取消订阅传感器数据。
Z
zengyawen 已提交
5250

C
cff-gite 已提交
5251
从API version 9 开始不再维护,建议使用[sensor.off.HEART_RATE](#heart_rate9-2)代替。
C
cff-gite 已提交
5252

C
cff-gite 已提交
5253
**需要权限**:ohos.permission.HEALTH_DATA 
C
cff-gite 已提交
5254

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

H
HelloCrease 已提交
5257
**参数:** 
Z
zengyawen 已提交
5258

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

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

C
cff-gite 已提交
5266
off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
Z
zengyawen 已提交
5267

C
cff-gite 已提交
5268
取消订阅传感器数据。
Z
zengyawen 已提交
5269

C
cff-gite 已提交
5270
从API version 9 开始不再维护,建议使用[sensor.off.HUMIDITY](#humidity9-2)代替。 
C
cff-gite 已提交
5271

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

H
HelloCrease 已提交
5274
**参数:** 
Z
zengyawen 已提交
5275

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

H
HelloCrease 已提交
5281
**示例:** 
Z
zengyawen 已提交
5282

C
cff-gite 已提交
5283 5284 5285 5286 5287 5288
```js
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```
Z
zengyawen 已提交
5289

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

C
cff-gite 已提交
5292
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
5293

C
cff-gite 已提交
5294
取消订阅传感器数据。
Z
zengyawen 已提交
5295

C
cff-gite 已提交
5296
从API version 9 开始不再维护,建议使用[sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)代替。
C
cff-gite 已提交
5297

C
cff-gite 已提交
5298
**需要权限**:ohos.permission.ACCELEROMETER
C
cff-gite 已提交
5299

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

H
HelloCrease 已提交
5302
**参数:** 
Z
zengyawen 已提交
5303

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

C
cff-gite 已提交
5309 5310 5311 5312 5313 5314
### MAGNETIC_FIELD<sup>(deprecated)</sup>

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

取消订阅传感器数据。

C
cff-gite 已提交
5315
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)代替。 
C
cff-gite 已提交
5316

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

H
HelloCrease 已提交
5319
**参数:** 
Z
zengyawen 已提交
5320

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

H
HelloCrease 已提交
5326
**示例:** 
Z
zengyawen 已提交
5327

C
cff-gite 已提交
5328 5329 5330 5331 5332 5333 5334 5335
```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 已提交
5336

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

C
cff-gite 已提交
5339
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
5340

C
cff-gite 已提交
5341
取消订阅传感器数据。
Z
zengyawen 已提交
5342

C
cff-gite 已提交
5343
从API version 9 开始不再维护,建议使用[sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)代替。
C
cff-gite 已提交
5344

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

H
HelloCrease 已提交
5347
**参数:** 
Z
zengyawen 已提交
5348

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

H
HelloCrease 已提交
5354
**示例:** 
Z
zengyawen 已提交
5355

C
cff-gite 已提交
5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366
```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 已提交
5367

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

C
cff-gite 已提交
5370
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
Z
zengyawen 已提交
5371

C
cff-gite 已提交
5372
取消订阅传感器数据。
Z
zengyawen 已提交
5373

C
cff-gite 已提交
5374
从API version 9 开始不再维护,建议使用[sensor.off.ORIENTATION](#orientation9-2)代替。 
C
cff-gite 已提交
5375

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

H
HelloCrease 已提交
5378
**参数:** 
Z
zengyawen 已提交
5379

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

H
HelloCrease 已提交
5385
**示例:** 
Z
zengyawen 已提交
5386

C
cff-gite 已提交
5387 5388 5389 5390 5391 5392 5393 5394
```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 已提交
5395

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

C
cff-gite 已提交
5398
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
5399

C
cff-gite 已提交
5400
取消订阅传感器数据。
Z
zengyawen 已提交
5401

C
cff-gite 已提交
5402
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER](#pedometer9-2)代替。 
Z
zengyawen 已提交
5403

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

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

H
HelloCrease 已提交
5408
**参数:** 
Z
zengyawen 已提交
5409

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

**示例:** 
Z
zengyawen 已提交
5416

C
cff-gite 已提交
5417 5418 5419 5420 5421 5422
```js
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```
Z
zengyawen 已提交
5423

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

C
cff-gite 已提交
5426
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
Z
zengyawen 已提交
5427

C
cff-gite 已提交
5428
取消订阅传感器数据。
Z
zengyawen 已提交
5429

C
cff-gite 已提交
5430
从API version 9 开始不再维护,建议使用[sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)代替。 
C
cff-gite 已提交
5431 5432

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

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

H
HelloCrease 已提交
5436
**参数:** 
Z
zengyawen 已提交
5437

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

H
HelloCrease 已提交
5443
**示例:** 
Z
zengyawen 已提交
5444

C
cff-gite 已提交
5445 5446 5447 5448 5449 5450
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```
Z
zengyawen 已提交
5451

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

C
cff-gite 已提交
5454
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
Z
zengyawen 已提交
5455

C
cff-gite 已提交
5456
取消订阅传感器数据。
Z
zengyawen 已提交
5457

C
cff-gite 已提交
5458
从API version 9 开始不再维护,建议使用[sensor.off.PROXIMITY](#proximity9-2)代替。 
C
cff-gite 已提交
5459

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

H
HelloCrease 已提交
5462
**参数:** 
Z
zengyawen 已提交
5463

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

H
HelloCrease 已提交
5469
**示例:** 
Z
zengyawen 已提交
5470

C
cff-gite 已提交
5471 5472 5473 5474 5475 5476
```js
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```
Z
zengyawen 已提交
5477

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

C
cff-gite 已提交
5480
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
Z
zengyawen 已提交
5481

C
cff-gite 已提交
5482
取消订阅传感器数据。
Z
zengyawen 已提交
5483

C
cff-gite 已提交
5484
从API version 9 开始不再维护,建议使用[sensor.off.ROTATION_VECTOR](#rotation_vector9-2)代替。 
C
cff-gite 已提交
5485

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

H
HelloCrease 已提交
5488
**参数:** 
Z
zengyawen 已提交
5489

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

H
HelloCrease 已提交
5495
**示例:** 
Z
zengyawen 已提交
5496

C
cff-gite 已提交
5497 5498 5499 5500 5501 5502 5503 5504 5505
```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 已提交
5506

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

C
cff-gite 已提交
5509
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
5510

C
cff-gite 已提交
5511
取消订阅传感器数据。
Z
zengyawen 已提交
5512

C
cff-gite 已提交
5513
从API version 9 开始不再维护,建议使用[sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)代替。
C
cff-gite 已提交
5514

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

H
HelloCrease 已提交
5517
**参数:** 
Z
zengyawen 已提交
5518

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

H
HelloCrease 已提交
5524
**示例:** 
Z
zengyawen 已提交
5525

C
cff-gite 已提交
5526 5527 5528 5529 5530 5531
```js
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
Z
zengyawen 已提交
5532

C
cff-gite 已提交
5533
### WEAR_DETECTION<sup>(deprecated)</sup>
C
cff-gite 已提交
5534

C
cff-gite 已提交
5535
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
C
cff-gite 已提交
5536

C
cff-gite 已提交
5537 5538
取消订阅传感器数据。

C
cff-gite 已提交
5539
从API version 9 开始不再维护,建议使用[sensor.off.WEAR_DETECTION](#wear_detection9-2)代替。 
C
cff-gite 已提交
5540 5541 5542 5543 5544

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

**参数:** 

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

**示例:** 

C
cff-gite 已提交
5552
```js
C
cff-gite 已提交
5553 5554 5555 5556
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
C
cff-gite 已提交
5557 5558
```

C
cff-gite 已提交
5559
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5560

C
cff-gite 已提交
5561
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5562

C
cff-gite 已提交
5563 5564
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。

C
cff-gite 已提交
5565
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9)代替。
C
cff-gite 已提交
5566 5567 5568

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

C
cff-gite 已提交
5569
**参数:** 
C
cff-gite 已提交
5570

C
cff-gite 已提交
5571 5572 5573 5574 5575
| 参数名              | 类型                                       | 必填   | 说明          |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。     |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。    |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回转换后的旋转矩阵。 |
C
cff-gite 已提交
5576 5577 5578

**示例:** 

C
cff-gite 已提交
5579
```js
C
cff-gite 已提交
5580 5581 5582 5583 5584 5585 5586 5587 5588 5589
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 已提交
5590
```
C
cff-gite 已提交
5591
## sensor.transformCoordinateSystem<sup>(deprecated)</sup>
C
cff-gite 已提交
5592

C
cff-gite 已提交
5593
transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5594

C
cff-gite 已提交
5595
旋转提供的旋转矩阵,使其可以以不同的方式表示坐标系。
C
cff-gite 已提交
5596

C
cff-gite 已提交
5597
从API version 9 开始不再维护,建议使用[sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)代替。
C
cff-gite 已提交
5598 5599 5600 5601 5602

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

**参数:** 

C
cff-gite 已提交
5603 5604 5605 5606
| 参数名              | 类型                                       | 必填   | 说明       |
| ---------------- | ---------------------------------------- | ---- | -------- |
| inRotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。  |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | 是    | 表示坐标系方向。 |
C
cff-gite 已提交
5607

C
cff-gite 已提交
5608 5609 5610 5611 5612 5613 5614
**返回值:** 

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

**示例:** 
C
cff-gite 已提交
5615

C
cff-gite 已提交
5616
```js
C
cff-gite 已提交
5617 5618 5619 5620 5621 5622 5623 5624 5625
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 已提交
5626 5627
```

C
cff-gite 已提交
5628
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5629

C
cff-gite 已提交
5630
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback&lt;GeomagneticResponse&gt;): void
C
cff-gite 已提交
5631

C
cff-gite 已提交
5632 5633
获取地球上特定位置的地磁场。

C
cff-gite 已提交
5634
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)代替。
C
cff-gite 已提交
5635 5636 5637 5638 5639

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

**参数:** 

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

C
cff-gite 已提交
5646
**示例:** 
C
cff-gite 已提交
5647
```js
C
cff-gite 已提交
5648 5649 5650 5651 5652 5653 5654 5655
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 已提交
5656
});
C
cff-gite 已提交
5657
```
C
cff-gite 已提交
5658
## sensor.getGeomagneticField<sup>(deprecated)</sup>
C
cff-gite 已提交
5659

C
cff-gite 已提交
5660
getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
Z
zengyawen 已提交
5661

C
cff-gite 已提交
5662
获取地球上特定位置的地磁场。
Z
zengyawen 已提交
5663

C
cff-gite 已提交
5664
从API version 9 开始不再维护,建议使用[sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)代替。
Z
zengyawen 已提交
5665

C
cff-gite 已提交
5666
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5667

C
cff-gite 已提交
5668
**参数:** 
C
cff-gite 已提交
5669

C
cff-gite 已提交
5670 5671 5672 5673
| 参数名             | 类型                                  | 必填   | 说明                |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | 是    | 地理位置。             |
| timeMillis      | number                              | 是    | 表示获取磁偏角的时间,单位为毫秒。 |
C
cff-gite 已提交
5674

C
cff-gite 已提交
5675 5676 5677 5678
**返回值:** 
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | 返回磁场信息。 |
C
cff-gite 已提交
5679

C
cff-gite 已提交
5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690
**示例:** 
  ```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 已提交
5691

C
cff-gite 已提交
5692
## sensor.getAltitude<sup>(deprecated)</sup>
C
cff-gite 已提交
5693

C
cff-gite 已提交
5694
getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5695

C
cff-gite 已提交
5696
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5697

C
cff-gite 已提交
5698
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9)代替。
Z
zengyawen 已提交
5699

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

C
cff-gite 已提交
5702
**参数:** 
Z
zengyawen 已提交
5703

C
cff-gite 已提交
5704 5705 5706 5707 5708
| 参数名             | 类型                          | 必填   | 说明                   |
| --------------- | --------------------------- | ---- | -------------------- |
| seaPressure     | number                      | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number                      | 是    | 表示设备所在高度的气压值,单位为hPa。 |
| callback        | AsyncCallback&lt;number&gt; | 是    | 返回设备所在的海拔高度,单位为米。    |
Z
zengyawen 已提交
5709

C
cff-gite 已提交
5710
**示例:** 
Z
zengyawen 已提交
5711

C
cff-gite 已提交
5712 5713 5714 5715 5716 5717 5718 5719 5720 5721
  ```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 已提交
5722

C
cff-gite 已提交
5723
## sensor.getAltitude<sup>(deprecated)</sup>
Z
zengyawen 已提交
5724

C
cff-gite 已提交
5725
getAltitude(seaPressure: number, currentPressure: number): Promise&lt;number&gt;
C
cff-gite 已提交
5726

C
cff-gite 已提交
5727
根据气压值获取设备所在的海拔高度。
Z
zengyawen 已提交
5728

C
cff-gite 已提交
5729
从API version 9 开始不再维护,建议使用[sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)代替。
Z
zengyawen 已提交
5730

C
cff-gite 已提交
5731
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5732

C
cff-gite 已提交
5733
**参数:** 
Z
zengyawen 已提交
5734

C
cff-gite 已提交
5735 5736 5737 5738
| 参数名             | 类型     | 必填   | 说明                   |
| --------------- | ------ | ---- | -------------------- |
| seaPressure     | number | 是    | 表示海平面气压值,单位为hPa。     |
| currentPressure | number | 是    | 表示设备所在高度的气压值,单位为hPa。 |
Z
zengyawen 已提交
5739

C
cff-gite 已提交
5740
**返回值:** 
C
cff-gite 已提交
5741

C
cff-gite 已提交
5742 5743 5744
| 类型                    | 说明                 |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回设备所在的海拔高度(单位:米)。 |
Z
zengyawen 已提交
5745

C
cff-gite 已提交
5746
**示例:** 
Z
zengyawen 已提交
5747

C
cff-gite 已提交
5748 5749 5750 5751 5752 5753 5754 5755
  ```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 已提交
5756

Z
zengyawen 已提交
5757

C
cff-gite 已提交
5758
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5759

C
cff-gite 已提交
5760
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
C
cff-gite 已提交
5761

C
cff-gite 已提交
5762
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5763

C
cff-gite 已提交
5764
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9)代替。
Z
zengyawen 已提交
5765

C
cff-gite 已提交
5766
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5767

C
cff-gite 已提交
5768
**参数:** 
Z
zengyawen 已提交
5769

C
cff-gite 已提交
5770 5771 5772 5773
| 参数名               | 类型                          | 必填   | 说明             |
| ----------------- | --------------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt;         | 是    | 表示倾斜矩阵。        |
| callback          | AsyncCallback&lt;number&gt; | 是    | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5774

C
cff-gite 已提交
5775
**示例:** 
C
cff-gite 已提交
5776

C
cff-gite 已提交
5777 5778 5779 5780 5781 5782 5783 5784 5785 5786
  ```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 已提交
5787

C
cff-gite 已提交
5788
## sensor.getGeomagneticDip<sup>(deprecated)</sup>
Z
zengyawen 已提交
5789

C
cff-gite 已提交
5790
getGeomagneticDip(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
Z
zengyawen 已提交
5791

C
cff-gite 已提交
5792
根据倾斜矩阵计算地磁倾斜角。
Z
zengyawen 已提交
5793

C
cff-gite 已提交
5794
从API version 9 开始不再维护,建议使用[sensor.getInclination](#sensorgetinclination9-1)代替。
Z
zengyawen 已提交
5795

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

C
cff-gite 已提交
5798
**参数:** 
Z
zengyawen 已提交
5799

C
cff-gite 已提交
5800 5801 5802
| 参数名               | 类型                  | 必填   | 说明      |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | 是    | 表示倾斜矩阵。 |
Z
zengyawen 已提交
5803

C
cff-gite 已提交
5804
**返回值:** 
Z
zengyawen 已提交
5805

C
cff-gite 已提交
5806 5807 5808
| 类型                    | 说明             |
| --------------------- | -------------- |
| Promise&lt;number&gt; | 返回地磁倾斜角,单位为弧度。 |
Z
zengyawen 已提交
5809

C
cff-gite 已提交
5810
**示例:** 
Z
zengyawen 已提交
5811

C
cff-gite 已提交
5812 5813 5814 5815 5816 5817 5818 5819
  ```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 已提交
5820

C
cff-gite 已提交
5821
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5822

C
cff-gite 已提交
5823
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5824

C
cff-gite 已提交
5825
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5826

C
cff-gite 已提交
5827
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9)代替。
Z
zengyawen 已提交
5828

C
cff-gite 已提交
5829
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5830

C
cff-gite 已提交
5831
**参数:** 
C
cff-gite 已提交
5832

C
cff-gite 已提交
5833 5834 5835 5836 5837
| 参数名                   | 类型                                       | 必填   | 说明                 |
| --------------------- | ---------------------------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | 是    | 表示当前旋转矩阵。          |
| preRotationMatrix     | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5838

C
cff-gite 已提交
5839
**示例:** 
Z
zengyawen 已提交
5840

C
cff-gite 已提交
5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852
  ```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 已提交
5853

Z
zengyawen 已提交
5854

C
cff-gite 已提交
5855
## sensor. getAngleModify<sup>(deprecated)</sup>
Z
zengyawen 已提交
5856

C
cff-gite 已提交
5857
getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
5858

C
cff-gite 已提交
5859
获取两个旋转矩阵之间的角度变化。
Z
zengyawen 已提交
5860

C
cff-gite 已提交
5861
从API version 9 开始不再维护,建议使用[sensor.getAngleVariation](#sensorgetanglevariation9-1)代替。
Z
zengyawen 已提交
5862

C
cff-gite 已提交
5863
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5864

C
cff-gite 已提交
5865
**参数:** 
Z
zengyawen 已提交
5866

C
cff-gite 已提交
5867 5868 5869 5870
| 参数名                   | 类型                  | 必填   | 说明        |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | 是    | 表示当前旋转矩阵。 |
| preRotationMatrix     | Array&lt;number&gt; | 是    | 表示旋转矩阵。   |
Z
zengyawen 已提交
5871

C
cff-gite 已提交
5872
**返回值:** 
C
cff-gite 已提交
5873

C
cff-gite 已提交
5874 5875 5876
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回z、x、y轴方向的旋转角度变化。 |
Z
zengyawen 已提交
5877

C
cff-gite 已提交
5878
**示例:** 
Z
zengyawen 已提交
5879

C
cff-gite 已提交
5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890
  ```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 已提交
5891

Z
zengyawen 已提交
5892

C
cff-gite 已提交
5893
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5894

C
cff-gite 已提交
5895
createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
C
cff-gite 已提交
5896

C
cff-gite 已提交
5897
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5898

C
cff-gite 已提交
5899
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9)代替。
Z
zengyawen 已提交
5900

C
cff-gite 已提交
5901
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5902

C
cff-gite 已提交
5903
**参数:** 
Z
zengyawen 已提交
5904

C
cff-gite 已提交
5905 5906 5907 5908
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
5909

C
cff-gite 已提交
5910
**示例:** 
C
cff-gite 已提交
5911

C
cff-gite 已提交
5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923
  ```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 已提交
5924 5925


C
cff-gite 已提交
5926
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
5927

C
cff-gite 已提交
5928
createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
5929

C
cff-gite 已提交
5930
将旋转矢量转换为旋转矩阵。
Z
zengyawen 已提交
5931

C
cff-gite 已提交
5932
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)代替。
C
cff-gite 已提交
5933

C
cff-gite 已提交
5934
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5935

C
cff-gite 已提交
5936
**参数:** 
Z
zengyawen 已提交
5937

C
cff-gite 已提交
5938 5939 5940
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
5941

C
cff-gite 已提交
5942
**返回值:** 
Z
zengyawen 已提交
5943

C
cff-gite 已提交
5944 5945 5946
| 类型                                 | 说明      |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | 返回旋转矩阵。 |
Z
zengyawen 已提交
5947

C
cff-gite 已提交
5948
**示例:** 
C
cff-gite 已提交
5949

C
cff-gite 已提交
5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960
  ```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 已提交
5961 5962


C
cff-gite 已提交
5963
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5964

C
cff-gite 已提交
5965
createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
5966

C
cff-gite 已提交
5967
将旋转矢量转换为四元数。
Z
zengyawen 已提交
5968

C
cff-gite 已提交
5969
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9)代替。
C
cff-gite 已提交
5970

C
cff-gite 已提交
5971
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
5972

C
cff-gite 已提交
5973
**参数:** 
Z
zengyawen 已提交
5974

C
cff-gite 已提交
5975 5976 5977 5978
| 参数名            | 类型                                       | 必填   | 说明      |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | 是    | 表示旋转矢量。 |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回四元数。  |
Z
zengyawen 已提交
5979

C
cff-gite 已提交
5980
**示例:** 
Z
zengyawen 已提交
5981

C
cff-gite 已提交
5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993
  ```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 已提交
5994

C
cff-gite 已提交
5995

C
cff-gite 已提交
5996
## sensor.createQuaternion<sup>(deprecated)</sup>
Z
zengyawen 已提交
5997

C
cff-gite 已提交
5998
createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
Z
zengyawen 已提交
5999

C
cff-gite 已提交
6000
将旋转矢量转换为四元数。
Z
zengyawen 已提交
6001

C
cff-gite 已提交
6002
从API version 9 开始不再维护,建议使用[sensor.getQuaternion](#sensorgetquaternion9-1)代替。
Z
zengyawen 已提交
6003

C
cff-gite 已提交
6004
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6005

C
cff-gite 已提交
6006
**参数:** 
C
cff-gite 已提交
6007

C
cff-gite 已提交
6008 6009 6010
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | 是    | 表示旋转矢量。 |
Z
zengyawen 已提交
6011

C
cff-gite 已提交
6012
**返回值:** 
Z
zengyawen 已提交
6013

C
cff-gite 已提交
6014 6015 6016
| 类型                                 | 说明     |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回四元数。 |
Z
zengyawen 已提交
6017

C
cff-gite 已提交
6018
**示例:** 
Z
zengyawen 已提交
6019

C
cff-gite 已提交
6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030
  ```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 已提交
6031

C
cff-gite 已提交
6032

C
cff-gite 已提交
6033
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
6034

C
cff-gite 已提交
6035
getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Z
zengyawen 已提交
6036

C
cff-gite 已提交
6037
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
6038

C
cff-gite 已提交
6039
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9)代替。
Z
zengyawen 已提交
6040

C
cff-gite 已提交
6041
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6042

C
cff-gite 已提交
6043
**参数:** 
C
cff-gite 已提交
6044

C
cff-gite 已提交
6045 6046 6047 6048
| 参数名            | 类型                                       | 必填   | 说明                 |
| -------------- | ---------------------------------------- | ---- | ------------------ |
| rotationMatrix | Array&lt;number&gt;                      | 是    | 表示旋转矩阵。            |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是    | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
6049

C
cff-gite 已提交
6050
**示例:** 
Z
zengyawen 已提交
6051

C
cff-gite 已提交
6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064
  ```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 已提交
6065

Z
zengyawen 已提交
6066

C
cff-gite 已提交
6067
## sensor.getDirection<sup>(deprecated)</sup>
Z
zengyawen 已提交
6068

C
cff-gite 已提交
6069
getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
C
cff-gite 已提交
6070

C
cff-gite 已提交
6071
根据旋转矩阵计算设备的方向。
Z
zengyawen 已提交
6072

C
cff-gite 已提交
6073
从API version 9 开始不再维护,建议使用[sensor.getOrientation](#sensorgetorientation9-1)代替。
Z
zengyawen 已提交
6074

C
cff-gite 已提交
6075
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6076

C
cff-gite 已提交
6077
**参数:** 
Z
zengyawen 已提交
6078

C
cff-gite 已提交
6079 6080 6081
| 参数名            | 类型                  | 必填   | 说明      |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | 是    | 表示旋转矩阵。 |
Z
zengyawen 已提交
6082

C
cff-gite 已提交
6083
**返回值:** 
C
cff-gite 已提交
6084

C
cff-gite 已提交
6085 6086 6087
| 类型                                 | 说明                 |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | 返回围绕z、x、y轴方向的旋转角度。 |
Z
zengyawen 已提交
6088

C
cff-gite 已提交
6089
**示例:** 
Z
zengyawen 已提交
6090

C
cff-gite 已提交
6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101
  ```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 已提交
6102 6103


C
cff-gite 已提交
6104
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
6105

C
cff-gite 已提交
6106
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;, callback: AsyncCallback&lt;RotationMatrixResponse&gt;): void
C
cff-gite 已提交
6107

C
cff-gite 已提交
6108
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
6109

C
cff-gite 已提交
6110
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)代替。
Z
zengyawen 已提交
6111

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

C
cff-gite 已提交
6114
**参数:** 
Z
zengyawen 已提交
6115

C
cff-gite 已提交
6116 6117 6118 6119 6120
| 参数名         | 类型                                       | 必填   | 说明      |
| ----------- | ---------------------------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt;                      | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt;                      | 是    | 表示地磁矢量。 |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 是    | 返回旋转矩阵。 |
Z
zengyawen 已提交
6121

C
cff-gite 已提交
6122
**示例:** 
Z
zengyawen 已提交
6123

C
cff-gite 已提交
6124 6125 6126 6127 6128 6129 6130 6131 6132
  ```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 已提交
6133

C
cff-gite 已提交
6134

C
cff-gite 已提交
6135
## sensor.createRotationMatrix<sup>(deprecated)</sup>
Z
zengyawen 已提交
6136

C
cff-gite 已提交
6137
createRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;,): Promise&lt;RotationMatrixResponse&gt;
Z
zengyawen 已提交
6138

C
cff-gite 已提交
6139
根据重力矢量和地磁矢量计算旋转矩阵。
Z
zengyawen 已提交
6140

C
cff-gite 已提交
6141
从API version 9 开始不再维护,建议使用[sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)代替。
Z
zengyawen 已提交
6142

C
cff-gite 已提交
6143
**系统能力**:SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
6144

C
cff-gite 已提交
6145
**参数:** 
C
cff-gite 已提交
6146

C
cff-gite 已提交
6147 6148 6149 6150
| 参数名         | 类型                  | 必填   | 说明      |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | 是    | 表示重力向量。 |
| geomagnetic | Array&lt;number&gt; | 是    | 表示地磁矢量。 |
Z
zengyawen 已提交
6151

C
cff-gite 已提交
6152
**返回值:** 
Z
zengyawen 已提交
6153

C
cff-gite 已提交
6154 6155 6156
| 类型                                       | 说明      |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | 返回旋转矩阵。 |
C
cff-gite 已提交
6157

C
cff-gite 已提交
6158
**示例:** 
C
cff-gite 已提交
6159

C
cff-gite 已提交
6160 6161 6162 6163 6164 6165 6166 6167
  ```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');
  })
  ```