js-apis-sensor.md 272.6 KB
Newer Older
W
wusongqing 已提交
1
# Sensor
Z
zengyawen 已提交
2

W
wusongqing 已提交
3 4 5 6 7 8 9 10 11 12 13
The **Sensor** module provides APIs for subscribing to and unsubscribing from sensor data, and obtaining the sensor list. It also provides common sensor algorithm APIs, for example, APIs for obtaining the altitude based on the atmospheric pressure and obtaining the device orientation based on the rotation matrix.

A sensor is a device to detect events or changes in an environment and send messages about the events or changes to another device (for example, a CPU). Generally, a sensor is composed of sensitive components and conversion components. Sensors are the cornerstone of the Internet of Things (IoT). A unified sensor management framework is required to achieve data sensing at a low latency and low power consumption, thereby keeping up with requirements of "1+8+N" products or business in the Seamless AI Life Strategy. Based on the usage, sensors are divided into the following categories:

- Motion: acceleration sensors, gyroscope sensors, gravity sensors, linear acceleration sensors, and more
- Orientation: rotation vector sensors, orientation sensors, and more
- Environment: magnetic field sensors, barometric pressure sensors, humidity sensors, and more
- Light: ambient light sensors, proximity sensors, color temperature sensors, and more
- Body: heart rate sensors, heartbeat sensors, and more
- Other: Hall effect sensors, grip detection sensors, and more

W
wusongqing 已提交
14 15
> **NOTE**
>
W
wusongqing 已提交
16
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
17

W
wusongqing 已提交
18 19

## Modules to Import
Z
zengyawen 已提交
20

W
wusongqing 已提交
21
```js
Z
zengyawen 已提交
22 23 24
import sensor from '@ohos.sensor';
```

G
Gloria 已提交
25
## sensor.on<sup>9+</sup>
W
wusongqing 已提交
26

G
Gloria 已提交
27
### ACCELEROMETER<sup>9+</sup>
W
wusongqing 已提交
28

G
Gloria 已提交
29
on(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;,options?: Options): void
W
wusongqing 已提交
30

G
Gloria 已提交
31
Subscribes to data of the acceleration sensor.
Z
zengyawen 已提交
32

G
Gloria 已提交
33
**Required permissions**: ohos.permission.ACCELEROMETER
Z
zengyawen 已提交
34

W
wusongqing 已提交
35
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
36

W
wusongqing 已提交
37
**Parameters**
W
wusongqing 已提交
38

G
Gloria 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ACCELEROMETER**.                  |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
52

W
wusongqing 已提交
53
**Example**
Z
zengyawen 已提交
54

G
Gloria 已提交
55 56 57 58 59 60 61 62 63 64 65
```js
try {
    sensor.on(sensor.SensorId.ACCELEROMETER,function(data){
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }, {interval: 10000000} );
} catch(err) {
        console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
66

G
Gloria 已提交
67
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
68

G
Gloria 已提交
69
on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;,options?: Options): void
Z
zengyawen 已提交
70

G
Gloria 已提交
71
Subscribes to data of the uncalibrated acceleration sensor.
W
wusongqing 已提交
72

G
Gloria 已提交
73
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
74 75 76

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
77
**Parameters**
G
Gloria 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
92

W
wusongqing 已提交
93
**Example**
Z
zengyawen 已提交
94

G
Gloria 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108
```js
try {
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED,function(data){
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
      }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
W
wusongqing 已提交
109

G
Gloria 已提交
110
### AMBIENT_LIGHT<sup>9+</sup>
W
wusongqing 已提交
111

G
Gloria 已提交
112
on(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
W
wusongqing 已提交
113

G
Gloria 已提交
114
Subscribes to data of the ambient light sensor.
W
wusongqing 已提交
115 116 117 118

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**
G
Gloria 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132

| Name  | Type                                           | Mandatory| Description                                                       |
| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9)                          | Yes  | Type of the sensor to subscribe to, which is **AMBIENT_LIGHT**.                  |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
| options  | [Options](#options)                             | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
133 134 135

**Example**

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

G
Gloria 已提交
146
###  AMBIENT_TEMPERATURE<sup>9+</sup>
Z
zengyawen 已提交
147

G
Gloria 已提交
148
on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;,options?: Options): void
Z
zengyawen 已提交
149

G
Gloria 已提交
150
Subscribes to data of the ambient temperature sensor.
W
wusongqing 已提交
151 152 153

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
154
**Parameters**
G
Gloria 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **AMBIENT_TEMPERATURE**.           |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
169

W
wusongqing 已提交
170
**Example**
Z
zengyawen 已提交
171

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

### BAROMETER<sup>9+</sup>
Z
zengyawen 已提交
183

G
Gloria 已提交
184
on(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;, options?: Options): void
Z
zengyawen 已提交
185

G
Gloria 已提交
186
Subscribes to data of the barometer sensor.
Z
zengyawen 已提交
187

W
wusongqing 已提交
188 189
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
190
**Parameters**
G
Gloria 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204

| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **BAROMETER**.                       |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
| options  | [Options](#options)                                     | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
205

W
wusongqing 已提交
206
**Example**
G
Gloria 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246

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

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

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

Subscribes to data of the gravity sensor.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name  | Type                                               | Mandatory| Description                                                       |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9)                              | Yes  | Type of the sensor to subscribe to, which is **GRAVITY**.                          |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
| options  | [Options](#options)                                 | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  sensor.on(sensor.SensorId.GRAVITY,function(data){
W
wusongqing 已提交
247 248 249
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
G
Gloria 已提交
250 251 252 253 254
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
255

G
Gloria 已提交
256
###  GYROSCOPE<sup>9+</sup>
Z
zengyawen 已提交
257

G
Gloria 已提交
258
on(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;,options?: Options): void
Z
zengyawen 已提交
259

G
Gloria 已提交
260
Subscribes to data of the gyroscope sensor.
Z
zengyawen 已提交
261

G
Gloria 已提交
262
**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
263 264 265

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
266
**Parameters**
G
Gloria 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280

| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **GYROSCOPE**.                       |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
| options  | [Options](#options)                                     | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
281

W
wusongqing 已提交
282
**Example**
G
Gloria 已提交
283 284 285 286

```js
try {
  sensor.on(sensor.SensorId.GYROSCOPE,function(data){
W
wusongqing 已提交
287 288 289
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
G
Gloria 已提交
290 291 292 293 294
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
295

G
Gloria 已提交
296
###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
297

G
Gloria 已提交
298 299
on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;,
      options?: Options): void
Z
zengyawen 已提交
300

G
Gloria 已提交
301
Subscribes to data of the uncalibrated gyroscope sensor.
Z
zengyawen 已提交
302

G
Gloria 已提交
303
**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
304

G
Gloria 已提交
305
**System capability**: SystemCapability.Sensors.Sensor 
W
wusongqing 已提交
306

W
wusongqing 已提交
307
**Parameters**
G
Gloria 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **GYROSCOPE_UNCALIBRATED**.    |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
322

W
wusongqing 已提交
323
**Example**
G
Gloria 已提交
324 325 326 327

```js
try {
  sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED,function(data){
W
wusongqing 已提交
328 329 330 331 332 333
      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);
G
Gloria 已提交
334 335 336 337 338
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
339

G
Gloria 已提交
340
###  HALL<sup>9+</sup>
Z
zengyawen 已提交
341

G
Gloria 已提交
342
on(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
Z
zengyawen 已提交
343

G
Gloria 已提交
344
Subscribes to data of the Hall effect sensor.
Z
zengyawen 已提交
345

W
wusongqing 已提交
346 347
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
348
**Parameters**
G
Gloria 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361 362

| Name  | Type                                         | Mandatory| Description                                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                        | Yes  | Type of the sensor to subscribe to, which is **HALL**.                              |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
| options  | [Options](#options)                           | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
363

W
wusongqing 已提交
364
**Example**
Z
zengyawen 已提交
365

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

G
Gloria 已提交
376
###   HEART_RATE<sup>9+</sup>
Z
zengyawen 已提交
377

G
Gloria 已提交
378
on(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;,options?: Options): void
Z
zengyawen 已提交
379

G
Gloria 已提交
380 381 382
Subscribes to data of the heart rate sensor.

**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
383 384 385

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
386
**Parameters**
G
Gloria 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400

| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **HEART_RATE**.                        |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | Callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
| options  | [Options](#options)                                     | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
401

W
wusongqing 已提交
402
**Example**
Z
zengyawen 已提交
403

G
Gloria 已提交
404 405 406 407 408 409 410 411 412
```js
try {
    sensor.on(sensor.SensorId.HEART_RATE,function(data){
        console.info('Heart rate: ' + data.heartRate);
    }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
413

G
Gloria 已提交
414
###  HUMIDITY<sup>9+</sup>
Z
zengyawen 已提交
415

G
Gloria 已提交
416
on(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
417

G
Gloria 已提交
418
Subscribes to data of the humidity sensor.
W
wusongqing 已提交
419 420 421

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
422
**Parameters**
G
Gloria 已提交
423 424 425 426 427 428 429 430 431 432 433 434 435 436

| Name  | Type                                                 | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                | Yes  | Type of the sensor to subscribe to, which is **HUMIDITY**.                          |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
| options  | [Options](#options)                                   | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
437

W
wusongqing 已提交
438
**Example**
Z
zengyawen 已提交
439

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

G
Gloria 已提交
450
###  LINEAR_ACCELERATION<sup>9+</sup>
Z
zengyawen 已提交
451

G
Gloria 已提交
452 453 454 455 456 457
on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerometerResponse&gt;,
        options?: Options): void

Subscribes to data of the linear acceleration sensor.

**Required permissions**: ohos.permission.ACCELEROMETER
Z
zengyawen 已提交
458

W
wusongqing 已提交
459 460
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
461
**Parameters**
G
Gloria 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **LINEAR_ACCELEROMETER**.        |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
476

W
wusongqing 已提交
477
**Example**
Z
zengyawen 已提交
478

G
Gloria 已提交
479 480 481 482 483 484 485 486 487 488 489 490 491
```js
try {
  sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

###  MAGNETIC_FIELD<sup>9+</sup>
Z
zengyawen 已提交
492

G
Gloria 已提交
493
on(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
Z
zengyawen 已提交
494

G
Gloria 已提交
495
Subscribes to data of the magnetic field sensor.
Z
zengyawen 已提交
496

W
wusongqing 已提交
497 498
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
499
**Parameters**
G
Gloria 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **MAGNETIC_FIELD**.                    |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
514

W
wusongqing 已提交
515
**Example**
G
Gloria 已提交
516 517 518 519

```js
try {
  sensor.on(sensor.SensorId.MAGNETIC_FIELD,function(data){
W
wusongqing 已提交
520 521 522
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
G
Gloria 已提交
523 524 525 526 527
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
528

G
Gloria 已提交
529
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
530

G
Gloria 已提交
531
on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
532

G
Gloria 已提交
533
Subscribes to data of the uncalibrated magnetic field sensor.
Z
zengyawen 已提交
534

W
wusongqing 已提交
535 536
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
537
**Parameters**
G
Gloria 已提交
538 539 540 541 542 543 544 545 546 547 548 549 550 551

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **MAGNETIC_FIELD_UNCALIBRATED**. |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
552

W
wusongqing 已提交
553
**Example**
G
Gloria 已提交
554 555 556 557

```js
try {
  sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED,function(data){
W
wusongqing 已提交
558 559 560 561 562 563
      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);
G
Gloria 已提交
564 565 566 567 568
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
569

G
Gloria 已提交
570
### ORIENTATION<sup>9+</sup>
Z
zengyawen 已提交
571

G
Gloria 已提交
572
on(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;,options?: Options): void
Z
zengyawen 已提交
573

G
Gloria 已提交
574
Subscribes to data of the orientation sensor.
Z
zengyawen 已提交
575

W
wusongqing 已提交
576 577
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
578 579 580 581 582 583 584 585
**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

W
wusongqing 已提交
586
**Parameters**
G
Gloria 已提交
587 588 589 590 591 592

| Name  | Type                                                       | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                      | Yes  | Type of the sensor to subscribe to, which is **ORIENTATION**.                       |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
| options  | [Options](#options)                                         | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |
W
wusongqing 已提交
593

W
wusongqing 已提交
594
**Example**
Z
zengyawen 已提交
595

G
Gloria 已提交
596 597 598 599 600 601 602 603 604 605 606
```js
try {
  sensor.on(sensor.SensorId.ORIENTATION,function(data){
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
607

G
Gloria 已提交
608
### PEDOMETER<sup>9+</sup>
Z
zengyawen 已提交
609

G
Gloria 已提交
610
on(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
W
wusongqing 已提交
611

G
Gloria 已提交
612
Subscribes to data of the pedometer sensor.
W
wusongqing 已提交
613

G
Gloria 已提交
614
**Required permissions**: ohos.permission.ACTIVITY_MOTION
Z
zengyawen 已提交
615

G
Gloria 已提交
616
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
617

G
Gloria 已提交
618
**Error code**
Z
zengyawen 已提交
619

G
Gloria 已提交
620
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
Z
zengyawen 已提交
621

G
Gloria 已提交
622 623 624
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
625

W
wusongqing 已提交
626
**Parameters**
G
Gloria 已提交
627 628 629 630 631 632

| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **PEDOMETER**.                         |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
| options  | [Options](#options)                                     | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |
W
wusongqing 已提交
633

W
wusongqing 已提交
634
**Example**
Z
zengyawen 已提交
635

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

G
Gloria 已提交
646
### PEDOMETER_DETECTION<sup>9+</sup>
Z
zengyawen 已提交
647

G
Gloria 已提交
648 649
on(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;,
        options?: Options): void
Z
zengyawen 已提交
650

G
Gloria 已提交
651
Subscribe to data of the pedometer detection sensor.
W
wusongqing 已提交
652

G
Gloria 已提交
653
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
654

G
Gloria 已提交
655
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
656

G
Gloria 已提交
657
**Parameters**
Z
zengyawen 已提交
658

G
Gloria 已提交
659 660 661 662 663
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **PEDOMETER_DETECTION**.           |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |
Z
zengyawen 已提交
664

G
Gloria 已提交
665
**Error code**
Z
zengyawen 已提交
666

G
Gloria 已提交
667
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
668

G
Gloria 已提交
669 670 671
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
672

W
wusongqing 已提交
673
**Example**
Z
zengyawen 已提交
674

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

### PROXIMITY<sup>9+</sup>
Z
zengyawen 已提交
686

G
Gloria 已提交
687
on(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;, options?: Options): void
Z
zengyawen 已提交
688

G
Gloria 已提交
689
Subscribes to data of the proximity sensor.
Z
zengyawen 已提交
690

W
wusongqing 已提交
691 692
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
693
**Parameters**
W
wusongqing 已提交
694

G
Gloria 已提交
695 696 697 698 699
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **PROXIMITY**.                       |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
| options  | [Options](#options)                                     | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |
Z
zengyawen 已提交
700

G
Gloria 已提交
701
**Error code**
W
wusongqing 已提交
702

G
Gloria 已提交
703
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
704

G
Gloria 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  sensor.on(sensor.SensorId.PROXIMITY,function(data){
      console.info('Distance: ' + data.distance);
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
W
wusongqing 已提交
720

G
Gloria 已提交
721
### ROTATION_VECTOR<sup>9+</sup>
W
wusongqing 已提交
722

G
Gloria 已提交
723 724 725 726
on(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;,
        options?: Options): void

Subscribes to data of the rotation vector sensor.
W
wusongqing 已提交
727 728 729

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
730
**Parameters**
W
wusongqing 已提交
731

G
Gloria 已提交
732 733 734 735 736 737 738 739 740 741 742 743 744
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ROTATION_VECTOR**.               |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
745

W
wusongqing 已提交
746
**Example**
Z
zengyawen 已提交
747

W
wusongqing 已提交
748
```js
G
Gloria 已提交
749 750 751 752 753 754 755 756 757 758
try {
  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.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
W
wusongqing 已提交
759
```
Z
zengyawen 已提交
760

G
Gloria 已提交
761
### SIGNIFICANT_MOTION<sup>9+</sup>
W
wusongqing 已提交
762

G
Gloria 已提交
763 764
on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;,
        options?: Options): void
W
wusongqing 已提交
765

G
Gloria 已提交
766
Subscribes to data of the significant motion sensor.
W
wusongqing 已提交
767 768 769 770 771

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
772 773 774 775 776 777 778 779 780 781 782 783 784
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **SIGNIFICANT_MOTION**.            |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
785 786 787 788

**Example**

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

G
Gloria 已提交
798
###  WEAR_DETECTION<sup>9+</sup>
W
wusongqing 已提交
799

G
Gloria 已提交
800 801
on(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,
        options?: Options): void
Z
zengyawen 已提交
802

G
Gloria 已提交
803
Subscribes to data of the wear detection sensor.
Z
zengyawen 已提交
804

W
wusongqing 已提交
805 806
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
807
**Parameters**
Z
zengyawen 已提交
808

G
Gloria 已提交
809 810 811 812 813
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **WEAR_DETECTION**.                |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
| options  | [Options](#options)                                          | No  | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.           |
Z
zengyawen 已提交
814

G
Gloria 已提交
815
**Error code**
Z
zengyawen 已提交
816

G
Gloria 已提交
817
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
818

G
Gloria 已提交
819 820 821
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
822

W
wusongqing 已提交
823
**Example**
G
Gloria 已提交
824 825 826 827

```js
try {
  sensor.on(sensor.SensorId.WEAR_DETECTION,function(data){
W
wusongqing 已提交
828
      console.info('Wear status: ' + data.value);
G
Gloria 已提交
829 830 831 832 833
  }, {interval: 10000000} );
} catch(err) {
      console.info('on fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
834

G
Gloria 已提交
835
## sensor.once<sup>9+</sup>
Z
zengyawen 已提交
836

G
Gloria 已提交
837
### ACCELEROMETER<sup>9+</sup>
Z
zengyawen 已提交
838

G
Gloria 已提交
839
once(type: SensorId.ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
Z
zengyawen 已提交
840

G
Gloria 已提交
841
Subscribes to data of the acceleration sensor once.
Z
zengyawen 已提交
842

G
Gloria 已提交
843
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
844 845 846

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
847
**Parameters**
Z
zengyawen 已提交
848

G
Gloria 已提交
849 850 851 852
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ACCELEROMETER**.                           |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
W
wusongqing 已提交
853

G
Gloria 已提交
854
**Error code**
W
wusongqing 已提交
855

G
Gloria 已提交
856
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
857

G
Gloria 已提交
858 859 860
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
861

W
wusongqing 已提交
862
**Example**
G
Gloria 已提交
863 864 865 866

```js
try {
  sensor.once(sensor.SensorId.ACCELEROMETER,function(data){
W
wusongqing 已提交
867 868 869 870 871
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
G
Gloria 已提交
872 873 874 875
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
Z
zengyawen 已提交
876

G
Gloria 已提交
877
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
W
wusongqing 已提交
878

G
Gloria 已提交
879
once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
W
wusongqing 已提交
880

G
Gloria 已提交
881
Subscribes to data of the uncalibrated acceleration sensor once.
W
wusongqing 已提交
882

G
Gloria 已提交
883
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
884 885 886 887 888

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
889 890 891 892
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ACCELEROMETER_UNCALIBRATED**.        |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
Z
zengyawen 已提交
893

G
Gloria 已提交
894
**Error code**
W
wusongqing 已提交
895

G
Gloria 已提交
896
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
897

G
Gloria 已提交
898 899 900
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
901

W
wusongqing 已提交
902
**Example**
G
Gloria 已提交
903 904 905 906

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

G
Gloria 已提交
920
### AMBIENT_LIGHT<sup>9+</sup>
W
wusongqing 已提交
921

G
Gloria 已提交
922
once(type: SensorId.AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void
W
wusongqing 已提交
923

G
Gloria 已提交
924
Subscribes to data of the ambient light sensor once.
W
wusongqing 已提交
925

W
wusongqing 已提交
926 927
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
928
**Parameters**
G
Gloria 已提交
929 930 931 932 933 934 935 936 937 938 939 940 941

| Name  | Type                                           | Mandatory| Description                                                        |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                          | Yes  | Type of the sensor to subscribe to, which is **AMBIENT_LIGHT**.                           |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
942

W
wusongqing 已提交
943
**Example**
W
wusongqing 已提交
944

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

G
Gloria 已提交
956
### AMBIENT_TEMPERATURE<sup>9+</sup>
W
wusongqing 已提交
957

G
Gloria 已提交
958
once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback&lt;AmbientTemperatureResponse&gt;): void
W
wusongqing 已提交
959

G
Gloria 已提交
960
Subscribes to data of the ambient temperature sensor once.
W
wusongqing 已提交
961 962 963

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
964
**Parameters**
G
Gloria 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **AMBIENT_TEMPERATURE**.                   |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
978

W
wusongqing 已提交
979
**Example**
Z
zengyawen 已提交
980

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

G
Gloria 已提交
992
### BAROMETER<sup>9+</sup>
Z
zengyawen 已提交
993

G
Gloria 已提交
994
once(type: SensorId.BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void
Z
zengyawen 已提交
995

G
Gloria 已提交
996
Subscribes to data of the barometer sensor once.
W
wusongqing 已提交
997 998 999

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1000
**Parameters**
W
wusongqing 已提交
1001

G
Gloria 已提交
1002 1003 1004 1005
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **BAROMETER**.                               |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
Z
zengyawen 已提交
1006

G
Gloria 已提交
1007
**Error code**
Z
zengyawen 已提交
1008

G
Gloria 已提交
1009
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
Z
zengyawen 已提交
1010

G
Gloria 已提交
1011 1012 1013
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
Z
zengyawen 已提交
1014

G
Gloria 已提交
1015
**Example**
W
wusongqing 已提交
1016

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

G
Gloria 已提交
1028
### GRAVITY<sup>9+</sup>
Z
zengyawen 已提交
1029

G
Gloria 已提交
1030
once(type: SensorId.GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
1031

G
Gloria 已提交
1032
Subscribes to data of the gravity sensor once.
W
wusongqing 已提交
1033 1034 1035

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1036
**Parameters**
W
wusongqing 已提交
1037

G
Gloria 已提交
1038 1039 1040 1041
| Name  | Type                                               | Mandatory| Description                                                        |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                              | Yes  | Type of the sensor to subscribe to, which is **GRAVITY**.                                   |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
Z
zengyawen 已提交
1042

G
Gloria 已提交
1043
**Error code**
Z
zengyawen 已提交
1044

G
Gloria 已提交
1045
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
Z
zengyawen 已提交
1046

G
Gloria 已提交
1047 1048 1049
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1050

G
Gloria 已提交
1051
**Example**
W
wusongqing 已提交
1052

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

G
Gloria 已提交
1066
### GYROSCOPE<sup>9+</sup>
Z
zengyawen 已提交
1067

G
Gloria 已提交
1068
once(type: SensorId.GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
Z
zengyawen 已提交
1069

G
Gloria 已提交
1070
Subscribes to data of the gyroscope sensor once.
Z
zengyawen 已提交
1071

G
Gloria 已提交
1072
**Required permissions**: ohos.permission.GYROSCOPE
Z
zengyawen 已提交
1073

W
wusongqing 已提交
1074 1075
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1076
**Parameters**
W
wusongqing 已提交
1077

G
Gloria 已提交
1078 1079 1080 1081
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **GYROSCOPE**.                               |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
Z
zengyawen 已提交
1082

G
Gloria 已提交
1083
**Error code**
Z
zengyawen 已提交
1084

G
Gloria 已提交
1085
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
Z
zengyawen 已提交
1086

G
Gloria 已提交
1087 1088 1089
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
Z
zengyawen 已提交
1090

G
Gloria 已提交
1091
**Example**
W
wusongqing 已提交
1092

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

G
Gloria 已提交
1106
### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
1107

G
Gloria 已提交
1108
once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
1109

G
Gloria 已提交
1110
Subscribes to data of the uncalibrated gyroscope sensor once.
Z
zengyawen 已提交
1111

G
Gloria 已提交
1112
**Required permissions**: ohos.permission.GYROSCOPE
Z
zengyawen 已提交
1113

W
wusongqing 已提交
1114 1115
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1116
**Parameters**
W
wusongqing 已提交
1117

G
Gloria 已提交
1118 1119 1120 1121
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **GYROSCOPE_UNCALIBRATED**.            |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
1122

G
Gloria 已提交
1123
**Error code**
W
wusongqing 已提交
1124

G
Gloria 已提交
1125
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1126

G
Gloria 已提交
1127 1128 1129
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1130

W
wusongqing 已提交
1131
**Example**
W
wusongqing 已提交
1132

G
Gloria 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
```js
try {
    sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

### HALL<sup>9+</sup>
W
wusongqing 已提交
1150

G
Gloria 已提交
1151
once(type: SensorId.HALL, callback: Callback&lt;HallResponse&gt;): void
W
wusongqing 已提交
1152

G
Gloria 已提交
1153
Subscribes to data of the Hall effect sensor once.
W
wusongqing 已提交
1154 1155 1156

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1157
**Parameters**
W
wusongqing 已提交
1158

G
Gloria 已提交
1159 1160 1161 1162
| Name  | Type                                         | Mandatory| Description                                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                        | Yes  | Type of the sensor to subscribe to, which is **HALL**.                                      |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
1163

G
Gloria 已提交
1164
**Error code**
W
wusongqing 已提交
1165

G
Gloria 已提交
1166
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1167

G
Gloria 已提交
1168 1169 1170
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1171

G
Gloria 已提交
1172
**Example**
W
wusongqing 已提交
1173

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

G
Gloria 已提交
1185
### HEART_RATE<sup>9+</sup>
W
wusongqing 已提交
1186

G
Gloria 已提交
1187
once(type: SensorId.HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void
W
wusongqing 已提交
1188

G
Gloria 已提交
1189
Subscribes to data of the heart rate sensor once.
W
wusongqing 已提交
1190

G
Gloria 已提交
1191
**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
1192 1193 1194

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1195
**Parameters**
W
wusongqing 已提交
1196

G
Gloria 已提交
1197 1198 1199 1200
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **HEART_RATE**.                                |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1201

G
Gloria 已提交
1202
**Error code**
W
wusongqing 已提交
1203

G
Gloria 已提交
1204
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1205

G
Gloria 已提交
1206 1207 1208
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1209

W
wusongqing 已提交
1210
**Example**
W
wusongqing 已提交
1211

G
Gloria 已提交
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
```js
try {
    sensor.once(sensor.SensorId.HEART_BEAT_RATE, function(data) {
        console.info('Heart rate: ' + data.heartRate);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
W
wusongqing 已提交
1222

G
Gloria 已提交
1223
### HUMIDITY<sup>9+</sup>
W
wusongqing 已提交
1224

G
Gloria 已提交
1225 1226 1227
once(type: SensorId.HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void

Subscribes to data of the humidity sensor once.
W
wusongqing 已提交
1228 1229 1230

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1231
**Parameters**
W
wusongqing 已提交
1232

G
Gloria 已提交
1233 1234 1235 1236
| Name  | Type                                                 | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                | Yes  | Type of the sensor to subscribe to, which is **HUMIDITY**.                                  |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
1237

G
Gloria 已提交
1238
**Error code**
W
wusongqing 已提交
1239

G
Gloria 已提交
1240
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1241

G
Gloria 已提交
1242 1243 1244
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1245

W
wusongqing 已提交
1246
**Example**
W
wusongqing 已提交
1247

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

G
Gloria 已提交
1259
### LINEAR_ACCELERATION<sup>9+</sup>
W
wusongqing 已提交
1260

G
Gloria 已提交
1261
once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback&lt;LinearAccelerometerResponse&gt;): void
W
wusongqing 已提交
1262

G
Gloria 已提交
1263
Subscribes to data of the linear acceleration sensor once.
W
wusongqing 已提交
1264

G
Gloria 已提交
1265
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1266 1267 1268

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1269
**Parameters**
G
Gloria 已提交
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **LINEAR_ACCELEROMETER**.                |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1283

W
wusongqing 已提交
1284
**Example**
W
wusongqing 已提交
1285

G
Gloria 已提交
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
```js
try {
    sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, function(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
W
wusongqing 已提交
1298

G
Gloria 已提交
1299
### MAGNETIC_FIELD<sup>9+</sup>
W
wusongqing 已提交
1300

G
Gloria 已提交
1301
once(type: SensorId.MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
W
wusongqing 已提交
1302

G
Gloria 已提交
1303
Subscribes to data of the magnetic field sensor once.
W
wusongqing 已提交
1304 1305 1306 1307 1308

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
1309 1310 1311 1312
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **MAGNETIC_FIELD**.                            |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
1313

G
Gloria 已提交
1314
**Error code**
W
wusongqing 已提交
1315

G
Gloria 已提交
1316
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1317

G
Gloria 已提交
1318 1319 1320
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1321

W
wusongqing 已提交
1322
**Example**
W
wusongqing 已提交
1323

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

G
Gloria 已提交
1337
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
W
wusongqing 已提交
1338

G
Gloria 已提交
1339
once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
W
wusongqing 已提交
1340

G
Gloria 已提交
1341
Subscribes to data of the uncalibrated magnetic field sensor once.
W
wusongqing 已提交
1342 1343 1344

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1345
**Parameters**
W
wusongqing 已提交
1346

G
Gloria 已提交
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **MAGNETIC_FIELD_UNCALIBRATED**.         |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1359

W
wusongqing 已提交
1360
**Example**
W
wusongqing 已提交
1361

W
wusongqing 已提交
1362
```js
G
Gloria 已提交
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
try {
    sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1375 1376 1377
}
```

G
Gloria 已提交
1378
### ORIENTATION<sup>9+</sup>
W
wusongqing 已提交
1379

G
Gloria 已提交
1380
once(type: SensorId.ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void
W
wusongqing 已提交
1381

G
Gloria 已提交
1382
Subscribes to data of the orientation sensor once.
W
wusongqing 已提交
1383 1384 1385

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1386
**Parameters**
W
wusongqing 已提交
1387

G
Gloria 已提交
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
| Name  | Type                                                       | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                      | Yes  | Type of the sensor to subscribe to, which is **ORIENTATION**.                               |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1400

W
wusongqing 已提交
1401
**Example**
W
wusongqing 已提交
1402

W
wusongqing 已提交
1403
```js
G
Gloria 已提交
1404 1405 1406 1407 1408 1409 1410 1411 1412
try {
   sensor.once(sensor.SensorId.ORIENTATION, function(data) {
       console.info('The device rotates at an angle around the X axis: ' + data.beta);
       console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
       console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
     }
   );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1413 1414 1415
}
```

G
Gloria 已提交
1416
### PEDOMETER<sup>9+</sup>
W
wusongqing 已提交
1417

G
Gloria 已提交
1418
once(type: SensorId.PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
W
wusongqing 已提交
1419

G
Gloria 已提交
1420 1421 1422
Subscribes to data of the pedometer sensor once.

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1423 1424 1425

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1426
**Parameters**
W
wusongqing 已提交
1427

G
Gloria 已提交
1428 1429 1430 1431
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **PEDOMETER**.                                 |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
1432

G
Gloria 已提交
1433
**Error code**
W
wusongqing 已提交
1434

G
Gloria 已提交
1435
For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
1436

G
Gloria 已提交
1437 1438 1439
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1440

W
wusongqing 已提交
1441
**Example**
W
wusongqing 已提交
1442

W
wusongqing 已提交
1443
```js
G
Gloria 已提交
1444 1445 1446 1447 1448 1449 1450
try {
    sensor.once(sensor.SensorId.PEDOMETER, function(data) {
        console.info('Steps: ' + data.steps);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1451 1452 1453
}
```

G
Gloria 已提交
1454
### PEDOMETER_DETECTION<sup>9+</sup>
W
wusongqing 已提交
1455

G
Gloria 已提交
1456
once(type: SensorId.PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;): void
W
wusongqing 已提交
1457

G
Gloria 已提交
1458 1459 1460
Subscribe to data of the pedometer detection sensor once.

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1461 1462 1463

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1464
**Parameters**
W
wusongqing 已提交
1465

G
Gloria 已提交
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **PEDOMETER_DETECTION**.                   |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1478

W
wusongqing 已提交
1479
**Example**
W
wusongqing 已提交
1480

W
wusongqing 已提交
1481
```js
G
Gloria 已提交
1482 1483 1484 1485 1486 1487 1488
try {
    sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function(data) {
        console.info('Scalar data: ' + data.scalar);
      }
    );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1489 1490 1491
}
```

G
Gloria 已提交
1492
### PROXIMITY<sup>9+</sup>
W
wusongqing 已提交
1493

G
Gloria 已提交
1494
once(type: SensorId.PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void
W
wusongqing 已提交
1495

G
Gloria 已提交
1496
Subscribes to data of the proximity sensor once.
W
wusongqing 已提交
1497 1498 1499

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1500
**Parameters**
W
wusongqing 已提交
1501

G
Gloria 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to subscribe to, which is **PROXIMITY**.                               |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1514

W
wusongqing 已提交
1515
**Example**
W
wusongqing 已提交
1516

W
wusongqing 已提交
1517
```js
G
Gloria 已提交
1518 1519 1520 1521 1522 1523 1524
try {
   sensor.once(sensor.SensorId.PROXIMITY, function(data) {
       console.info('Distance: ' + data.distance);
     }
   );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1525 1526 1527
}
```

G
Gloria 已提交
1528
### ROTATION_VECTOR<sup>9+</sup>
W
wusongqing 已提交
1529

G
Gloria 已提交
1530
once(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void
W
wusongqing 已提交
1531

G
Gloria 已提交
1532
Subscribes to data of the rotation vector sensor once.
W
wusongqing 已提交
1533 1534 1535

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1536
**Parameters**
W
wusongqing 已提交
1537

G
Gloria 已提交
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **ROTATION_VECTOR**.                       |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1550

W
wusongqing 已提交
1551
**Example**
W
wusongqing 已提交
1552

W
wusongqing 已提交
1553
```js
G
Gloria 已提交
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
try {
   sensor.once(sensor.SensorId.ROTATION_VECTOR, function(data) {
       console.info('X-coordinate component: ' + data.x);
       console.info('Y-coordinate component: ' + data.y);
       console.info('Z-coordinate component: ' + data.z);
       console.info('Scalar quantity: ' + data.w);
     }
   );
} catch(err) {
      console.info('once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1564 1565 1566
}
```

G
Gloria 已提交
1567
### SIGNIFICANT_MOTION<sup>9+</sup>
W
wusongqing 已提交
1568

G
Gloria 已提交
1569
once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;): void
W
wusongqing 已提交
1570

G
Gloria 已提交
1571
Subscribes to data of the significant motion sensor once.
W
wusongqing 已提交
1572 1573 1574

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1575
**Parameters**
W
wusongqing 已提交
1576

G
Gloria 已提交
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **SIGNIFICANT_MOTION**.                    |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1589

W
wusongqing 已提交
1590
**Example**
W
wusongqing 已提交
1591

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

G
Gloria 已提交
1603
### WEAR_DETECTION<sup>9+</sup>
W
wusongqing 已提交
1604

G
Gloria 已提交
1605
once(type: SensorId.WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void
W
wusongqing 已提交
1606

G
Gloria 已提交
1607
Subscribes to data of the wear detection sensor once.
W
wusongqing 已提交
1608 1609 1610

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1611
**Parameters**
W
wusongqing 已提交
1612

G
Gloria 已提交
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to subscribe to, which is **WEAR_DETECTION**.                        |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|

**Error code**

For details about the following error codes, see [Error Codes of ohos.sensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1625

W
wusongqing 已提交
1626
**Example**
W
wusongqing 已提交
1627

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

G
Gloria 已提交
1639
## sensor.off<sup>9+</sup>
W
wusongqing 已提交
1640

G
Gloria 已提交
1641
### ACCELEROMETER<sup>9+</sup> 
W
wusongqing 已提交
1642

G
Gloria 已提交
1643
off(type: SensorId.ACCELEROMETER, callback?: Callback&lt;AccelerometerResponse&gt;): void
W
wusongqing 已提交
1644

G
Gloria 已提交
1645
Unsubscribes from data of the acceleration sensor.
W
wusongqing 已提交
1646

G
Gloria 已提交
1647
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1648 1649 1650

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1651
**Parameters**
W
wusongqing 已提交
1652

G
Gloria 已提交
1653 1654 1655 1656
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **ACCELEROMETER**.               |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
W
wusongqing 已提交
1657

W
wusongqing 已提交
1658
**Example**
W
wusongqing 已提交
1659

W
wusongqing 已提交
1660
```js
G
Gloria 已提交
1661 1662 1663 1664 1665 1666 1667 1668 1669
try {
    function callback(data) {
        console.info('x-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off(sensor.SensorId.ACCELEROMETER, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1670 1671 1672
}
```

G
Gloria 已提交
1673
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>  
W
wusongqing 已提交
1674

G
Gloria 已提交
1675
off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
W
wusongqing 已提交
1676

G
Gloria 已提交
1677
Unsubscribes from data of the uncalibrated acceleration sensor.
W
wusongqing 已提交
1678

G
Gloria 已提交
1679
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1680 1681 1682 1683 1684

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
1685 1686 1687 1688
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
W
wusongqing 已提交
1689 1690 1691 1692

**Example**

```js
G
Gloria 已提交
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
    }
    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1705 1706 1707
}
```

G
Gloria 已提交
1708
### AMBIENT_LIGHT<sup>9+</sup> 
W
wusongqing 已提交
1709

G
Gloria 已提交
1710
off(type: SensorId.AMBIENT_LIGHT, callback?: Callback&lt;LightResponse&gt;): void
W
wusongqing 已提交
1711

G
Gloria 已提交
1712
Unsubscribes from data of the ambient light sensor.
W
wusongqing 已提交
1713 1714 1715

**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
1716
**Parameters**
W
wusongqing 已提交
1717

G
Gloria 已提交
1718 1719 1720 1721
| Name  | Type                                           | Mandatory| Description                                                        |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                          | Yes  | Type of the sensor to unsubscribe from, which is **AMBIENT_LIGHT**.               |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
W
wusongqing 已提交
1722

W
wusongqing 已提交
1723
**Example**
W
wusongqing 已提交
1724

W
wusongqing 已提交
1725
```js
G
Gloria 已提交
1726 1727 1728 1729 1730 1731 1732
try {
    function callback(data) {
        console.info('Illumination: ' + data.intensity);
    }
    sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1733 1734 1735
}
```

G
Gloria 已提交
1736
### AMBIENT_TEMPERATURE<sup>9+</sup> 
Z
zengyawen 已提交
1737

G
Gloria 已提交
1738
off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback&lt;AmbientTemperatureResponse&gt;): void
W
wusongqing 已提交
1739

G
Gloria 已提交
1740
Unsubscribes from data of the ambient temperature sensor.
W
wusongqing 已提交
1741 1742

**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1743

W
wusongqing 已提交
1744
**Parameters**
W
wusongqing 已提交
1745

G
Gloria 已提交
1746 1747 1748 1749
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **AMBIENT_TEMPERATURE**.       |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
W
wusongqing 已提交
1750

W
wusongqing 已提交
1751
**Example**
Z
zengyawen 已提交
1752

W
wusongqing 已提交
1753
```js
G
Gloria 已提交
1754 1755 1756 1757 1758 1759 1760
try {
    function callback(data) {
        console.info('Temperature: ' + data.temperature);
    }
    sensor.off( sensor.SensorId.AMBIENT_TEMPERATURE, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1761 1762
}
```
Z
zengyawen 已提交
1763

G
Gloria 已提交
1764
### BAROMETER<sup>9+</sup>  
W
wusongqing 已提交
1765

G
Gloria 已提交
1766
off(type: SensorId.BAROMETER, callback?: Callback&lt;BarometerResponse&gt;): void
W
wusongqing 已提交
1767

G
Gloria 已提交
1768
Unsubscribes from data of the barometer sensor.
W
wusongqing 已提交
1769 1770 1771 1772 1773

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
1774 1775 1776 1777
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to unsubscribe from, which is **BAROMETER**.                   |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
W
wusongqing 已提交
1778 1779 1780 1781

**Example**

```js
G
Gloria 已提交
1782 1783 1784 1785 1786 1787 1788
try {
    function callback(data) {
        console.info('Atmospheric pressure: ' + data.pressure);
    }
    sensor.off(sensor.SensorId.BAROMETER, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1789 1790 1791
}
```

G
Gloria 已提交
1792
### GRAVITY<sup>9+</sup> 
Z
zengyawen 已提交
1793

G
Gloria 已提交
1794
off(type: SensorId.GRAVITY, callback?: Callback&lt;GravityResponse&gt;): void
Z
zengyawen 已提交
1795

G
Gloria 已提交
1796
Unsubscribes from data of the gravity sensor.
W
wusongqing 已提交
1797 1798

**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1799

W
wusongqing 已提交
1800
**Parameters**
W
wusongqing 已提交
1801

G
Gloria 已提交
1802 1803 1804 1805
| Name  | Type                                               | Mandatory| Description                                                        |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                              | Yes  | Type of the sensor to unsubscribe from, which is **GRAVITY**.                       |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
W
wusongqing 已提交
1806

W
wusongqing 已提交
1807
**Example**
W
wusongqing 已提交
1808

W
wusongqing 已提交
1809
```js
G
Gloria 已提交
1810 1811 1812 1813 1814 1815 1816 1817 1818
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off( sensor.SensorId.GRAVITY, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1819 1820
}
```
W
wusongqing 已提交
1821

G
Gloria 已提交
1822
### GYROSCOPE<sup>9+</sup> 
W
wusongqing 已提交
1823

G
Gloria 已提交
1824
off(type: SensorId.GYROSCOPE, callback?: Callback&lt;GyroscopeResponse&gt;): void
W
wusongqing 已提交
1825

G
Gloria 已提交
1826 1827 1828
Unsubscribes from data of the gyroscope sensor.

**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
1829 1830

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
1831

W
wusongqing 已提交
1832
**Parameters**
W
wusongqing 已提交
1833

G
Gloria 已提交
1834 1835 1836 1837
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to unsubscribe from, which is **GYROSCOPE**.                   |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
W
wusongqing 已提交
1838

W
wusongqing 已提交
1839
**Example**
Z
zengyawen 已提交
1840

W
wusongqing 已提交
1841
```js
G
Gloria 已提交
1842 1843 1844 1845 1846 1847 1848 1849 1850
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off(sensor.SensorId.GYROSCOPE, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1851 1852 1853
}
```

G
Gloria 已提交
1854
### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 
Z
zengyawen 已提交
1855

G
Gloria 已提交
1856
off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
1857

G
Gloria 已提交
1858 1859 1860
 Unsubscribes from data of the uncalibrated gyroscope sensor.

**Required permissions**: ohos.permission.GYROSCOPE
Z
zengyawen 已提交
1861

W
wusongqing 已提交
1862
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1863

W
wusongqing 已提交
1864
**Parameters**
W
wusongqing 已提交
1865

G
Gloria 已提交
1866 1867 1868 1869
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **GYROSCOPE_UNCALIBRATED**.|
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
1870

W
wusongqing 已提交
1871
**Example**
Z
zengyawen 已提交
1872

W
wusongqing 已提交
1873
```js
G
Gloria 已提交
1874 1875 1876 1877 1878 1879 1880 1881 1882
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1883 1884
}
```
Z
zengyawen 已提交
1885

G
Gloria 已提交
1886
### HALL<sup>9+</sup> 
Z
zengyawen 已提交
1887

G
Gloria 已提交
1888
off(type: SensorId.HALL, callback?: Callback&lt;HallResponse&gt;): void
W
wusongqing 已提交
1889

G
Gloria 已提交
1890
Unsubscribes from data of the Hall effect sensor.
W
wusongqing 已提交
1891

W
wusongqing 已提交
1892
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1893

W
wusongqing 已提交
1894
**Parameters**
W
wusongqing 已提交
1895

G
Gloria 已提交
1896 1897 1898 1899
| Name  | Type                                         | Mandatory| Description                                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                        | Yes  | Type of the sensor to unsubscribe from, which is **HALL**.                          |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
1900

W
wusongqing 已提交
1901
**Example**
W
wusongqing 已提交
1902

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

G
Gloria 已提交
1914
### HEART_RATE<sup>9+</sup> 
W
wusongqing 已提交
1915

G
Gloria 已提交
1916
off(type: SensorId.HEART_RATE, callback?: Callback&lt;HeartRateResponse&gt;): void
W
wusongqing 已提交
1917

G
Gloria 已提交
1918
Unsubscribes from data of the heart rate sensor.
W
wusongqing 已提交
1919

G
Gloria 已提交
1920
**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
1921

W
wusongqing 已提交
1922
**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
1923

W
wusongqing 已提交
1924
**Parameters**
W
wusongqing 已提交
1925

G
Gloria 已提交
1926 1927 1928 1929
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to unsubscribe from, which is **HEART_RATE**.                    |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1930

W
wusongqing 已提交
1931
**Example**
Z
zengyawen 已提交
1932

W
wusongqing 已提交
1933
```js
G
Gloria 已提交
1934 1935 1936 1937 1938 1939 1940
try {
    function callback(data) {
        console.info("Heart rate: " + data.heartRate);
    }
    sensor.off(sensor.SensorId.HEART_RATE, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1941 1942 1943
}
```

G
Gloria 已提交
1944
### HUMIDITY<sup>9+</sup> 
Z
zengyawen 已提交
1945

G
Gloria 已提交
1946
off(type: SensorId.HUMIDITY, callback?: Callback&lt;HumidityResponse&gt;): void
Z
zengyawen 已提交
1947

G
Gloria 已提交
1948
Unsubscribes from data of the humidity sensor.
Z
zengyawen 已提交
1949

W
wusongqing 已提交
1950
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1951

W
wusongqing 已提交
1952
**Parameters**
W
wusongqing 已提交
1953

G
Gloria 已提交
1954 1955 1956 1957
| Name  | Type                                                 | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                | Yes  | Type of the sensor to unsubscribe from, which is **HUMIDITY**.                      |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
1958

W
wusongqing 已提交
1959
**Example**
Z
zengyawen 已提交
1960

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

G
Gloria 已提交
1972
### LINEAR_ACCELEROMETER<sup>9+</sup> 
Z
zengyawen 已提交
1973

G
Gloria 已提交
1974
off(type: SensorId.LINEAR_ACCELEROMETER, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
1975

G
Gloria 已提交
1976 1977 1978
Unsubscribes from data of the linear acceleration sensor.

**Required permissions**: ohos.permission.ACCELEROMETER
Z
zengyawen 已提交
1979

W
wusongqing 已提交
1980
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1981

W
wusongqing 已提交
1982
**Parameters**
W
wusongqing 已提交
1983

G
Gloria 已提交
1984 1985 1986 1987
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **LINEAR_ACCELERATION**.     |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
W
wusongqing 已提交
1988

W
wusongqing 已提交
1989
**Example**
Z
zengyawen 已提交
1990

W
wusongqing 已提交
1991
```js
G
Gloria 已提交
1992 1993 1994 1995 1996 1997 1998 1999 2000
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2001 2002
}
```
Z
zengyawen 已提交
2003

G
Gloria 已提交
2004
### MAGNETIC_FIELD<sup>9+</sup> 
Z
zengyawen 已提交
2005

G
Gloria 已提交
2006
off(type: SensorId.MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
Z
zengyawen 已提交
2007

G
Gloria 已提交
2008
Unsubscribes from data of the magnetic field sensor.
W
wusongqing 已提交
2009 2010

**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2011

W
wusongqing 已提交
2012
**Parameters**
W
wusongqing 已提交
2013

G
Gloria 已提交
2014 2015 2016 2017
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **MAGNETIC_FIELD**.                |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
2018

W
wusongqing 已提交
2019
**Example**
Z
zengyawen 已提交
2020

W
wusongqing 已提交
2021
```js
G
Gloria 已提交
2022 2023 2024 2025 2026 2027 2028 2029 2030
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }
    sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2031 2032
}
```
Z
zengyawen 已提交
2033

G
Gloria 已提交
2034
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 
Z
zengyawen 已提交
2035

G
Gloria 已提交
2036
off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
2037

G
Gloria 已提交
2038
Unsubscribes from data of the uncalibrated magnetic field sensor.
Z
zengyawen 已提交
2039

W
wusongqing 已提交
2040 2041
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
2042
**Parameters**
W
wusongqing 已提交
2043

G
Gloria 已提交
2044 2045 2046 2047
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
W
wusongqing 已提交
2048

W
wusongqing 已提交
2049
**Example**
W
wusongqing 已提交
2050

W
wusongqing 已提交
2051
```js
G
Gloria 已提交
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
    }
    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2064 2065
}
```
W
wusongqing 已提交
2066

G
Gloria 已提交
2067
### ORIENTATION<sup>9+</sup> 
W
wusongqing 已提交
2068

G
Gloria 已提交
2069
off(type: SensorId.ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
W
wusongqing 已提交
2070

G
Gloria 已提交
2071
Unsubscribes from data of the orientation sensor.
W
wusongqing 已提交
2072 2073

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2074

W
wusongqing 已提交
2075
**Parameters**
W
wusongqing 已提交
2076

G
Gloria 已提交
2077 2078 2079 2080
| Name  | Type                                                       | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                      | Yes  | Type of the sensor to unsubscribe from, which is **ORIENTATION**.                   |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
W
wusongqing 已提交
2081

W
wusongqing 已提交
2082
**Example**
W
wusongqing 已提交
2083

W
wusongqing 已提交
2084
```js
G
Gloria 已提交
2085 2086 2087 2088 2089
try {
    function callback(data) {
        console.info('The device rotates at an angle around the X axis: ' + data.beta);
        console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
        console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
W
wusongqing 已提交
2090
    }
G
Gloria 已提交
2091 2092 2093 2094
    sensor.off(sensor.SensorId.ORIENTATION, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
W
wusongqing 已提交
2095
```
W
wusongqing 已提交
2096

G
Gloria 已提交
2097
### PEDOMETER<sup>9+</sup>
W
wusongqing 已提交
2098

G
Gloria 已提交
2099
off(type: SensorId.PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
W
wusongqing 已提交
2100

G
Gloria 已提交
2101
Unsubscribes from data of the pedometer sensor.
W
wusongqing 已提交
2102

G
Gloria 已提交
2103
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
2104

G
Gloria 已提交
2105
**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2106

G
Gloria 已提交
2107
**Parameters**
W
wusongqing 已提交
2108

G
Gloria 已提交
2109 2110 2111 2112
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to unsubscribe from, which is **PEDOMETER**.                     |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
2113

W
wusongqing 已提交
2114
**Example**
W
wusongqing 已提交
2115

W
wusongqing 已提交
2116
```js
G
Gloria 已提交
2117 2118 2119 2120 2121 2122 2123 2124
try {
    function callback(data) {
        console.info('Steps: ' + data.steps);
    }
    sensor.off(sensor.SensorId.PEDOMETER, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
W
wusongqing 已提交
2125
```
W
wusongqing 已提交
2126

G
Gloria 已提交
2127
### PEDOMETER_DETECTION<sup>9+</sup> 
W
wusongqing 已提交
2128

G
Gloria 已提交
2129
off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
W
wusongqing 已提交
2130

G
Gloria 已提交
2131 2132 2133
Unsubscribes from data of the pedometer detection sensor.

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
2134 2135

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2136

W
wusongqing 已提交
2137
**Parameters**
G
Gloria 已提交
2138 2139 2140 2141 2142

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **PEDOMETER_DETECTION**.       |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
W
wusongqing 已提交
2143

W
wusongqing 已提交
2144
**Example**
G
Gloria 已提交
2145

W
wusongqing 已提交
2146
```js
G
Gloria 已提交
2147 2148 2149
try {
    function callback(data) {
        console.info('Scalar data: ' + data.scalar);
W
wusongqing 已提交
2150
    }
G
Gloria 已提交
2151 2152 2153 2154
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
W
wusongqing 已提交
2155
```
W
wusongqing 已提交
2156

G
Gloria 已提交
2157
### PROXIMITY<sup>9+</sup>  
W
wusongqing 已提交
2158

G
Gloria 已提交
2159 2160 2161
off(type: SensorId.PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void

Unsubscribes from data of the proximity sensor.
W
wusongqing 已提交
2162 2163

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2164

W
wusongqing 已提交
2165
**Parameters**
Z
zengyawen 已提交
2166

G
Gloria 已提交
2167 2168 2169 2170
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                  | Yes  | Type of the sensor to unsubscribe from, which is **PROXIMITY**.                   |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
Z
zengyawen 已提交
2171

W
wusongqing 已提交
2172
**Example**
W
wusongqing 已提交
2173

G
Gloria 已提交
2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185
```js
try {
    function callback(data) {
        console.info('Distance: ' + data.distance);
    }
    sensor.off(sensor.SensorId.PROXIMITY, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

### ROTATION_VECTOR<sup>9+</sup> 
W
wusongqing 已提交
2186

G
Gloria 已提交
2187
off(type: SensorId.ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
W
wusongqing 已提交
2188

G
Gloria 已提交
2189
Unsubscribes from data of the rotation vector sensor.
W
wusongqing 已提交
2190 2191

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2192

W
wusongqing 已提交
2193
**Parameters**
W
wusongqing 已提交
2194

G
Gloria 已提交
2195 2196 2197 2198
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **ROTATION_VECTOR**.           |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
W
wusongqing 已提交
2199

W
wusongqing 已提交
2200
**Example**
W
wusongqing 已提交
2201

G
Gloria 已提交
2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
```js
try {
    function callback(data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('Scalar quantity: ' + data.w);
    }
    sensor.off(sensor.SensorId.ROTATION_VECTOR, callback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```
W
wusongqing 已提交
2215

G
Gloria 已提交
2216
### SIGNIFICANT_MOTION<sup>9+</sup> 
W
wusongqing 已提交
2217

G
Gloria 已提交
2218
off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
W
wusongqing 已提交
2219

G
Gloria 已提交
2220
Unsubscribes from data of the significant motion sensor.
W
wusongqing 已提交
2221 2222

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2223

W
wusongqing 已提交
2224
**Parameters**
W
wusongqing 已提交
2225

G
Gloria 已提交
2226 2227 2228 2229
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **SIGNIFICANT_MOTION**.        |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
W
wusongqing 已提交
2230

G
Gloria 已提交
2231
**Example**
W
wusongqing 已提交
2232

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

G
Gloria 已提交
2244
### WEAR_DETECTION<sup>9+</sup> 
W
wusongqing 已提交
2245

G
Gloria 已提交
2246
off(type: SensorId.WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
W
wusongqing 已提交
2247

G
Gloria 已提交
2248
Unsubscribes from data of the wear detection sensor.
W
wusongqing 已提交
2249

G
Gloria 已提交
2250
**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2251

G
Gloria 已提交
2252
**Parameters**
W
wusongqing 已提交
2253

G
Gloria 已提交
2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | [SensorId](#sensorid9)                                       | Yes  | Type of the sensor to unsubscribe from, which is **WEAR_DETECTION**.            |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|

**Example**

```js
try {
    function accCallback(data) {
        console.info('Wear status: ' + data.value);
    }
    sensor.off(sensor.SensorId.WEAR_DETECTION, accCallback);
} catch(err) {
      console.info('off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
}
```

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

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

Obtains the geomagnetic field of a geographic location. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2277 2278

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2279

W
wusongqing 已提交
2280
**Parameters**
W
wusongqing 已提交
2281

G
Gloria 已提交
2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
| Name         | Type                                                        | Mandatory| Description                              |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions)                          | Yes  | Geographic location.                        |
| timeMillis      | number                                                       | Yes  | Time for obtaining the magnetic declination, in milliseconds.|
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes  | Callback used to return the geomagnetic field.                    |

**Error code**

For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2295

W
wusongqing 已提交
2296
**Example**
W
wusongqing 已提交
2297

G
Gloria 已提交
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
```js
try {
    sensor.getGeomagneticInfo({latitude:80, longitude:0, altitude:0}, 1580486400000, function(data)  {
    console.info('sensor_getGeomagneticInfo_callback x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
    });
} catch (err) {
        console.error('getGeomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2309

G
Gloria 已提交
2310
## sensor.getGeomagneticInfo<sup>9+</sup> 
W
wusongqing 已提交
2311

G
Gloria 已提交
2312
getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promise&lt;GeomagneticResponse&gt;
W
wusongqing 已提交
2313

G
Gloria 已提交
2314
Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.
W
wusongqing 已提交
2315 2316

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2317

W
wusongqing 已提交
2318
**Parameters**
W
wusongqing 已提交
2319

G
Gloria 已提交
2320 2321 2322 2323
| Name         | Type                               | Mandatory| Description                              |
| --------------- | ----------------------------------- | ---- | ---------------------------------- |
| locationOptions | [LocationOptions](#locationoptions) | Yes  | Geographic location.                        |
| timeMillis      | number                              | Yes  | Time for obtaining the magnetic declination, in milliseconds.|
W
wusongqing 已提交
2324

W
wusongqing 已提交
2325
**Return value**
W
wusongqing 已提交
2326

G
Gloria 已提交
2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
| Type                                                      | Description          |
| ---------------------------------------------------------- | -------------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2338

W
wusongqing 已提交
2339
**Example**
W
wusongqing 已提交
2340

G
Gloria 已提交
2341 2342 2343
```js
try {
      const promise = sensor.getGeomagneticInfo({latitude:80, longitude:0, altitude:0}, 1580486400000);
W
wusongqing 已提交
2344
      promise.then((data) => {
G
Gloria 已提交
2345 2346 2347 2348 2349
          console.info('sensor_getGeomagneticInfo_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
      }).catch((reason) => {
          console.info('Operation failed.');
W
wusongqing 已提交
2350
  })
G
Gloria 已提交
2351 2352 2353 2354
} catch (err) {
        console.error('getGeomagneticInfo failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2355

G
Gloria 已提交
2356
## sensor.getDeviceAltitude<sup>9+</sup> 
W
wusongqing 已提交
2357

G
Gloria 已提交
2358
getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback&lt;number&gt;): void
W
wusongqing 已提交
2359

G
Gloria 已提交
2360
Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2361 2362

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2363

W
wusongqing 已提交
2364
**Parameters**
W
wusongqing 已提交
2365

G
Gloria 已提交
2366 2367 2368 2369 2370
| Name         | Type                       | Mandatory| Description                                 |
| --------------- | --------------------------- | ---- | ------------------------------------- |
| seaPressure     | number                      | Yes  | Sea-level atmospheric pressure, in hPa.        |
| currentPressure | number                      | Yes  | Atmospheric pressure at the altitude where the device is located, in hPa.|
| callback        | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the altitude, in meters.   |
W
wusongqing 已提交
2371

G
Gloria 已提交
2372
**Error code**
W
wusongqing 已提交
2373

G
Gloria 已提交
2374
For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md).
W
wusongqing 已提交
2375

G
Gloria 已提交
2376 2377 2378
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2379

G
Gloria 已提交
2380
**Example**
W
wusongqing 已提交
2381

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

G
Gloria 已提交
2392 2393 2394 2395 2396
## sensor.getDeviceAltitude<sup>9+</sup> 

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

Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a promise to return the result.
W
wusongqing 已提交
2397 2398

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2399

W
wusongqing 已提交
2400
**Parameters**
W
wusongqing 已提交
2401

G
Gloria 已提交
2402 2403 2404 2405
| Name         | Type  | Mandatory| Description                                 |
| --------------- | ------ | ---- | ------------------------------------- |
| seaPressure     | number | Yes  | Sea-level atmospheric pressure, in hPa.        |
| currentPressure | number | Yes  | Atmospheric pressure at the altitude where the device is located, in hPa.|
W
wusongqing 已提交
2406

W
wusongqing 已提交
2407
**Return value**
W
wusongqing 已提交
2408

G
Gloria 已提交
2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419
| Type                 | Description                                |
| --------------------- | ------------------------------------ |
| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2420

W
wusongqing 已提交
2421
**Example**
W
wusongqing 已提交
2422

G
Gloria 已提交
2423 2424 2425
```js
try {
  const promise = sensor.getDeviceAltitude (0, 200);
W
wusongqing 已提交
2426
      promise.then((data) => {
G
Gloria 已提交
2427 2428 2429
          console.info('sensor_getDeviceAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
W
wusongqing 已提交
2430
  })
G
Gloria 已提交
2431 2432 2433 2434
} catch (err) {
        console.error('getDeviceAltitude failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2435

G
Gloria 已提交
2436
## sensor.getInclination<sup>9+</sup> 
W
wusongqing 已提交
2437

G
Gloria 已提交
2438
getInclination(inclinationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;number&gt;): void
W
wusongqing 已提交
2439

G
Gloria 已提交
2440
Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2441 2442

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2443

W
wusongqing 已提交
2444
**Parameters**
W
wusongqing 已提交
2445

G
Gloria 已提交
2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457
| Name           | Type                       | Mandatory| Description                        |
| ----------------- | --------------------------- | ---- | ---------------------------- |
| inclinationMatrix | Array&lt;number&gt;         | Yes  | Inclination matrix.              |
| callback          | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the magnetic dip, in radians.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2458

W
wusongqing 已提交
2459
**Example**
W
wusongqing 已提交
2460

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

G
Gloria 已提交
2471
## sensor.getInclination<sup>9+</sup> 
W
wusongqing 已提交
2472

G
Gloria 已提交
2473
 getInclination(inclinationMatrix: Array&lt;number&gt;): Promise&lt;number&gt;
W
wusongqing 已提交
2474

G
Gloria 已提交
2475
 Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.
W
wusongqing 已提交
2476 2477

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2478

W
wusongqing 已提交
2479
**Parameters**
W
wusongqing 已提交
2480

G
Gloria 已提交
2481 2482 2483
| Name           | Type               | Mandatory| Description          |
| ----------------- | ------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt; | Yes  | Inclination matrix.|
W
wusongqing 已提交
2484

W
wusongqing 已提交
2485
**Return value**
W
wusongqing 已提交
2486

G
Gloria 已提交
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497
| Type                 | Description                        |
| --------------------- | ---------------------------- |
| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2498

W
wusongqing 已提交
2499
**Example**
W
wusongqing 已提交
2500

G
Gloria 已提交
2501 2502 2503
```js
try {
  const promise = sensor.getInclination ([1, 0, 0, 0, 1, 0, 0, 0, 1]);
W
wusongqing 已提交
2504
      promise.then((data) => {
G
Gloria 已提交
2505 2506 2507 2508 2509 2510 2511 2512
          console.info('getInclination_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
} catch (err) {
        console.error('getInclination failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2513

G
Gloria 已提交
2514
## sensor.getAngleVariation<sup>9+</sup>
W
wusongqing 已提交
2515

G
Gloria 已提交
2516 2517
 getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;,
        callback: AsyncCallback<Array&lt;number&gt;>): void
W
wusongqing 已提交
2518

G
Gloria 已提交
2519
Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2520 2521

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2522

W
wusongqing 已提交
2523
**Parameters**
W
wusongqing 已提交
2524

G
Gloria 已提交
2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537
| Name               | Type                                    | Mandatory| Description                             |
| --------------------- | ---------------------------------------- | ---- | --------------------------------- |
| currentRotationMatrix | Array&lt;number&gt;                      | Yes  | Current rotation matrix.               |
| preRotationMatrix     | Array&lt;number&gt;                      | Yes  | The other rotation matrix.                   |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the angle change around the z, x, and y axes.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2538

W
wusongqing 已提交
2539
**Example**
W
wusongqing 已提交
2540

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

G
Gloria 已提交
2553
## sensor.getAngleVariation<sup>9+</sup>
W
wusongqing 已提交
2554

G
Gloria 已提交
2555
getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise<Array&lt;number&gt;> 
W
wusongqing 已提交
2556

G
Gloria 已提交
2557
Obtains the angle change between two rotation matrices. This API uses a promise to return the result.
W
wusongqing 已提交
2558 2559

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2560

W
wusongqing 已提交
2561
**Parameters**
W
wusongqing 已提交
2562

G
Gloria 已提交
2563 2564 2565 2566
| Name               | Type               | Mandatory| Description              |
| --------------------- | ------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt; | Yes  | Current rotation matrix.|
| preRotationMatrix     | Array&lt;number&gt; | Yes  | The other rotation matrix. |
W
wusongqing 已提交
2567

W
wusongqing 已提交
2568
**Return value**
W
wusongqing 已提交
2569

G
Gloria 已提交
2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580
| Type                              | Description                             |
| ---------------------------------- | --------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2581

W
wusongqing 已提交
2582
**Example**
W
wusongqing 已提交
2583

G
Gloria 已提交
2584 2585 2586
```js
try {
  const promise = sensor.getAngleVariation([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
W
wusongqing 已提交
2587 2588
      promise.then((data) => {
          for (var i=0; i < data.length; i++) {
G
Gloria 已提交
2589
              console.info('data[' + i + ']: ' + data[i]);
W
wusongqing 已提交
2590
          }
G
Gloria 已提交
2591 2592
      }).catch((reason) => {
          console.info('promise::catch ', reason);
W
wusongqing 已提交
2593
  })
G
Gloria 已提交
2594 2595 2596 2597
} catch (err) {
        console.error('getAngleVariation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2598

G
Gloria 已提交
2599
## sensor.getRotationMatrix<sup>9+</sup> 
W
wusongqing 已提交
2600

G
Gloria 已提交
2601
getRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback<Array&lt;number&gt;>): void
W
wusongqing 已提交
2602

G
Gloria 已提交
2603
Obtains the rotation matrix from a rotation vector. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2604 2605

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2606

W
wusongqing 已提交
2607
**Parameters**
W
wusongqing 已提交
2608

G
Gloria 已提交
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620
| Name        | Type                                    | Mandatory| Description          |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector.|
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation matrix.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2621

W
wusongqing 已提交
2622
**Example**
W
wusongqing 已提交
2623

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

G
Gloria 已提交
2636
## sensor.getRotationMatrix<sup>9+</sup>
W
wusongqing 已提交
2637

G
Gloria 已提交
2638
getRotationMatrix(rotationVector: Array&lt;number&gt;): Promise<Array<number&gt;> 
W
wusongqing 已提交
2639

G
Gloria 已提交
2640
Obtains the rotation matrix from a rotation vector. This API uses a promise to return the result.
W
wusongqing 已提交
2641 2642

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2643

W
wusongqing 已提交
2644
**Parameters**
W
wusongqing 已提交
2645

G
Gloria 已提交
2646 2647 2648
| Name        | Type               | Mandatory| Description          |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt; | Yes  | Rotation vector.|
W
wusongqing 已提交
2649

W
wusongqing 已提交
2650
**Return value**
W
wusongqing 已提交
2651

G
Gloria 已提交
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662
| Type                              | Description          |
| ---------------------------------- | -------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2663

W
wusongqing 已提交
2664
**Example**
W
wusongqing 已提交
2665

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

G
Gloria 已提交
2681
## sensor.transformRotationMatrix<sup>9+</sup> 
W
wusongqing 已提交
2682

G
Gloria 已提交
2683 2684
transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions,
        callback: AsyncCallback<Array&lt;number&gt;>): void
W
wusongqing 已提交
2685

G
Gloria 已提交
2686
Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2687

G
Gloria 已提交
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770
**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name          | Type                                     | Mandatory| Description                  |
| ---------------- | ----------------------------------------- | ---- | ---------------------- |
| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector to rotate.        |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Direction of the coordinate system.      |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes  | Callback used to return the rotation vector after being rotated.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
    sensor.transformRotationMatrix([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(data) {
        for (var i=0; i < data.length; i++) {
            console.info('transformRotationMatrix  data[' + i + '] = ' + data[i]);
        }
    })
} catch (err) {
        console.error('transformRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name          | Type                                     | Mandatory| Description            |
| ---------------- | ----------------------------------------- | ---- | ---------------- |
| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector to rotate.  |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Direction of the coordinate system.|

**Return value**

| Type                              | Description                  |
| ---------------------------------- | ---------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
    const promise = sensor.transformRotationMatrix([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
    promise.then((data) => {
        for (var i=0; i < data.length; i++) {
            console.info('transformRotationMatrix  data[' + i + '] = ' + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
} catch (err) {
        console.error('transformRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Obtains the quaternion from a rotation vector. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2771 2772

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2773

W
wusongqing 已提交
2774
**Parameters**
W
wusongqing 已提交
2775

G
Gloria 已提交
2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787
| Name        | Type                                    | Mandatory| Description          |
| -------------- | ---------------------------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt;                      | Yes  | Rotation vector.|
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the quaternion.  |

**Error code**

For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2788

W
wusongqing 已提交
2789
**Example**
W
wusongqing 已提交
2790

G
Gloria 已提交
2791 2792 2793 2794 2795
```js
try {
    sensor.getQuaternion ([0.20046076, 0.21907, 0.73978853, 0.60376877], function(data)  {
      for (var i=0; i < data.length; i++) {
          console.info('data[' + i + ']: ' + data[i]);
W
wusongqing 已提交
2796
      }
G
Gloria 已提交
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879
  })
} catch (err) {
        console.error('getQuaternion failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Obtains the quaternion from a rotation vector. This API uses a promise to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name        | Type               | Mandatory| Description          |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt; | Yes  | Rotation vector.|

**Return value**

| Type                              | Description        |
| ---------------------------------- | ------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Callback used to return the quaternion.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  const promise = sensor.getQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('getQuaternionn_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info('data[' + i + ']: ' + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
} catch (err) {
        console.error('getQuaternion failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name        | Type                                    | Mandatory| Description                             |
| -------------- | ---------------------------------------- | ---- | --------------------------------- |
| rotationMatrix | Array&lt;number&gt;                      | Yes  | Rotation matrix.                   |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes  | Callback used to return the rotation angle around the z, x, and y axes.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  sensor.getOrientation([1, 0, 0, 0, 1, 0, 0, 0, 1], function(data)  {
      console.info("SensorJsAPI--->Successed to get getOrientation interface get data: " + data);
      for (var i = 1; i < data.length; i++) {
          console.info('sensor_getOrientation_callback ' + data[i]);
W
wusongqing 已提交
2880 2881
      }
  })
G
Gloria 已提交
2882 2883 2884 2885
} catch (err) {
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```
W
wusongqing 已提交
2886

G
Gloria 已提交
2887
## sensor.getOrientation<sup>9+</sup>
W
wusongqing 已提交
2888

G
Gloria 已提交
2889
getOrientation(rotationMatrix: Array&lt;number&gt;): Promise<Array&lt;number&gt;> 
W
wusongqing 已提交
2890

G
Gloria 已提交
2891
Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.
W
wusongqing 已提交
2892

G
Gloria 已提交
2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973
**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name        | Type               | Mandatory| Description          |
| -------------- | ------------------- | ---- | -------------- |
| rotationMatrix | Array&lt;number&gt; | Yes  | Rotation matrix.|

**Return value**

| Type                              | Description                             |
| ---------------------------------- | --------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  const promise = sensor.getOrientation([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info('sensor_getOrientation_Promise success', data);
          for (var i = 1; i < data.length; i++) {
              console.info('sensor_getOrientation_promise ' + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
} catch (err) {
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                        | Mandatory| Description          |
| ----------- | ------------------------------------------------------------ | ---- | -------------- |
| gravity     | Array&lt;number&gt;                                          | Yes  | Gravity vector.|
| geomagnetic | Array&lt;number&gt;                                          | Yes  | Geomagnetic vector.|
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes  | Callback used to return the rotation matrix.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
  sensor.getRotationMatrix ([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(data)  {
      console.info('sensor_getRotationMatrix_callback ' + JSON.stringify(data));
  })
} catch (err) {
        console.error('getRotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
}
```

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

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

Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses a promise to return the result.
W
wusongqing 已提交
2974 2975

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2976

W
wusongqing 已提交
2977
**Parameters**
W
wusongqing 已提交
2978

G
Gloria 已提交
2979 2980 2981 2982
| Name     | Type               | Mandatory| Description          |
| ----------- | ------------------- | ---- | -------------- |
| gravity     | Array&lt;number&gt; | Yes  | Gravity vector.|
| geomagnetic | Array&lt;number&gt; | Yes  | Geomagnetic vector.|
W
wusongqing 已提交
2983

W
wusongqing 已提交
2984
**Return value**
W
wusongqing 已提交
2985

G
Gloria 已提交
2986 2987
| Type                                                        | Description          |
| ------------------------------------------------------------ | -------------- |
W
wusongqing 已提交
2988
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
2989

G
Gloria 已提交
2990 2991 2992 2993 2994 2995 2996 2997
**Error code**

For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

W
wusongqing 已提交
2998
**Example**
W
wusongqing 已提交
2999

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

G
Gloria 已提交
3013
## sensor.getSensorList<sup>9+</sup>
G
Gloria 已提交
3014

G
Gloria 已提交
3015
 getSensorList(callback: AsyncCallback<Array&lt;Sensor&gt;>): void
G
Gloria 已提交
3016 3017 3018 3019 3020 3021 3022

Obtains information about all sensors on the device. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033
| Name  | Type                                          | Mandatory| Description            |
| -------- | ---------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<Array&lt;[Sensor](#sensor9)&gt;> | Yes  | Callback used to return the sensor list.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
G
Gloria 已提交
3034 3035 3036 3037

**Example**

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

G
Gloria 已提交
3050
## sensor.getSensorList<sup>9+</sup>
G
Gloria 已提交
3051

G
Gloria 已提交
3052
 getSensorList(): Promise< Array&lt;Sensor&gt;>
G
Gloria 已提交
3053 3054 3055 3056 3057 3058 3059

Obtains information about all sensors on the device. This API uses a promise to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Return value**

G
Gloria 已提交
3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070
| Name | Type                                    | Mandatory| Description            |
| ------- | ---------------------------------------- | ---- | ---------------- |
| promise | Promise<Array&lt;[Sensor](#sensor9)&gt;> | Yes  | Promise used to return the sensor list.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
G
Gloria 已提交
3071 3072 3073 3074

**Example**

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

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

G
Gloria 已提交
3091
getSingleSensor(type: SensorId, callback: AsyncCallback&lt;Sensor&gt;): void
G
Gloria 已提交
3092 3093 3094 3095 3096 3097 3098

Obtains information about the sensor of a specific type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110
| Name  | Type                                   | Mandatory| Description            |
| -------- | --------------------------------------- | ---- | ---------------- |
| type     | [SensorId](#sensorid9)                  | Yes  | Sensor type.    |
| callback | AsyncCallback&lt;[Sensor](#sensor9)&gt; | Yes  | Callback used to return the sensor information.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
G
Gloria 已提交
3111 3112 3113 3114

**Example**

```js
G
Gloria 已提交
3115 3116 3117 3118 3119 3120 3121
try {
    sensor.getSingleSensor(sensor.SensorId.SENSOR_TYPE_ID_ACCELEROMETER, (error, data) =>     {
        console.info('getSingleSensor ' + JSON.stringify(data));
    });
} catch (err) {
        console.error('getSingleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
}
G
Gloria 已提交
3122 3123 3124 3125
```

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

G
Gloria 已提交
3126
 getSingleSensor(type: SensorId): Promise&lt;Sensor&gt;
G
Gloria 已提交
3127 3128 3129 3130 3131 3132 3133

Obtains information about the sensor of a specific type. This API uses a promise to return the result.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

G
Gloria 已提交
3134 3135 3136
| Name| Type                  | Mandatory| Description        |
| ------ | ---------------------- | ---- | ------------ |
| type   | [SensorId](#sensorid9) | Yes  | Sensor type.|
G
Gloria 已提交
3137 3138 3139

**Return value**

G
Gloria 已提交
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150
| Name | Type                             | Mandatory| Description            |
| ------- | --------------------------------- | ---- | ---------------- |
| promise | Promise&lt;[Sensor](#sensor9)&gt; | Yes  | Promise used to return the sensor information.|

**Error code**

For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md).

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
G
Gloria 已提交
3151 3152 3153 3154

**Example**

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

G
Gloria 已提交
3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196
## SensorId<sup>9+</sup>

Enumerates the sensor types.

**System capability**: SystemCapability.Sensors.Sensor

| Name                       | Default Value| Description                  |
| --------------------------- | ------ | ---------------------- |
| ACCELEROMETER               | 1      | Acceleration sensor.        |
| GYROSCOPE                   | 2      | Gyroscope sensor.        |
| AMBIENT_LIGHT               | 5      | Ambient light sensor.        |
| MAGNETIC_FIELD              | 6      | Magnetic field sensor.          |
| BAROMETER                   | 8      | Barometer sensor.        |
| HALL                        | 10     | Hall effect sensor.          |
| PROXIMITY                   | 12     | Proximity sensor.        |
| HUMIDITY                    | 13     | Humidity sensor.          |
| ORIENTATION                 | 256    | Orientation sensor.          |
| GRAVITY                     | 257    | Gravity sensor.          |
| LINEAR_ACCELEROMETER        | 258    | Linear acceleration sensor.    |
| ROTATION_VECTOR             | 259    | Rotation vector sensor.      |
| AMBIENT_TEMPERATURE         | 260    | Ambient temperature sensor.      |
| MAGNETIC_FIELD_UNCALIBRATED | 261    | Uncalibrated magnetic field sensor.    |
| GYROSCOPE_UNCALIBRATED      | 263    | Uncalibrated gyroscope sensor.  |
| SIGNIFICANT_MOTION          | 264    | Significant motion sensor.      |
| PEDOMETER_DETECTION         | 265    | Pedometer detection sensor.      |
| PEDOMETER                   | 266    | Pedometer sensor.          |
| HEART_RATE                  | 278    | Heart rate sensor.          |
| WEAR_DETECTION              | 280    | Wear detection sensor.      |
| ACCELEROMETER_UNCALIBRATED  | 281    | Uncalibrated acceleration sensor.|

## SensorType<sup>(deprecated)</sup>
Z
zengyawen 已提交
3197 3198 3199

Enumerates the sensor types.

W
wusongqing 已提交
3200 3201
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3202

G
Gloria 已提交
3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225
| Name                                      | Default Value| Description                  |
| ------------------------------------------ | ------ | ---------------------- |
| SENSOR_TYPE_ID_ACCELEROMETER               | 1      | Acceleration sensor.        |
| SENSOR_TYPE_ID_GYROSCOPE                   | 2      | Gyroscope sensor.        |
| SENSOR_TYPE_ID_AMBIENT_LIGHT               | 5      | Ambient light sensor.        |
| SENSOR_TYPE_ID_MAGNETIC_FIELD              | 6      | Magnetic field sensor.          |
| SENSOR_TYPE_ID_BAROMETER                   | 8      | Barometer sensor.        |
| SENSOR_TYPE_ID_HALL                        | 10     | Hall effect sensor.          |
| SENSOR_TYPE_ID_PROXIMITY                   | 12     | Proximity sensor.        |
| SENSOR_TYPE_ID_HUMIDITY                    | 13     | Humidity sensor.          |
| SENSOR_TYPE_ID_ORIENTATION                 | 256    | Orientation sensor.          |
| SENSOR_TYPE_ID_GRAVITY                     | 257    | Gravity sensor.          |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION         | 258    | Linear acceleration sensor.    |
| SENSOR_TYPE_ID_ROTATION_VECTOR             | 259    | Rotation vector sensor.      |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE         | 260    | Ambient temperature sensor.      |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261    | Uncalibrated magnetic field sensor.    |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED      | 263    | Uncalibrated gyroscope sensor.  |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION          | 264    | Significant motion sensor.      |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION         | 265    | Pedometer detection sensor.      |
| SENSOR_TYPE_ID_PEDOMETER                   | 266    | Pedometer sensor.          |
| SENSOR_TYPE_ID_HEART_RATE                  | 278    | Heart rate sensor.          |
| SENSOR_TYPE_ID_WEAR_DETECTION              | 280    | Wear detection sensor.      |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED  | 281    | Uncalibrated acceleration sensor.|
W
wusongqing 已提交
3226 3227 3228 3229 3230 3231


## Response

Describes the timestamp of the sensor data.

W
wusongqing 已提交
3232 3233
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3234 3235 3236 3237
| Name     | Type| Readable| Writable| Description                    |
| --------- | -------- | ---- | ---- | ------------------------ |
| timestamp | number   | Yes  | Yes  | Timestamp when the sensor reports data.|

G
Gloria 已提交
3238
## Sensor<sup>9+</sup>
G
Gloria 已提交
3239 3240 3241 3242

Describes the sensor information.

**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
3243

G
Gloria 已提交
3244 3245 3246 3247 3248 3249
| Name           | Type| Description                  |
| --------------- | -------- | ---------------------- |
| sensorName      | string   | Sensor name.          |
| venderName      | string   | Vendor of the sensor.        |
| firmwareVersion | string   | Firmware version of the sensor.      |
| hardwareVersion | string   | Hardware version of the sensor.      |
G
Gloria 已提交
3250
| sensorId        | number   | Sensor type ID.        |
G
Gloria 已提交
3251
| maxRange        | number   | Maximum measurement range of the sensor.|
G
Gloria 已提交
3252 3253
| minSamplePeriod | number   | Minimum sampling period.  |
| maxSamplePeriod | number   | Maximum sampling period.  |
G
Gloria 已提交
3254 3255
| precision       | number   | Precision of the sensor.          |
| power           | number   | Power supply of the sensor.          |
W
wusongqing 已提交
3256 3257 3258 3259 3260

## AccelerometerResponse

Describes the acceleration sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3261 3262
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3263

G
Gloria 已提交
3264 3265 3266 3267 3268
| Name| Type| Readable| Writable| Description                                |
| ---- | -------- | ---- | ---- | ------------------------------------ |
| x    | number   | Yes  | Yes  | Acceleration along the x-axis of the device, in m/s2.|
| y    | number   | Yes  | Yes  | Acceleration along the y-axis of the device, in m/s2.|
| z    | number   | Yes  | Yes  | Acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
3269 3270 3271 3272 3273 3274


## LinearAccelerometerResponse

Describes the linear acceleration sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3275 3276
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3277

G
Gloria 已提交
3278 3279 3280 3281 3282
| Name| Type| Readable| Writable| Description                                    |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | Yes  | Yes  | Linear acceleration along the x-axis of the device, in m/s2.|
| y    | number   | Yes  | Yes  | Linear acceleration along the y-axis of the device, in m/s2.|
| z    | number   | Yes  | Yes  | Linear acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
3283 3284 3285 3286 3287 3288


## AccelerometerUncalibratedResponse

Describes the uncalibrated acceleration sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3289 3290
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3291

G
Gloria 已提交
3292 3293 3294 3295 3296 3297 3298 3299
| Name | Type| Readable| Writable| Description                                            |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| x     | number   | Yes  | Yes  | Uncalibrated acceleration along the x-axis of the device, in m/s2.      |
| y     | number   | Yes  | Yes  | Uncalibrated acceleration along the y-axis of the device, in m/s2.      |
| z     | number   | Yes  | Yes  | Uncalibrated acceleration along the z-axis of the device, in m/s2.      |
| biasX | number   | Yes  | Yes  | Uncalibrated acceleration bias along the x-axis of the device, in m/s2.  |
| biasY | number   | Yes  | Yes  | Uncalibrated acceleration bias along the y-axis of the device, in m/s2.|
| biasZ | number   | Yes  | Yes  | Uncalibrated acceleration bias along the z-axis of the device, in m/s2.  |
W
wusongqing 已提交
3300 3301 3302 3303 3304 3305


## GravityResponse

Describes the gravity sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3306 3307
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3308

G
Gloria 已提交
3309 3310 3311 3312 3313
| Name| Type| Readable| Writable| Description                                    |
| ---- | -------- | ---- | ---- | ---------------------------------------- |
| x    | number   | Yes  | Yes  | Gravitational acceleration along the x-axis of the device, in m/s2.|
| y    | number   | Yes  | Yes  | Gravitational acceleration along the y-axis of the device, in m/s2.|
| z    | number   | Yes  | Yes  | Gravitational acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
3314 3315 3316 3317 3318 3319


## OrientationResponse

Describes the orientation sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3320 3321
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3322

G
Gloria 已提交
3323 3324 3325 3326 3327
| Name | Type| Readable| Writable| Description                             |
| ----- | -------- | ---- | ---- | --------------------------------- |
| alpha | number   | Yes  | Yes  | Rotation angle of the device around the z-axis, in degrees.|
| beta  | number   | Yes  | Yes  | Rotation angle of the device around the x-axis, in degrees.|
| gamma | number   | Yes  | Yes  | Rotation angle of the device around the y-axis, in degrees.|
W
wusongqing 已提交
3328 3329 3330 3331 3332 3333


## RotationVectorResponse

Describes the rotation vector sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3334 3335
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3336

G
Gloria 已提交
3337 3338 3339 3340 3341 3342
| Name| Type| Readable| Writable| Description             |
| ---- | -------- | ---- | ---- | ----------------- |
| x    | number   | Yes  | Yes  | X-component of the rotation vector.|
| y    | number   | Yes  | Yes  | Y-component of the rotation vector.|
| z    | number   | Yes  | Yes  | Z-component of the rotation vector.|
| w    | number   | Yes  | Yes  | Scalar.           |
W
wusongqing 已提交
3343 3344 3345 3346 3347 3348


## GyroscopeResponse

Describes the gyroscope sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3349 3350
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3351

G
Gloria 已提交
3352 3353 3354 3355 3356
| Name| Type| Readable| Writable| Description                            |
| ---- | -------- | ---- | ---- | -------------------------------- |
| x    | number   | Yes  | Yes  | Angular velocity of rotation around the x-axis of the device, in rad/s.|
| y    | number   | Yes  | Yes  | Angular velocity of rotation around the y-axis of the device, in rad/s.|
| z    | number   | Yes  | Yes  | Angular velocity of rotation around the z-axis of the device, in rad/s.|
W
wusongqing 已提交
3357 3358 3359 3360 3361 3362


## GyroscopeUncalibratedResponse

Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3363 3364
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3365

G
Gloria 已提交
3366 3367 3368 3369 3370 3371 3372 3373
| Name | Type| Readable| Writable| Description                                      |
| ----- | -------- | ---- | ---- | ------------------------------------------ |
| x     | number   | Yes  | Yes  | Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.    |
| y     | number   | Yes  | Yes  | Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.    |
| z     | number   | Yes  | Yes  | Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.    |
| biasX | number   | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.|
| biasY | number   | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.|
| biasZ | number   | Yes  | Yes  | Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.|
W
wusongqing 已提交
3374 3375 3376 3377 3378 3379


## SignificantMotionResponse

Describes the significant motion sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3380 3381
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3382

G
Gloria 已提交
3383 3384 3385
| Name  | Type| Readable| Writable| Description                                                        |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | Yes  | Yes  | Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.|
W
wusongqing 已提交
3386 3387 3388 3389 3390 3391


## ProximityResponse

Describes the proximity sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3392 3393
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3394

G
Gloria 已提交
3395 3396 3397
| Name    | Type| Readable| Writable| Description                                                  |
| -------- | -------- | ---- | ---- | ------------------------------------------------------ |
| distance | number   | Yes  | Yes  | Proximity between the visible object and the device monitor. The value **0** means the two are close to each other, and **1** means that they are far away from each other.|
W
wusongqing 已提交
3398 3399 3400 3401 3402 3403


## LightResponse

Describes the ambient light sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3404 3405
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3406

G
Gloria 已提交
3407 3408 3409
| Name     | Type| Readable| Writable| Description                  |
| --------- | -------- | ---- | ---- | ---------------------- |
| intensity | number   | Yes  | Yes  | Illumination, in lux.|
W
wusongqing 已提交
3410 3411 3412 3413 3414 3415


## HallResponse

Describes the Hall effect sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3416 3417
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3418

G
Gloria 已提交
3419 3420 3421
| Name  | Type| Readable| Writable| Description                                                        |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| status | number   | Yes  | Yes  | Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value **0** means that a magnetic field does not exist, and a value greater than **0** means the opposite.|
W
wusongqing 已提交
3422 3423 3424 3425 3426 3427


## MagneticFieldResponse

Describes the magnetic field sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3428 3429
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3430

W
wusongqing 已提交
3431 3432 3433 3434 3435
| Name| Type| Readable| Writable| Description                        |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | Yes  | Yes  | Magnetic field strength on the x-axis, in μT.|
| y    | number   | Yes  | Yes  | Magnetic field strength on the y-axis, in μT.|
| z    | number   | Yes  | Yes  | Magnetic field strength on the z-axis, in μT.|
W
wusongqing 已提交
3436 3437 3438 3439 3440 3441


## MagneticFieldUncalibratedResponse

Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3442 3443
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3444

G
Gloria 已提交
3445 3446 3447 3448 3449 3450 3451 3452
| Name | Type| Readable| Writable| Description                                  |
| ----- | -------- | ---- | ---- | -------------------------------------- |
| x     | number   | Yes  | Yes  | Uncalibrated magnetic field strength on the x-axis, in μT.    |
| y     | number   | Yes  | Yes  | Uncalibrated magnetic field strength on the y-axis, in μT.    |
| z     | number   | Yes  | Yes  | Uncalibrated magnetic field strength on the z-axis, in μT.    |
| biasX | number   | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the x-axis, in μT.|
| biasY | number   | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the y-axis, in μT.|
| biasZ | number   | Yes  | Yes  | Bias of the uncalibrated magnetic field strength on the z-axis, in μT.|
W
wusongqing 已提交
3453 3454 3455 3456 3457 3458


## PedometerResponse

Describes the pedometer sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3459 3460
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3461

G
Gloria 已提交
3462 3463 3464
| Name | Type| Readable| Writable| Description            |
| ----- | -------- | ---- | ---- | ---------------- |
| steps | number   | Yes  | Yes  | Number of steps a user has walked.|
W
wusongqing 已提交
3465 3466 3467 3468 3469 3470


## HumidityResponse

Describes the humidity sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3471 3472
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3473

G
Gloria 已提交
3474 3475 3476
| Name    | Type| Readable| Writable| Description                                                     |
| -------- | -------- | ---- | ---- | --------------------------------------------------------- |
| humidity | number   | Yes  | Yes  | Ambient relative humidity, in a percentage (%).|
W
wusongqing 已提交
3477 3478


W
wusongqing 已提交
3479
## PedometerDetectionResponse
W
wusongqing 已提交
3480 3481 3482

Describes the pedometer detection sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3483 3484
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3485

G
Gloria 已提交
3486 3487 3488
| Name  | Type| Readable| Writable| Description                                                        |
| ------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| scalar | number   | Yes  | Yes  | Pedometer detection. This parameter specifies whether a user takes a step. The value **0** means that the user does not take a step, and **1** means that the user takes a step.|
W
wusongqing 已提交
3489 3490 3491 3492 3493 3494


## AmbientTemperatureResponse

Describes the ambient temperature sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3495 3496
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3497

G
Gloria 已提交
3498 3499 3500
| Name       | Type| Readable| Writable| Description                      |
| ----------- | -------- | ---- | ---- | -------------------------- |
| temperature | number   | Yes  | Yes  | Ambient temperature, in degree Celsius.|
W
wusongqing 已提交
3501 3502 3503 3504 3505 3506


## BarometerResponse

Describes the barometer sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3507 3508
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3509

G
Gloria 已提交
3510 3511 3512
| Name    | Type| Readable| Writable| Description                    |
| -------- | -------- | ---- | ---- | ------------------------ |
| pressure | number   | Yes  | Yes  | Atmospheric pressure, in pascal.|
W
wusongqing 已提交
3513 3514 3515 3516 3517 3518


## HeartRateResponse

Describes the heart rate sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3519 3520
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3521

G
Gloria 已提交
3522 3523 3524
| Name     | Type| Readable| Writable| Description                                   |
| --------- | -------- | ---- | ---- | --------------------------------------- |
| heartRate | number   | Yes  | Yes  | Heart rate, in beats per minute (bpm).|
W
wusongqing 已提交
3525 3526 3527 3528 3529 3530


## WearDetectionResponse

Describes the wear detection sensor data. It extends from [Response](#response).

W
wusongqing 已提交
3531 3532
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
3533

G
Gloria 已提交
3534 3535 3536
| Name | Type| Readable| Writable| Description                                            |
| ----- | -------- | ---- | ---- | ------------------------------------------------ |
| value | number   | Yes  | Yes  | Whether the device is being worn. The value **1** means that the device is being worn, and **0** means the opposite.|
W
wusongqing 已提交
3537 3538 3539


## Options
Z
zengyawen 已提交
3540 3541 3542

Describes the sensor data reporting frequency.

W
wusongqing 已提交
3543 3544
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3545 3546 3547
| Name    | Type| Description                                       |
| -------- | -------- | ------------------------------------------- |
| interval | number   | Frequency at which a sensor reports data. The default value is 200,000,000 ns.|
W
wusongqing 已提交
3548

W
wusongqing 已提交
3549 3550 3551 3552
## RotationMatrixResponse

Describes the response for setting the rotation matrix.

W
wusongqing 已提交
3553 3554
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3555 3556 3557 3558
| Name       | Type           | Readable| Writable| Description      |
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | Yes  | Yes  | Rotation matrix.|
| inclination | Array&lt;number&gt; | Yes  | Yes  | Inclination matrix.|
W
wusongqing 已提交
3559 3560 3561 3562 3563 3564


## CoordinatesOptions

Describes the coordinate options.

W
wusongqing 已提交
3565 3566
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3567 3568 3569 3570
| Name| Type| Readable| Writable| Description       |
| ---- | -------- | ---- | ---- | ----------- |
| x    | number   | Yes  | Yes  | X coordinate direction.|
| y    | number   | Yes  | Yes  | Y coordinate direction.|
W
wusongqing 已提交
3571

W
wusongqing 已提交
3572 3573 3574 3575 3576

## GeomagneticResponse

Describes a geomagnetic response object. It extends from [Response](#response).

W
wusongqing 已提交
3577 3578
**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3579 3580 3581 3582 3583 3584 3585 3586 3587
| Name           | Type| Readable| Writable| Description                                              |
| --------------- | -------- | ---- | ---- | -------------------------------------------------- |
| x               | number   | Yes  | Yes  | North component of the geomagnetic field.                                  |
| y               | number   | Yes  | Yes  | East component of the geomagnetic field.                                  |
| z               | number   | Yes  | Yes  | Vertical component of the geomagnetic field.                                |
| geomagneticDip  | number   | Yes  | Yes  | Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.            |
| deflectionAngle | number   | Yes  | Yes  | Magnetic declination, which is the angle between true north (geographic north) and the magnetic north (the horizontal component of the field).|
| levelIntensity  | number   | Yes  | Yes  | Horizontal intensity of the magnetic field vector field.                                |
| totalIntensity  | number   | Yes  | Yes  | Total intensity of the magnetic field vector.                                  |
W
wusongqing 已提交
3588 3589

## LocationOptions
Z
zengyawen 已提交
3590

W
wusongqing 已提交
3591 3592 3593 3594
Describes the geographical location.

**System capability**: SystemCapability.Sensors.Sensor

G
Gloria 已提交
3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 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 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198
| Name     | Type| Readable| Writable| Description      |
| --------- | -------- | ---- | ---- | ---------- |
| latitude  | number   | Yes  | Yes  | Latitude.    |
| longitude | number   | Yes  | Yes  | Longitude.    |
| altitude  | number   | Yes  | Yes  | Altitude.|

## sensor.on<sup>(deprecated)</sup>

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

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

Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER](#accelerometer9) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes       | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_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}
  );
  ```

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

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

Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

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

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

Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELEROMETER**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.GRAVITY](#gravity9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                | Mandatory | Description                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                           | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes       | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. |
| options  | [Options](#options)                                 | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE](#gyroscope9) instead.

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes       | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. |
| options  | [Options](#options)                                     | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9) instead.

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. |

**Example**

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

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

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

Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.SIGNIFICANT_MOTION](#significant_motion9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes       | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER_DETECTION](#pedometer_detection9) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes       | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER](#pedometer9) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes       | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. |
| options  | [Options](#options)                                     | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes       | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD](#magnetic_field9) instead. 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes       | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the uncalibrated magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.PROXIMITY](#proximity9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes       | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. |
| options  | [Options](#options)                                     | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.HUMIDITY](#humidity9) instead. 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                  | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                             | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes       | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. |
| options  | [Options](#options)                                   | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.BAROMETER](#barometer9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes       | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. |
| options  | [Options](#options)                                     | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.HALL](#hall9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                          | Mandatory | Description                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes       | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. |
| options  | [Options](#options)                           | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_LIGHT](#ambient_light9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                            | Mandatory | Description                                                  |
| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                       | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes       | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. |
| options  | [Options](#options)                             | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

  ```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

Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.ORIENTATION](#orientation9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                        | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                   | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes       | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. |
| options  | [Options](#options)                                         | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

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

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

Subscribes to only one data change of the heart rate sensor.

This API is deprecated since API version 9. You are advised to use [sensor.on.HEART_BEAT_RATE](#heart_beat_rate9) instead.

**Required permissions**: ohos.permission.HEALTH_DATA

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

### HEART_BEAT_RATE<sup>9+</sup>

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

Subscribes to only one data change of the heart rate sensor.

**Required permissions**: ohos.permission.HEALTH_DATA

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

**Example**

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

```

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

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

Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.ROTATION_VECTOR](#rotation_vector9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes       | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

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

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

Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect.

This API is deprecated since API version 9. You are advised to use [sensor.on.WEAR_DETECTION](#wear_detection9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes       | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. |
| options  | [Options](#options)                                          | No        | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns. |

**Example**

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

  ```

## sensor.once<sup>(deprecated)</sup>

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

once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void

Subscribes to only one data change of the acceleration sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER](#accelerometer9-1) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes       | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. |

**Example**

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

  ```

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

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

Subscribes to only one data change of the linear acceleration sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9) instead.

**Required permissions**: ohos.permission.ACCELERATION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |

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

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

Subscribes to only one data change of the linear acceleration sensor.

**Required permissions**: ohos.permission.ACCELERATION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELEROMETER**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void

Subscribes to only one data change of the uncalibrated acceleration sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes       | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void

Subscribes to only one data change of the gravity sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.GRAVITY](#gravity9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                | Mandatory | Description                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                           | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes       | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void

Subscribes to only one data change of the gyroscope sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE](#gyroscope9-1) instead.

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes       | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void

Subscribes to only one data change of the uncalibrated gyroscope sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1) instead.

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes       | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void

Subscribes to only one data change of the significant motion sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes       | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void

Subscribes to only one data change of the pedometer detection sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes       | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void

Subscribes to only one data change of the pedometer sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER](#pedometer9-1) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes       | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. |

**Example**

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

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

once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void

Subscribes to only one data change of the ambient temperature sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes       | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void

Subscribes to only one data change of the magnetic field sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD](#magnetic_field9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes       | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void

Subscribes to only one data change of the uncalibrated magnetic field sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes       | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void

Subscribes to only one data change of the proximity sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.PROXIMITY](#proximity9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes       | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. |

**Example**

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

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

once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void

Subscribes to only one data change of the humidity sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.HUMIDITY](#humidity9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                  | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                             | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes       | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void

Subscribes to only one data change of the barometer sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.BAROMETER](#barometer9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes       | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void

Subscribes to only one data change of the Hall effect sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.HALL](#hall9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                          | Mandatory | Description                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes       | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void

Subscribes to only one data change of the ambient light sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_LIGHT](#ambient_light9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                            | Mandatory | Description                                                  |
| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                       | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes       | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void

Subscribes to only one data change of the orientation sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.ORIENTATION](#orientation9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                        | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                   | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes       | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void

Subscribes to only one data change of the rotation vector sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.ROTATION_VECTOR](#rotation_vector9-1) instead. 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes       | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. |

**Example**

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

  ```

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

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

Subscribes to only one data change of the heart rate sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.HEART_BEAT_RATE](#heart_beat_rate9) instead.

**Required permissions**: ohos.permission.HEART_RATE 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

### HEART_BEAT_RATE<sup>9+</sup>

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

Subscribes to only one data change of the heart rate sensor.

**Required permissions**: ohos.permission.HEART_RATE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

**Example**

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

  ```

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

once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void

Subscribes to only one data change of the wear detection sensor.

This API is deprecated since API version 9. You are advised to use [sensor.once.WEAR_DETECTION](#wear_detection9-1) instead. 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes       | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. |

**Example**

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

  ```

## sensor.off<sup>(deprecated)</sup>

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER](#accelerometer9-2) instead. 

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes       | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. |

**Example**

```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_ACCELEROMETER, callback);

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. |

**Example**

```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_ACCELEROMETER_UNCALIBRATED, callback);

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_LIGHT](#ambient_light9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                            | Mandatory | Description                                                  |
| -------- | ----------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                       | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes       | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes       | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.BAROMETER](#barometer9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**. |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes       | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. |

**Example**

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

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.GRAVITY](#gravity9-2) instead. 

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                | Mandatory | Description                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                           | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**. |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes       | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. |

**Example**

```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_GRAVITY, callback);
```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE](#gyroscope9-2) instead.

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes       | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. |

**Example**

```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>

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2) instead. 

**Required permissions**: ohos.permission.GYROSCOPE

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.HALL](#hall9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                          | Mandatory | Description                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                     | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**. |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes       | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.HEART_BEAT_RATE](#heart_beat_rate9) instead.

**Required permissions**: ohos.permission.HEALTH_DATA

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

### HEART_BEAT_RATE<sup>9+</sup>

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.HEALTH_DATA

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes       | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.HUMIDITY](#humidity9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                  | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                             | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**. |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes       | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9) instead.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |

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

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.ACCELEROMETER

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELEROMETER**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes       | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD](#magnetic_field9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name             | Type                                                         | Mandatory | Description                                                  |
| ---------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type             | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
| callbackcallback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes       | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes       | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.ORIENTATION](#orientation9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                        | Mandatory | Description                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                   | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**. |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes       | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER](#pedometer9-2) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes       | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2) instead.

**Required permissions**: ohos.permission.ACTIVITY_MOTION

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes       | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. |

**Example**

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

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.PROXIMITY](#proximity9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                               | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**. |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes       | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. |

**Example**

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

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.ROTATION_VECTOR](#rotation_vector9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes       | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes       | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. |

**Example**

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

```

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

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

Unsubscribes from sensor data changes.

This API is deprecated since API version 9. You are advised to use [sensor.off.WEAR_DETECTION](#wear_detection9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype)                                    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes       | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. |

**Example**

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

```

## sensor.transformCoordinateSystem<sup>(deprecated)</sup>

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

Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name             | Type                                      | Mandatory | Description                                                  |
| ---------------- | ----------------------------------------- | --------- | ------------------------------------------------------------ |
| inRotationVector | Array&lt;number&gt;                       | Yes       | Rotation vector to rotate.                                   |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes       | Direction of the coordinate system.                          |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes       | Callback used to return the rotation vector after being rotated. |

**Example**

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

```

## sensor.transformCoordinateSystem<sup>(deprecated)</sup>

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

Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name             | Type                                      | Mandatory | Description                         |
| ---------------- | ----------------------------------------- | --------- | ----------------------------------- |
| inRotationVector | Array&lt;number&gt;                       | Yes       | Rotation vector to rotate.          |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes       | Direction of the coordinate system. |

**Return value**

| Type                               | Description                                                  |
| ---------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated. |

**Example**

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

```

## sensor.getGeomagneticField<sup>(deprecated)</sup>

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

Obtains the geomagnetic field of a geographic location. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name            | Type                                                         | Mandatory | Description                                                  |
| --------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| locationOptions | [LocationOptions](#locationoptions)                          | Yes       | Geographic location.                                         |
| timeMillis      | number                                                       | Yes       | Time for obtaining the magnetic declination, in milliseconds. |
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes       | Callback used to return the geomagnetic field.               |

**Example**

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

```

## sensor.getGeomagneticField<sup>(deprecated)</sup>

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

Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name            | Type                                | Mandatory | Description                                                  |
| --------------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
| locationOptions | [LocationOptions](#locationoptions) | Yes       | Geographic location.                                         |
| timeMillis      | number                              | Yes       | Time for obtaining the magnetic declination, in milliseconds. |

**Return value**

| Type                                                       | Description                                   |
| ---------------------------------------------------------- | --------------------------------------------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field. |

**Example**

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

  ```

## sensor.getAltitude<sup>(deprecated)</sup>

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

Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name            | Type                        | Mandatory | Description                                                  |
| --------------- | --------------------------- | --------- | ------------------------------------------------------------ |
| seaPressure     | number                      | Yes       | Sea-level atmospheric pressure, in hPa.                      |
| currentPressure | number                      | Yes       | Atmospheric pressure at the altitude where the device is located, in hPa. |
| callback        | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the altitude, in meters.             |

**Example**

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

  ```

## sensor.getAltitude<sup>(deprecated)</sup>

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

Obtains the altitude at which the device is located based on the sea-level atmospheric pressure and the current atmospheric pressure. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name            | Type   | Mandatory | Description                                                  |
| --------------- | ------ | --------- | ------------------------------------------------------------ |
| seaPressure     | number | Yes       | Sea-level atmospheric pressure, in hPa.                      |
| currentPressure | number | Yes       | Atmospheric pressure at the altitude where the device is located, in hPa. |

**Return value**

| Type                  | Description                                     |
| --------------------- | ----------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the altitude, in meters. |

**Example**

  ```js
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })

  ```


## sensor.getGeomagneticDip<sup>(deprecated)</sup>

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

Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name              | Type                        | Mandatory | Description                                           |
| ----------------- | --------------------------- | --------- | ----------------------------------------------------- |
| inclinationMatrix | Array&lt;number&gt;         | Yes       | Inclination matrix.                                   |
| callback          | AsyncCallback&lt;number&gt; | Yes       | Callback used to return the magnetic dip, in radians. |

**Example**

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

## sensor.getGeomagneticDip<sup>(deprecated)</sup>

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

Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name              | Type                | Mandatory | Description         |
| ----------------- | ------------------- | --------- | ------------------- |
| inclinationMatrix | Array&lt;number&gt; | Yes       | Inclination matrix. |

**Return value**

| Type                  | Description                                          |
| --------------------- | ---------------------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians. |

**Example**

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

## sensor. getAngleModify<sup>(deprecated)</sup>

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name                  | Type                                     | Mandatory | Description                                                  |
| --------------------- | ---------------------------------------- | --------- | ------------------------------------------------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | Yes       | Current rotation matrix.                                     |
| preRotationMatrix     | Array&lt;number&gt;                      | Yes       | The other rotation matrix.                                   |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes       | Callback used to return the angle change around the z, x, and y axes. |

**Example**

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

  ```


## sensor. getAngleModify<sup>(deprecated)</sup>

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

Obtains the angle change between two rotation matrices. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name                  | Type                | Mandatory | Description                |
| --------------------- | ------------------- | --------- | -------------------------- |
| currentRotationMatrix | Array&lt;number&gt; | Yes       | Current rotation matrix.   |
| preRotationMatrix     | Array&lt;number&gt; | Yes       | The other rotation matrix. |

**Return value**

| Type                               | Description                                                  |
| ---------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes. |

**Example**

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


## sensor.createRotationMatrix<sup>(deprecated)</sup>

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

Converts a rotation vector into a rotation matrix. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                                     | Mandatory | Description                                  |
| -------------- | ---------------------------------------- | --------- | -------------------------------------------- |
| rotationVector | Array&lt;number&gt;                      | Yes       | Rotation vector to convert.                  |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes       | Callback used to return the rotation matrix. |

**Example**

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

  ```


## sensor.createRotationMatrix<sup>(deprecated)</sup>

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

Converts a rotation vector into a rotation matrix. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                | Mandatory | Description                 |
| -------------- | ------------------- | --------- | --------------------------- |
| rotationVector | Array&lt;number&gt; | Yes       | Rotation vector to convert. |

**Return value**

| Type                               | Description                                 |
| ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix. |

**Example**

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

  ```


## sensor.createQuaternion<sup>(deprecated)</sup>

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

Converts a rotation vector into a quaternion. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                                     | Mandatory | Description                             |
| -------------- | ---------------------------------------- | --------- | --------------------------------------- |
| rotationVector | Array&lt;number&gt;                      | Yes       | Rotation vector to convert.             |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes       | Callback used to return the quaternion. |

**Example**

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

  ```


## sensor.createQuaternion<sup>(deprecated)</sup>

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

Converts a rotation vector into a quaternion. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                | Mandatory | Description                 |
| -------------- | ------------------- | --------- | --------------------------- |
| rotationVector | Array&lt;number&gt; | Yes       | Rotation vector to convert. |

**Return value**

| Type                               | Description                            |
| ---------------------------------- | -------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion. |

**Example**

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


## sensor.getDirection<sup>(deprecated)</sup>

getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                                     | Mandatory | Description                                                  |
| -------------- | ---------------------------------------- | --------- | ------------------------------------------------------------ |
| rotationMatrix | Array&lt;number&gt;                      | Yes       | Rotation matrix.                                             |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes       | Callback used to return the rotation angle around the z, x, and y axes. |

**Example**

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

  ```


## sensor.getDirection<sup>(deprecated)</sup>

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

Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9-1) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name           | Type                | Mandatory | Description      |
| -------------- | ------------------- | --------- | ---------------- |
| rotationMatrix | Array&lt;number&gt; | Yes       | Rotation matrix. |

**Return value**

| Type                               | Description                                                  |
| ---------------------------------- | ------------------------------------------------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes. |

**Example**

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


## sensor.createRotationMatrix<sup>(deprecated)</sup>

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

Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-2) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name        | Type                                                         | Mandatory | Description                                  |
| ----------- | ------------------------------------------------------------ | --------- | -------------------------------------------- |
| gravity     | Array&lt;number&gt;                                          | Yes       | Gravity vector.                              |
| geomagnetic | Array&lt;number&gt;                                          | Yes       | Geomagnetic vector.                          |
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes       | Callback used to return the rotation matrix. |

**Example**

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


## sensor.createRotationMatrix<sup>(deprecated)</sup>

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

Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-3) instead.

**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name        | Type                | Mandatory | Description         |
| ----------- | ------------------- | --------- | ------------------- |
| gravity     | Array&lt;number&gt; | Yes       | Gravity vector.     |
| geomagnetic | Array&lt;number&gt; | Yes       | Geomagnetic vector. |

**Return value**

| Type                                                         | Description                                 |
| ------------------------------------------------------------ | ------------------------------------------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix. |

**Example**

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

<!--no_check-->