You need to sign in or sign up before continuing.
js-apis-sensor.md 270.0 KB
Newer Older
1
# @ohos.sensor (Sensor)
Z
zengyawen 已提交
2

3
The **Sensor** module provides APIs for obtaining the sensor list and subscribing to sensor data. It also provides some common sensor algorithms.
W
wusongqing 已提交
4

W
wusongqing 已提交
5
> **NOTE**
6
>
W
wusongqing 已提交
7
> 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 已提交
8

W
wusongqing 已提交
9 10

## Modules to Import
Z
zengyawen 已提交
11

W
wusongqing 已提交
12
```js
Z
zengyawen 已提交
13 14 15
import sensor from '@ohos.sensor';
```

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

G
Gloria 已提交
18
### ACCELEROMETER<sup>9+</sup>
W
wusongqing 已提交
19

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

G
Gloria 已提交
22
Subscribes to data of the acceleration sensor.
Z
zengyawen 已提交
23

G
Gloria 已提交
24
**Required permissions**: ohos.permission.ACCELEROMETER
Z
zengyawen 已提交
25

W
wusongqing 已提交
26
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
27

W
wusongqing 已提交
28
**Parameters**
W
wusongqing 已提交
29

30 31 32 33 34
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.             |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                        |
G
Gloria 已提交
35 36 37

**Error code**

G
Gloria 已提交
38
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
39 40 41 42

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

W
wusongqing 已提交
44
**Example**
Z
zengyawen 已提交
45

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

G
Gloria 已提交
58
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
59

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

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

G
Gloria 已提交
64
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
65 66 67

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

W
wusongqing 已提交
68
**Parameters**
G
Gloria 已提交
69 70 71

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
72 73 74
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
75 76 77

**Error code**

G
Gloria 已提交
78
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
79 80 81 82

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

W
wusongqing 已提交
84
**Example**
Z
zengyawen 已提交
85

G
Gloria 已提交
86 87
```js
try {
88
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) {
G
Gloria 已提交
89 90 91 92 93 94
        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);
95 96 97
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
98 99
}
```
W
wusongqing 已提交
100

G
Gloria 已提交
101
### AMBIENT_LIGHT<sup>9+</sup>
W
wusongqing 已提交
102

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

G
Gloria 已提交
105
Subscribes to data of the ambient light sensor.
W
wusongqing 已提交
106 107 108 109

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

**Parameters**
G
Gloria 已提交
110

111 112 113 114 115
| Name  | Type                                           | Mandatory| Description                                               |
| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.     |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LightResponse** object.|
| options  | [Options](#options)                             | No  | Data reporting frequency. The default value is 200,000,000 ns.                |
G
Gloria 已提交
116 117 118

**Error code**

G
Gloria 已提交
119
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
120 121 122 123

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
124 125 126

**Example**

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

G
Gloria 已提交
137
###  AMBIENT_TEMPERATURE<sup>9+</sup>
Z
zengyawen 已提交
138

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

G
Gloria 已提交
141
Subscribes to data of the ambient temperature sensor.
W
wusongqing 已提交
142 143 144

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

W
wusongqing 已提交
145
**Parameters**
G
Gloria 已提交
146 147 148

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
149 150 151
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
152 153 154

**Error code**

G
Gloria 已提交
155
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
156 157 158 159

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

W
wusongqing 已提交
161
**Example**
Z
zengyawen 已提交
162

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

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

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

G
Gloria 已提交
177
Subscribes to data of the barometer sensor.
Z
zengyawen 已提交
178

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

W
wusongqing 已提交
181
**Parameters**
G
Gloria 已提交
182

183 184 185 186 187
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.             |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **BarometerResponse** object.|
| options  | [Options](#options)                                     | No  | Data reporting frequency. The default value is 200,000,000 ns.                    |
G
Gloria 已提交
188 189 190

**Error code**

G
Gloria 已提交
191
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
192 193 194 195

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

W
wusongqing 已提交
197
**Example**
G
Gloria 已提交
198 199 200

```js
try {
201 202 203 204 205
    sensor.on(sensor.SensorId.BAROMETER, function (data) {
        console.info('Atmospheric pressure: ' + data.pressure);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218
}
```

###  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**

219 220 221 222 223
| Name  | Type                                               | Mandatory| Description                                                 |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.             |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GravityResponse** object.|
| options  | [Options](#options)                                 | No  | Data reporting frequency. The default value is 200,000,000 ns.                  |
G
Gloria 已提交
224 225 226

**Error code**

G
Gloria 已提交
227
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
228 229 230 231 232 233 234 235 236

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

**Example**

```js
try {
237 238 239 240 241 242 243
    sensor.on(sensor.SensorId.GRAVITY, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
244 245
}
```
Z
zengyawen 已提交
246

G
Gloria 已提交
247
###  GYROSCOPE<sup>9+</sup>
Z
zengyawen 已提交
248

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

G
Gloria 已提交
251
Subscribes to data of the gyroscope sensor.
Z
zengyawen 已提交
252

G
Gloria 已提交
253
**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
254 255 256

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

W
wusongqing 已提交
257
**Parameters**
G
Gloria 已提交
258

259 260 261 262 263
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.             |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeResponse** object.|
| options  | [Options](#options)                                     | No  | Data reporting frequency. The default value is 200,000,000 ns.                    |
G
Gloria 已提交
264 265 266

**Error code**

G
Gloria 已提交
267
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
268 269 270 271

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

W
wusongqing 已提交
273
**Example**
G
Gloria 已提交
274 275 276

```js
try {
277 278 279 280 281 282 283
    sensor.on(sensor.SensorId.GYROSCOPE, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
284 285
}
```
Z
zengyawen 已提交
286

G
Gloria 已提交
287
###  GYROSCOPE_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
288

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

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

G
Gloria 已提交
294
**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
295

G
Gloria 已提交
296
**System capability**: SystemCapability.Sensors.Sensor 
W
wusongqing 已提交
297

W
wusongqing 已提交
298
**Parameters**
G
Gloria 已提交
299 300 301

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
302 303 304
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
305 306 307

**Error code**

G
Gloria 已提交
308
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
309 310 311 312

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

W
wusongqing 已提交
314
**Example**
G
Gloria 已提交
315 316 317

```js
try {
318 319 320 321 322 323 324 325 326 327
    sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
328 329
}
```
Z
zengyawen 已提交
330

G
Gloria 已提交
331
###  HALL<sup>9+</sup>
Z
zengyawen 已提交
332

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

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

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

W
wusongqing 已提交
339
**Parameters**
G
Gloria 已提交
340

341 342 343 344 345
| Name  | Type                                         | Mandatory| Description                                              |
| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.             |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HallResponse** object.|
| options  | [Options](#options)                           | No  | Data reporting frequency. The default value is 200,000,000 ns.               |
G
Gloria 已提交
346 347 348

**Error code**

G
Gloria 已提交
349
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
350 351 352 353

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

W
wusongqing 已提交
355
**Example**
Z
zengyawen 已提交
356

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

G
Gloria 已提交
367
###   HEART_RATE<sup>9+</sup>
Z
zengyawen 已提交
368

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

G
Gloria 已提交
371 372 373
Subscribes to data of the heart rate sensor.

**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
374 375 376

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

W
wusongqing 已提交
377
**Parameters**
G
Gloria 已提交
378

379 380 381 382 383
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.            |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HeartRateResponse** object.|
| options  | [Options](#options)                                     | No  | Data reporting frequency. The default value is 200,000,000 ns.                    |
G
Gloria 已提交
384 385 386

**Error code**

G
Gloria 已提交
387
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
388 389 390 391

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

W
wusongqing 已提交
393
**Example**
Z
zengyawen 已提交
394

G
Gloria 已提交
395 396
```js
try {
397
    sensor.on(sensor.SensorId.HEART_RATE, function (data) {
G
Gloria 已提交
398
        console.info('Heart rate: ' + data.heartRate);
399 400 401
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
402 403
}
```
Z
zengyawen 已提交
404

G
Gloria 已提交
405
###  HUMIDITY<sup>9+</sup>
Z
zengyawen 已提交
406

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

G
Gloria 已提交
409
Subscribes to data of the humidity sensor.
W
wusongqing 已提交
410 411 412

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

W
wusongqing 已提交
413
**Parameters**
G
Gloria 已提交
414

415 416 417 418 419
| Name  | Type                                                 | Mandatory| Description                                                  |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.             |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HumidityResponse** object.|
| options  | [Options](#options)                                   | No  | Data reporting frequency. The default value is 200,000,000 ns.                   |
G
Gloria 已提交
420 421 422

**Error code**

G
Gloria 已提交
423
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
424 425 426 427

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

W
wusongqing 已提交
429
**Example**
Z
zengyawen 已提交
430

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

441
###   LINEAR_ACCELEROMETER<sup>9+</sup>
Z
zengyawen 已提交
442

G
Gloria 已提交
443 444 445 446 447 448
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 已提交
449

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

W
wusongqing 已提交
452
**Parameters**
G
Gloria 已提交
453 454 455

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
456 457 458
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**.       |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
459 460 461

**Error code**

G
Gloria 已提交
462
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
463 464 465 466

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

W
wusongqing 已提交
468
**Example**
Z
zengyawen 已提交
469

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

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

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

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

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

W
wusongqing 已提交
490
**Parameters**
G
Gloria 已提交
491

492 493 494 495 496
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.            |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                        |
G
Gloria 已提交
497 498 499

**Error code**

G
Gloria 已提交
500
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
501 502 503 504

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

W
wusongqing 已提交
506
**Example**
G
Gloria 已提交
507 508 509

```js
try {
510 511 512 513 514 515 516
    sensor.on(sensor.SensorId.MAGNETIC_FIELD, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
517 518
}
```
Z
zengyawen 已提交
519

G
Gloria 已提交
520
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
521

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

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

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

W
wusongqing 已提交
528
**Parameters**
G
Gloria 已提交
529 530 531

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
532 533 534
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
535 536 537

**Error code**

G
Gloria 已提交
538
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
539 540 541 542

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

W
wusongqing 已提交
544
**Example**
G
Gloria 已提交
545 546 547

```js
try {
548 549 550 551 552 553 554 555 556 557
    sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
558 559
}
```
Z
zengyawen 已提交
560

G
Gloria 已提交
561
### ORIENTATION<sup>9+</sup>
Z
zengyawen 已提交
562

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

G
Gloria 已提交
565
Subscribes to data of the orientation sensor.
Z
zengyawen 已提交
566

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

G
Gloria 已提交
569 570
**Error code**

G
Gloria 已提交
571
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
572 573 574 575 576

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

W
wusongqing 已提交
577
**Parameters**
G
Gloria 已提交
578

579 580 581 582 583
| Name  | Type                                                       | Mandatory| Description                                                     |
| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.             |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **OrientationResponse** object.|
| options  | [Options](#options)                                         | No  | Data reporting frequency. The default value is 200,000,000 ns.                      |
W
wusongqing 已提交
584

W
wusongqing 已提交
585
**Example**
Z
zengyawen 已提交
586

G
Gloria 已提交
587 588
```js
try {
589 590 591 592 593 594 595
    sensor.on(sensor.SensorId.ORIENTATION, function (data) {
        console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
        console.info('The device rotates at an angle around the X axis: ' + data.beta);
        console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
596 597
}
```
Z
zengyawen 已提交
598

G
Gloria 已提交
599
### PEDOMETER<sup>9+</sup>
Z
zengyawen 已提交
600

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

G
Gloria 已提交
603
Subscribes to data of the pedometer sensor.
W
wusongqing 已提交
604

G
Gloria 已提交
605
**Required permissions**: ohos.permission.ACTIVITY_MOTION
Z
zengyawen 已提交
606

G
Gloria 已提交
607
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
608

G
Gloria 已提交
609
**Error code**
Z
zengyawen 已提交
610

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

G
Gloria 已提交
613 614 615
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
616

W
wusongqing 已提交
617
**Parameters**
G
Gloria 已提交
618

619 620 621 622 623
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.             |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerResponse** object.|
| options  | [Options](#options)                                     | No  | Data reporting frequency. The default value is 200,000,000 ns.                    |
W
wusongqing 已提交
624

W
wusongqing 已提交
625
**Example**
Z
zengyawen 已提交
626

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

G
Gloria 已提交
637
### PEDOMETER_DETECTION<sup>9+</sup>
Z
zengyawen 已提交
638

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

642
Subscribes to data of the pedometer detection sensor.
W
wusongqing 已提交
643

G
Gloria 已提交
644
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
645

G
Gloria 已提交
646
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
647

G
Gloria 已提交
648
**Parameters**
Z
zengyawen 已提交
649

G
Gloria 已提交
650 651
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
652 653 654
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
Z
zengyawen 已提交
655

G
Gloria 已提交
656
**Error code**
Z
zengyawen 已提交
657

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

G
Gloria 已提交
660 661 662
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
663

W
wusongqing 已提交
664
**Example**
Z
zengyawen 已提交
665

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

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

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

G
Gloria 已提交
680
Subscribes to data of the proximity sensor.
Z
zengyawen 已提交
681

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

W
wusongqing 已提交
684
**Parameters**
W
wusongqing 已提交
685

686 687 688 689 690
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.             |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **ProximityResponse** object.|
| options  | [Options](#options)                                     | No  | Data reporting frequency. The default value is 200,000,000 ns.                    |
Z
zengyawen 已提交
691

G
Gloria 已提交
692
**Error code**
W
wusongqing 已提交
693

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

G
Gloria 已提交
696 697 698 699 700 701 702 703
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |

**Example**

```js
try {
704 705 706 707 708
    sensor.on(sensor.SensorId.PROXIMITY, function (data) {
        console.info('Distance: ' + data.distance);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
709 710
}
```
W
wusongqing 已提交
711

G
Gloria 已提交
712
### ROTATION_VECTOR<sup>9+</sup>
W
wusongqing 已提交
713

G
Gloria 已提交
714 715 716 717
on(type: SensorId.ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;,
        options?: Options): void

Subscribes to data of the rotation vector sensor.
W
wusongqing 已提交
718 719 720

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

W
wusongqing 已提交
721
**Parameters**
W
wusongqing 已提交
722

G
Gloria 已提交
723 724
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
725 726 727
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **RotationVectorResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
728 729 730

**Error code**

G
Gloria 已提交
731
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
732 733 734 735

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

W
wusongqing 已提交
737
**Example**
Z
zengyawen 已提交
738

W
wusongqing 已提交
739
```js
G
Gloria 已提交
740
try {
741 742 743 744 745 746 747 748
    sensor.on(sensor.SensorId.ROTATION_VECTOR, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('Scalar quantity: ' + data.w);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
749
}
W
wusongqing 已提交
750
```
Z
zengyawen 已提交
751

G
Gloria 已提交
752
### SIGNIFICANT_MOTION<sup>9+</sup>
W
wusongqing 已提交
753

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

G
Gloria 已提交
757
Subscribes to data of the significant motion sensor.
W
wusongqing 已提交
758 759 760 761 762

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

**Parameters**

G
Gloria 已提交
763 764
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
765 766 767
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                         |
G
Gloria 已提交
768 769 770

**Error code**

G
Gloria 已提交
771
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
772 773 774 775

| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
776 777 778 779

**Example**

```js
G
Gloria 已提交
780
try {
781 782 783 784 785
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, function (data) {
        console.info('Scalar data: ' + data.scalar);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
786
}
W
wusongqing 已提交
787 788
```

G
Gloria 已提交
789
###  WEAR_DETECTION<sup>9+</sup>
W
wusongqing 已提交
790

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

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

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

W
wusongqing 已提交
798
**Parameters**
Z
zengyawen 已提交
799

800 801 802 803 804
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.            |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **WearDetectionResponse** object.|
| options  | [Options](#options)                                          | No  | Data reporting frequency. The default value is 200,000,000 ns.                        |
Z
zengyawen 已提交
805

G
Gloria 已提交
806
**Error code**
Z
zengyawen 已提交
807

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

G
Gloria 已提交
810 811 812
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
813

W
wusongqing 已提交
814
**Example**
G
Gloria 已提交
815 816 817

```js
try {
818 819 820 821 822
    sensor.on(sensor.SensorId.WEAR_DETECTION, function (data) {
        console.info('Wear status: ' + data.value);
    }, { interval: 10000000 });
} catch (err) {
    console.error('On fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
823 824
}
```
Z
zengyawen 已提交
825

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

G
Gloria 已提交
828
### ACCELEROMETER<sup>9+</sup>
Z
zengyawen 已提交
829

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

832
Obtains data of the acceleration sensor once.
Z
zengyawen 已提交
833

G
Gloria 已提交
834
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
835 836 837

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

W
wusongqing 已提交
838
**Parameters**
Z
zengyawen 已提交
839

840 841 842 843
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.             |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerResponse** object.|
W
wusongqing 已提交
844

G
Gloria 已提交
845
**Error code**
W
wusongqing 已提交
846

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

G
Gloria 已提交
849 850 851
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
852

W
wusongqing 已提交
853
**Example**
G
Gloria 已提交
854 855 856

```js
try {
857 858 859 860 861 862 863
    sensor.once(sensor.SensorId.ACCELEROMETER, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
864 865
}
```
Z
zengyawen 已提交
866

G
Gloria 已提交
867
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>
W
wusongqing 已提交
868

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

871
Obtains data of the uncalibrated acceleration sensor once.
W
wusongqing 已提交
872

G
Gloria 已提交
873
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
874 875 876 877 878

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

**Parameters**

G
Gloria 已提交
879 880
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
881 882
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.|
Z
zengyawen 已提交
883

G
Gloria 已提交
884
**Error code**
W
wusongqing 已提交
885

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

G
Gloria 已提交
888 889 890
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
891

W
wusongqing 已提交
892
**Example**
G
Gloria 已提交
893 894 895

```js
try {
896 897 898 899 900 901 902 903 904 905
    sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, function (data) {
        console.info('X-coordinate component: ' + data.x);
        console.info('Y-coordinate component: ' + data.y);
        console.info('Z-coordinate component: ' + data.z);
        console.info('X-coordinate bias: ' + data.biasX);
        console.info('Y-coordinate bias: ' + data.biasY);
        console.info('Z-coordinate bias: ' + data.biasZ);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
906 907
}
```
W
wusongqing 已提交
908

G
Gloria 已提交
909
### AMBIENT_LIGHT<sup>9+</sup>
W
wusongqing 已提交
910

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

913
Obtains data of the ambient light sensor once.
W
wusongqing 已提交
914

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

W
wusongqing 已提交
917
**Parameters**
G
Gloria 已提交
918

919 920 921 922
| Name  | Type                                           | Mandatory| Description                                               |
| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- |
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.     |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LightResponse** object.|
G
Gloria 已提交
923 924 925

**Error code**

G
Gloria 已提交
926
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
927 928 929 930

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

W
wusongqing 已提交
932
**Example**
W
wusongqing 已提交
933

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

G
Gloria 已提交
944
### AMBIENT_TEMPERATURE<sup>9+</sup>
W
wusongqing 已提交
945

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

948
Obtains data of the temperature sensor once.
W
wusongqing 已提交
949 950 951

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

W
wusongqing 已提交
952
**Parameters**
G
Gloria 已提交
953 954 955

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
956 957
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes  | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.|
G
Gloria 已提交
958 959 960

**Error code**

G
Gloria 已提交
961
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
962 963 964 965

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

W
wusongqing 已提交
967
**Example**
Z
zengyawen 已提交
968

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

G
Gloria 已提交
979
### BAROMETER<sup>9+</sup>
Z
zengyawen 已提交
980

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

983
Obtains data of the barometer sensor once.
W
wusongqing 已提交
984 985 986

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

W
wusongqing 已提交
987
**Parameters**
W
wusongqing 已提交
988

989 990 991 992
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.             |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **BarometerResponse** object.|
Z
zengyawen 已提交
993

G
Gloria 已提交
994
**Error code**
Z
zengyawen 已提交
995

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

G
Gloria 已提交
998 999 1000
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
Z
zengyawen 已提交
1001

G
Gloria 已提交
1002
**Example**
W
wusongqing 已提交
1003

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

G
Gloria 已提交
1014
### GRAVITY<sup>9+</sup>
Z
zengyawen 已提交
1015

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

1018
Obtains data of the gravity sensor once.
W
wusongqing 已提交
1019 1020 1021

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

W
wusongqing 已提交
1022
**Parameters**
W
wusongqing 已提交
1023

1024 1025 1026 1027
| Name  | Type                                               | Mandatory| Description                                                 |
| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- |
| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.             |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GravityResponse** object.|
Z
zengyawen 已提交
1028

G
Gloria 已提交
1029
**Error code**
Z
zengyawen 已提交
1030

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

G
Gloria 已提交
1033 1034 1035
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1036

G
Gloria 已提交
1037
**Example**
W
wusongqing 已提交
1038

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

G
Gloria 已提交
1051
### GYROSCOPE<sup>9+</sup>
Z
zengyawen 已提交
1052

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

1055
Obtains to data of the gyroscope sensor once.
Z
zengyawen 已提交
1056

G
Gloria 已提交
1057
**Required permissions**: ohos.permission.GYROSCOPE
Z
zengyawen 已提交
1058

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

W
wusongqing 已提交
1061
**Parameters**
W
wusongqing 已提交
1062

1063 1064 1065 1066
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.             |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeResponse** object.|
Z
zengyawen 已提交
1067

G
Gloria 已提交
1068
**Error code**
Z
zengyawen 已提交
1069

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

G
Gloria 已提交
1072 1073 1074
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
Z
zengyawen 已提交
1075

G
Gloria 已提交
1076
**Example**
W
wusongqing 已提交
1077

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

G
Gloria 已提交
1090
### GYROSCOPE_UNCALIBRATED<sup>9+</sup>
Z
zengyawen 已提交
1091

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

1094
Obtains data of the uncalibrated gyroscope sensor once.
Z
zengyawen 已提交
1095

G
Gloria 已提交
1096
**Required permissions**: ohos.permission.GYROSCOPE
Z
zengyawen 已提交
1097

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

W
wusongqing 已提交
1100
**Parameters**
W
wusongqing 已提交
1101

G
Gloria 已提交
1102 1103
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1104 1105
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.|
W
wusongqing 已提交
1106

G
Gloria 已提交
1107
**Error code**
W
wusongqing 已提交
1108

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

G
Gloria 已提交
1111 1112 1113
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1114

W
wusongqing 已提交
1115
**Example**
W
wusongqing 已提交
1116

G
Gloria 已提交
1117 1118
```js
try {
1119
    sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, function (data) {
G
Gloria 已提交
1120 1121 1122 1123 1124 1125
        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);
1126 1127 1128
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
1129 1130 1131 1132
}
```

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

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

1136
Obtains data of the Hall effect sensor once.
W
wusongqing 已提交
1137 1138 1139

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

W
wusongqing 已提交
1140
**Parameters**
W
wusongqing 已提交
1141

1142 1143 1144 1145
| Name  | Type                                         | Mandatory| Description                                              |
| -------- | --------------------------------------------- | ---- | -------------------------------------------------- |
| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.             |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HallResponse** object.|
W
wusongqing 已提交
1146

G
Gloria 已提交
1147
**Error code**
W
wusongqing 已提交
1148

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

G
Gloria 已提交
1151 1152 1153
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1154

G
Gloria 已提交
1155
**Example**
W
wusongqing 已提交
1156

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

G
Gloria 已提交
1167
### HEART_RATE<sup>9+</sup>
W
wusongqing 已提交
1168

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

1171
Obtains data of the heart rate sensor once.
W
wusongqing 已提交
1172

G
Gloria 已提交
1173
**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
1174 1175 1176

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

W
wusongqing 已提交
1177
**Parameters**
W
wusongqing 已提交
1178

1179 1180 1181 1182
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.            |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HeartRateResponse** object.|
W
wusongqing 已提交
1183

G
Gloria 已提交
1184
**Error code**
W
wusongqing 已提交
1185

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

G
Gloria 已提交
1188 1189 1190
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1191

W
wusongqing 已提交
1192
**Example**
W
wusongqing 已提交
1193

G
Gloria 已提交
1194 1195
```js
try {
1196
    sensor.once(sensor.SensorId.HEART_RATE, function (data) {
G
Gloria 已提交
1197
        console.info('Heart rate: ' + data.heartRate);
1198 1199 1200
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
1201 1202
}
```
W
wusongqing 已提交
1203

G
Gloria 已提交
1204
### HUMIDITY<sup>9+</sup>
W
wusongqing 已提交
1205

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

1208
Obtains data of the humidity sensor once.
W
wusongqing 已提交
1209 1210 1211

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

W
wusongqing 已提交
1212
**Parameters**
W
wusongqing 已提交
1213

1214 1215 1216 1217
| Name  | Type                                                 | Mandatory| Description                                                  |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.             |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **HumidityResponse** object.|
W
wusongqing 已提交
1218

G
Gloria 已提交
1219
**Error code**
W
wusongqing 已提交
1220

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

G
Gloria 已提交
1223 1224 1225
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1226

W
wusongqing 已提交
1227
**Example**
W
wusongqing 已提交
1228

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

G
Gloria 已提交
1239
### LINEAR_ACCELEROMETER<sup>9+</sup>
W
wusongqing 已提交
1240

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

1243
Obtains data of the linear acceleration sensor once.
W
wusongqing 已提交
1244

G
Gloria 已提交
1245
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1246 1247 1248

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

W
wusongqing 已提交
1249
**Parameters**
G
Gloria 已提交
1250 1251 1252

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1253 1254
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**.       |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.|
G
Gloria 已提交
1255 1256 1257

**Error code**

G
Gloria 已提交
1258
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1259 1260 1261 1262

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

W
wusongqing 已提交
1264
**Example**
W
wusongqing 已提交
1265

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

G
Gloria 已提交
1278
### MAGNETIC_FIELD<sup>9+</sup>
W
wusongqing 已提交
1279

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

1282
Obtains data of the magnetic field sensor once.
W
wusongqing 已提交
1283 1284 1285 1286 1287

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

**Parameters**

1288 1289 1290 1291
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.            |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.|
W
wusongqing 已提交
1292

G
Gloria 已提交
1293
**Error code**
W
wusongqing 已提交
1294

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

G
Gloria 已提交
1297 1298 1299
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1300

W
wusongqing 已提交
1301
**Example**
W
wusongqing 已提交
1302

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

G
Gloria 已提交
1315
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup>
W
wusongqing 已提交
1316

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

1319
Obtains data of the uncalibrated magnetic field sensor once.
W
wusongqing 已提交
1320 1321 1322

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

W
wusongqing 已提交
1323
**Parameters**
W
wusongqing 已提交
1324

G
Gloria 已提交
1325 1326
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1327 1328
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.|
G
Gloria 已提交
1329 1330 1331

**Error code**

G
Gloria 已提交
1332
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1333 1334 1335 1336

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

W
wusongqing 已提交
1338
**Example**
W
wusongqing 已提交
1339

W
wusongqing 已提交
1340
```js
G
Gloria 已提交
1341
try {
1342
    sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, function (data) {
G
Gloria 已提交
1343 1344 1345 1346 1347 1348
        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);
1349 1350 1351
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1352 1353 1354
}
```

G
Gloria 已提交
1355
### ORIENTATION<sup>9+</sup>
W
wusongqing 已提交
1356

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

1359
Obtains data of the orientation sensor once.
W
wusongqing 已提交
1360 1361 1362

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

W
wusongqing 已提交
1363
**Parameters**
W
wusongqing 已提交
1364

1365 1366 1367 1368
| Name  | Type                                                       | Mandatory| Description                                                     |
| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- |
| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.             |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **OrientationResponse** object.|
G
Gloria 已提交
1369 1370 1371

**Error code**

G
Gloria 已提交
1372
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1373 1374 1375 1376

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

W
wusongqing 已提交
1378
**Example**
W
wusongqing 已提交
1379

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

G
Gloria 已提交
1392
### PEDOMETER<sup>9+</sup>
W
wusongqing 已提交
1393

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

1396
Obtains data of the pedometer sensor once.
G
Gloria 已提交
1397 1398

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1399 1400 1401

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

W
wusongqing 已提交
1402
**Parameters**
W
wusongqing 已提交
1403

1404 1405 1406 1407
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.             |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerResponse** object.|
W
wusongqing 已提交
1408

G
Gloria 已提交
1409
**Error code**
W
wusongqing 已提交
1410

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

G
Gloria 已提交
1413 1414 1415
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
1416

W
wusongqing 已提交
1417
**Example**
W
wusongqing 已提交
1418

W
wusongqing 已提交
1419
```js
G
Gloria 已提交
1420
try {
1421 1422 1423 1424 1425
    sensor.once(sensor.SensorId.PEDOMETER, function (data) {
        console.info('Step count: ' + data.steps);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1426 1427 1428
}
```

G
Gloria 已提交
1429
### PEDOMETER_DETECTION<sup>9+</sup>
W
wusongqing 已提交
1430

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

1433
Obtains data of the pedometer sensor once.
G
Gloria 已提交
1434 1435

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1436 1437 1438

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

W
wusongqing 已提交
1439
**Parameters**
W
wusongqing 已提交
1440

G
Gloria 已提交
1441 1442
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1443 1444
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.|
G
Gloria 已提交
1445 1446 1447

**Error code**

G
Gloria 已提交
1448
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1449 1450 1451 1452

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

W
wusongqing 已提交
1454
**Example**
W
wusongqing 已提交
1455

W
wusongqing 已提交
1456
```js
G
Gloria 已提交
1457
try {
1458
    sensor.once(sensor.SensorId.PEDOMETER_DETECTION, function (data) {
G
Gloria 已提交
1459
        console.info('Scalar data: ' + data.scalar);
1460 1461 1462
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1463 1464 1465
}
```

G
Gloria 已提交
1466
### PROXIMITY<sup>9+</sup>
W
wusongqing 已提交
1467

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

1470
Obtains data of the proximity sensor once.
W
wusongqing 已提交
1471 1472 1473

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

W
wusongqing 已提交
1474
**Parameters**
W
wusongqing 已提交
1475

1476 1477 1478 1479
| Name  | Type                                                   | Mandatory| Description                                                   |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- |
| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.             |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **ProximityResponse** object.|
G
Gloria 已提交
1480 1481 1482

**Error code**

G
Gloria 已提交
1483
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1484 1485 1486 1487

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

W
wusongqing 已提交
1489
**Example**
W
wusongqing 已提交
1490

W
wusongqing 已提交
1491
```js
G
Gloria 已提交
1492
try {
1493 1494 1495 1496 1497
    sensor.once(sensor.SensorId.PROXIMITY, function (data) {
        console.info('Distance: ' + data.distance);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1498 1499 1500
}
```

G
Gloria 已提交
1501
### ROTATION_VECTOR<sup>9+</sup>
W
wusongqing 已提交
1502

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

1505
Obtains data of the rotation vector sensor once.
W
wusongqing 已提交
1506 1507 1508

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

W
wusongqing 已提交
1509
**Parameters**
W
wusongqing 已提交
1510

G
Gloria 已提交
1511 1512
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1513 1514
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **RotationVectorResponse** object.|
G
Gloria 已提交
1515 1516 1517

**Error code**

G
Gloria 已提交
1518
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1519 1520 1521 1522

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

W
wusongqing 已提交
1524
**Example**
W
wusongqing 已提交
1525

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

G
Gloria 已提交
1539
### SIGNIFICANT_MOTION<sup>9+</sup>
W
wusongqing 已提交
1540

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

1543
Obtains data of the significant motion sensor once.
W
wusongqing 已提交
1544 1545 1546

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

W
wusongqing 已提交
1547
**Parameters**
W
wusongqing 已提交
1548

G
Gloria 已提交
1549 1550
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1551 1552
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.|
G
Gloria 已提交
1553 1554 1555

**Error code**

G
Gloria 已提交
1556
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1557 1558 1559 1560

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

W
wusongqing 已提交
1562
**Example**
W
wusongqing 已提交
1563

W
wusongqing 已提交
1564
```js
G
Gloria 已提交
1565
try {
1566 1567 1568 1569 1570
    sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, function (data) {
        console.info('Scalar data: ' + data.scalar);
    });
} catch (err) {
    console.error('Once fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1571 1572 1573
}
```

G
Gloria 已提交
1574
### WEAR_DETECTION<sup>9+</sup>
W
wusongqing 已提交
1575

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

1578
Obtains data of the wear detection sensor once.
W
wusongqing 已提交
1579 1580 1581

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

W
wusongqing 已提交
1582
**Parameters**
W
wusongqing 已提交
1583

1584 1585 1586 1587
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- |
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.            |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes  | Callback used to report the sensor data, which is a **WearDetectionResponse** object.|
G
Gloria 已提交
1588 1589 1590

**Error code**

G
Gloria 已提交
1591
For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md).
G
Gloria 已提交
1592 1593 1594 1595

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

W
wusongqing 已提交
1597
**Example**
W
wusongqing 已提交
1598

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

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

G
Gloria 已提交
1611
### ACCELEROMETER<sup>9+</sup> 
W
wusongqing 已提交
1612

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

G
Gloria 已提交
1615
Unsubscribes from data of the acceleration sensor.
W
wusongqing 已提交
1616

G
Gloria 已提交
1617
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1618 1619 1620

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

W
wusongqing 已提交
1621
**Parameters**
W
wusongqing 已提交
1622

G
Gloria 已提交
1623 1624
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1625 1626
| type     | [SensorId](#sensorid9).ACCELEROMETER                         | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**.              |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1627

W
wusongqing 已提交
1628
**Example**
W
wusongqing 已提交
1629

W
wusongqing 已提交
1630
```js
1631 1632 1633 1634 1635 1636
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1637
try {
1638 1639 1640 1641 1642 1643 1644 1645
    sensor.on(sensor.SensorId.ACCELEROMETER, callback1);
    sensor.on(sensor.SensorId.ACCELEROMETER, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.ACCELEROMETER, callback1);
    // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER type.
    sensor.off(sensor.SensorId.ACCELEROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1646 1647 1648
}
```

G
Gloria 已提交
1649
### ACCELEROMETER_UNCALIBRATED<sup>9+</sup>  
W
wusongqing 已提交
1650

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

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

G
Gloria 已提交
1655
**Required permissions**: ohos.permission.ACCELEROMETER
W
wusongqing 已提交
1656 1657 1658 1659 1660

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

**Parameters**

G
Gloria 已提交
1661 1662
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1663 1664
| type     | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED            | Yes  | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1665 1666 1667 1668

**Example**

```js
1669 1670 1671 1672 1673 1674
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1675
try {
1676 1677 1678 1679 1680 1681 1682 1683
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1);
    // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER_UNCALIBRATED type.
    sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1684 1685 1686
}
```

G
Gloria 已提交
1687
### AMBIENT_LIGHT<sup>9+</sup> 
W
wusongqing 已提交
1688

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

G
Gloria 已提交
1691
Unsubscribes from data of the ambient light sensor.
W
wusongqing 已提交
1692 1693 1694

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

W
wusongqing 已提交
1695
**Parameters**
W
wusongqing 已提交
1696

G
Gloria 已提交
1697 1698
| Name  | Type                                           | Mandatory| Description                                                        |
| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
1699 1700
| type     | [SensorId](#sensorid9).AMBIENT_LIGHT            | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**.              |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1701

W
wusongqing 已提交
1702
**Example**
W
wusongqing 已提交
1703

W
wusongqing 已提交
1704
```js
1705 1706 1707 1708 1709 1710
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1711
try {
1712 1713 1714 1715 1716 1717 1718 1719
    sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1);
    sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1);
    // Unsubscribe from all callbacks of the SensorId.AMBIENT_LIGHT type.
    sensor.off(sensor.SensorId.AMBIENT_LIGHT);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1720 1721 1722
}
```

G
Gloria 已提交
1723
### AMBIENT_TEMPERATURE<sup>9+</sup> 
Z
zengyawen 已提交
1724

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

G
Gloria 已提交
1727
Unsubscribes from data of the ambient temperature sensor.
W
wusongqing 已提交
1728 1729

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

W
wusongqing 已提交
1731
**Parameters**
W
wusongqing 已提交
1732

G
Gloria 已提交
1733 1734
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1735 1736
| type     | [SensorId](#sensorid9).AMBIENT_TEMPERATURE                   | Yes  | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**.        |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1737

W
wusongqing 已提交
1738
**Example**
Z
zengyawen 已提交
1739

W
wusongqing 已提交
1740
```js
1741 1742 1743 1744 1745 1746
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1747
try {
1748 1749 1750 1751 1752 1753 1754 1755
    sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
    sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1);
    // Unsubscribe from all callbacks of the SensorId.AMBIENT_TEMPERATURE type.
    sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1756 1757
}
```
Z
zengyawen 已提交
1758

G
Gloria 已提交
1759
### BAROMETER<sup>9+</sup>  
W
wusongqing 已提交
1760

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

G
Gloria 已提交
1763
Unsubscribes from data of the barometer sensor.
W
wusongqing 已提交
1764 1765 1766 1767 1768

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

**Parameters**

G
Gloria 已提交
1769 1770
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1771 1772
| type     | [SensorId](#sensorid9).BAROMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.BAROMETER**.                  |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1773 1774 1775 1776

**Example**

```js
1777 1778 1779 1780 1781 1782
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1783
try {
1784 1785 1786 1787 1788 1789 1790 1791
    sensor.on(sensor.SensorId.BAROMETER, callback1);
    sensor.on(sensor.SensorId.BAROMETER, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.BAROMETER, callback1);
    // Unsubscribe from all callbacks of the SensorId.BAROMETER type.
    sensor.off(sensor.SensorId.BAROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1792 1793 1794
}
```

G
Gloria 已提交
1795
### GRAVITY<sup>9+</sup> 
Z
zengyawen 已提交
1796

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

G
Gloria 已提交
1799
Unsubscribes from data of the gravity sensor.
W
wusongqing 已提交
1800 1801

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

W
wusongqing 已提交
1803
**Parameters**
W
wusongqing 已提交
1804

G
Gloria 已提交
1805 1806
| Name  | Type                                               | Mandatory| Description                                                        |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
1807 1808
| type     | [SensorId](#sensorid9).GRAVITY                      | Yes  | Sensor type. The value is fixed at **SensorId.GRAVITY**.                    |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1809

W
wusongqing 已提交
1810
**Example**
W
wusongqing 已提交
1811

W
wusongqing 已提交
1812
```js
1813 1814 1815 1816 1817 1818
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1819
try {
1820 1821 1822 1823 1824 1825 1826 1827
    sensor.on(sensor.SensorId.GRAVITY, callback1);
    sensor.on(sensor.SensorId.GRAVITY, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.GRAVITY, callback1);
    // Unsubscribe from all callbacks of the SensorId.GRAVITY type.
    sensor.off(sensor.SensorId.GRAVITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1828 1829
}
```
W
wusongqing 已提交
1830

G
Gloria 已提交
1831
### GYROSCOPE<sup>9+</sup> 
W
wusongqing 已提交
1832

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

G
Gloria 已提交
1835 1836 1837
Unsubscribes from data of the gyroscope sensor.

**Required permissions**: ohos.permission.GYROSCOPE
W
wusongqing 已提交
1838 1839

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

W
wusongqing 已提交
1841
**Parameters**
W
wusongqing 已提交
1842

G
Gloria 已提交
1843 1844
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1845 1846
| type     | [SensorId](#sensorid9).GYROSCOPE                        | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE**.                  |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1847

W
wusongqing 已提交
1848
**Example**
Z
zengyawen 已提交
1849

W
wusongqing 已提交
1850
```js
1851 1852 1853 1854 1855 1856
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1857
try {
1858 1859 1860 1861 1862 1863 1864 1865
    sensor.on(sensor.SensorId.GYROSCOPE, callback1);
    sensor.on(sensor.SensorId.GYROSCOPE, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.GYROSCOPE, callback1);
    // Unsubscribe from all callbacks of the SensorId.GYROSCOPE type.
    sensor.off(sensor.SensorId.GYROSCOPE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1866 1867 1868
}
```

G
Gloria 已提交
1869
### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 
Z
zengyawen 已提交
1870

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

G
Gloria 已提交
1873 1874 1875
 Unsubscribes from data of the uncalibrated gyroscope sensor.

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

W
wusongqing 已提交
1877
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1878

W
wusongqing 已提交
1879
**Parameters**
W
wusongqing 已提交
1880

G
Gloria 已提交
1881 1882
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1883 1884
| type     | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED                | Yes  | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**.     |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1885

W
wusongqing 已提交
1886
**Example**
Z
zengyawen 已提交
1887

W
wusongqing 已提交
1888
```js
1889 1890 1891 1892 1893 1894
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1895
try {
1896 1897 1898 1899 1900 1901 1902 1903
    sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1);
    // Unsubscribe from all callbacks of the SensorId.GYROSCOPE_UNCALIBRATED type.
    sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1904 1905
}
```
Z
zengyawen 已提交
1906

G
Gloria 已提交
1907
### HALL<sup>9+</sup> 
Z
zengyawen 已提交
1908

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

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

W
wusongqing 已提交
1913
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1914

W
wusongqing 已提交
1915
**Parameters**
W
wusongqing 已提交
1916

G
Gloria 已提交
1917 1918
| Name  | Type                                         | Mandatory| Description                                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
1919 1920
| type     | [SensorId](#sensorid9).HALL                   | Yes  | Sensor type. The value is fixed at **SensorId.HALL**.                       |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1921

W
wusongqing 已提交
1922
**Example**
W
wusongqing 已提交
1923

W
wusongqing 已提交
1924
```js
1925 1926 1927 1928 1929 1930
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1931
try {
1932 1933 1934 1935 1936 1937 1938 1939
    sensor.on(sensor.SensorId.HALL, callback1);
    sensor.on(sensor.SensorId.HALL, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.HALL, callback1);
    // Unsubscribe from all callbacks of the SensorId.HALL type.
    sensor.off(sensor.SensorId.HALL);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1940 1941 1942
}
```

G
Gloria 已提交
1943
### HEART_RATE<sup>9+</sup> 
W
wusongqing 已提交
1944

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

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

G
Gloria 已提交
1949
**Required permissions**: ohos.permission.READ_HEALTH_DATA
W
wusongqing 已提交
1950

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

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

G
Gloria 已提交
1955 1956
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1957 1958
| type     | [SensorId](#sensorid9).HEART_RATE                       | Yes  | Sensor type. The value is fixed at **SensorId.HEART_RATE**.                 |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1959

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

W
wusongqing 已提交
1962
```js
1963 1964 1965 1966 1967 1968
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
1969
try {
1970 1971 1972 1973 1974 1975 1976 1977
    sensor.on(sensor.SensorId.HEART_RATE, callback1);
    sensor.on(sensor.SensorId.HEART_RATE, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.HEART_RATE, callback1);
    // Unsubscribe from all callbacks of the SensorId.HEART_RATE type.
    sensor.off(sensor.SensorId.HEART_RATE);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
1978 1979 1980
}
```

G
Gloria 已提交
1981
### HUMIDITY<sup>9+</sup> 
Z
zengyawen 已提交
1982

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

G
Gloria 已提交
1985
Unsubscribes from data of the humidity sensor.
Z
zengyawen 已提交
1986

W
wusongqing 已提交
1987
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1988

W
wusongqing 已提交
1989
**Parameters**
W
wusongqing 已提交
1990

G
Gloria 已提交
1991 1992
| Name  | Type                                                 | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
1993 1994
| type     | [SensorId](#sensorid9).HUMIDITY                       | Yes  | Sensor type. The value is fixed at **SensorId.HUMIDITY**.                   |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
1995

W
wusongqing 已提交
1996
**Example**
Z
zengyawen 已提交
1997

W
wusongqing 已提交
1998
```js
1999 2000 2001 2002 2003 2004
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2005
try {
2006 2007 2008 2009 2010 2011 2012 2013
    sensor.on(sensor.SensorId.HUMIDITY, callback1);
    sensor.on(sensor.SensorId.HUMIDITY, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.HUMIDITY, callback1);
    // Unsubscribe from all callbacks of the SensorId.HUMIDITY type.
    sensor.off(sensor.SensorId.HUMIDITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2014 2015 2016
}
```

G
Gloria 已提交
2017
### LINEAR_ACCELEROMETER<sup>9+</sup> 
Z
zengyawen 已提交
2018

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

G
Gloria 已提交
2021 2022 2023
Unsubscribes from data of the linear acceleration sensor.

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

W
wusongqing 已提交
2025
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
2026

W
wusongqing 已提交
2027
**Parameters**
W
wusongqing 已提交
2028

G
Gloria 已提交
2029 2030
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2031 2032
| type     | [SensorId](#sensorid9).LINEAR_ACCELEROMETER                  | Yes  | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELERATION**.        |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2033

W
wusongqing 已提交
2034
**Example**
Z
zengyawen 已提交
2035

W
wusongqing 已提交
2036
```js
2037 2038 2039 2040 2041 2042
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2043
try {
2044 2045 2046 2047 2048 2049 2050 2051
    sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
    sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1);
    // Unsubscribe from all callbacks of the SensorId.LINEAR_ACCELEROMETER type.
    sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2052 2053
}
```
Z
zengyawen 已提交
2054

G
Gloria 已提交
2055
### MAGNETIC_FIELD<sup>9+</sup> 
Z
zengyawen 已提交
2056

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

G
Gloria 已提交
2059
Unsubscribes from data of the magnetic field sensor.
W
wusongqing 已提交
2060 2061

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

W
wusongqing 已提交
2063
**Parameters**
W
wusongqing 已提交
2064

G
Gloria 已提交
2065 2066
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2067 2068
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD                        | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**.             |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2069

W
wusongqing 已提交
2070
**Example**
Z
zengyawen 已提交
2071

W
wusongqing 已提交
2072
```js
2073 2074 2075 2076 2077 2078
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2079
try {
2080 2081 2082 2083 2084 2085 2086 2087
    sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1);
    sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1);
    // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD type.
    sensor.off(sensor.SensorId.MAGNETIC_FIELD);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2088 2089
}
```
Z
zengyawen 已提交
2090

G
Gloria 已提交
2091
### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 
Z
zengyawen 已提交
2092

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

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

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

W
wusongqing 已提交
2099
**Parameters**
W
wusongqing 已提交
2100

G
Gloria 已提交
2101 2102
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2103 2104
| type     | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED           | Yes  | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2105

W
wusongqing 已提交
2106
**Example**
W
wusongqing 已提交
2107

W
wusongqing 已提交
2108
```js
2109 2110 2111 2112 2113 2114
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2115
try {
2116 2117 2118 2119 2120 2121 2122 2123
    sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
    sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1);
    // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD_UNCALIBRATED type.
    sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
W
wusongqing 已提交
2124 2125
}
```
W
wusongqing 已提交
2126

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

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

G
Gloria 已提交
2131
Unsubscribes from data of the orientation sensor.
W
wusongqing 已提交
2132 2133

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

W
wusongqing 已提交
2135
**Parameters**
W
wusongqing 已提交
2136

G
Gloria 已提交
2137 2138
| Name  | Type                                                       | Mandatory| Description                                                        |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2139 2140
| type     | [SensorId](#sensorid9).ORIENTATION                          | Yes  | Sensor type. The value is fixed at **SensorId.ORIENTATION**.                |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2141

W
wusongqing 已提交
2142
**Example**
W
wusongqing 已提交
2143

W
wusongqing 已提交
2144
```js
2145 2146 2147 2148 2149 2150
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2151
try {
2152 2153 2154 2155 2156 2157 2158 2159
    sensor.on(sensor.SensorId.ORIENTATION, callback1);
    sensor.on(sensor.SensorId.ORIENTATION, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.ORIENTATION, callback1);
    // Unsubscribe from all callbacks of the SensorId.ORIENTATION type.
    sensor.off(sensor.SensorId.ORIENTATION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2160
}
W
wusongqing 已提交
2161
```
W
wusongqing 已提交
2162

G
Gloria 已提交
2163
### PEDOMETER<sup>9+</sup>
W
wusongqing 已提交
2164

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

G
Gloria 已提交
2167
Unsubscribes from data of the pedometer sensor.
W
wusongqing 已提交
2168

G
Gloria 已提交
2169
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
2170

G
Gloria 已提交
2171
**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2172

G
Gloria 已提交
2173
**Parameters**
W
wusongqing 已提交
2174

G
Gloria 已提交
2175 2176
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2177 2178
| type     | [SensorId](#sensorid9).PEDOMETER                        | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER**.                  |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2179

W
wusongqing 已提交
2180
**Example**
W
wusongqing 已提交
2181

W
wusongqing 已提交
2182
```js
2183 2184 2185 2186 2187 2188
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2189
try {
2190 2191 2192 2193 2194 2195 2196 2197
    sensor.on(sensor.SensorId.PEDOMETER, callback1);
    sensor.on(sensor.SensorId.PEDOMETER, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.PEDOMETER, callback1);
    // Unsubscribe from all callbacks of the SensorId.PEDOMETER type.
    sensor.off(sensor.SensorId.PEDOMETER);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2198
}
W
wusongqing 已提交
2199
```
W
wusongqing 已提交
2200

G
Gloria 已提交
2201
### PEDOMETER_DETECTION<sup>9+</sup> 
W
wusongqing 已提交
2202

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

G
Gloria 已提交
2205 2206 2207
Unsubscribes from data of the pedometer detection sensor.

**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
2208 2209

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

W
wusongqing 已提交
2211
**Parameters**
G
Gloria 已提交
2212 2213 2214

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2215 2216
| type     | [SensorId](#sensorid9).PEDOMETER_DETECTION                   | Yes  | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**.        |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2217

W
wusongqing 已提交
2218
**Example**
G
Gloria 已提交
2219

W
wusongqing 已提交
2220
```js
2221 2222 2223 2224 2225 2226
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2227
try {
2228 2229 2230 2231 2232 2233 2234 2235
    sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1);
    sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1);
    // Unsubscribe from all callbacks of the SensorId.PEDOMETER_DETECTION type.
    sensor.off(sensor.SensorId.PEDOMETER_DETECTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2236
}
W
wusongqing 已提交
2237
```
W
wusongqing 已提交
2238

G
Gloria 已提交
2239
### PROXIMITY<sup>9+</sup>  
W
wusongqing 已提交
2240

G
Gloria 已提交
2241 2242 2243
off(type: SensorId.PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void

Unsubscribes from data of the proximity sensor.
W
wusongqing 已提交
2244 2245

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

W
wusongqing 已提交
2247
**Parameters**
Z
zengyawen 已提交
2248

G
Gloria 已提交
2249 2250
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2251 2252
| type     | [SensorId](#sensorid9).PROXIMITY                        | Yes  | Sensor type. The value is fixed at **SensorId.PROXIMITY**.                  |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
Z
zengyawen 已提交
2253

W
wusongqing 已提交
2254
**Example**
W
wusongqing 已提交
2255

G
Gloria 已提交
2256
```js
2257 2258 2259 2260 2261 2262
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2263
try {
2264 2265 2266 2267 2268 2269 2270 2271
    sensor.on(sensor.SensorId.PROXIMITY, callback1);
    sensor.on(sensor.SensorId.PROXIMITY, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.PROXIMITY, callback1);
    // Unsubscribe from all callbacks of the SensorId.PROXIMITY type.
    sensor.off(sensor.SensorId.PROXIMITY);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2272 2273 2274 2275
}
```

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

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

G
Gloria 已提交
2279
Unsubscribes from data of the rotation vector sensor.
W
wusongqing 已提交
2280 2281

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

W
wusongqing 已提交
2283
**Parameters**
W
wusongqing 已提交
2284

G
Gloria 已提交
2285 2286
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2287 2288
| type     | [SensorId](#sensorid9).ROTATION_VECTOR                       | Yes  | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**.            |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2289

W
wusongqing 已提交
2290
**Example**
W
wusongqing 已提交
2291

G
Gloria 已提交
2292
```js
2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
try {
    sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1);
    sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1);
    // Unsubscribe from all callbacks of the SensorId.ROTATION_VECTOR type.
    sensor.off(sensor.SensorId.ROTATION_VECTOR);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2308 2309
}
```
W
wusongqing 已提交
2310

G
Gloria 已提交
2311
### SIGNIFICANT_MOTION<sup>9+</sup> 
W
wusongqing 已提交
2312

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

G
Gloria 已提交
2315
Unsubscribes from data of the significant motion sensor.
W
wusongqing 已提交
2316 2317

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

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

G
Gloria 已提交
2321 2322
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2323 2324
| type     | [SensorId](#sensorid9).SIGNIFICANT_MOTION                    | Yes  | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**.         |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
W
wusongqing 已提交
2325

G
Gloria 已提交
2326
**Example**
W
wusongqing 已提交
2327

G
Gloria 已提交
2328
```js
2329 2330 2331 2332 2333 2334
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2335
try {
2336 2337 2338 2339 2340 2341 2342 2343
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
    sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1);
    // Unsubscribe from all callbacks of the SensorId.SIGNIFICANT_MOTION type.
    sensor.off(sensor.SensorId.SIGNIFICANT_MOTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2344 2345
}
```
W
wusongqing 已提交
2346

G
Gloria 已提交
2347
### WEAR_DETECTION<sup>9+</sup> 
W
wusongqing 已提交
2348

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

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

G
Gloria 已提交
2353
**System capability**: SystemCapability.Sensors.Sensor
W
wusongqing 已提交
2354

G
Gloria 已提交
2355
**Parameters**
W
wusongqing 已提交
2356

G
Gloria 已提交
2357 2358
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2359 2360
| type     | [SensorId](#sensorid9).WEAR_DETECTION                        | Yes  | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**.             |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | No  | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.|
G
Gloria 已提交
2361 2362 2363 2364

**Example**

```js
2365 2366 2367 2368 2369 2370
function callback1(data) {
    console.info('Callback1 data: ' + JSON.stringify(data));
}
function callback2(data) {
    console.info('Callback2 data: ' + JSON.stringify(data));
}
G
Gloria 已提交
2371
try {
2372 2373 2374 2375 2376 2377 2378 2379
    sensor.on(sensor.SensorId.WEAR_DETECTION, callback1);
    sensor.on(sensor.SensorId.WEAR_DETECTION, callback2);
    // Unsubscribe from callback1.
    sensor.off(sensor.SensorId.WEAR_DETECTION, callback1);
    // Unsubscribe from all callbacks of the SensorId.WEAR_DETECTION type.
    sensor.off(sensor.SensorId.WEAR_DETECTION);
} catch (err) {
    console.error('Off fail, errCode: ' + err.code + ' ,msg: ' + err.message);
G
Gloria 已提交
2380 2381 2382 2383 2384 2385 2386
}
```

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

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

2387
Obtains the geomagnetic field of a geographic location at a certain time. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2388 2389

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

W
wusongqing 已提交
2391
**Parameters**
W
wusongqing 已提交
2392

G
Gloria 已提交
2393 2394
| Name         | Type                                                        | Mandatory| Description                              |
| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
2395 2396
| locationOptions | [LocationOptions](#locationoptions)                          | Yes  | Geographic location, including the longitude, latitude, and altitude.                        |
| timeMillis      | number                                                       | Yes  | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.|
G
Gloria 已提交
2397 2398 2399 2400 2401 2402 2403 2404 2405
| 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 已提交
2406

W
wusongqing 已提交
2407
**Example**
W
wusongqing 已提交
2408

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

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

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

2433
Obtains the geomagnetic field of a geographic location at a certain time. This API uses a promise to return the result.
W
wusongqing 已提交
2434 2435

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

W
wusongqing 已提交
2437
**Parameters**
W
wusongqing 已提交
2438

G
Gloria 已提交
2439 2440
| Name         | Type                               | Mandatory| Description                              |
| --------------- | ----------------------------------- | ---- | ---------------------------------- |
2441 2442
| locationOptions | [LocationOptions](#locationoptions) | Yes  | Geographic location, including the longitude, latitude, and altitude.                        |
| timeMillis      | number                              | Yes  | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.|
W
wusongqing 已提交
2443

W
wusongqing 已提交
2444
**Return value**
W
wusongqing 已提交
2445

G
Gloria 已提交
2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456
| 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 已提交
2457

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

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

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

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

2483
Obtains the altitude based on the atmospheric pressure. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2484 2485

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

W
wusongqing 已提交
2487
**Parameters**
W
wusongqing 已提交
2488

G
Gloria 已提交
2489 2490 2491
| Name         | Type                       | Mandatory| Description                                 |
| --------------- | --------------------------- | ---- | ------------------------------------- |
| seaPressure     | number                      | Yes  | Sea-level atmospheric pressure, in hPa.        |
2492
| currentPressure | number                      | Yes  | Specified atmospheric pressure, in hPa.|
G
Gloria 已提交
2493
| callback        | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the altitude, in meters.   |
W
wusongqing 已提交
2494

G
Gloria 已提交
2495
**Error code**
W
wusongqing 已提交
2496

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

G
Gloria 已提交
2499 2500 2501
| Error Code ID| Error Message          |
| -------- | ------------------ |
| 14500101 | Service exception. |
W
wusongqing 已提交
2502

G
Gloria 已提交
2503
**Example**
W
wusongqing 已提交
2504

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

G
Gloria 已提交
2521 2522 2523 2524
## sensor.getDeviceAltitude<sup>9+</sup> 

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

2525
Obtains the altitude based on the atmospheric pressure. This API uses a promise to return the result.
W
wusongqing 已提交
2526 2527

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

W
wusongqing 已提交
2529
**Parameters**
W
wusongqing 已提交
2530

G
Gloria 已提交
2531 2532 2533
| Name         | Type  | Mandatory| Description                                 |
| --------------- | ------ | ---- | ------------------------------------- |
| seaPressure     | number | Yes  | Sea-level atmospheric pressure, in hPa.        |
2534
| currentPressure | number | Yes  | Specified atmospheric pressure, in hPa.|
W
wusongqing 已提交
2535

W
wusongqing 已提交
2536
**Return value**
W
wusongqing 已提交
2537

G
Gloria 已提交
2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
| 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 已提交
2549

W
wusongqing 已提交
2550
**Example**
W
wusongqing 已提交
2551

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

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

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

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

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

W
wusongqing 已提交
2575
**Parameters**
W
wusongqing 已提交
2576

G
Gloria 已提交
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
| 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 已提交
2589

W
wusongqing 已提交
2590
**Example**
W
wusongqing 已提交
2591

G
Gloria 已提交
2592 2593
```js
try {
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
    // inclinationMatrix can be 3*3 or 4*4.
    let inclinationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ]
    sensor.getInclination(inclinationMatrix, function (err, data) {
        if (err) {
            console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('Inclination: ' + data);
    })
G
Gloria 已提交
2607
} catch (err) {
2608
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
2609 2610
}
```
W
wusongqing 已提交
2611

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

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

2616
Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.
W
wusongqing 已提交
2617 2618

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

W
wusongqing 已提交
2620
**Parameters**
W
wusongqing 已提交
2621

G
Gloria 已提交
2622 2623 2624
| Name           | Type               | Mandatory| Description          |
| ----------------- | ------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt; | Yes  | Inclination matrix.|
W
wusongqing 已提交
2625

W
wusongqing 已提交
2626
**Return value**
W
wusongqing 已提交
2627

G
Gloria 已提交
2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638
| 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 已提交
2639

W
wusongqing 已提交
2640
**Example**
W
wusongqing 已提交
2641

G
Gloria 已提交
2642 2643
```js
try {
2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655
    // inclinationMatrix can be 3*3 or 4*4.
    let inclinationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ]
    const promise = sensor.getInclination(inclinationMatrix);
    promise.then((data) => {
        console.info('Inclination: ' + data);
    }, (err) => {
        console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
    });
G
Gloria 已提交
2656
} catch (err) {
2657
    console.error('Get inclination failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
2658 2659
}
```
W
wusongqing 已提交
2660

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

G
Gloria 已提交
2663
 getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;,
G
Gloria 已提交
2664
        callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
W
wusongqing 已提交
2665

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

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

W
wusongqing 已提交
2670
**Parameters**
W
wusongqing 已提交
2671

G
Gloria 已提交
2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684
| 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 已提交
2685

W
wusongqing 已提交
2686
**Example**
W
wusongqing 已提交
2687

G
Gloria 已提交
2688 2689
```js
try {
2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712
    // The rotation matrix can be 3*3 or 4*4.
    let currentRotationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ];
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, function (err, data) {
        if (err) {
            console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        if (data.length < 3) {
            console.error("Get angle variation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    })
G
Gloria 已提交
2713
} catch (err) {
2714
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
2715 2716
}
```
W
wusongqing 已提交
2717

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

G
Gloria 已提交
2720
getAngleVariation(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt; 
W
wusongqing 已提交
2721

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

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

W
wusongqing 已提交
2726
**Parameters**
W
wusongqing 已提交
2727

G
Gloria 已提交
2728 2729 2730
| Name               | Type               | Mandatory| Description              |
| --------------------- | ------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt; | Yes  | Current rotation matrix.|
2731
| preRotationMatrix     | Array&lt;number&gt; | Yes  | The other rotation matrix.                 |
W
wusongqing 已提交
2732

W
wusongqing 已提交
2733
**Return value**
W
wusongqing 已提交
2734

G
Gloria 已提交
2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745
| 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 已提交
2746

W
wusongqing 已提交
2747
**Example**
W
wusongqing 已提交
2748

G
Gloria 已提交
2749 2750
```js
try {
2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772
    // The rotation matrix can be 3*3 or 4*4.
    let currentRotationMatrix = [
        1, 0, 0,
        0, 1, 0,
        0, 0, 1
    ];
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix);
    promise.then((data) => {
        if (data.length < 3) {
            console.error("Get angle variation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    }, (err) => {
        console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
    });
G
Gloria 已提交
2773
} catch (err) {
2774
    console.error('Get angle variation failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
2775 2776
}
```
W
wusongqing 已提交
2777

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

G
Gloria 已提交
2780
getRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
W
wusongqing 已提交
2781

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

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

W
wusongqing 已提交
2786
**Parameters**
W
wusongqing 已提交
2787

G
Gloria 已提交
2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799
| 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 已提交
2800

W
wusongqing 已提交
2801
**Example**
W
wusongqing 已提交
2802

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

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

G
Gloria 已提交
2822
getRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt; 
W
wusongqing 已提交
2823

G
Gloria 已提交
2824
Obtains the rotation matrix from a rotation vector. This API uses a promise to return the result.
W
wusongqing 已提交
2825 2826

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

W
wusongqing 已提交
2828
**Parameters**
W
wusongqing 已提交
2829

G
Gloria 已提交
2830 2831 2832
| Name        | Type               | Mandatory| Description          |
| -------------- | ------------------- | ---- | -------------- |
| rotationVector | Array&lt;number&gt; | Yes  | Rotation vector.|
W
wusongqing 已提交
2833

W
wusongqing 已提交
2834
**Return value**
W
wusongqing 已提交
2835

G
Gloria 已提交
2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846
| 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 已提交
2847

W
wusongqing 已提交
2848
**Example**
W
wusongqing 已提交
2849

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

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

G
Gloria 已提交
2868
transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions,
G
Gloria 已提交
2869
        callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
W
wusongqing 已提交
2870

2871
Transforms a rotation vector based on the coordinate system. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
2872

G
Gloria 已提交
2873 2874 2875 2876 2877 2878
**System capability**: SystemCapability.Sensors.Sensor

**Parameters**

| Name          | Type                                     | Mandatory| Description                  |
| ---------------- | ----------------------------------------- | ---- | ---------------------- |
G
Gloria 已提交
2879
| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector.        |
2880 2881
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Rotation vector to transform.      |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt;  | Yes  | Callback used to return the rotation vector after being transformed.|
G
Gloria 已提交
2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894

**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 {
2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906
    let rotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, function (err, data) {
        if (err) {
            console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + '] = ' + data[i]);
G
Gloria 已提交
2907 2908 2909
        }
    })
} catch (err) {
2910
    console.error('Transform rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
2911 2912 2913 2914 2915
}
```

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

G
Gloria 已提交
2916
transformRotationMatrix(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;
G
Gloria 已提交
2917

2918
Transforms a rotation vector based on the coordinate system. This API uses a promise to return the result.
G
Gloria 已提交
2919 2920 2921 2922 2923 2924 2925

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

**Parameters**

| Name          | Type                                     | Mandatory| Description            |
| ---------------- | ----------------------------------------- | ---- | ---------------- |
G
Gloria 已提交
2926
| inRotationVector | Array&lt;number&gt;                       | Yes  | Rotation vector.  |
2927
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes  | Rotation vector to transform.|
G
Gloria 已提交
2928 2929 2930 2931 2932

**Return value**

| Type                              | Description                  |
| ---------------------------------- | ---------------------- |
2933
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being transformed.|
G
Gloria 已提交
2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946

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

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

G
Gloria 已提交
2967
getQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void 
G
Gloria 已提交
2968 2969

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

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

W
wusongqing 已提交
2973
**Parameters**
W
wusongqing 已提交
2974

G
Gloria 已提交
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986
| 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 已提交
2987

W
wusongqing 已提交
2988
**Example**
W
wusongqing 已提交
2989

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

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

G
Gloria 已提交
3009
getQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
G
Gloria 已提交
3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024

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        |
| ---------------------------------- | ------------ |
3025
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
G
Gloria 已提交
3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038

**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 {
3039 3040 3041 3042 3043 3044 3045 3046 3047
    let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877];
    const promise = sensor.getQuaternion(rotationVector);
    promise.then((data) => {
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    }, (err) => {
        console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
    });
G
Gloria 已提交
3048
} catch (err) {
3049
    console.error('Get quaternion failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3050 3051 3052 3053 3054
}
```

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

G
Gloria 已提交
3055
getOrientation(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void 
G
Gloria 已提交
3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079

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 {
3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    sensor.getOrientation(preRotationMatrix, function (err, data) {
        if (err) {
            console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        if (data.length < 3) {
            console.error("Get orientation failed, length" + data.length);
        }
        console.info("Z: " + data[0]);
        console.info("X: " + data[1]);
        console.info("Y  : " + data[2]);
    })
G
Gloria 已提交
3097
} catch (err) {
3098
    console.error('Get orientation failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3099 3100
}
```
W
wusongqing 已提交
3101

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

G
Gloria 已提交
3104
getOrientation(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;
W
wusongqing 已提交
3105

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

G
Gloria 已提交
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133
**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 {
3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144
    let preRotationMatrix = [
        1, 0, 0,
        0, 0.87, -0.50,
        0, 0.50, 0.87
    ];
    const promise = sensor.getOrientation(preRotationMatrix);
    promise.then((data) => {
        for (var i = 0; i < data.length; i++) {
            console.info('data[' + i + ']: ' + data[i]);
        }
    }, (err) => {
G
Gloria 已提交
3145
        console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
3146 3147 3148
    });
} catch (err) {
    console.error('getOrientation failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179
}
```

## 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 {
3180 3181
    let gravity = [-0.27775216, 0.5351276, 9.788099];
    let geomagnetic = [210.87253, -78.6096, -111.44444];
G
Gloria 已提交
3182
    sensor.getRotationMatrix(gravity, geomagnetic, function (err, data) {
3183 3184 3185 3186 3187 3188
        if (err) {
            console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('RotationMatrix' + JSON.stringify(data));
    })
G
Gloria 已提交
3189
} catch (err) {
3190
    console.error('Get rotationMatrix failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3191 3192 3193 3194 3195
}
```

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

G
Gloria 已提交
3196
getRotationMatrix(gravity: Array&lt;number&gt;, geomagnetic: Array&lt;number&gt;): Promise&lt;RotationMatrixResponse&gt;
G
Gloria 已提交
3197 3198

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

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

W
wusongqing 已提交
3202
**Parameters**
W
wusongqing 已提交
3203

G
Gloria 已提交
3204 3205 3206 3207
| Name     | Type               | Mandatory| Description          |
| ----------- | ------------------- | ---- | -------------- |
| gravity     | Array&lt;number&gt; | Yes  | Gravity vector.|
| geomagnetic | Array&lt;number&gt; | Yes  | Geomagnetic vector.|
W
wusongqing 已提交
3208

W
wusongqing 已提交
3209
**Return value**
W
wusongqing 已提交
3210

G
Gloria 已提交
3211 3212
| Type                                                        | Description          |
| ------------------------------------------------------------ | -------------- |
W
wusongqing 已提交
3213
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
3214

G
Gloria 已提交
3215 3216 3217 3218 3219 3220 3221 3222
**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 已提交
3223
**Example**
W
wusongqing 已提交
3224

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

G
Gloria 已提交
3240
## sensor.getSensorList<sup>9+</sup>
G
Gloria 已提交
3241

G
Gloria 已提交
3242
getSensorList(callback: AsyncCallback&lt;Array&lt;Sensor&gt;&gt;): void
G
Gloria 已提交
3243 3244 3245 3246 3247 3248 3249

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 已提交
3250 3251
| Name  | Type                                          | Mandatory| Description            |
| -------- | ---------------------------------------------- | ---- | ---------------- |
G
Gloria 已提交
3252
| callback | AsyncCallback&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | Yes  | Callback used to return the sensor list.|
G
Gloria 已提交
3253 3254 3255 3256 3257 3258 3259 3260

**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 已提交
3261 3262 3263 3264

**Example**

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

G
Gloria 已提交
3280
## sensor.getSensorList<sup>9+</sup>
G
Gloria 已提交
3281

G
Gloria 已提交
3282
 getSensorList(): Promise&lt;Array&lt;Sensor&gt;&gt;
G
Gloria 已提交
3283 3284 3285 3286 3287 3288 3289

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 已提交
3290 3291
| Name | Type                                    | Mandatory| Description            |
| ------- | ---------------------------------------- | ---- | ---------------- |
G
Gloria 已提交
3292
| promise | Promise&lt;Array&lt;[Sensor](#sensor9)&gt;&gt; | Yes  | Promise used to return the sensor list.|
G
Gloria 已提交
3293 3294 3295 3296 3297 3298 3299 3300

**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 已提交
3301 3302 3303 3304

**Example**

```js
G
Gloria 已提交
3305 3306 3307
try {
    sensor.getSensorList().then((data) => {
        for (var i = 0; i < data.length; i++) {
3308
            console.info('data[' + i + ']: ' + JSON.stringify(data[i]));
G
Gloria 已提交
3309
        }
3310 3311
    }, (err) => {
        console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3312 3313
    });
} catch (err) {
3314
    console.error('Get sensorList failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3315
}
G
Gloria 已提交
3316 3317 3318 3319
```

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

G
Gloria 已提交
3320
getSingleSensor(type: SensorId, callback: AsyncCallback&lt;Sensor&gt;): void
G
Gloria 已提交
3321 3322 3323 3324 3325 3326 3327

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 已提交
3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339
| 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 已提交
3340 3341 3342 3343

**Example**

```js
G
Gloria 已提交
3344
try {
3345 3346 3347 3348 3349 3350
    sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err, data) => {
        if (err) {
            console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
            return;
        }
        console.info('Sensor: ' + JSON.stringify(data));
G
Gloria 已提交
3351 3352
    });
} catch (err) {
3353
    console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3354
}
G
Gloria 已提交
3355 3356 3357 3358
```

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

G
Gloria 已提交
3359
 getSingleSensor(type: SensorId): Promise&lt;Sensor&gt;
G
Gloria 已提交
3360 3361 3362 3363 3364 3365 3366

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 已提交
3367 3368 3369
| Name| Type                  | Mandatory| Description        |
| ------ | ---------------------- | ---- | ------------ |
| type   | [SensorId](#sensorid9) | Yes  | Sensor type.|
G
Gloria 已提交
3370 3371 3372

**Return value**

G
Gloria 已提交
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383
| 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 已提交
3384 3385 3386 3387

**Example**

```js
G
Gloria 已提交
3388
try {
3389 3390 3391 3392
    sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data) => {
        console.info('Sensor: ' + JSON.stringify(data));
    }, (err) => {
        console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3393 3394
    });
} catch (err) {
3395
    console.error('Get singleSensor failed. Error code: ' + err.code + '; message: ' + err.message);
G
Gloria 已提交
3396
}
G
Gloria 已提交
3397
```
W
wusongqing 已提交
3398

G
Gloria 已提交
3399 3400 3401 3402 3403 3404
## SensorId<sup>9+</sup>

Enumerates the sensor types.

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

3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427
| Name                       | 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.|
G
Gloria 已提交
3428 3429

## SensorType<sup>(deprecated)</sup>
Z
zengyawen 已提交
3430 3431 3432

Enumerates the sensor types.

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

W
wusongqing 已提交
3435

3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458
| Name                                      | 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 已提交
3459 3460 3461 3462 3463 3464


## Response

Describes the timestamp of the sensor data.

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

3467 3468 3469
| Name     | Type  | Readable| Writable| Description                    |
| --------- | ------ | ---- | ---- | ------------------------ |
| timestamp | number | Yes  | Yes  | Timestamp when the sensor reports data.|
G
Gloria 已提交
3470

G
Gloria 已提交
3471
## Sensor<sup>9+</sup>
G
Gloria 已提交
3472 3473 3474 3475

Describes the sensor information.

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

3477 3478 3479
| Name           | Type| Readable| Writable| Description                  |
| --------------- | -------- | ---------------------- | ---------------------- | ---------------------- |
| sensorName      | string   | Yes | Yes | Sensor name.          |
G
Gloria 已提交
3480
| vendorName      | string   | Yes | Yes | Vendor of the sensor.        |
3481 3482 3483 3484 3485 3486 3487 3488
| firmwareVersion | string   | Yes | Yes | Firmware version of the sensor.      |
| hardwareVersion | string   | Yes | Yes | Hardware version of the sensor.      |
| sensorId        | number   | Yes | Yes | Sensor type ID.        |
| maxRange        | number   | Yes | Yes | Maximum measurement range of the sensor.|
| minSamplePeriod | number   | Yes | Yes | Minimum sampling period.  |
| maxSamplePeriod | number   | Yes | Yes | Maximum sampling period.  |
| precision       | number   | Yes | Yes | Precision of the sensor.          |
| power           | number   | Yes | Yes | Power of the sensor.          |
W
wusongqing 已提交
3489 3490 3491 3492 3493

## AccelerometerResponse

Describes the acceleration sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3496

3497 3498
| Name| Type  | Readable| Writable| Description                                |
| ---- | ------ | ---- | ---- | ------------------------------------ |
G
Gloria 已提交
3499 3500 3501
| x    | number | Yes  | Yes  | Acceleration along the x-axis of the device, in m/s².|
| y    | number | Yes  | Yes  | Acceleration along the y-axis of the device, in m/s².|
| z    | number | Yes  | Yes  | Acceleration along the z-axis of the device, in m/s².|
W
wusongqing 已提交
3502 3503 3504 3505 3506 3507


## LinearAccelerometerResponse

Describes the linear acceleration sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3510

3511 3512
| Name| Type  | Readable| Writable| Description                                    |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
G
Gloria 已提交
3513 3514 3515
| x    | number | Yes  | Yes  | Linear acceleration along the x-axis of the device, in m/s².|
| y    | number | Yes  | Yes  | Linear acceleration along the y-axis of the device, in m/s².|
| z    | number | Yes  | Yes  | Linear acceleration along the z-axis of the device, in m/s².|
W
wusongqing 已提交
3516 3517 3518 3519 3520 3521


## AccelerometerUncalibratedResponse

Describes the uncalibrated acceleration sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3524

3525 3526
| Name | Type  | Readable| Writable| Description                                            |
| ----- | ------ | ---- | ---- | ------------------------------------------------ |
G
Gloria 已提交
3527 3528 3529 3530 3531 3532
| x     | number | Yes  | Yes  | Uncalibrated acceleration along the x-axis of the device, in m/s².      |
| y     | number | Yes  | Yes  | Uncalibrated acceleration along the y-axis of the device, in m/s².      |
| z     | number | Yes  | Yes  | Uncalibrated acceleration along the z-axis of the device, in m/s².      |
| biasX | number | Yes  | Yes  | Uncalibrated acceleration bias along the x-axis of the device, in m/s².  |
| biasY | number | Yes  | Yes  | Uncalibrated acceleration bias along the y-axis of the device, in m/s².|
| biasZ | number | Yes  | Yes  | Uncalibrated acceleration bias along the z-axis of the device, in m/s².  |
W
wusongqing 已提交
3533 3534 3535 3536 3537 3538


## GravityResponse

Describes the gravity sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3541

3542 3543
| Name| Type  | Readable| Writable| Description                                    |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
G
Gloria 已提交
3544 3545 3546
| x    | number | Yes  | Yes  | Gravitational acceleration along the x-axis of the device, in m/s².|
| y    | number | Yes  | Yes  | Gravitational acceleration along the y-axis of the device, in m/s².|
| z    | number | Yes  | Yes  | Gravitational acceleration along the z-axis of the device, in m/s².|
W
wusongqing 已提交
3547 3548 3549 3550 3551 3552


## OrientationResponse

Describes the orientation sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3555

3556 3557 3558 3559 3560
| 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 已提交
3561 3562 3563 3564 3565 3566


## RotationVectorResponse

Describes the rotation vector sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3569

3570 3571 3572 3573 3574 3575
| 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 已提交
3576 3577 3578 3579 3580 3581


## GyroscopeResponse

Describes the gyroscope sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3584

3585 3586 3587 3588 3589
| 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 已提交
3590 3591 3592 3593 3594 3595


## GyroscopeUncalibratedResponse

Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3598

3599 3600 3601 3602 3603 3604 3605 3606
| 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 已提交
3607 3608 3609 3610 3611 3612


## SignificantMotionResponse

Describes the significant motion sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3615

3616 3617 3618
| 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 已提交
3619 3620 3621 3622 3623 3624


## ProximityResponse

Describes the proximity sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3627

3628 3629 3630
| 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 已提交
3631 3632 3633 3634 3635 3636


## LightResponse

Describes the ambient light sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3639

3640 3641 3642
| Name     | Type  | Readable| Writable| Description                  |
| --------- | ------ | ---- | ---- | ---------------------- |
| intensity | number | Yes  | Yes  | Illumination, in lux.|
W
wusongqing 已提交
3643 3644 3645 3646 3647 3648


## HallResponse

Describes the Hall effect sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3651

3652 3653 3654
| 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 已提交
3655 3656 3657 3658 3659 3660


## MagneticFieldResponse

Describes the magnetic field sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3663

3664 3665 3666 3667 3668
| 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 已提交
3669 3670 3671 3672 3673 3674


## MagneticFieldUncalibratedResponse

Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3677

3678 3679 3680 3681 3682 3683 3684 3685
| 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 已提交
3686 3687 3688 3689 3690 3691


## PedometerResponse

Describes the pedometer sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3694

3695 3696 3697
| Name | Type  | Readable| Writable| Description            |
| ----- | ------ | ---- | ---- | ---------------- |
| steps | number | Yes  | Yes  | Number of steps a user has walked.|
W
wusongqing 已提交
3698 3699 3700 3701 3702 3703


## HumidityResponse

Describes the humidity sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3706

3707 3708 3709
| Name    | Type  | Readable| Writable| Description                                                     |
| -------- | ------ | ---- | ---- | --------------------------------------------------------- |
| humidity | number | Yes  | Yes  | Ambient relative humidity, in a percentage (%).|
W
wusongqing 已提交
3710 3711


W
wusongqing 已提交
3712
## PedometerDetectionResponse
W
wusongqing 已提交
3713 3714 3715

Describes the pedometer detection sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3718

3719 3720 3721
| 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 已提交
3722 3723 3724 3725 3726 3727


## AmbientTemperatureResponse

Describes the ambient temperature sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3730

3731 3732 3733
| Name       | Type  | Readable| Writable| Description                      |
| ----------- | ------ | ---- | ---- | -------------------------- |
| temperature | number | Yes  | Yes  | Ambient temperature, in degree Celsius.|
W
wusongqing 已提交
3734 3735 3736 3737 3738 3739


## BarometerResponse

Describes the barometer sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3742

3743 3744 3745
| Name    | Type  | Readable| Writable| Description                    |
| -------- | ------ | ---- | ---- | ------------------------ |
| pressure | number | Yes  | Yes  | Atmospheric pressure, in pascal.|
W
wusongqing 已提交
3746 3747 3748 3749 3750 3751


## HeartRateResponse

Describes the heart rate sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3754

3755 3756 3757
| Name     | Type  | Readable| Writable| Description                                   |
| --------- | ------ | ---- | ---- | --------------------------------------- |
| heartRate | number | Yes  | Yes  | Heart rate, in beats per minute (bpm).|
W
wusongqing 已提交
3758 3759 3760 3761 3762 3763


## WearDetectionResponse

Describes the wear detection sensor data. It extends from [Response](#response).

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

W
wusongqing 已提交
3766

3767 3768 3769
| 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 已提交
3770 3771 3772


## Options
Z
zengyawen 已提交
3773 3774 3775

Describes the sensor data reporting frequency.

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

3778 3779 3780
| Name    | Type  | Readable| Writable| Description                                       |
| -------- | ------ | ---- | ---- | ------------------------------------------- |
| interval | number | Yes  | Yes  | Frequency at which a sensor reports data. The default value is 200,000,000 ns.|
W
wusongqing 已提交
3781

W
wusongqing 已提交
3782 3783 3784 3785
## RotationMatrixResponse

Describes the response for setting the rotation matrix.

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

3788
| Name       | Type               | Readable| Writable| Description      |
G
Gloria 已提交
3789 3790 3791
| ----------- | ------------------- | ---- | ---- | ---------- |
| rotation    | Array&lt;number&gt; | Yes  | Yes  | Rotation matrix.|
| inclination | Array&lt;number&gt; | Yes  | Yes  | Inclination matrix.|
W
wusongqing 已提交
3792 3793 3794 3795 3796 3797


## CoordinatesOptions

Describes the coordinate options.

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

3800 3801 3802 3803
| Name| Type  | Readable| Writable| Description       |
| ---- | ------ | ---- | ---- | ----------- |
| x    | number | Yes  | Yes  | X coordinate direction.|
| y    | number | Yes  | Yes  | Y coordinate direction.|
W
wusongqing 已提交
3804

W
wusongqing 已提交
3805 3806 3807 3808 3809

## GeomagneticResponse

Describes a geomagnetic response object. It extends from [Response](#response).

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

3812 3813 3814 3815 3816 3817 3818 3819 3820
| 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 已提交
3821 3822

## LocationOptions
Z
zengyawen 已提交
3823

W
wusongqing 已提交
3824 3825 3826 3827
Describes the geographical location.

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

3828 3829 3830 3831 3832
| Name     | Type  | Readable| Writable| Description      |
| --------- | ------ | ---- | ---- | ---------- |
| latitude  | number | Yes  | Yes  | Latitude.    |
| longitude | number | Yes  | Yes  | Longitude.    |
| altitude  | number | Yes  | Yes  | Altitude.|
G
Gloria 已提交
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851

## 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
3852
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER       | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
G
Gloria 已提交
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
| 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
3884
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
G
Gloria 已提交
3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903
| 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. |

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
3904
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
G
Gloria 已提交
3905 3906 3907 3908
| 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**
3909

G
Gloria 已提交
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
  ```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                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
3937
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. |
G
Gloria 已提交
3938 3939 3940 3941
| 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**
3942

G
Gloria 已提交
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
  ```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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
3969
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
G
Gloria 已提交
3970 3971 3972 3973
| 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**
3974

G
Gloria 已提交
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
  ```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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4001
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
G
Gloria 已提交
4002 4003 4004 4005
| 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**
4006

G
Gloria 已提交
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
  ```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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4034
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
G
Gloria 已提交
4035 4036 4037 4038
| 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**
4039

G
Gloria 已提交
4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063
  ```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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4064
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
G
Gloria 已提交
4065 4066 4067 4068
| 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**
4069

G
Gloria 已提交
4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093
  ```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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4094
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. |
G
Gloria 已提交
4095 4096 4097 4098
| 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**
4099

G
Gloria 已提交
4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121
  ```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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4122
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
G
Gloria 已提交
4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133
| 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}
  );
4134

G
Gloria 已提交
4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4151
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
G
Gloria 已提交
4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164
| 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}
  );
4165

G
Gloria 已提交
4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4182
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
G
Gloria 已提交
4183 4184 4185 4186
| 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**
4187

G
Gloria 已提交
4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198
  ```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}
  );
4199

G
Gloria 已提交
4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4216
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. |
G
Gloria 已提交
4217 4218 4219 4220
| 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**
4221

G
Gloria 已提交
4222 4223 4224 4225 4226 4227
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
      console.info('Distance: ' + data.distance);
  },
      {interval: 10000000}
  );
4228

G
Gloria 已提交
4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244
  ```

### 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                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
4245
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. |
G
Gloria 已提交
4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256
| 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}
  );
4257

G
Gloria 已提交
4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4274
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. |
G
Gloria 已提交
4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285
| 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}
  );
4286

G
Gloria 已提交
4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302
  ```

### 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                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
4303
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. |
G
Gloria 已提交
4304 4305 4306 4307
| 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**
4308

G
Gloria 已提交
4309 4310 4311 4312 4313 4314
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
      console.info('Status: ' + data.status);
  },
      {interval: 10000000}
  );
4315

G
Gloria 已提交
4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329
  ```

### 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**

4330 4331 4332 4333 4334
| Name     | Type                                                   | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | 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. |
G
Gloria 已提交
4335 4336 4337 4338 4339 4340 4341 4342 4343

**Example**

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

G
Gloria 已提交
4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360
  ```

### 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                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4361
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. |
G
Gloria 已提交
4362 4363 4364 4365
| 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**
4366

G
Gloria 已提交
4367 4368 4369 4370 4371 4372 4373 4374
  ```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}
  );
4375

G
Gloria 已提交
4376 4377 4378 4379 4380 4381 4382 4383
  ```

### 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.

G
Gloria 已提交
4384
This API is deprecated since API version 9. You are advised to use [sensor.on.HEART_RATE](#heart_rate9) instead.
G
Gloria 已提交
4385 4386 4387 4388 4389 4390 4391 4392 4393

**Required permissions**: ohos.permission.HEALTH_DATA

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

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4394
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HEART_RATE     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. |
G
Gloria 已提交
4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410
| 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**. |

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4411
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
G
Gloria 已提交
4412 4413 4414 4415
| 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**
4416

G
Gloria 已提交
4417 4418 4419 4420 4421 4422 4423 4424 4425
  ```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}
  );
4426

G
Gloria 已提交
4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4443
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
G
Gloria 已提交
4444 4445 4446 4447
| 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**
4448

G
Gloria 已提交
4449 4450 4451 4452 4453 4454
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
      console.info('Wear status: ' + data.value);
  },
      {interval: 10000000}
  );
4455

G
Gloria 已提交
4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475
  ```

## 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4476
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER       | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
G
Gloria 已提交
4477 4478 4479
| 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**
4480

G
Gloria 已提交
4481 4482 4483 4484 4485 4486 4487
  ```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);
    }
  );
4488

G
Gloria 已提交
4489 4490 4491 4492 4493 4494 4495 4496
  ```

### 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.

G
Gloria 已提交
4497
This API is deprecated since API version 9. You are advised to use [sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1) instead.
G
Gloria 已提交
4498 4499 4500 4501 4502 4503 4504 4505 4506

**Required permissions**: ohos.permission.ACCELERATION

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

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4507
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
G
Gloria 已提交
4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525
| 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**. |

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4526
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
G
Gloria 已提交
4527 4528 4529
| 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**
4530

G
Gloria 已提交
4531 4532 4533 4534 4535 4536 4537 4538 4539 4540
  ```
  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);
    }
  );
4541

G
Gloria 已提交
4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557
  ```

### 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                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
4558
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. |
G
Gloria 已提交
4559 4560 4561
| 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**
4562

G
Gloria 已提交
4563 4564 4565 4566 4567 4568 4569
  ```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);
    }
  );
4570

G
Gloria 已提交
4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4589
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
G
Gloria 已提交
4590 4591 4592
| 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**
4593

G
Gloria 已提交
4594 4595 4596 4597 4598 4599 4600
  ```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);
    }
  );
4601

G
Gloria 已提交
4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4620
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
G
Gloria 已提交
4621 4622 4623
| 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**
4624

G
Gloria 已提交
4625 4626 4627 4628 4629 4630 4631 4632 4633 4634
  ```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);
    }
  );
4635

G
Gloria 已提交
4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4652
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
G
Gloria 已提交
4653 4654 4655
| 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**
4656

G
Gloria 已提交
4657 4658 4659 4660 4661
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
4662

G
Gloria 已提交
4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4681
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
G
Gloria 已提交
4682 4683 4684
| 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**
4685

G
Gloria 已提交
4686 4687 4688 4689 4690
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
      console.info('Scalar data: ' + data.scalar);
    }
  );
4691

G
Gloria 已提交
4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4710
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. |
G
Gloria 已提交
4711 4712 4713
| 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**
4714

G
Gloria 已提交
4715 4716 4717 4718 4719
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
      console.info('Steps: ' + data.steps);
    }
  );
4720

G
Gloria 已提交
4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4737
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
G
Gloria 已提交
4738 4739 4740
| 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**
4741

G
Gloria 已提交
4742 4743 4744 4745 4746
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
      console.info('Temperature: ' + data.temperature);
    }
  );
4747

G
Gloria 已提交
4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4764
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
G
Gloria 已提交
4765 4766 4767
| 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**
4768

G
Gloria 已提交
4769 4770 4771 4772 4773 4774 4775
  ```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);
    }
  );
4776

G
Gloria 已提交
4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4793
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
G
Gloria 已提交
4794 4795 4796
| 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**
4797

G
Gloria 已提交
4798 4799 4800 4801 4802 4803 4804 4805 4806 4807
  ```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);
    }
  );
4808

G
Gloria 已提交
4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4825
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. |
G
Gloria 已提交
4826 4827 4828
| 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**
4829

G
Gloria 已提交
4830 4831 4832 4833 4834
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
      console.info('Distance: ' + data.distance);
    }
  );
4835

G
Gloria 已提交
4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851
  ```

### 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                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
4852
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. |
G
Gloria 已提交
4853 4854 4855
| 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**
4856

G
Gloria 已提交
4857 4858 4859 4860 4861
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
4862

G
Gloria 已提交
4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878
  ```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4879
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. |
G
Gloria 已提交
4880 4881 4882
| 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**
4883

G
Gloria 已提交
4884 4885 4886 4887 4888
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
4889

G
Gloria 已提交
4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905
  ```

### 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                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
4906
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. |
G
Gloria 已提交
4907 4908 4909
| 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**
4910

G
Gloria 已提交
4911 4912 4913 4914 4915
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
4916

G
Gloria 已提交
4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930
  ```

### 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**

4931 4932 4933 4934
| Name     | Type                                                   | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | 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**. |
G
Gloria 已提交
4935 4936 4937 4938 4939 4940 4941 4942

**Example**

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

G
Gloria 已提交
4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959
  ```

### 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                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
4960
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. |
G
Gloria 已提交
4961 4962 4963
| 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**
4964

G
Gloria 已提交
4965 4966 4967 4968 4969 4970 4971
  ```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);
    }
  );
4972

G
Gloria 已提交
4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988
  ```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
4989
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
G
Gloria 已提交
4990 4991 4992
| 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**
4993

G
Gloria 已提交
4994 4995 4996 4997 4998 4999 5000 5001
  ```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);
    }
  );
5002

G
Gloria 已提交
5003 5004 5005 5006 5007 5008 5009 5010
  ```

### 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.

G
Gloria 已提交
5011
This API is deprecated since API version 9. You are advised to use [sensor.once.HEART_RATE](#heart_rate9-1) instead.
G
Gloria 已提交
5012 5013 5014 5015 5016 5017 5018 5019 5020

**Required permissions**: ohos.permission.HEART_RATE 

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

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5021
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HEART_RATE     | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. |
G
Gloria 已提交
5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037
| 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**. |

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5038
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | Yes       | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
G
Gloria 已提交
5039 5040 5041
| 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**
5042

G
Gloria 已提交
5043 5044 5045 5046 5047
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
    }
  );
5048

G
Gloria 已提交
5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068
  ```

## 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5069 5070
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER       | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**. |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | No        | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. |
G
Gloria 已提交
5071 5072 5073 5074 5075 5076 5077 5078 5079 5080

**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);
5081

G
Gloria 已提交
5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5100 5101
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. |
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | No        | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. |
G
Gloria 已提交
5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114

**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);
5115

G
Gloria 已提交
5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129
```

### 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**

5130 5131 5132 5133
| Name     | Type                                                   | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------ | --------- | ------------------------------------------------------------ |
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. |
| callback | Callback&lt;[LightResponse](#lightresponse)&gt;        | No        | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. |
G
Gloria 已提交
5134 5135 5136 5137 5138 5139 5140 5141

**Example**

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

G
Gloria 已提交
5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5159 5160
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. |
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | No        | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. |
G
Gloria 已提交
5161 5162 5163 5164 5165 5166 5167 5168

**Example**

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

G
Gloria 已提交
5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185
```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5186 5187
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_BAROMETER      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**. |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | No        | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. |
G
Gloria 已提交
5188 5189 5190 5191 5192 5193 5194 5195

**Example**

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

G
Gloria 已提交
5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212
```

### 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                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
5213 5214
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GRAVITY    | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**. |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | No        | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. |
G
Gloria 已提交
5215 5216 5217 5218 5219 5220 5221 5222 5223 5224

**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);
5225

G
Gloria 已提交
5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243
```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5244 5245
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**. |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | No        | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. |
G
Gloria 已提交
5246 5247 5248 5249 5250 5251 5252 5253 5254 5255

**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);
5256

G
Gloria 已提交
5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5275 5276
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. |
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | No        | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. |
G
Gloria 已提交
5277 5278 5279 5280 5281 5282 5283 5284 5285 5286

**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);
5287

G
Gloria 已提交
5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303
```

### 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                                                  |
| -------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
5304 5305
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HALL | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**. |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | No        | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. |
G
Gloria 已提交
5306 5307 5308 5309 5310 5311 5312 5313

**Example**

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

G
Gloria 已提交
5315 5316 5317 5318 5319 5320 5321 5322
```

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

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

Unsubscribes from sensor data changes.

G
Gloria 已提交
5323
This API is deprecated since API version 9. You are advised to use [sensor.off.HEART_RATE](#heart_rate9-2) instead.
G
Gloria 已提交
5324 5325 5326 5327 5328 5329 5330 5331 5332

**Required permissions**: ohos.permission.HEALTH_DATA

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

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5333 5334
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HEART_RATE     | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**. |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | No        | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. |
G
Gloria 已提交
5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349

### 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                                                  |
| -------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
5350 5351
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_HUMIDITY     | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**. |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | No        | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. |
G
Gloria 已提交
5352 5353 5354 5355 5356 5357 5358 5359

**Example**

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

G
Gloria 已提交
5361 5362 5363 5364 5365 5366 5367 5368
```

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

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

Unsubscribes from sensor data changes.

G
Gloria 已提交
5369
This API is deprecated since API version 9. You are advised to use [sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2) instead.
G
Gloria 已提交
5370 5371 5372 5373 5374 5375 5376 5377 5378

**Required permissions**: ohos.permission.ACCELEROMETER

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

**Parameters**

| Name     | Type                                                         | Mandatory | Description                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5379 5380
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. |
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | No        | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. |
G
Gloria 已提交
5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395

### 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                                                  |
| ---------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5396 5397
| type             | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. |
| callbackcallback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | No        | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. |
G
Gloria 已提交
5398 5399 5400 5401 5402 5403 5404 5405 5406 5407

**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);
5408

G
Gloria 已提交
5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5425 5426
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. |
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | No        | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. |
G
Gloria 已提交
5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439

**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);
5440

G
Gloria 已提交
5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456
```

### 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                                                  |
| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5457 5458
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ORIENTATION        | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**. |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | No        | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. |
G
Gloria 已提交
5459 5460 5461 5462 5463 5464 5465 5466 5467 5468

**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);
5469

G
Gloria 已提交
5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487
```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5488 5489
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | No        | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. |
G
Gloria 已提交
5490 5491 5492 5493 5494 5495 5496 5497

**Example**

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

G
Gloria 已提交
5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5517 5518
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. |
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | No        | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. |
G
Gloria 已提交
5519 5520 5521 5522 5523 5524 5525 5526

**Example**

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

G
Gloria 已提交
5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543
```

### 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                                                  |
| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ |
5544 5545
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_PROXIMITY      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**. |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | No        | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. |
G
Gloria 已提交
5546 5547 5548 5549 5550 5551 5552 5553

**Example**

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

G
Gloria 已提交
5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5571 5572
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_ROTATION_VECTOR     | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. |
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | No        | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. |
G
Gloria 已提交
5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583

**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);
5584

G
Gloria 已提交
5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5601 5602
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_SIGNIFICANT_MOTION  | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. |
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | No        | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. |
G
Gloria 已提交
5603 5604 5605 5606 5607 5608 5609 5610

**Example**

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

G
Gloria 已提交
5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627
```

### 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                                                  |
| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ |
5628 5629
| type     | [SensorType](#sensortype).SENSOR_TYPE_ID_WEAR_DETECTION      | Yes       | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. |
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | No        | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. |
G
Gloria 已提交
5630 5631 5632 5633 5634 5635 5636 5637

**Example**

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

G
Gloria 已提交
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
```

## 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;
    }
J
Jiefeng Li 已提交
5667
    console.info("Operation succeeded. Data obtained: " + data);
G
Gloria 已提交
5668 5669 5670 5671
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
5672

G
Gloria 已提交
5673
```
5674

G
Gloria 已提交
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
## 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) => {
J
Jiefeng Li 已提交
5703
        console.info("Operation succeeded.");
G
Gloria 已提交
5704 5705 5706 5707 5708 5709
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
5710

G
Gloria 已提交
5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731
```

## 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**
5732

G
Gloria 已提交
5733 5734 5735 5736 5737 5738 5739 5740 5741 5742
```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);
});
5743

G
Gloria 已提交
5744
```
5745

G
Gloria 已提交
5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769
## 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**
5770

G
Gloria 已提交
5771 5772 5773 5774 5775 5776 5777 5778 5779
  ```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.');
  })
5780

G
Gloria 已提交
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
  ```

## 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;
      }
J
Jiefeng Li 已提交
5810
          console.info("Succeeded to get getAltitude interface get data: " + data);
G
Gloria 已提交
5811
  });
5812

G
Gloria 已提交
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
  ```

## 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");
  })
5847

G
Gloria 已提交
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
  ```


## 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;
      }
J
Jiefeng Li 已提交
5877
          console.info("Succeeded to get getGeomagneticDip interface get data: " + data);
G
Gloria 已提交
5878
  })
5879

G
Gloria 已提交
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
  ```

## 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) => {
J
Jiefeng Li 已提交
5909
          console.info('getGeomagneticDip_promise succeeded', data);
G
Gloria 已提交
5910 5911 5912
      }).catch((err) => {
           console.error("Operation failed");
  })
5913

G
Gloria 已提交
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
  ```

## 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]);
      }
  })
5947

G
Gloria 已提交
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
  ```


## 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) => {
J
Jiefeng Li 已提交
5979
          console.info('getAngleModify_promise success');
G
Gloria 已提交
5980 5981 5982 5983 5984 5985
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info("promise::catch", reason);
  })
5986

G
Gloria 已提交
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
  ```


## 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]);
      }
  })
6020

G
Gloria 已提交
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
  ```


## 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);
  })	
6058

G
Gloria 已提交
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
  ```


## 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]);
      }
  })
6092

G
Gloria 已提交
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
  ```


## 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) => {
J
Jiefeng Li 已提交
6123
          console.info('createQuaternion_promise succeeded');
G
Gloria 已提交
6124 6125 6126 6127 6128 6129
          for (var i=0; i < data.length; i++) {
              console.info("data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info('promise failed');
  })
6130

G
Gloria 已提交
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
  ```


## 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;
      }
J
Jiefeng Li 已提交
6160
      console.info("SensorJsAPI--->Succeeded to get getDirection interface get data: " + data);
G
Gloria 已提交
6161 6162 6163 6164
      for (var i = 1; i < data.length; i++) {
          console.info("sensor_getDirection_callback" + data[i]);
      }
  })
6165

G
Gloria 已提交
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 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268
  ```


## 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');
  })
6269
  ```