1# @ohos.sensor (Sensor) 2 3The **Sensor** module provides APIs for obtaining the sensor list and subscribing to sensor data. It also provides some common sensor algorithms. 4 5> **NOTE** 6> 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. 8 9 10## Modules to Import 11 12```ts 13import sensor from '@ohos.sensor'; 14``` 15## sensor.on 16 17### COLOR<sup>10+</sup> 18 19on(type: SensorId.COLOR, callback: Callback\<ColorResponse>, options?: Options): void 20 21Subscribes to data of the color sensor. 22 23**System capability**: SystemCapability.Sensors.Sensor 24 25**System API**: This is a system API. 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| -------- | ------------------------------------------------- | ---- | ----------------------------------------------------------- | 31| type | [SensorId](#sensorid9).COLOR | Yes | Sensor type. The value is fixed at **SensorId.COLOR**. | 32| callback | Callback<[ColorResponse](#colorresponse10)> | Yes | Callback used to report the sensor data, which is a **ColorResponse** object. | 33| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 34 35**Error codes** 36 37For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 38 39| ID| Error Message | 40| -------- | ------------------ | 41| 14500101 | Service exception. | 42 43**Example** 44 45```ts 46import sensor from "@ohos.sensor"; 47import BusinessError from "@ohos.base"; 48 49try{ 50 sensor.on(sensor.SensorId.COLOR, (data: sensor.ColorResponse) => { 51 console.log('Succeeded in getting the intensity of light: ' + data.lightIntensity); 52 console.log('Succeeded in getting the color temperature: ' + data.colorTemperature); 53 }, { interval: 100000000 }); 54 setTimeout(() => { 55 sensor.off(sensor.SensorId.COLOR); 56 }, 500); 57} catch (error) { 58 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 59 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 60} 61``` 62 63### SAR<sup>10+</sup> 64 65on(type: SensorId.SAR, callback: Callback\<SarResponse>, options?: Options): void 66 67Subscribes to data of the Sodium Adsorption Ratio (SAR) sensor. 68 69**System capability**: SystemCapability.Sensors.Sensor 70 71**System API**: This is a system API. 72 73**Parameters** 74 75| Name | Type | Mandatory| Description | 76| -------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 77| type | [SensorId](#sensorid9).SAR | Yes | Sensor type. The value is fixed at **SensorId.SAR**. | 78| callback | Callback<[SarResponse](#sarresponse10)> | Yes | Callback used to report the sensor data, which is a **SarResponse** object. | 79| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 80 81**Error codes** 82 83For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 84 85| ID| Error Message | 86| -------- | ------------------ | 87| 14500101 | Service exception. | 88 89**Example** 90 91```ts 92import sensor from "@ohos.sensor"; 93import BusinessError from "@ohos.base"; 94 95try { 96 sensor.on(sensor.SensorId.SAR, (data: sensor.SarResponse) => { 97 console.info('Succeeded in getting specific absorption rate : ' + data.absorptionRatio); 98 }, { interval: 100000000 }); 99 setTimeout(() => { 100 sensor.off(sensor.SensorId.SAR); 101 }, 500); 102} catch (error) { 103 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 104 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 105} 106``` 107 108### ACCELEROMETER<sup>9+</sup> 109 110on(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse>, options?: Options): void 111 112Subscribes to data of the acceleration sensor. 113 114**Required permissions**: ohos.permission.ACCELEROMETER 115 116**System capability**: SystemCapability.Sensors.Sensor 117 118**Parameters** 119 120| Name | Type | Mandatory| Description | 121| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 122| type | [SensorId](#sensorid9).ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**. | 123| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerResponse** object.| 124| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 125 126**Error codes** 127 128For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 129 130| ID| Error Message | 131| -------- | ------------------ | 132| 14500101 | Service exception. | 133 134**Example** 135 136```ts 137import sensor from "@ohos.sensor"; 138import BusinessError from "@ohos.base"; 139 140try { 141 sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { 142 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 143 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 144 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 145 }, { interval: 100000000 }); 146 setTimeout(() => { 147 sensor.off(sensor.SensorId.ACCELEROMETER); 148 }, 500); 149} catch (error) { 150 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 151 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 152} 153``` 154 155### ACCELEROMETER_UNCALIBRATED<sup>9+</sup> 156 157on(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<AccelerometerUncalibratedResponse>, options?: Options): void 158 159Subscribes to data of the uncalibrated acceleration sensor. 160 161**Required permissions**: ohos.permission.ACCELEROMETER 162 163**System capability**: SystemCapability.Sensors.Sensor 164 165**Parameters** 166 167| Name | Type | Mandatory| Description | 168| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 169| type | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. | 170| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.| 171| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 172 173**Error codes** 174 175For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 176 177| ID| Error Message | 178| -------- | ------------------ | 179| 14500101 | Service exception. | 180 181**Example** 182 183```ts 184import sensor from "@ohos.sensor"; 185import BusinessError from "@ohos.base"; 186 187try { 188 sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => { 189 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 190 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 191 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 192 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 193 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 194 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 195 }, { interval: 100000000 }); 196 setTimeout(() => { 197 sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED); 198 }, 500); 199} catch (error) { 200 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 201 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 202} 203``` 204 205### AMBIENT_LIGHT<sup>9+</sup> 206 207on(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>, options?: Options): void 208 209Subscribes to data of the ambient light sensor. 210 211**System capability**: SystemCapability.Sensors.Sensor 212 213**Parameters** 214 215| Name | Type | Mandatory| Description | 216| -------- | ----------------------------------------------- | ---- | ----------------------------------------------------------- | 217| type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | 218| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object. | 219| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 220 221**Error codes** 222 223For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 224 225| ID| Error Message | 226| -------- | ------------------ | 227| 14500101 | Service exception. | 228 229**Example** 230 231```ts 232import sensor from "@ohos.sensor"; 233import BusinessError from "@ohos.base"; 234 235try { 236 sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data: sensor.LightResponse) => { 237 console.info('Succeeded in getting the ambient light intensity: ' + data.intensity); 238 }, { interval: 100000000 }); 239 setTimeout(() => { 240 sensor.off(sensor.SensorId.AMBIENT_LIGHT); 241 }, 500); 242} catch (error) { 243 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 244 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 245} 246``` 247 248### AMBIENT_TEMPERATURE<sup>9+</sup> 249 250on(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatureResponse>, options?: Options): void 251 252Subscribes to data of the ambient temperature sensor. 253 254**System capability**: SystemCapability.Sensors.Sensor 255 256**Parameters** 257 258| Name | Type | Mandatory| Description | 259| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 260| type | [SensorId](#sensorid9).AMBIENT_TEMPERATURE | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**. | 261| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.| 262| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 263 264**Error codes** 265 266For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 267 268| ID| Error Message | 269| -------- | ------------------ | 270| 14500101 | Service exception. | 271 272**Example** 273 274```ts 275import sensor from "@ohos.sensor"; 276import BusinessError from "@ohos.base"; 277 278try { 279 sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => { 280 console.info('Succeeded in invoking on. Temperature: ' + data.temperature); 281 }, { interval: 100000000 }); 282 setTimeout(() => { 283 sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE); 284 }, 500); 285} catch (error) { 286 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 287 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 288} 289``` 290 291### BAROMETER<sup>9+</sup> 292 293on(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>, options?: Options): void 294 295Subscribes to data of the barometer sensor. 296 297**System capability**: SystemCapability.Sensors.Sensor 298 299**Parameters** 300 301| Name | Type | Mandatory| Description | 302| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | 303| type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | 304| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object. | 305| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 306 307**Error codes** 308 309For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 310 311| ID| Error Message | 312| -------- | ------------------ | 313| 14500101 | Service exception. | 314 315**Example** 316 317```ts 318import sensor from "@ohos.sensor"; 319import BusinessError from "@ohos.base"; 320 321try { 322 sensor.on(sensor.SensorId.BAROMETER, (data: sensor.BarometerResponse) => { 323 console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure); 324 }, { interval: 100000000 }); 325 setTimeout(() => { 326 sensor.off(sensor.SensorId.BAROMETER); 327 }, 500); 328} catch (error) { 329 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 330 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 331} 332``` 333 334### GRAVITY<sup>9+</sup> 335 336on(type: SensorId.GRAVITY, callback: Callback<GravityResponse>, options?: Options): void 337 338Subscribes to data of the gravity sensor. 339 340**System capability**: SystemCapability.Sensors.Sensor 341 342**Parameters** 343 344| Name | Type | Mandatory| Description | 345| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------------- | 346| type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | 347| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object. | 348| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 349 350**Error codes** 351 352For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 353 354| ID| Error Message | 355| -------- | ------------------ | 356| 14500101 | Service exception. | 357 358**Example** 359 360```ts 361import sensor from "@ohos.sensor"; 362import BusinessError from "@ohos.base"; 363 364try { 365 sensor.on(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { 366 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 367 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 368 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 369 }, { interval: 100000000 }); 370 setTimeout(() => { 371 sensor.off(sensor.SensorId.GRAVITY); 372 }, 500); 373} catch (error) { 374 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 375 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 376} 377``` 378 379### GYROSCOPE<sup>9+</sup> 380 381on(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>, options?: Options): void 382 383Subscribes to data of the gyroscope sensor. 384 385**Required permissions**: ohos.permission.GYROSCOPE 386 387**System capability**: SystemCapability.Sensors.Sensor 388 389**Parameters** 390 391| Name | Type | Mandatory| Description | 392| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | 393| type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | 394| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object. | 395| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 396 397**Error codes** 398 399For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 400 401| ID| Error Message | 402| -------- | ------------------ | 403| 14500101 | Service exception. | 404 405**Example** 406 407```ts 408import sensor from "@ohos.sensor"; 409import BusinessError from "@ohos.base"; 410 411try { 412 sensor.on(sensor.SensorId.GYROSCOPE, (data: sensor.GyroscopeResponse) => { 413 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 414 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 415 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 416 }, { interval: 100000000 }); 417 setTimeout(() => { 418 sensor.off(sensor.SensorId.GYROSCOPE); 419 }, 500); 420} catch (error) { 421 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 422 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 423} 424``` 425 426### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 427 428on(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncalibratedResponse>, 429 options?: Options): void 430 431Subscribes to data of the uncalibrated gyroscope sensor. 432 433**Required permissions**: ohos.permission.GYROSCOPE 434 435**System capability**: SystemCapability.Sensors.Sensor 436 437**Parameters** 438 439| Name | Type | Mandatory| Description | 440| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 441| type | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**. | 442| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.| 443| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 444 445**Error codes** 446 447For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 448 449| ID| Error Message | 450| -------- | ------------------ | 451| 14500101 | Service exception. | 452 453**Example** 454 455```ts 456import sensor from "@ohos.sensor"; 457import BusinessError from "@ohos.base"; 458 459try { 460 sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => { 461 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 462 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 463 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 464 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 465 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 466 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 467 }, { interval: 100000000 }); 468 setTimeout(() => { 469 sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED); 470 }, 500); 471} catch (error) { 472 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 473 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 474} 475 476``` 477 478### HALL<sup>9+</sup> 479 480on(type: SensorId.HALL, callback: Callback<HallResponse>, options?: Options): void 481 482Subscribes to data of the Hall effect sensor. 483 484**System capability**: SystemCapability.Sensors.Sensor 485 486**Parameters** 487 488| Name | Type | Mandatory| Description | 489| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 490| type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | 491| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object. | 492| options | [Options](#options) | No | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when Hall effect events are frequently triggered.| 493 494**Error codes** 495 496For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 497 498| ID| Error Message | 499| -------- | ------------------ | 500| 14500101 | Service exception. | 501 502**Example** 503 504```ts 505import sensor from "@ohos.sensor"; 506import BusinessError from "@ohos.base"; 507 508try { 509 sensor.on(sensor.SensorId.HALL, (data: sensor.HallResponse) => { 510 console.info('Succeeded in invoking on. Hall status: ' + data.status); 511 }, { interval: 100000000 }); 512 setTimeout(() => { 513 sensor.off(sensor.SensorId.HALL); 514 }, 500); 515} catch (error) { 516 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 517 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 518} 519 520``` 521 522### HEART_RATE<sup>9+</sup> 523 524on(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>, options?: Options): void 525 526Subscribes to data of the heart rate sensor. 527 528**Required permissions**: ohos.permission.READ_HEALTH_DATA 529 530**System capability**: SystemCapability.Sensors.Sensor 531 532**Parameters** 533 534| Name | Type | Mandatory| Description | 535| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | 536| type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | 537| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object. | 538| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 539 540**Error codes** 541 542For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 543 544| ID| Error Message | 545| -------- | ------------------ | 546| 14500101 | Service exception. | 547 548**Example** 549 550```ts 551import sensor from "@ohos.sensor"; 552import BusinessError from "@ohos.base"; 553 554try { 555 sensor.on(sensor.SensorId.HEART_RATE, (data: sensor.HeartRateResponse) => { 556 console.info('Succeeded in invoking on. Heart rate: ' + data.heartRate); 557 }, { interval: 100000000 }); 558 setTimeout(() => { 559 sensor.off(sensor.SensorId.HEART_RATE); 560 }, 500); 561} catch (error) { 562 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 563 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 564} 565``` 566 567### HUMIDITY<sup>9+</sup> 568 569on(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>, options?: Options): void 570 571Subscribes to data of the humidity sensor. 572 573**System capability**: SystemCapability.Sensors.Sensor 574 575**Parameters** 576 577| Name | Type | Mandatory| Description | 578| -------- | ----------------------------------------------------- | ---- | ----------------------------------------------------------- | 579| type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | 580| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object. | 581| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 582 583**Error codes** 584 585For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 586 587| ID| Error Message | 588| -------- | ------------------ | 589| 14500101 | Service exception. | 590 591**Example** 592 593```ts 594import sensor from "@ohos.sensor"; 595import BusinessError from "@ohos.base"; 596 597try { 598 sensor.on(sensor.SensorId.HUMIDITY, (data: sensor.HumidityResponse) => { 599 console.info('Succeeded in invoking on. Humidity: ' + data.humidity); 600 }, { interval: 100000000 }); 601 setTimeout(() => { 602 sensor.off(sensor.SensorId.HUMIDITY); 603 }, 500); 604} catch (error) { 605 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 606 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 607} 608``` 609 610### LINEAR_ACCELEROMETER<sup>9+</sup> 611 612on(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAccelerometerResponse>, 613 options?: Options): void 614 615Subscribes to data of the linear acceleration sensor. 616 617**Required permissions**: ohos.permission.ACCELEROMETER 618 619**System capability**: SystemCapability.Sensors.Sensor 620 621**Parameters** 622 623| Name | Type | Mandatory| Description | 624| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 625| type | [SensorId](#sensorid9).LINEAR_ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**. | 626| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.| 627| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 628 629**Error codes** 630 631For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 632 633| ID| Error Message | 634| -------- | ------------------ | 635| 14500101 | Service exception. | 636 637**Example** 638 639```ts 640import sensor from "@ohos.sensor"; 641import BusinessError from "@ohos.base"; 642 643try { 644 sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, (data: sensor.LinearAccelerometerResponse) => { 645 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 646 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 647 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 648 }, { interval: 100000000 }); 649 setTimeout(() => { 650 sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER); 651 }, 500); 652} catch (error) { 653 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 654 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 655} 656``` 657 658### MAGNETIC_FIELD<sup>9+</sup> 659 660on(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>, options?: Options): void 661 662Subscribes to data of the magnetic field sensor. 663 664**System capability**: SystemCapability.Sensors.Sensor 665 666**Parameters** 667 668| Name | Type | Mandatory| Description | 669| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 670| type | [SensorId](#sensorid9).MAGNETIC_FIELD | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**. | 671| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.| 672| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 673 674**Error codes** 675 676For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 677 678| ID| Error Message | 679| -------- | ------------------ | 680| 14500101 | Service exception. | 681 682**Example** 683 684```ts 685import sensor from "@ohos.sensor"; 686import BusinessError from "@ohos.base"; 687 688try { 689 sensor.on(sensor.SensorId.MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => { 690 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 691 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 692 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 693 }, { interval: 100000000 }); 694 setTimeout(() => { 695 sensor.off(sensor.SensorId.MAGNETIC_FIELD); 696 }, 500); 697} catch (error) { 698 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 699 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 700} 701``` 702 703### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 704 705on(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticFieldUncalibratedResponse>, options?: Options): void 706 707Subscribes to data of the uncalibrated magnetic field sensor. 708 709**System capability**: SystemCapability.Sensors.Sensor 710 711**Parameters** 712 713| Name | Type | Mandatory| Description | 714| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 715| type | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.| 716| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.| 717| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 718 719**Error codes** 720 721For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 722 723| ID| Error Message | 724| -------- | ------------------ | 725| 14500101 | Service exception. | 726 727**Example** 728 729```ts 730import sensor from "@ohos.sensor"; 731import BusinessError from "@ohos.base"; 732 733try { 734 sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => { 735 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 736 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 737 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 738 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 739 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 740 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 741 }, { interval: 100000000 }); 742 setTimeout(() => { 743 sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED); 744 }, 500); 745} catch (error) { 746 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 747 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 748} 749``` 750 751### ORIENTATION<sup>9+</sup> 752 753on(type: SensorId.ORIENTATION, callback: Callback<OrientationResponse>, options?: Options): void 754 755Subscribes to data of the orientation sensor. 756 757**System capability**: SystemCapability.Sensors.Sensor 758 759**Error codes** 760 761For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 762 763| ID| Error Message | 764| -------- | ------------------ | 765| 14500101 | Service exception. | 766 767**Parameters** 768 769| Name | Type | Mandatory| Description | 770| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------------------------- | 771| type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | 772| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to report the sensor data, which is a **OrientationResponse** object. | 773| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 774 775**Example** 776 777```ts 778import sensor from "@ohos.sensor"; 779import BusinessError from "@ohos.base"; 780 781try { 782 sensor.on(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => { 783 console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); 784 console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); 785 console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); 786 }, { interval: 100000000 }); 787 setTimeout(() => { 788 sensor.off(sensor.SensorId.ORIENTATION); 789 }, 500); 790} catch (error) { 791 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 792 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 793} 794``` 795 796### PEDOMETER<sup>9+</sup> 797 798on(type: SensorId.PEDOMETER, callback: Callback<PedometerResponse>, options?: Options): void 799 800Subscribes to data of the pedometer sensor. 801 802**Required permissions**: ohos.permission.ACTIVITY_MOTION 803 804**System capability**: SystemCapability.Sensors.Sensor 805 806**Error codes** 807 808For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 809 810| ID| Error Message | 811| -------- | ------------------ | 812| 14500101 | Service exception. | 813 814**Parameters** 815 816| Name | Type | Mandatory| Description | 817| -------- | ------------------------------------------------------- | ---- | ----------------------------------------------------------- | 818| type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | 819| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerResponse** object. | 820| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 821 822**Example** 823 824```ts 825import sensor from "@ohos.sensor"; 826import BusinessError from "@ohos.base"; 827 828try { 829 sensor.on(sensor.SensorId.PEDOMETER, (data: sensor.PedometerResponse) => { 830 console.info('Succeeded in invoking on. Step count: ' + data.steps); 831 }, { interval: 100000000 }); 832 setTimeout(() => { 833 sensor.off(sensor.SensorId.PEDOMETER); 834 }, 500); 835} catch (error) { 836 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 837 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 838} 839``` 840 841### PEDOMETER_DETECTION<sup>9+</sup> 842 843on(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>, 844 options?: Options): void 845 846Subscribes to data of the pedometer detection sensor. 847 848**Required permissions**: ohos.permission.ACTIVITY_MOTION 849 850**System capability**: SystemCapability.Sensors.Sensor 851 852**Parameters** 853 854| Name | Type | Mandatory| Description | 855| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 856| type | [SensorId](#sensorid9).PEDOMETER_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**. | 857| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.| 858| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 859 860**Error codes** 861 862For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 863 864| ID| Error Message | 865| -------- | ------------------ | 866| 14500101 | Service exception. | 867 868**Example** 869 870```ts 871import sensor from "@ohos.sensor"; 872import BusinessError from "@ohos.base"; 873 874try { 875 sensor.on(sensor.SensorId.PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => { 876 console.info('Succeeded in invoking on. Pedometer scalar: ' + data.scalar); 877 }, { interval: 100000000 }); 878 setTimeout(() => { 879 sensor.off(sensor.SensorId.PEDOMETER_DETECTION); 880 }, 500); 881} catch (error) { 882 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 883 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 884} 885``` 886 887### PROXIMITY<sup>9+</sup> 888 889on(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>, options?: Options): void 890 891Subscribes to data of the proximity sensor. 892 893**System capability**: SystemCapability.Sensors.Sensor 894 895**Parameters** 896 897| Name | Type | Mandatory| Description | 898| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 899| type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | 900| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object. | 901| options | [Options](#options) | No | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when proximity sensor events are frequently triggered.| 902 903**Error codes** 904 905For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 906 907| ID| Error Message | 908| -------- | ------------------ | 909| 14500101 | Service exception. | 910 911**Example** 912 913```ts 914import sensor from "@ohos.sensor"; 915import BusinessError from "@ohos.base"; 916 917try { 918 sensor.on(sensor.SensorId.PROXIMITY, (data: sensor.ProximityResponse) => { 919 console.info('Succeeded in invoking on. Distance: ' + data.distance); 920 }, { interval: 100000000 }); 921 setTimeout(() => { 922 sensor.off(sensor.SensorId.PROXIMITY); 923 }, 500); 924} catch (error) { 925 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 926 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 927} 928``` 929 930### ROTATION_VECTOR<sup>9+</sup> 931 932on(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorResponse>, 933 options?: Options): void 934 935Subscribes to data of the rotation vector sensor. 936 937**System capability**: SystemCapability.Sensors.Sensor 938 939**Parameters** 940 941| Name | Type | Mandatory| Description | 942| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 943| type | [SensorId](#sensorid9).ROTATION_VECTOR | Yes | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**. | 944| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to report the sensor data, which is a **RotationVectorResponse** object.| 945| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 946 947**Error codes** 948 949For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 950 951| ID| Error Message | 952| -------- | ------------------ | 953| 14500101 | Service exception. | 954 955**Example** 956 957```ts 958import sensor from "@ohos.sensor"; 959import BusinessError from "@ohos.base"; 960 961try { 962 sensor.on(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => { 963 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 964 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 965 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 966 console.info('Succeeded in invoking on. Scalar quantity: ' + data.w); 967 }, { interval: 100000000 }); 968 setTimeout(() => { 969 sensor.off(sensor.SensorId.ROTATION_VECTOR); 970 }, 500); 971} catch (error) { 972 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 973 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 974} 975``` 976 977### SIGNIFICANT_MOTION<sup>9+</sup> 978 979on(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>, 980 options?: Options): void 981 982Subscribes to data of the significant motion sensor. 983 984**System capability**: SystemCapability.Sensors.Sensor 985 986**Parameters** 987 988| Name | Type | Mandatory| Description | 989| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 990| type | [SensorId](#sensorid9).SIGNIFICANT_MOTION | Yes | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**. | 991| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.| 992| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 993 994**Error codes** 995 996For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 997 998| ID| Error Message | 999| -------- | ------------------ | 1000| 14500101 | Service exception. | 1001 1002**Example** 1003 1004```ts 1005import sensor from "@ohos.sensor"; 1006import BusinessError from "@ohos.base"; 1007 1008try { 1009 sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => { 1010 console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); 1011 }, { interval: 100000000 }); 1012 setTimeout(() => { 1013 sensor.off(sensor.SensorId.SIGNIFICANT_MOTION); 1014 }, 500); 1015} catch (error) { 1016 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1017 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 1018} 1019``` 1020 1021### WEAR_DETECTION<sup>9+</sup> 1022 1023on(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse>, 1024 options?: Options): void 1025 1026Subscribes to data of the wear detection sensor. 1027 1028**System capability**: SystemCapability.Sensors.Sensor 1029 1030**Parameters** 1031 1032| Name | Type | Mandatory| Description | 1033| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 1034| type | [SensorId](#sensorid9).WEAR_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**. | 1035| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to report the sensor data, which is a **WearDetectionResponse** object.| 1036| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns.| 1037 1038**Error codes** 1039 1040For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1041 1042| ID| Error Message | 1043| -------- | ------------------ | 1044| 14500101 | Service exception. | 1045 1046**Example** 1047 1048```ts 1049import sensor from "@ohos.sensor"; 1050import BusinessError from "@ohos.base"; 1051 1052try { 1053 sensor.on(sensor.SensorId.WEAR_DETECTION, (data: sensor.WearDetectionResponse) => { 1054 console.info('Succeeded in invoking on. Wear status: ' + data.value); 1055 }, { interval: 100000000 }); 1056 setTimeout(() => { 1057 sensor.off(sensor.SensorId.WEAR_DETECTION); 1058 }, 500); 1059} catch (error) { 1060 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1061 console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`); 1062} 1063``` 1064 1065## sensor.once<sup>9+</sup> 1066 1067### ACCELEROMETER<sup>9+</sup> 1068 1069once(type: SensorId.ACCELEROMETER, callback: Callback<AccelerometerResponse>): void 1070 1071Obtains data of the acceleration sensor once. 1072 1073**Required permissions**: ohos.permission.ACCELEROMETER 1074 1075**System capability**: SystemCapability.Sensors.Sensor 1076 1077**Parameters** 1078 1079| Name | Type | Mandatory| Description | 1080| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 1081| type | [SensorId](#sensorid9).ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**. | 1082| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerResponse** object.| 1083 1084**Error codes** 1085 1086For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1087 1088| ID| Error Message | 1089| -------- | ------------------ | 1090| 14500101 | Service exception. | 1091 1092**Example** 1093 1094```ts 1095import sensor from "@ohos.sensor"; 1096import BusinessError from "@ohos.base"; 1097 1098try { 1099 sensor.once(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => { 1100 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1101 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1102 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1103 }); 1104} catch (error) { 1105 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1106 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1107} 1108``` 1109 1110### ACCELEROMETER_UNCALIBRATED<sup>9+</sup> 1111 1112once(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback: Callback<AccelerometerUncalibratedResponse>): void 1113 1114Obtains data of the uncalibrated acceleration sensor once. 1115 1116**Required permissions**: ohos.permission.ACCELEROMETER 1117 1118**System capability**: SystemCapability.Sensors.Sensor 1119 1120**Parameters** 1121 1122| Name | Type | Mandatory| Description | 1123| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1124| type | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. | 1125| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to report the sensor data, which is an **AccelerometerUncalibratedResponse** object.| 1126 1127**Error codes** 1128 1129For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1130 1131| ID| Error Message | 1132| -------- | ------------------ | 1133| 14500101 | Service exception. | 1134 1135**Example** 1136 1137```ts 1138import sensor from "@ohos.sensor"; 1139import BusinessError from "@ohos.base"; 1140 1141try { 1142 sensor.once(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => { 1143 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1144 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1145 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1146 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 1147 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 1148 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 1149 }); 1150} catch (error) { 1151 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1152 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1153} 1154``` 1155 1156### AMBIENT_LIGHT<sup>9+</sup> 1157 1158once(type: SensorId.AMBIENT_LIGHT, callback: Callback<LightResponse>): void 1159 1160Obtains data of the ambient light sensor once. 1161 1162**System capability**: SystemCapability.Sensors.Sensor 1163 1164**Parameters** 1165 1166| Name | Type | Mandatory| Description | 1167| -------- | ----------------------------------------------- | ---- | --------------------------------------------------- | 1168| type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | 1169| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to report the sensor data, which is a **LightResponse** object.| 1170 1171**Error codes** 1172 1173For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1174 1175| ID| Error Message | 1176| -------- | ------------------ | 1177| 14500101 | Service exception. | 1178 1179**Example** 1180 1181```ts 1182import sensor from "@ohos.sensor"; 1183import BusinessError from "@ohos.base"; 1184 1185try { 1186 sensor.once(sensor.SensorId.AMBIENT_LIGHT, (data: sensor.LightResponse) => { 1187 console.info('Succeeded in invoking once. the ambient light intensity: ' + data.intensity); 1188 }); 1189} catch (error) { 1190 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1191 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1192} 1193``` 1194 1195### AMBIENT_TEMPERATURE<sup>9+</sup> 1196 1197once(type: SensorId.AMBIENT_TEMPERATURE, callback: Callback<AmbientTemperatureResponse>): void 1198 1199Obtains data of the temperature sensor once. 1200 1201**System capability**: SystemCapability.Sensors.Sensor 1202 1203**Parameters** 1204 1205| Name | Type | Mandatory| Description | 1206| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1207| type | [SensorId](#sensorid9).AMBIENT_TEMPERATURE | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**. | 1208| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to report the sensor data, which is an **AmbientTemperatureResponse** object.| 1209 1210**Error codes** 1211 1212For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1213 1214| ID| Error Message | 1215| -------- | ------------------ | 1216| 14500101 | Service exception. | 1217 1218**Example** 1219 1220```ts 1221import sensor from "@ohos.sensor"; 1222import BusinessError from "@ohos.base"; 1223 1224try { 1225 sensor.once(sensor.SensorId.AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => { 1226 console.info('Succeeded in invoking once. Temperature: ' + data.temperature); 1227 }); 1228} catch (error) { 1229 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1230 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1231} 1232``` 1233 1234### BAROMETER<sup>9+</sup> 1235 1236once(type: SensorId.BAROMETER, callback: Callback<BarometerResponse>): void 1237 1238Obtains data of the barometer sensor once. 1239 1240**System capability**: SystemCapability.Sensors.Sensor 1241 1242**Parameters** 1243 1244| Name | Type | Mandatory| Description | 1245| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | 1246| type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | 1247| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to report the sensor data, which is a **BarometerResponse** object.| 1248 1249**Error codes** 1250 1251For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1252 1253| ID| Error Message | 1254| -------- | ------------------ | 1255| 14500101 | Service exception. | 1256 1257**Example** 1258 1259```ts 1260import sensor from "@ohos.sensor"; 1261import BusinessError from "@ohos.base"; 1262 1263try { 1264 sensor.once(sensor.SensorId.BAROMETER, (data: sensor.BarometerResponse) => { 1265 console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure); 1266 }); 1267} catch (error) { 1268 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1269 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1270} 1271``` 1272 1273### GRAVITY<sup>9+</sup> 1274 1275once(type: SensorId.GRAVITY, callback: Callback<GravityResponse>): void 1276 1277Obtains data of the gravity sensor once. 1278 1279**System capability**: SystemCapability.Sensors.Sensor 1280 1281**Parameters** 1282 1283| Name | Type | Mandatory| Description | 1284| -------- | --------------------------------------------------- | ---- | ----------------------------------------------------- | 1285| type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | 1286| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to report the sensor data, which is a **GravityResponse** object.| 1287 1288**Error codes** 1289 1290For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1291 1292| ID| Error Message | 1293| -------- | ------------------ | 1294| 14500101 | Service exception. | 1295 1296**Example** 1297 1298```ts 1299import sensor from "@ohos.sensor"; 1300import BusinessError from "@ohos.base"; 1301 1302try { 1303 sensor.once(sensor.SensorId.GRAVITY, (data: sensor.GravityResponse) => { 1304 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1305 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1306 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1307 }); 1308} catch (error) { 1309 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1310 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1311} 1312``` 1313 1314### GYROSCOPE<sup>9+</sup> 1315 1316once(type: SensorId.GYROSCOPE, callback: Callback<GyroscopeResponse>): void 1317 1318Obtains to data of the gyroscope sensor once. 1319 1320**Required permissions**: ohos.permission.GYROSCOPE 1321 1322**System capability**: SystemCapability.Sensors.Sensor 1323 1324**Parameters** 1325 1326| Name | Type | Mandatory| Description | 1327| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | 1328| type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | 1329| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeResponse** object.| 1330 1331**Error codes** 1332 1333For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1334 1335| ID| Error Message | 1336| -------- | ------------------ | 1337| 14500101 | Service exception. | 1338 1339**Example** 1340 1341```ts 1342import sensor from '@ohos.sensor'; 1343import BusinessError from "@ohos.base"; 1344 1345try { 1346 sensor.once(sensor.SensorId.GYROSCOPE, (data: sensor.GyroscopeResponse) => { 1347 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1348 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1349 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1350 }); 1351} catch (error) { 1352 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1353 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1354} 1355``` 1356 1357### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 1358 1359once(type: SensorId.GYROSCOPE_UNCALIBRATED, callback: Callback<GyroscopeUncalibratedResponse>): void 1360 1361Obtains data of the uncalibrated gyroscope sensor once. 1362 1363**Required permissions**: ohos.permission.GYROSCOPE 1364 1365**System capability**: SystemCapability.Sensors.Sensor 1366 1367**Parameters** 1368 1369| Name | Type | Mandatory| Description | 1370| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1371| type | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**. | 1372| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **GyroscopeUncalibratedResponse** object.| 1373 1374**Error codes** 1375 1376For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1377 1378| ID| Error Message | 1379| -------- | ------------------ | 1380| 14500101 | Service exception. | 1381 1382**Example** 1383 1384```ts 1385import sensor from "@ohos.sensor"; 1386import BusinessError from "@ohos.base"; 1387 1388try { 1389 sensor.once(sensor.SensorId.GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => { 1390 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1391 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1392 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1393 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 1394 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 1395 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 1396 }); 1397} catch (error) { 1398 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1399 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1400} 1401``` 1402 1403### HALL<sup>9+</sup> 1404 1405once(type: SensorId.HALL, callback: Callback<HallResponse>): void 1406 1407Obtains data of the Hall effect sensor once. 1408 1409**System capability**: SystemCapability.Sensors.Sensor 1410 1411**Parameters** 1412 1413| Name | Type | Mandatory| Description | 1414| -------- | --------------------------------------------- | ---- | -------------------------------------------------- | 1415| type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | 1416| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to report the sensor data, which is a **HallResponse** object.| 1417 1418**Error codes** 1419 1420For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1421 1422| ID| Error Message | 1423| -------- | ------------------ | 1424| 14500101 | Service exception. | 1425 1426**Example** 1427 1428```ts 1429import sensor from "@ohos.sensor"; 1430import BusinessError from "@ohos.base"; 1431 1432try { 1433 sensor.once(sensor.SensorId.HALL, (data: sensor.HallResponse) => { 1434 console.info('Succeeded in invoking once. Status: ' + data.status); 1435 }); 1436} catch (error) { 1437 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1438 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1439} 1440``` 1441 1442### HEART_RATE<sup>9+</sup> 1443 1444once(type: SensorId.HEART_RATE, callback: Callback<HeartRateResponse>): void 1445 1446Obtains data of the heart rate sensor once. 1447 1448**Required permissions**: ohos.permission.READ_HEALTH_DATA 1449 1450**System capability**: SystemCapability.Sensors.Sensor 1451 1452**Parameters** 1453 1454| Name | Type | Mandatory| Description | 1455| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | 1456| type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | 1457| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to report the sensor data, which is a **HeartRateResponse** object.| 1458 1459**Error codes** 1460 1461For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1462 1463| ID| Error Message | 1464| -------- | ------------------ | 1465| 14500101 | Service exception. | 1466 1467**Example** 1468 1469```ts 1470import sensor from "@ohos.sensor"; 1471import BusinessError from "@ohos.base"; 1472 1473try { 1474 sensor.once(sensor.SensorId.HEART_RATE, (data: sensor.HeartRateResponse) => { 1475 console.info('Succeeded in invoking once. Heart rate: ' + data.heartRate); 1476 }); 1477} catch (error) { 1478 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1479 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1480} 1481``` 1482 1483### HUMIDITY<sup>9+</sup> 1484 1485once(type: SensorId.HUMIDITY, callback: Callback<HumidityResponse>): void 1486 1487Obtains data of the humidity sensor once. 1488 1489**System capability**: SystemCapability.Sensors.Sensor 1490 1491**Parameters** 1492 1493| Name | Type | Mandatory| Description | 1494| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------ | 1495| type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | 1496| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to report the sensor data, which is a **HumidityResponse** object.| 1497 1498**Error codes** 1499 1500For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1501 1502| ID| Error Message | 1503| -------- | ------------------ | 1504| 14500101 | Service exception. | 1505 1506**Example** 1507 1508```ts 1509import sensor from "@ohos.sensor"; 1510import BusinessError from "@ohos.base"; 1511 1512try { 1513 sensor.once(sensor.SensorId.HUMIDITY, (data: sensor.HumidityResponse) => { 1514 console.info('Succeeded in invoking once. Humidity: ' + data.humidity); 1515 }); 1516} catch (error) { 1517 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1518 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1519} 1520``` 1521 1522### LINEAR_ACCELEROMETER<sup>9+</sup> 1523 1524once(type: SensorId.LINEAR_ACCELEROMETER, callback: Callback<LinearAccelerometerResponse>): void 1525 1526Obtains data of the linear acceleration sensor once. 1527 1528**Required permissions**: ohos.permission.ACCELEROMETER 1529 1530**System capability**: SystemCapability.Sensors.Sensor 1531 1532**Parameters** 1533 1534| Name | Type | Mandatory| Description | 1535| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1536| type | [SensorId](#sensorid9).LINEAR_ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELEROMETER**. | 1537| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to report the sensor data, which is a **LinearAccelerometerResponse** object.| 1538 1539**Error codes** 1540 1541For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1542 1543| ID| Error Message | 1544| -------- | ------------------ | 1545| 14500101 | Service exception. | 1546 1547**Example** 1548 1549```ts 1550import sensor from "@ohos.sensor"; 1551import BusinessError from "@ohos.base"; 1552 1553try { 1554 sensor.once(sensor.SensorId.LINEAR_ACCELEROMETER, (data: sensor.LinearAccelerometerResponse) => { 1555 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1556 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1557 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1558 }); 1559} catch (error) { 1560 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1561 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1562} 1563``` 1564 1565### MAGNETIC_FIELD<sup>9+</sup> 1566 1567once(type: SensorId.MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>): void 1568 1569Obtains data of the magnetic field sensor once. 1570 1571**System capability**: SystemCapability.Sensors.Sensor 1572 1573**Parameters** 1574 1575| Name | Type | Mandatory| Description | 1576| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 1577| type | [SensorId](#sensorid9).MAGNETIC_FIELD | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**. | 1578| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldResponse** object.| 1579 1580**Error codes** 1581 1582For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1583 1584| ID| Error Message | 1585| -------- | ------------------ | 1586| 14500101 | Service exception. | 1587 1588**Example** 1589 1590```ts 1591import sensor from "@ohos.sensor"; 1592import BusinessError from "@ohos.base"; 1593 1594try { 1595 sensor.once(sensor.SensorId.MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => { 1596 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1597 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1598 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1599 }); 1600} catch (error) { 1601 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1602 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1603} 1604``` 1605 1606### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 1607 1608once(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback: Callback<MagneticFieldUncalibratedResponse>): void 1609 1610Obtains data of the uncalibrated magnetic field sensor once. 1611 1612**System capability**: SystemCapability.Sensors.Sensor 1613 1614**Parameters** 1615 1616| Name | Type | Mandatory| Description | 1617| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1618| type | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.| 1619| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to report the sensor data, which is a **MagneticFieldUncalibratedResponse** object.| 1620 1621**Error codes** 1622 1623For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1624 1625| ID| Error Message | 1626| -------- | ------------------ | 1627| 14500101 | Service exception. | 1628 1629**Example** 1630 1631```ts 1632import sensor from "@ohos.sensor"; 1633import BusinessError from "@ohos.base"; 1634 1635try { 1636 sensor.once(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => { 1637 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1638 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1639 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1640 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 1641 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 1642 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 1643 }); 1644} catch (error) { 1645 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1646 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1647} 1648``` 1649 1650### ORIENTATION<sup>9+</sup> 1651 1652once(type: SensorId.ORIENTATION, callback: Callback<OrientationResponse>): void 1653 1654Obtains data of the orientation sensor once. 1655 1656**System capability**: SystemCapability.Sensors.Sensor 1657 1658**Parameters** 1659 1660| Name | Type | Mandatory| Description | 1661| -------- | ----------------------------------------------------------- | ---- | --------------------------------------------------------- | 1662| type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | 1663| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to report the sensor data, which is a **OrientationResponse** object.| 1664 1665**Error codes** 1666 1667For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1668 1669| ID| Error Message | 1670| -------- | ------------------ | 1671| 14500101 | Service exception. | 1672 1673**Example** 1674 1675```ts 1676import sensor from "@ohos.sensor"; 1677import BusinessError from "@ohos.base"; 1678 1679try { 1680 sensor.once(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => { 1681 console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); 1682 console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); 1683 console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); 1684 }); 1685} catch (error) { 1686 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1687 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1688} 1689``` 1690 1691### PEDOMETER<sup>9+</sup> 1692 1693once(type: SensorId.PEDOMETER, callback: Callback<PedometerResponse>): void 1694 1695Obtains data of the pedometer sensor once. 1696 1697**Required permissions**: ohos.permission.ACTIVITY_MOTION 1698 1699**System capability**: SystemCapability.Sensors.Sensor 1700 1701**Parameters** 1702 1703| Name | Type | Mandatory| Description | 1704| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | 1705| type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | 1706| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerResponse** object.| 1707 1708**Error codes** 1709 1710For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1711 1712| ID| Error Message | 1713| -------- | ------------------ | 1714| 14500101 | Service exception. | 1715 1716**Example** 1717 1718```ts 1719import sensor from "@ohos.sensor"; 1720import BusinessError from "@ohos.base"; 1721 1722try { 1723 sensor.once(sensor.SensorId.PEDOMETER, (data: sensor.PedometerResponse) => { 1724 console.info('Succeeded in invoking once. Step count: ' + data.steps); 1725 }); 1726} catch (error) { 1727 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1728 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1729} 1730``` 1731 1732### PEDOMETER_DETECTION<sup>9+</sup> 1733 1734once(type: SensorId.PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>): void 1735 1736Obtains data of the pedometer sensor once. 1737 1738**Required permissions**: ohos.permission.ACTIVITY_MOTION 1739 1740**System capability**: SystemCapability.Sensors.Sensor 1741 1742**Parameters** 1743 1744| Name | Type | Mandatory| Description | 1745| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1746| type | [SensorId](#sensorid9).PEDOMETER_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**. | 1747| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to report the sensor data, which is a **PedometerDetectionResponse** object.| 1748 1749**Error codes** 1750 1751For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1752 1753| ID| Error Message | 1754| -------- | ------------------ | 1755| 14500101 | Service exception. | 1756 1757**Example** 1758 1759```ts 1760import sensor from "@ohos.sensor"; 1761import BusinessError from "@ohos.base"; 1762 1763try { 1764 sensor.once(sensor.SensorId.PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => { 1765 console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); 1766 }); 1767} catch (error) { 1768 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1769 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1770} 1771``` 1772 1773### PROXIMITY<sup>9+</sup> 1774 1775once(type: SensorId.PROXIMITY, callback: Callback<ProximityResponse>): void 1776 1777Obtains data of the proximity sensor once. 1778 1779**System capability**: SystemCapability.Sensors.Sensor 1780 1781**Parameters** 1782 1783| Name | Type | Mandatory| Description | 1784| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------- | 1785| type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | 1786| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to report the sensor data, which is a **ProximityResponse** object.| 1787 1788**Error codes** 1789 1790For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1791 1792| ID| Error Message | 1793| -------- | ------------------ | 1794| 14500101 | Service exception. | 1795 1796**Example** 1797 1798```ts 1799import sensor from "@ohos.sensor"; 1800import BusinessError from "@ohos.base"; 1801 1802try { 1803 sensor.once(sensor.SensorId.PROXIMITY, (data: sensor.ProximityResponse) => { 1804 console.info('Succeeded in invoking once. Distance: ' + data.distance); 1805 }); 1806} catch (error) { 1807 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1808 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1809} 1810``` 1811 1812### ROTATION_VECTOR<sup>9+</sup> 1813 1814once(type: SensorId.ROTATION_VECTOR, callback: Callback<RotationVectorResponse>): void 1815 1816Obtains data of the rotation vector sensor once. 1817 1818**System capability**: SystemCapability.Sensors.Sensor 1819 1820**Parameters** 1821 1822| Name | Type | Mandatory| Description | 1823| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1824| type | [SensorId](#sensorid9).ROTATION_VECTOR | Yes | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**. | 1825| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to report the sensor data, which is a **RotationVectorResponse** object.| 1826 1827**Error codes** 1828 1829For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1830 1831| ID| Error Message | 1832| -------- | ------------------ | 1833| 14500101 | Service exception. | 1834 1835**Example** 1836 1837```ts 1838import sensor from "@ohos.sensor"; 1839import BusinessError from "@ohos.base"; 1840 1841try { 1842 sensor.once(sensor.SensorId.ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => { 1843 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 1844 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 1845 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 1846 console.info('Succeeded in invoking once. Scalar quantity: ' + data.w); 1847 }); 1848} catch (error) { 1849 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1850 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1851} 1852``` 1853 1854### SIGNIFICANT_MOTION<sup>9+</sup> 1855 1856once(type: SensorId.SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>): void 1857 1858Obtains data of the significant motion sensor once. 1859 1860**System capability**: SystemCapability.Sensors.Sensor 1861 1862**Parameters** 1863 1864| Name | Type | Mandatory| Description | 1865| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1866| type | [SensorId](#sensorid9).SIGNIFICANT_MOTION | Yes | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**. | 1867| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to report the sensor data, which is a **SignificantMotionResponse** object.| 1868 1869**Error codes** 1870 1871For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1872 1873| ID| Error Message | 1874| -------- | ------------------ | 1875| 14500101 | Service exception. | 1876 1877**Example** 1878 1879```ts 1880import sensor from "@ohos.sensor"; 1881import BusinessError from "@ohos.base"; 1882 1883try { 1884 sensor.once(sensor.SensorId.SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => { 1885 console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); 1886 }); 1887} catch (error) { 1888 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1889 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1890} 1891``` 1892 1893### WEAR_DETECTION<sup>9+</sup> 1894 1895once(type: SensorId.WEAR_DETECTION, callback: Callback<WearDetectionResponse>): void 1896 1897Obtains data of the wear detection sensor once. 1898 1899**System capability**: SystemCapability.Sensors.Sensor 1900 1901**Parameters** 1902 1903| Name | Type | Mandatory| Description | 1904| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------------- | 1905| type | [SensorId](#sensorid9).WEAR_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**. | 1906| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to report the sensor data, which is a **WearDetectionResponse** object.| 1907 1908**Error codes** 1909 1910For details about the following error codes, see [Sensor Error Codes](../errorcodes/errorcode-sensor.md). 1911 1912| ID| Error Message | 1913| -------- | ------------------ | 1914| 14500101 | Service exception. | 1915 1916**Example** 1917 1918```ts 1919import sensor from "@ohos.sensor"; 1920import BusinessError from "@ohos.base"; 1921 1922try { 1923 sensor.once(sensor.SensorId.WEAR_DETECTION, (data: sensor.WearDetectionResponse) => { 1924 console.info('Succeeded in invoking once. Wear status: ' + data.value); 1925 }); 1926} catch (error) { 1927 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1928 console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`); 1929} 1930``` 1931 1932## sensor.off 1933 1934### COLOR<sup>10+</sup> 1935 1936off(type: SensorId.COLOR, callback?: Callback\<ColorResponse>): void 1937 1938Unsubscribes from data of the color sensor. 1939 1940**System capability**: SystemCapability.Sensors.Sensor 1941 1942**System API**: This is a system API. 1943 1944**Parameters** 1945 1946| Name | Type | Mandatory| Description | 1947| -------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | 1948| type | [SensorId](#sensorid9).COLOR | Yes | Sensor type. The value is fixed at **SensorId.COLOR**. | 1949| callback | Callback<[ColorResponse](#colorresponse10)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 1950 1951**Example** 1952 1953```ts 1954import sensor from "@ohos.sensor"; 1955import BusinessError from "@ohos.base"; 1956 1957function callback1(data: object) { 1958 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 1959} 1960 1961function callback2(data: object) { 1962 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 1963} 1964 1965try { 1966 sensor.on(sensor.SensorId.COLOR, callback1); 1967 sensor.on(sensor.SensorId.COLOR, callback2); 1968 // Unsubscribe from callback1. 1969 sensor.off(sensor.SensorId.COLOR, callback1); 1970 // Unsubscribe from all callbacks of the SensorId.COLOR type. 1971 sensor.off(sensor.SensorId.COLOR); 1972} catch (error) { 1973 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 1974 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 1975} 1976``` 1977 1978### SAR<sup>10+</sup> 1979 1980off(type: SensorId.SAR, callback?: Callback\<SarResponse>): void 1981 1982Unsubscribes from data of the SAR sensor. 1983 1984**System capability**: SystemCapability.Sensors.Sensor 1985 1986**System API**: This is a system API. 1987 1988**Parameters** 1989 1990| Name | Type | Mandatory| Description | 1991| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | 1992| type | [SensorId](#sensorid9).SAR | Yes | Sensor type. The value is fixed at **SensorId.SAR**. | 1993| callback | Callback<[SarResponse](#sarresponse10)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 1994 1995**Example** 1996 1997```ts 1998import sensor from "@ohos.sensor"; 1999import BusinessError from "@ohos.base"; 2000 2001function callback1(data: object) { 2002 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2003} 2004 2005function callback2(data: object) { 2006 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2007} 2008 2009try { 2010 sensor.on(sensor.SensorId.SAR, callback1); 2011 sensor.on(sensor.SensorId.SAR, callback2); 2012 // Unsubscribe from callback1. 2013 sensor.off(sensor.SensorId.SAR, callback1); 2014 // Unsubscribe from all callbacks of the SensorId.SAR type. 2015 sensor.off(sensor.SensorId.SAR); 2016} catch (error) { 2017 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2018 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2019} 2020``` 2021 2022### ACCELEROMETER<sup>9+</sup> 2023 2024off(type: SensorId.ACCELEROMETER, callback?: Callback<AccelerometerResponse>): void 2025 2026Unsubscribes from data of the acceleration sensor. 2027 2028**Required permissions**: ohos.permission.ACCELEROMETER 2029 2030**System capability**: SystemCapability.Sensors.Sensor 2031 2032**Parameters** 2033 2034| Name | Type | Mandatory| Description | 2035| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2036| type | [SensorId](#sensorid9).ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER**. | 2037| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2038 2039**Example** 2040 2041```ts 2042import sensor from "@ohos.sensor"; 2043import BusinessError from "@ohos.base"; 2044 2045function callback1(data: object) { 2046 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2047} 2048 2049function callback2(data: object) { 2050 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2051} 2052 2053try { 2054 sensor.on(sensor.SensorId.ACCELEROMETER, callback1); 2055 sensor.on(sensor.SensorId.ACCELEROMETER, callback2); 2056 // Unsubscribe from callback1. 2057 sensor.off(sensor.SensorId.ACCELEROMETER, callback1); 2058 // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER type. 2059 sensor.off(sensor.SensorId.ACCELEROMETER); 2060} catch (error) { 2061 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2062 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2063} 2064``` 2065 2066### ACCELEROMETER_UNCALIBRATED<sup>9+</sup> 2067 2068off(type: SensorId.ACCELEROMETER_UNCALIBRATED, callback?: Callback<AccelerometerUncalibratedResponse>): void 2069 2070Unsubscribes from data of the uncalibrated acceleration sensor. 2071 2072**Required permissions**: ohos.permission.ACCELEROMETER 2073 2074**System capability**: SystemCapability.Sensors.Sensor 2075 2076**Parameters** 2077 2078| Name | Type | Mandatory| Description | 2079| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2080| type | [SensorId](#sensorid9).ACCELEROMETER_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.ACCELEROMETER_UNCALIBRATED**. | 2081| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2082 2083**Example** 2084 2085```ts 2086import sensor from "@ohos.sensor"; 2087import BusinessError from "@ohos.base"; 2088 2089function callback1(data: object) { 2090 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2091} 2092 2093function callback2(data: object) { 2094 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2095} 2096 2097try { 2098 sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); 2099 sensor.on(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback2); 2100 // Unsubscribe from callback1. 2101 sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED, callback1); 2102 // Unsubscribe from all callbacks of the SensorId.ACCELEROMETER_UNCALIBRATED type. 2103 sensor.off(sensor.SensorId.ACCELEROMETER_UNCALIBRATED); 2104} catch (error) { 2105 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2106 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2107} 2108``` 2109 2110### AMBIENT_LIGHT<sup>9+</sup> 2111 2112off(type: SensorId.AMBIENT_LIGHT, callback?: Callback<LightResponse>): void 2113 2114Unsubscribes from data of the ambient light sensor. 2115 2116**System capability**: SystemCapability.Sensors.Sensor 2117 2118**Parameters** 2119 2120| Name | Type | Mandatory| Description | 2121| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 2122| type | [SensorId](#sensorid9).AMBIENT_LIGHT | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_LIGHT**. | 2123| callback | Callback<[LightResponse](#lightresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2124 2125**Example** 2126 2127```ts 2128import sensor from "@ohos.sensor"; 2129import BusinessError from "@ohos.base"; 2130 2131function callback1(data: object) { 2132 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2133} 2134 2135function callback2(data: object) { 2136 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2137} 2138 2139try { 2140 sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback1); 2141 sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2); 2142 // Unsubscribe from callback1. 2143 sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback1); 2144 // Unsubscribe from all callbacks of the SensorId.AMBIENT_LIGHT type. 2145 sensor.off(sensor.SensorId.AMBIENT_LIGHT); 2146} catch (error) { 2147 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2148 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2149} 2150``` 2151 2152### AMBIENT_TEMPERATURE<sup>9+</sup> 2153 2154off(type: SensorId.AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatureResponse>): void 2155 2156Unsubscribes from data of the ambient temperature sensor. 2157 2158**System capability**: SystemCapability.Sensors.Sensor 2159 2160**Parameters** 2161 2162| Name | Type | Mandatory| Description | 2163| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2164| type | [SensorId](#sensorid9).AMBIENT_TEMPERATURE | Yes | Sensor type. The value is fixed at **SensorId.AMBIENT_TEMPERATURE**. | 2165| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2166 2167**Example** 2168 2169```ts 2170import sensor from "@ohos.sensor"; 2171import BusinessError from "@ohos.base"; 2172 2173function callback1(data: object) { 2174 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2175} 2176 2177function callback2(data: object) { 2178 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2179} 2180 2181try { 2182 sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); 2183 sensor.on(sensor.SensorId.AMBIENT_TEMPERATURE, callback2); 2184 // Unsubscribe from callback1. 2185 sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE, callback1); 2186 // Unsubscribe from all callbacks of the SensorId.AMBIENT_TEMPERATURE type. 2187 sensor.off(sensor.SensorId.AMBIENT_TEMPERATURE); 2188} catch (error) { 2189 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2190 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2191} 2192``` 2193 2194### BAROMETER<sup>9+</sup> 2195 2196off(type: SensorId.BAROMETER, callback?: Callback<BarometerResponse>): void 2197 2198Unsubscribes from data of the barometer sensor. 2199 2200**System capability**: SystemCapability.Sensors.Sensor 2201 2202**Parameters** 2203 2204| Name | Type | Mandatory| Description | 2205| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2206| type | [SensorId](#sensorid9).BAROMETER | Yes | Sensor type. The value is fixed at **SensorId.BAROMETER**. | 2207| callback | Callback<[BarometerResponse](#barometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2208 2209**Example** 2210 2211```ts 2212import sensor from "@ohos.sensor"; 2213import BusinessError from "@ohos.base"; 2214 2215function callback1(data: object) { 2216 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2217} 2218 2219function callback2(data: object) { 2220 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2221} 2222 2223try { 2224 sensor.on(sensor.SensorId.BAROMETER, callback1); 2225 sensor.on(sensor.SensorId.BAROMETER, callback2); 2226 // Unsubscribe from callback1. 2227 sensor.off(sensor.SensorId.BAROMETER, callback1); 2228 // Unsubscribe from all callbacks of the SensorId.BAROMETER type. 2229 sensor.off(sensor.SensorId.BAROMETER); 2230} catch (error) { 2231 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2232 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2233} 2234``` 2235 2236### GRAVITY<sup>9+</sup> 2237 2238off(type: SensorId.GRAVITY, callback?: Callback<GravityResponse>): void 2239 2240Unsubscribes from data of the gravity sensor. 2241 2242**System capability**: SystemCapability.Sensors.Sensor 2243 2244**Parameters** 2245 2246| Name | Type | Mandatory| Description | 2247| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ | 2248| type | [SensorId](#sensorid9).GRAVITY | Yes | Sensor type. The value is fixed at **SensorId.GRAVITY**. | 2249| callback | Callback<[GravityResponse](#gravityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2250 2251**Example** 2252 2253```ts 2254import sensor from "@ohos.sensor"; 2255import BusinessError from "@ohos.base"; 2256 2257function callback1(data: object) { 2258 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2259} 2260 2261function callback2(data: object) { 2262 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2263} 2264 2265try { 2266 sensor.on(sensor.SensorId.GRAVITY, callback1); 2267 sensor.on(sensor.SensorId.GRAVITY, callback2); 2268 // Unsubscribe from callback1. 2269 sensor.off(sensor.SensorId.GRAVITY, callback1); 2270 // Unsubscribe from all callbacks of the SensorId.GRAVITY type. 2271 sensor.off(sensor.SensorId.GRAVITY); 2272} catch (error) { 2273 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2274 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2275} 2276 2277``` 2278 2279### GYROSCOPE<sup>9+</sup> 2280 2281off(type: SensorId.GYROSCOPE, callback?: Callback<GyroscopeResponse>): void 2282 2283Unsubscribes from data of the gyroscope sensor. 2284 2285**Required permissions**: ohos.permission.GYROSCOPE 2286 2287**System capability**: SystemCapability.Sensors.Sensor 2288 2289**Parameters** 2290 2291| Name | Type | Mandatory| Description | 2292| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2293| type | [SensorId](#sensorid9).GYROSCOPE | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE**. | 2294| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2295 2296**Example** 2297 2298```ts 2299import sensor from "@ohos.sensor"; 2300import BusinessError from "@ohos.base"; 2301 2302function callback1(data: object) { 2303 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2304} 2305 2306function callback2(data: object) { 2307 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2308} 2309 2310try { 2311 sensor.on(sensor.SensorId.GYROSCOPE, callback1); 2312 sensor.on(sensor.SensorId.GYROSCOPE, callback2); 2313 // Unsubscribe from callback1. 2314 sensor.off(sensor.SensorId.GYROSCOPE, callback1); 2315 // Unsubscribe from all callbacks of the SensorId.GYROSCOPE type. 2316 sensor.off(sensor.SensorId.GYROSCOPE); 2317} catch (error) { 2318 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2319 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2320} 2321``` 2322 2323### GYROSCOPE_UNCALIBRATED<sup>9+</sup> 2324 2325off(type: SensorId.GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncalibratedResponse>): void 2326 2327 Unsubscribes from data of the uncalibrated gyroscope sensor. 2328 2329**Required permissions**: ohos.permission.GYROSCOPE 2330 2331**System capability**: SystemCapability.Sensors.Sensor 2332 2333**Parameters** 2334 2335| Name | Type | Mandatory| Description | 2336| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2337| type | [SensorId](#sensorid9).GYROSCOPE_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.GYROSCOPE_UNCALIBRATED**. | 2338| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2339 2340**Example** 2341 2342```ts 2343import sensor from "@ohos.sensor"; 2344import BusinessError from "@ohos.base"; 2345 2346function callback1(data: object) { 2347 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2348} 2349 2350function callback2(data: object) { 2351 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2352} 2353 2354try { 2355 sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); 2356 sensor.on(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback2); 2357 // Unsubscribe from callback1. 2358 sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED, callback1); 2359 // Unsubscribe from all callbacks of the SensorId.GYROSCOPE_UNCALIBRATED type. 2360 sensor.off(sensor.SensorId.GYROSCOPE_UNCALIBRATED); 2361} catch (error) { 2362 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2363 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2364} 2365``` 2366 2367### HALL<sup>9+</sup> 2368 2369off(type: SensorId.HALL, callback?: Callback<HallResponse>): void 2370 2371Unsubscribes from data of the Hall effect sensor. 2372 2373**System capability**: SystemCapability.Sensors.Sensor 2374 2375**Parameters** 2376 2377| Name | Type | Mandatory| Description | 2378| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 2379| type | [SensorId](#sensorid9).HALL | Yes | Sensor type. The value is fixed at **SensorId.HALL**. | 2380| callback | Callback<[HallResponse](#hallresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2381 2382**Example** 2383 2384```ts 2385import sensor from "@ohos.sensor"; 2386import BusinessError from "@ohos.base"; 2387 2388function callback1(data: object) { 2389 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2390} 2391 2392function callback2(data: object) { 2393 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2394} 2395 2396try { 2397 sensor.on(sensor.SensorId.HALL, callback1); 2398 sensor.on(sensor.SensorId.HALL, callback2); 2399 // Unsubscribe from callback1. 2400 sensor.off(sensor.SensorId.HALL, callback1); 2401 // Unsubscribe from all callbacks of the SensorId.HALL type. 2402 sensor.off(sensor.SensorId.HALL); 2403} catch (error) { 2404 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2405 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2406} 2407``` 2408 2409### HEART_RATE<sup>9+</sup> 2410 2411off(type: SensorId.HEART_RATE, callback?: Callback<HeartRateResponse>): void 2412 2413Unsubscribes from data of the heart rate sensor. 2414 2415**Required permissions**: ohos.permission.READ_HEALTH_DATA 2416 2417**System capability**: SystemCapability.Sensors.Sensor 2418 2419**Parameters** 2420 2421| Name | Type | Mandatory| Description | 2422| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2423| type | [SensorId](#sensorid9).HEART_RATE | Yes | Sensor type. The value is fixed at **SensorId.HEART_RATE**. | 2424| callback | Callback<[HeartRateResponse](#heartrateresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2425 2426**Example** 2427 2428```ts 2429import sensor from "@ohos.sensor"; 2430import BusinessError from "@ohos.base"; 2431 2432function callback1(data: object) { 2433 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2434} 2435 2436function callback2(data: object) { 2437 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2438} 2439 2440try { 2441 sensor.on(sensor.SensorId.HEART_RATE, callback1); 2442 sensor.on(sensor.SensorId.HEART_RATE, callback2); 2443 // Unsubscribe from callback1. 2444 sensor.off(sensor.SensorId.HEART_RATE, callback1); 2445 // Unsubscribe from all callbacks of the SensorId.HEART_RATE type. 2446 sensor.off(sensor.SensorId.HEART_RATE); 2447} catch (error) { 2448 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2449 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2450} 2451``` 2452 2453### HUMIDITY<sup>9+</sup> 2454 2455off(type: SensorId.HUMIDITY, callback?: Callback<HumidityResponse>): void 2456 2457Unsubscribes from data of the humidity sensor. 2458 2459**System capability**: SystemCapability.Sensors.Sensor 2460 2461**Parameters** 2462 2463| Name | Type | Mandatory| Description | 2464| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ | 2465| type | [SensorId](#sensorid9).HUMIDITY | Yes | Sensor type. The value is fixed at **SensorId.HUMIDITY**. | 2466| callback | Callback<[HumidityResponse](#humidityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2467 2468**Example** 2469 2470```ts 2471import sensor from "@ohos.sensor"; 2472import BusinessError from "@ohos.base"; 2473 2474function callback1(data: object) { 2475 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2476} 2477 2478function callback2(data: object) { 2479 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2480} 2481 2482try { 2483 sensor.on(sensor.SensorId.HUMIDITY, callback1); 2484 sensor.on(sensor.SensorId.HUMIDITY, callback2); 2485 // Unsubscribe from callback1. 2486 sensor.off(sensor.SensorId.HUMIDITY, callback1); 2487 // Unsubscribe from all callbacks of the SensorId.HUMIDITY type. 2488 sensor.off(sensor.SensorId.HUMIDITY); 2489} catch (error) { 2490 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2491 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2492} 2493``` 2494 2495### LINEAR_ACCELEROMETER<sup>9+</sup> 2496 2497off(type: SensorId.LINEAR_ACCELEROMETER, callback?: Callback<LinearAccelerometerResponse>): void 2498 2499Unsubscribes from data of the linear acceleration sensor. 2500 2501**Required permissions**: ohos.permission.ACCELEROMETER 2502 2503**System capability**: SystemCapability.Sensors.Sensor 2504 2505**Parameters** 2506 2507| Name | Type | Mandatory| Description | 2508| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2509| type | [SensorId](#sensorid9).LINEAR_ACCELEROMETER | Yes | Sensor type. The value is fixed at **SensorId.LINEAR_ACCELERATION**. | 2510| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2511 2512**Example** 2513 2514```ts 2515import sensor from "@ohos.sensor"; 2516import BusinessError from "@ohos.base"; 2517 2518function callback1(data: object) { 2519 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2520} 2521 2522function callback2(data: object) { 2523 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2524} 2525 2526try { 2527 sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); 2528 sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, callback2); 2529 // Unsubscribe from callback1. 2530 sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER, callback1); 2531 // Unsubscribe from all callbacks of the SensorId.LINEAR_ACCELEROMETER type. 2532 sensor.off(sensor.SensorId.LINEAR_ACCELEROMETER); 2533} catch (error) { 2534 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2535 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2536} 2537``` 2538 2539### MAGNETIC_FIELD<sup>9+</sup> 2540 2541off(type: SensorId.MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void 2542 2543Unsubscribes from data of the magnetic field sensor. 2544 2545**System capability**: SystemCapability.Sensors.Sensor 2546 2547**Parameters** 2548 2549| Name | Type | Mandatory| Description | 2550| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2551| type | [SensorId](#sensorid9).MAGNETIC_FIELD | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD**. | 2552| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2553 2554**Example** 2555 2556```ts 2557import sensor from "@ohos.sensor"; 2558import BusinessError from "@ohos.base"; 2559 2560function callback1(data: object) { 2561 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2562} 2563 2564function callback2(data: object) { 2565 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2566} 2567 2568try { 2569 sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback1); 2570 sensor.on(sensor.SensorId.MAGNETIC_FIELD, callback2); 2571 // Unsubscribe from callback1. 2572 sensor.off(sensor.SensorId.MAGNETIC_FIELD, callback1); 2573 // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD type. 2574 sensor.off(sensor.SensorId.MAGNETIC_FIELD); 2575} catch (error) { 2576 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2577 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2578} 2579``` 2580 2581### MAGNETIC_FIELD_UNCALIBRATED<sup>9+</sup> 2582 2583off(type: SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void 2584 2585Unsubscribes from data of the uncalibrated magnetic field sensor. 2586 2587**System capability**: SystemCapability.Sensors.Sensor 2588 2589**Parameters** 2590 2591| Name | Type | Mandatory| Description | 2592| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2593| type | [SensorId](#sensorid9).MAGNETIC_FIELD_UNCALIBRATED | Yes | Sensor type. The value is fixed at **SensorId.MAGNETIC_FIELD_UNCALIBRATED**.| 2594| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2595 2596**Example** 2597 2598```ts 2599import sensor from "@ohos.sensor"; 2600import BusinessError from "@ohos.base"; 2601 2602function callback1(data: object) { 2603 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2604} 2605 2606function callback2(data: object) { 2607 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2608} 2609 2610try { 2611 sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); 2612 sensor.on(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback2); 2613 // Unsubscribe from callback1. 2614 sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED, callback1); 2615 // Unsubscribe from all callbacks of the SensorId.MAGNETIC_FIELD_UNCALIBRATED type. 2616 sensor.off(sensor.SensorId.MAGNETIC_FIELD_UNCALIBRATED); 2617} catch (error) { 2618 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2619 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2620} 2621``` 2622 2623### ORIENTATION<sup>9+</sup> 2624 2625off(type: SensorId.ORIENTATION, callback?: Callback<OrientationResponse>): void 2626 2627Unsubscribes from data of the orientation sensor. 2628 2629**System capability**: SystemCapability.Sensors.Sensor 2630 2631**Parameters** 2632 2633| Name | Type | Mandatory| Description | 2634| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2635| type | [SensorId](#sensorid9).ORIENTATION | Yes | Sensor type. The value is fixed at **SensorId.ORIENTATION**. | 2636| callback | Callback<[OrientationResponse](#orientationresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2637 2638**Example** 2639 2640```ts 2641import sensor from "@ohos.sensor"; 2642import BusinessError from "@ohos.base"; 2643 2644function callback1(data: object) { 2645 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2646} 2647 2648function callback2(data: object) { 2649 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2650} 2651 2652try { 2653 sensor.on(sensor.SensorId.ORIENTATION, callback1); 2654 sensor.on(sensor.SensorId.ORIENTATION, callback2); 2655 // Unsubscribe from callback1. 2656 sensor.off(sensor.SensorId.ORIENTATION, callback1); 2657 // Unsubscribe from all callbacks of the SensorId.ORIENTATION type. 2658 sensor.off(sensor.SensorId.ORIENTATION); 2659} catch (error) { 2660 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2661 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2662} 2663``` 2664 2665### PEDOMETER<sup>9+</sup> 2666 2667off(type: SensorId.PEDOMETER, callback?: Callback<PedometerResponse>): void 2668 2669Unsubscribes from data of the pedometer sensor. 2670 2671**Required permissions**: ohos.permission.ACTIVITY_MOTION 2672 2673**System capability**: SystemCapability.Sensors.Sensor 2674 2675**Parameters** 2676 2677| Name | Type | Mandatory| Description | 2678| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2679| type | [SensorId](#sensorid9).PEDOMETER | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER**. | 2680| callback | Callback<[PedometerResponse](#pedometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2681 2682**Example** 2683 2684```ts 2685import sensor from "@ohos.sensor"; 2686import BusinessError from "@ohos.base"; 2687 2688function callback1(data: object) { 2689 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2690} 2691 2692function callback2(data: object) { 2693 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2694} 2695 2696try { 2697 sensor.on(sensor.SensorId.PEDOMETER, callback1); 2698 sensor.on(sensor.SensorId.PEDOMETER, callback2); 2699 // Unsubscribe from callback1. 2700 sensor.off(sensor.SensorId.PEDOMETER, callback1); 2701 // Unsubscribe from all callbacks of the SensorId.ORIENTATION type. 2702 sensor.off(sensor.SensorId.PEDOMETER); 2703} catch (error) { 2704 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2705 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2706} 2707``` 2708 2709### PEDOMETER_DETECTION<sup>9+</sup> 2710 2711off(type: SensorId.PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void 2712 2713Unsubscribes from data of the pedometer detection sensor. 2714 2715**Required permissions**: ohos.permission.ACTIVITY_MOTION 2716 2717**System capability**: SystemCapability.Sensors.Sensor 2718 2719**Parameters** 2720 2721| Name | Type | Mandatory| Description | 2722| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2723| type | [SensorId](#sensorid9).PEDOMETER_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.PEDOMETER_DETECTION**. | 2724| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2725 2726**Example** 2727 2728```ts 2729import sensor from "@ohos.sensor"; 2730import BusinessError from "@ohos.base"; 2731 2732function callback1(data: object) { 2733 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2734} 2735 2736function callback2(data: object) { 2737 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2738} 2739 2740try { 2741 sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback1); 2742 sensor.on(sensor.SensorId.PEDOMETER_DETECTION, callback2); 2743 // Unsubscribe from callback1. 2744 sensor.off(sensor.SensorId.PEDOMETER_DETECTION, callback1); 2745 // Unsubscribe from all callbacks of the SensorId.PEDOMETER_DETECTION type. 2746 sensor.off(sensor.SensorId.PEDOMETER_DETECTION); 2747} catch (error) { 2748 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2749 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2750} 2751``` 2752 2753### PROXIMITY<sup>9+</sup> 2754 2755off(type: SensorId.PROXIMITY, callback?: Callback<ProximityResponse>): void 2756 2757Unsubscribes from data of the proximity sensor. 2758 2759**System capability**: SystemCapability.Sensors.Sensor 2760 2761**Parameters** 2762 2763| Name | Type | Mandatory| Description | 2764| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2765| type | [SensorId](#sensorid9).PROXIMITY | Yes | Sensor type. The value is fixed at **SensorId.PROXIMITY**. | 2766| callback | Callback<[ProximityResponse](#proximityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2767 2768**Example** 2769 2770```ts 2771import sensor from "@ohos.sensor"; 2772import BusinessError from "@ohos.base"; 2773 2774function callback1(data: object) { 2775 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2776} 2777 2778function callback2(data: object) { 2779 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2780} 2781 2782try { 2783 sensor.on(sensor.SensorId.PROXIMITY, callback1); 2784 sensor.on(sensor.SensorId.PROXIMITY, callback2); 2785 // Unsubscribe from callback1. 2786 sensor.off(sensor.SensorId.PROXIMITY, callback1); 2787 // Unsubscribe from all callbacks of the SensorId.PROXIMITY type. 2788 sensor.off(sensor.SensorId.PROXIMITY); 2789} catch (error) { 2790 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2791 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2792} 2793``` 2794 2795### ROTATION_VECTOR<sup>9+</sup> 2796 2797off(type: SensorId.ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void 2798 2799Unsubscribes from data of the rotation vector sensor. 2800 2801**System capability**: SystemCapability.Sensors.Sensor 2802 2803**Parameters** 2804 2805| Name | Type | Mandatory| Description | 2806| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2807| type | [SensorId](#sensorid9).ROTATION_VECTOR | Yes | Sensor type. The value is fixed at **SensorId.ROTATION_VECTOR**. | 2808| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2809 2810**Example** 2811 2812```ts 2813import sensor from "@ohos.sensor"; 2814import BusinessError from "@ohos.base"; 2815 2816function callback1(data: object) { 2817 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2818} 2819 2820function callback2(data: object) { 2821 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2822} 2823 2824try { 2825 sensor.on(sensor.SensorId.ROTATION_VECTOR, callback1); 2826 sensor.on(sensor.SensorId.ROTATION_VECTOR, callback2); 2827 // Unsubscribe from callback1. 2828 sensor.off(sensor.SensorId.ROTATION_VECTOR, callback1); 2829 // Unsubscribe from all callbacks of the SensorId.ROTATION_VECTOR type. 2830 sensor.off(sensor.SensorId.ROTATION_VECTOR); 2831} catch (error) { 2832 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2833 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2834} 2835``` 2836 2837### SIGNIFICANT_MOTION<sup>9+</sup> 2838 2839off(type: SensorId.SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void 2840 2841Unsubscribes from data of the significant motion sensor. 2842 2843**System capability**: SystemCapability.Sensors.Sensor 2844 2845**Parameters** 2846 2847| Name | Type | Mandatory| Description | 2848| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2849| type | [SensorId](#sensorid9).SIGNIFICANT_MOTION | Yes | Sensor type. The value is fixed at **SensorId.SIGNIFICANT_MOTION**. | 2850| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2851 2852**Example** 2853 2854```ts 2855import sensor from "@ohos.sensor"; 2856import BusinessError from "@ohos.base"; 2857 2858function callback1(data: object) { 2859 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2860} 2861 2862function callback2(data: object) { 2863 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2864} 2865 2866try { 2867 sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback1); 2868 sensor.on(sensor.SensorId.SIGNIFICANT_MOTION, callback2); 2869 // Unsubscribe from callback1. 2870 sensor.off(sensor.SensorId.SIGNIFICANT_MOTION, callback1); 2871 // Unsubscribe from all callbacks of the SensorId.SIGNIFICANT_MOTION type. 2872 sensor.off(sensor.SensorId.SIGNIFICANT_MOTION); 2873} catch (error) { 2874 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2875 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2876} 2877``` 2878 2879### WEAR_DETECTION<sup>9+</sup> 2880 2881off(type: SensorId.WEAR_DETECTION, callback?: Callback<WearDetectionResponse>): void 2882 2883Unsubscribes from data of the wear detection sensor. 2884 2885**System capability**: SystemCapability.Sensors.Sensor 2886 2887**Parameters** 2888 2889| Name | Type | Mandatory| Description | 2890| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2891| type | [SensorId](#sensorid9).WEAR_DETECTION | Yes | Sensor type. The value is fixed at **SensorId.WEAR_DETECTION**. | 2892| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from.| 2893 2894**Example** 2895 2896```ts 2897import sensor from "@ohos.sensor"; 2898import BusinessError from "@ohos.base"; 2899 2900function callback1(data: object) { 2901 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(data)); 2902} 2903 2904function callback2(data: object) { 2905 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(data)); 2906} 2907 2908try { 2909 sensor.on(sensor.SensorId.WEAR_DETECTION, callback1); 2910 sensor.on(sensor.SensorId.WEAR_DETECTION, callback2); 2911 // Unsubscribe from callback1. 2912 sensor.off(sensor.SensorId.WEAR_DETECTION, callback1); 2913 // Unsubscribe from all callbacks of the SensorId.WEAR_DETECTION type. 2914 sensor.off(sensor.SensorId.WEAR_DETECTION); 2915} catch (error) { 2916 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2917 console.error(`Failed to invoke off. Code: ${e.code}, message: ${e.message}`); 2918} 2919``` 2920 2921## sensor.getGeomagneticInfo<sup>9+</sup> 2922 2923getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void 2924 2925Obtains the geomagnetic field of a geographic location at a certain time. This API uses an asynchronous callback to return the result. 2926 2927**System capability**: SystemCapability.Sensors.Sensor 2928 2929**Parameters** 2930 2931| Name | Type | Mandatory| Description | 2932| --------------- | ------------------------------------------------------------ | ---- | ---------------------------------- | 2933| locationOptions | [LocationOptions](#locationoptions) | Yes | Geographic location, including the longitude, latitude, and altitude. | 2934| timeMillis | number | Yes | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.| 2935| callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes | Callback used to return the geomagnetic field. | 2936 2937**Error codes** 2938 2939For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). 2940 2941| ID| Error Message | 2942| -------- | ------------------ | 2943| 14500101 | Service exception. | 2944 2945**Example** 2946 2947```ts 2948import sensor from "@ohos.sensor"; 2949import BusinessError from "@ohos.base"; 2950 2951try { 2952 sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, 2953 (err: BusinessError.BusinessError, data: sensor.GeomagneticResponse) => { 2954 if (err) { 2955 console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`); 2956 return; 2957 } 2958 console.info("Succeeded in getting geomagneticInfo x" + data.x); 2959 console.info("Succeeded in getting geomagneticInfo y" + data.y); 2960 console.info("Succeeded in getting geomagneticInfo z" + data.z); 2961 console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip); 2962 console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle); 2963 console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity); 2964 console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity); 2965 }); 2966} catch (error) { 2967 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 2968 console.error(`Failed to get geomagneticInfo. Code: ${e.code}, message: ${e.message}`); 2969} 2970``` 2971 2972## sensor.getGeomagneticInfo<sup>9+</sup> 2973 2974getGeomagneticInfo(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse> 2975 2976Obtains the geomagnetic field of a geographic location at a certain time. This API uses a promise to return the result. 2977 2978**System capability**: SystemCapability.Sensors.Sensor 2979 2980**Parameters** 2981 2982| Name | Type | Mandatory| Description | 2983| --------------- | ----------------------------------- | ---- | ---------------------------------- | 2984| locationOptions | [LocationOptions](#locationoptions) | Yes | Geographic location, including the longitude, latitude, and altitude. | 2985| timeMillis | number | Yes | Time when the magnetic declination is obtained. The value is a Unix timestamp, in ms.| 2986 2987**Return value** 2988 2989| Type | Description | 2990| ---------------------------------------------------------- | -------------- | 2991| Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field.| 2992 2993**Error codes** 2994 2995For details about the following error codes, see [Error Codes of sensor.getGeomagneticInfo](../errorcodes/errorcode-sensor.md). 2996 2997| ID| Error Message | 2998| -------- | ------------------ | 2999| 14500101 | Service exception. | 3000 3001**Example** 3002 3003```ts 3004import sensor from "@ohos.sensor"; 3005import BusinessError from "@ohos.base"; 3006 3007try { 3008 const promise = sensor.getGeomagneticInfo({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000); 3009 promise.then((data: sensor.GeomagneticResponse) => { 3010 console.info("Succeeded in getting geomagneticInfo x" + data.x); 3011 console.info("Succeeded in getting geomagneticInfo y" + data.y); 3012 console.info("Succeeded in getting geomagneticInfo z" + data.z); 3013 console.info("Succeeded in getting geomagneticInfo geomagneticDip" + data.geomagneticDip); 3014 console.info("Succeeded in getting geomagneticInfo deflectionAngle" + data.deflectionAngle); 3015 console.info("Succeeded in getting geomagneticInfo levelIntensity" + data.levelIntensity); 3016 console.info("Succeeded in getting geomagneticInfo totalIntensity" + data.totalIntensity); 3017 }, (err: BusinessError.BusinessError) => { 3018 console.error(`Failed to get geomagneticInfo. Code: ${err.code}, message: ${err.message}`); 3019 }); 3020} catch (error) { 3021 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3022 console.error(`Failed to get geomagneticInfo. Code: ${e.code}, message: ${e.message}`); 3023} 3024``` 3025 3026## sensor.getDeviceAltitude<sup>9+</sup> 3027 3028getDeviceAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback<number>): void 3029 3030Obtains the altitude based on the atmospheric pressure. This API uses an asynchronous callback to return the result. 3031 3032**System capability**: SystemCapability.Sensors.Sensor 3033 3034**Parameters** 3035 3036| Name | Type | Mandatory| Description | 3037| --------------- | --------------------------- | ---- | ------------------------------------- | 3038| seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | 3039| currentPressure | number | Yes | Specified atmospheric pressure, in hPa.| 3040| callback | AsyncCallback<number> | Yes | Callback used to return the altitude, in meters. | 3041 3042**Error codes** 3043 3044For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). 3045 3046| ID| Error Message | 3047| -------- | ------------------ | 3048| 14500101 | Service exception. | 3049 3050**Example** 3051 3052```ts 3053import sensor from "@ohos.sensor"; 3054import BusinessError from "@ohos.base"; 3055 3056try { 3057 let seaPressure = 1013.2; 3058 let currentPressure = 1500.0; 3059 sensor.getDeviceAltitude(seaPressure, currentPressure, (err: BusinessError.BusinessError, data: number) => { 3060 if (err) { 3061 console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`); 3062 return; 3063 } 3064 console.info('Succeeded in getting altitude: ' + data); 3065 }); 3066} catch (error) { 3067 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3068 console.error(`Failed to get altitude. Code: ${e.code}, message: ${e.message}`); 3069} 3070``` 3071 3072## sensor.getDeviceAltitude<sup>9+</sup> 3073 3074getDeviceAltitude(seaPressure: number, currentPressure: number): Promise<number> 3075 3076Obtains the altitude based on the atmospheric pressure. This API uses a promise to return the result. 3077 3078**System capability**: SystemCapability.Sensors.Sensor 3079 3080**Parameters** 3081 3082| Name | Type | Mandatory| Description | 3083| --------------- | ------ | ---- | ------------------------------------- | 3084| seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | 3085| currentPressure | number | Yes | Specified atmospheric pressure, in hPa.| 3086 3087**Return value** 3088 3089| Type | Description | 3090| --------------------- | ------------------------------------ | 3091| Promise<number> | Promise used to return the altitude, in meters.| 3092 3093**Error codes** 3094 3095For details about the following error codes, see [Error Codes of sensor.getDeviceAltitude](../errorcodes/errorcode-sensor.md). 3096 3097| ID| Error Message | 3098| -------- | ------------------ | 3099| 14500101 | Service exception. | 3100 3101**Example** 3102 3103```ts 3104import sensor from "@ohos.sensor"; 3105import BusinessError from "@ohos.base"; 3106 3107try { 3108 let seaPressure = 1013.2; 3109 let currentPressure = 1500.0; 3110 const promise = sensor.getDeviceAltitude(seaPressure, currentPressure); 3111 promise.then((data: number) => { 3112 console.info('Succeeded in getting sensor_getDeviceAltitude_Promise', data); 3113 }, (err: BusinessError.BusinessError) => { 3114 console.error(`Failed to get altitude. Code: ${err.code}, message: ${err.message}`); 3115 }); 3116} catch (error) { 3117 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3118 console.error(`Failed to get altitude. Code: ${e.code}, message: ${e.message}`); 3119} 3120``` 3121 3122## sensor.getInclination<sup>9+</sup> 3123 3124getInclination(inclinationMatrix: Array<number>, callback: AsyncCallback<number>): void 3125 3126Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result. 3127 3128**System capability**: SystemCapability.Sensors.Sensor 3129 3130**Parameters** 3131 3132| Name | Type | Mandatory| Description | 3133| ----------------- | --------------------------- | ---- | ---------------------------- | 3134| inclinationMatrix | Array<number> | Yes | Inclination matrix. | 3135| callback | AsyncCallback<number> | Yes | Callback used to return the magnetic dip, in radians.| 3136 3137**Error codes** 3138 3139For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). 3140 3141| ID| Error Message | 3142| -------- | ------------------ | 3143| 14500101 | Service exception. | 3144 3145**Example** 3146 3147```ts 3148import sensor from "@ohos.sensor"; 3149import BusinessError from "@ohos.base"; 3150 3151try { 3152 // inclinationMatrix can be 3*3 or 4*4. 3153 let inclinationMatrix = [ 3154 1, 0, 0, 3155 0, 1, 0, 3156 0, 0, 1 3157 ] 3158 sensor.getInclination(inclinationMatrix, (err: BusinessError.BusinessError, data: number) => { 3159 if (err) { 3160 console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`); 3161 return; 3162 } 3163 console.info('Succeeded in getting inclination: ' + data); 3164 }) 3165} catch (error) { 3166 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3167 console.error(`Failed to get inclination. Code: ${e.code}, message: ${e.message}`); 3168} 3169``` 3170 3171## sensor.getInclination<sup>9+</sup> 3172 3173 getInclination(inclinationMatrix: Array<number>): Promise<number> 3174 3175Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result. 3176 3177**System capability**: SystemCapability.Sensors.Sensor 3178 3179**Parameters** 3180 3181| Name | Type | Mandatory| Description | 3182| ----------------- | ------------------- | ---- | -------------- | 3183| inclinationMatrix | Array<number> | Yes | Inclination matrix.| 3184 3185**Return value** 3186 3187| Type | Description | 3188| --------------------- | ---------------------------- | 3189| Promise<number> | Promise used to return the magnetic dip, in radians.| 3190 3191**Error codes** 3192 3193For details about the following error codes, see [Error Codes of sensor.getInclination](../errorcodes/errorcode-sensor.md). 3194 3195| ID| Error Message | 3196| -------- | ------------------ | 3197| 14500101 | Service exception. | 3198 3199**Example** 3200 3201```ts 3202import sensor from "@ohos.sensor"; 3203import BusinessError from "@ohos.base"; 3204 3205try { 3206 // inclinationMatrix can be 3*3 or 4*4. 3207 let inclinationMatrix = [ 3208 1, 0, 0, 3209 0, 1, 0, 3210 0, 0, 1 3211 ] 3212 const promise = sensor.getInclination(inclinationMatrix); 3213 promise.then((data: number) => { 3214 console.info('Succeeded in getting inclination: ' + data); 3215 }, (err: BusinessError.BusinessError) => { 3216 console.error(`Failed to get inclination. Code: ${err.code}, message: ${err.message}`); 3217 }); 3218} catch (error) { 3219 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3220 console.error(`Failed to get inclination. Code: ${e.code}, message: ${e.message}`); 3221} 3222``` 3223 3224## sensor.getAngleVariation<sup>9+</sup> 3225 3226 getAngleVariation(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>, 3227 callback: AsyncCallback<Array<number>>): void 3228 3229Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result. 3230 3231**System capability**: SystemCapability.Sensors.Sensor 3232 3233**Parameters** 3234 3235| Name | Type | Mandatory| Description | 3236| --------------------- | ---------------------------------------- | ---- | --------------------------------- | 3237| currentRotationMatrix | Array<number> | Yes | Current rotation matrix. | 3238| preRotationMatrix | Array<number> | Yes | The other rotation matrix. | 3239| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the angle change around the z, x, and y axes.| 3240 3241**Error codes** 3242 3243For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). 3244 3245| ID| Error Message | 3246| -------- | ------------------ | 3247| 14500101 | Service exception. | 3248 3249**Example** 3250 3251```ts 3252import sensor from "@ohos.sensor"; 3253import BusinessError from "@ohos.base"; 3254 3255try { 3256 // The rotation matrix can be 3*3 or 4*4. 3257 let currentRotationMatrix = [ 3258 1, 0, 0, 3259 0, 1, 0, 3260 0, 0, 1 3261 ]; 3262 let preRotationMatrix = [ 3263 1, 0, 0, 3264 0, 0.87, -0.50, 3265 0, 0.50, 0.87 3266 ]; 3267 sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix, (err: BusinessError.BusinessError, data: Array<number>) => { 3268 if (err) { 3269 console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`); 3270 return; 3271 } 3272 if (data.length < 3) { 3273 console.error("Failed to get angle variation, length" + data.length); 3274 } 3275 console.info("Z: " + data[0]); 3276 console.info("X: " + data[1]); 3277 console.info("Y : " + data[2]); 3278 }) 3279} catch (error) { 3280 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3281 console.error(`Failed to get angle variation. Code: ${e.code}, message: ${e.message}`); 3282} 3283``` 3284 3285## sensor.getAngleVariation<sup>9+</sup> 3286 3287getAngleVariation(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>): Promise<Array<number>> 3288 3289Obtains the angle change between two rotation matrices. This API uses a promise to return the result. 3290 3291**System capability**: SystemCapability.Sensors.Sensor 3292 3293**Parameters** 3294 3295| Name | Type | Mandatory| Description | 3296| --------------------- | ------------------- | ---- | ------------------ | 3297| currentRotationMatrix | Array<number> | Yes | Current rotation matrix.| 3298| preRotationMatrix | Array<number> | Yes | The other rotation matrix. | 3299 3300**Return value** 3301 3302| Type | Description | 3303| ---------------------------------- | --------------------------------- | 3304| Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes.| 3305 3306**Error codes** 3307 3308For details about the following error codes, see [Error Codes of sensor.getAngleVariation](../errorcodes/errorcode-sensor.md). 3309 3310| ID| Error Message | 3311| -------- | ------------------ | 3312| 14500101 | Service exception. | 3313 3314**Example** 3315 3316```ts 3317import sensor from "@ohos.sensor"; 3318import BusinessError from "@ohos.base"; 3319 3320try { 3321 // The rotation matrix can be 3*3 or 4*4. 3322 let currentRotationMatrix = [ 3323 1, 0, 0, 3324 0, 1, 0, 3325 0, 0, 1 3326 ]; 3327 let preRotationMatrix = [ 3328 1, 0, 0, 3329 0, 0.87, -0.50, 3330 0, 0.50, 0.87 3331 ]; 3332 const promise = sensor.getAngleVariation(currentRotationMatrix, preRotationMatrix); 3333 promise.then((data: Array<number>) => { 3334 if (data.length < 3) { 3335 console.error("Failed to get angle variation, length" + data.length); 3336 } 3337 console.info("Z: " + data[0]); 3338 console.info("X: " + data[1]); 3339 console.info("Y : " + data[2]); 3340 }, (err: BusinessError.BusinessError) => { 3341 console.error(`Failed to get angle variation. Code: ${err.code}, message: ${err.message}`); 3342 }); 3343} catch (error) { 3344 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3345 console.error(`Failed to get angle variation. Code: ${e.code}, message: ${e.message}`); 3346} 3347``` 3348 3349## sensor.getRotationMatrix<sup>9+</sup> 3350 3351getRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void 3352 3353Obtains the rotation matrix from a rotation vector. This API uses an asynchronous callback to return the result. 3354 3355**System capability**: SystemCapability.Sensors.Sensor 3356 3357**Parameters** 3358 3359| Name | Type | Mandatory| Description | 3360| -------------- | ---------------------------------------- | ---- | -------------- | 3361| rotationVector | Array<number> | Yes | Rotation vector.| 3362| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation matrix.| 3363 3364**Error codes** 3365 3366For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). 3367 3368| ID| Error Message | 3369| -------- | ------------------ | 3370| 14500101 | Service exception. | 3371 3372**Example** 3373 3374```ts 3375import sensor from "@ohos.sensor"; 3376import BusinessError from "@ohos.base"; 3377 3378try { 3379 let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; 3380 sensor.getRotationMatrix(rotationVector, (err: BusinessError.BusinessError, data: Array<number>) => { 3381 if (err) { 3382 console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3383 return; 3384 } 3385 for (let i = 0; i < data.length; i++) { 3386 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3387 } 3388 }) 3389} catch (error) { 3390 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3391 console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3392} 3393``` 3394 3395## sensor.getRotationMatrix<sup>9+</sup> 3396 3397getRotationMatrix(rotationVector: Array<number>): Promise<Array<number>> 3398 3399Obtains the rotation matrix from a rotation vector. This API uses a promise to return the result. 3400 3401**System capability**: SystemCapability.Sensors.Sensor 3402 3403**Parameters** 3404 3405| Name | Type | Mandatory| Description | 3406| -------------- | ------------------- | ---- | -------------- | 3407| rotationVector | Array<number> | Yes | Rotation vector.| 3408 3409**Return value** 3410 3411| Type | Description | 3412| ---------------------------------- | -------------- | 3413| Promise<Array<number>> | Promise used to return the rotation matrix.| 3414 3415**Error codes** 3416 3417For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). 3418 3419| ID| Error Message | 3420| -------- | ------------------ | 3421| 14500101 | Service exception. | 3422 3423**Example** 3424 3425```ts 3426import sensor from "@ohos.sensor"; 3427import BusinessError from "@ohos.base"; 3428 3429try { 3430 let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; 3431 const promise = sensor.getRotationMatrix(rotationVector); 3432 promise.then((data: Array<number>) => { 3433 for (let i = 0; i < data.length; i++) { 3434 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3435 } 3436 }, (err: BusinessError.BusinessError) => { 3437 console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3438 }); 3439} catch (error) { 3440 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3441 console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3442} 3443``` 3444 3445## sensor.transformRotationMatrix<sup>9+</sup> 3446 3447transformRotationMatrix(inRotationVector: Array<number>, coordinates: CoordinatesOptions, 3448 callback: AsyncCallback<Array<number>>): void 3449 3450Transforms a rotation vector based on the coordinate system. This API uses an asynchronous callback to return the result. 3451 3452**System capability**: SystemCapability.Sensors.Sensor 3453 3454**Parameters** 3455 3456| Name | Type | Mandatory| Description | 3457| ---------------- | ----------------------------------------- | ---- | ---------------------- | 3458| inRotationVector | Array<number> | Yes | Rotation vector. | 3459| coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Rotation vector to transform. | 3460| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation vector after being transformed.| 3461 3462**Error codes** 3463 3464For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md). 3465 3466| ID| Error Message | 3467| -------- | ------------------ | 3468| 14500101 | Service exception. | 3469 3470**Example** 3471 3472```ts 3473import sensor from "@ohos.sensor"; 3474import BusinessError from "@ohos.base"; 3475 3476try { 3477 let rotationMatrix = [ 3478 1, 0, 0, 3479 0, 0.87, -0.50, 3480 0, 0.50, 0.87 3481 ]; 3482 sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }, (err: BusinessError.BusinessError, data: Array<number>) => { 3483 if (err) { 3484 console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3485 return; 3486 } 3487 for (let i = 0; i < data.length; i++) { 3488 console.info('Succeeded in getting data[' + i + '] = ' + data[i]); 3489 } 3490 }) 3491} catch (error) { 3492 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3493 console.error(`Failed to transform rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3494} 3495``` 3496 3497## sensor.transformRotationMatrix<sup>9+</sup> 3498 3499transformRotationMatrix(inRotationVector: Array<number>, coordinates: CoordinatesOptions): Promise<Array<number>> 3500 3501Transforms a rotation vector based on the coordinate system. This API uses a promise to return the result. 3502 3503**System capability**: SystemCapability.Sensors.Sensor 3504 3505**Parameters** 3506 3507| Name | Type | Mandatory| Description | 3508| ---------------- | ----------------------------------------- | ---- | ---------------- | 3509| inRotationVector | Array<number> | Yes | Rotation vector. | 3510| coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Rotation vector to transform.| 3511 3512**Return value** 3513 3514| Type | Description | 3515| ---------------------------------- | ---------------------- | 3516| Promise<Array<number>> | Promise used to return the rotation vector after being transformed.| 3517 3518**Error codes** 3519 3520For details about the following error codes, see [Error Codes of sensor.transformRotationMatrix](../errorcodes/errorcode-sensor.md). 3521 3522| ID| Error Message | 3523| -------- | ------------------ | 3524| 14500101 | Service exception. | 3525 3526**Example** 3527 3528```ts 3529import sensor from "@ohos.sensor"; 3530import BusinessError from "@ohos.base"; 3531 3532try { 3533 let rotationMatrix = [ 3534 1, 0, 0, 3535 0, 0.87, -0.50, 3536 0, 0.50, 0.87 3537 ]; 3538 const promise = sensor.transformRotationMatrix(rotationMatrix, { x: 1, y: 3 }); 3539 promise.then((data: Array<number>) => { 3540 for (let i = 0; i < data.length; i++) { 3541 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3542 } 3543 }, (err: BusinessError.BusinessError) => { 3544 console.error(`Failed to transform rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3545 }); 3546} catch (error) { 3547 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3548 console.error(`Failed to transform rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3549} 3550``` 3551 3552## sensor.getQuaternion<sup>9+</sup> 3553 3554getQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void 3555 3556Obtains the quaternion from a rotation vector. This API uses an asynchronous callback to return the result. 3557 3558**System capability**: SystemCapability.Sensors.Sensor 3559 3560**Parameters** 3561 3562| Name | Type | Mandatory| Description | 3563| -------------- | ---------------------------------------- | ---- | -------------- | 3564| rotationVector | Array<number> | Yes | Rotation vector.| 3565| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the quaternion.| 3566 3567**Error codes** 3568 3569For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). 3570 3571| ID| Error Message | 3572| -------- | ------------------ | 3573| 14500101 | Service exception. | 3574 3575**Example** 3576 3577```ts 3578import sensor from "@ohos.sensor"; 3579import BusinessError from "@ohos.base"; 3580 3581try { 3582 let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; 3583 sensor.getQuaternion(rotationVector, (err: BusinessError.BusinessError, data: Array<number>) => { 3584 if (err) { 3585 console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`); 3586 return; 3587 } 3588 for (let i = 0; i < data.length; i++) { 3589 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3590 } 3591 }) 3592} catch (error) { 3593 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3594 console.error(`Failed to get quaternion. Code: ${e.code}, message: ${e.message}`); 3595} 3596``` 3597 3598## sensor.getQuaternion<sup>9+</sup> 3599 3600getQuaternion(rotationVector: Array<number>): Promise<Array<number>> 3601 3602Obtains the quaternion from a rotation vector. This API uses a promise to return the result. 3603 3604**System capability**: SystemCapability.Sensors.Sensor 3605 3606**Parameters** 3607 3608| Name | Type | Mandatory| Description | 3609| -------------- | ------------------- | ---- | -------------- | 3610| rotationVector | Array<number> | Yes | Rotation vector.| 3611 3612**Return value** 3613 3614| Type | Description | 3615| ---------------------------------- | ------------ | 3616| Promise<Array<number>> | Promise used to return the quaternion.| 3617 3618**Error codes** 3619 3620For details about the following error codes, see [Error Codes of sensor.getQuaternion](../errorcodes/errorcode-sensor.md). 3621 3622| ID| Error Message | 3623| -------- | ------------------ | 3624| 14500101 | Service exception. | 3625 3626**Example** 3627 3628```ts 3629import sensor from "@ohos.sensor"; 3630import BusinessError from "@ohos.base"; 3631 3632try { 3633 let rotationVector = [0.20046076, 0.21907, 0.73978853, 0.60376877]; 3634 const promise = sensor.getQuaternion(rotationVector); 3635 promise.then((data: Array<number>) => { 3636 for (let i = 0; i < data.length; i++) { 3637 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3638 } 3639 }, (err: BusinessError.BusinessError) => { 3640 console.error(`Failed to get quaternion. Code: ${err.code}, message: ${err.message}`); 3641 }); 3642} catch (error) { 3643 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3644 console.error(`Failed to get quaternion. Code: ${e.code}, message: ${e.message}`); 3645} 3646``` 3647 3648## sensor.getOrientation<sup>9+</sup> 3649 3650getOrientation(rotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void 3651 3652Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result. 3653 3654**System capability**: SystemCapability.Sensors.Sensor 3655 3656**Parameters** 3657 3658| Name | Type | Mandatory| Description | 3659| -------------- | ---------------------------------------- | ---- | --------------------------------- | 3660| rotationMatrix | Array<number> | Yes | Rotation matrix. | 3661| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes.| 3662 3663**Error codes** 3664 3665For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). 3666 3667| ID| Error Message | 3668| -------- | ------------------ | 3669| 14500101 | Service exception. | 3670 3671**Example** 3672 3673```ts 3674import sensor from "@ohos.sensor"; 3675import BusinessError from "@ohos.base"; 3676 3677try { 3678 let preRotationMatrix = [ 3679 1, 0, 0, 3680 0, 0.87, -0.50, 3681 0, 0.50, 0.87 3682 ]; 3683 sensor.getOrientation(preRotationMatrix, (err: BusinessError.BusinessError, data: Array<number>) => { 3684 if (err) { 3685 console.error(`Failed to get orientation. Code: ${err.code}, message: ${err.message}`); 3686 return; 3687 } 3688 if (data.length < 3) { 3689 console.error("Failed to get orientation, length" + data.length); 3690 } 3691 console.info("Succeeded in getting data. Z: " + data[0]); 3692 console.info("Succeeded in getting data. X: " + data[1]); 3693 console.info("Succeeded in getting data. Y: " + data[2]); 3694 }) 3695} catch (error) { 3696 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3697 console.error(`Failed to get orientation. Code: ${e.code}, message: ${e.message}`); 3698} 3699``` 3700 3701## sensor.getOrientation<sup>9+</sup> 3702 3703getOrientation(rotationMatrix: Array<number>): Promise<Array<number>> 3704 3705Obtains the device direction based on the rotation matrix. This API uses a promise to return the result. 3706 3707**System capability**: SystemCapability.Sensors.Sensor 3708 3709**Parameters** 3710 3711| Name | Type | Mandatory| Description | 3712| -------------- | ------------------- | ---- | -------------- | 3713| rotationMatrix | Array<number> | Yes | Rotation matrix.| 3714 3715**Return value** 3716 3717| Type | Description | 3718| ---------------------------------- | --------------------------------- | 3719| Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes.| 3720 3721**Error codes** 3722 3723For details about the following error codes, see [Error Codes of sensor.getOrientation](../errorcodes/errorcode-sensor.md). 3724 3725| ID| Error Message | 3726| -------- | ------------------ | 3727| 14500101 | Service exception. | 3728 3729**Example** 3730 3731```ts 3732import sensor from '@ohos.sensor'; 3733import BusinessError from '@ohos.base'; 3734 3735try { 3736 let preRotationMatrix = [ 3737 1, 0, 0, 3738 0, 0.87, -0.50, 3739 0, 0.50, 0.87 3740 ]; 3741 const promise = sensor.getOrientation(preRotationMatrix); 3742 promise.then((data: Array<number>) => { 3743 for (let i = 0; i < data.length; i++) { 3744 console.info('Succeeded in getting data[' + i + ']: ' + data[i]); 3745 } 3746 }, (err: BusinessError.BusinessError) => { 3747 console.error(`Failed to getOrientatin. Code: ${err.code}, message: ${err.message}`); 3748 }); 3749} catch (error) { 3750 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3751 console.error(`Failed to getOrientatin Code: ${e.code}, message: ${e.message}`); 3752} 3753``` 3754 3755## sensor.getRotationMatrix<sup>9+</sup> 3756 3757getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>, callback: AsyncCallback<RotationMatrixResponse>): void 3758 3759Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result. 3760 3761**System capability**: SystemCapability.Sensors.Sensor 3762 3763**Parameters** 3764 3765| Name | Type | Mandatory| Description | 3766| ----------- | ------------------------------------------------------------ | ---- | -------------- | 3767| gravity | Array<number> | Yes | Gravity vector.| 3768| geomagnetic | Array<number> | Yes | Geomagnetic vector.| 3769| callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes | Callback used to return the rotation matrix.| 3770 3771**Error codes** 3772 3773For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). 3774 3775| ID| Error Message | 3776| -------- | ------------------ | 3777| 14500101 | Service exception. | 3778 3779**Example** 3780 3781```ts 3782import sensor from '@ohos.sensor'; 3783import BusinessError from '@ohos.base'; 3784 3785try { 3786 let gravity = [-0.27775216, 0.5351276, 9.788099]; 3787 let geomagnetic = [210.87253, -78.6096, -111.44444]; 3788 sensor.getRotationMatrix(gravity, geomagnetic, (err: BusinessError.BusinessError, data: sensor.RotationMatrixResponse) => { 3789 if (err) { 3790 console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3791 return; 3792 } 3793 console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); 3794 }) 3795} catch (error) { 3796 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3797 console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3798} 3799``` 3800 3801## sensor.getRotationMatrix<sup>9+</sup> 3802 3803getRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>): Promise<RotationMatrixResponse> 3804 3805Obtains the rotation matrix based on a gravity vector and geomagnetic vector. This API uses a promise to return the result. 3806 3807**System capability**: SystemCapability.Sensors.Sensor 3808 3809**Parameters** 3810 3811| Name | Type | Mandatory| Description | 3812| ----------- | ------------------- | ---- | -------------- | 3813| gravity | Array<number> | Yes | Gravity vector.| 3814| geomagnetic | Array<number> | Yes | Geomagnetic vector.| 3815 3816**Return value** 3817 3818| Type | Description | 3819| ------------------------------------------------------------ | -------------- | 3820| Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix.| 3821 3822**Error codes** 3823 3824For details about the following error codes, see [Error Codes of sensor.getRotationMatrix](../errorcodes/errorcode-sensor.md). 3825 3826| ID| Error Message | 3827| -------- | ------------------ | 3828| 14500101 | Service exception. | 3829 3830**Example** 3831 3832```ts 3833import sensor from '@ohos.sensor'; 3834import BusinessError from '@ohos.base'; 3835 3836try { 3837 let gravity = [-0.27775216, 0.5351276, 9.788099]; 3838 let geomagnetic = [210.87253, -78.6096, -111.44444]; 3839 const promise = sensor.getRotationMatrix(gravity, geomagnetic); 3840 promise.then((data: sensor.RotationMatrixResponse) => { 3841 console.info('Succeeded in getting rotationMatrix' + JSON.stringify(data)); 3842 }, (err: BusinessError.BusinessError) => { 3843 console.error(`Failed to get rotationMatrix. Code: ${err.code}, message: ${err.message}`); 3844 }); 3845} catch (error) { 3846 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3847 console.error(`Failed to get rotationMatrix. Code: ${e.code}, message: ${e.message}`); 3848} 3849``` 3850 3851## sensor.getSensorList<sup>9+</sup> 3852 3853getSensorList(callback: AsyncCallback<Array<Sensor>>): void 3854 3855Obtains information about all sensors on the device. This API uses an asynchronous callback to return the result. 3856 3857**System capability**: SystemCapability.Sensors.Sensor 3858 3859**Parameters** 3860 3861| Name | Type | Mandatory| Description | 3862| -------- | ---------------------------------------------- | ---- | ---------------- | 3863| callback | AsyncCallback<Array<[Sensor](#sensor9)>> | Yes | Callback used to return the sensor list.| 3864 3865**Error codes** 3866 3867For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). 3868 3869| ID| Error Message | 3870| -------- | ------------------ | 3871| 14500101 | Service exception. | 3872 3873**Example** 3874 3875```ts 3876import sensor from '@ohos.sensor'; 3877import BusinessError from '@ohos.base'; 3878 3879try { 3880 sensor.getSensorList((err: BusinessError.BusinessError, data: Array<sensor.Sensor>) => { 3881 if (err) { 3882 console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`); 3883 return; 3884 } 3885 for (let i = 0; i < data.length; i++) { 3886 console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i])); 3887 } 3888 }); 3889} catch (error) { 3890 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3891 console.error(`Failed to get sensorList. Code: ${e.code}, message: ${e.message}`); 3892} 3893``` 3894 3895## sensor.getSensorList<sup>9+</sup> 3896 3897 getSensorList(): Promise<Array<Sensor>> 3898 3899Obtains information about all sensors on the device. This API uses a promise to return the result. 3900 3901**System capability**: SystemCapability.Sensors.Sensor 3902 3903**Return value** 3904 3905| Name | Type | Mandatory| Description | 3906| ------- | ---------------------------------------- | ---- | ---------------- | 3907| promise | Promise<Array<[Sensor](#sensor9)>> | Yes | Promise used to return the sensor list.| 3908 3909**Error codes** 3910 3911For details about the following error codes, see [Error Codes of sensor.getSensorList](../errorcodes/errorcode-sensor.md). 3912 3913| ID| Error Message | 3914| -------- | ------------------ | 3915| 14500101 | Service exception. | 3916 3917**Example** 3918 3919```ts 3920import sensor from '@ohos.sensor'; 3921import BusinessError from '@ohos.base'; 3922 3923try { 3924 sensor.getSensorList().then((data: Array<sensor.Sensor>) => { 3925 for (let i = 0; i < data.length; i++) { 3926 console.info('Succeeded in getting data[' + i + ']: ' + JSON.stringify(data[i])); 3927 } 3928 }, (err: BusinessError.BusinessError) => { 3929 console.error(`Failed to get sensorList. Code: ${err.code}, message: ${err.message}`); 3930 }); 3931} catch (error) { 3932 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3933 console.error(`Failed to get sensorList. Code: ${e.code}, message: ${e.message}`); 3934} 3935``` 3936 3937## sensor.getSingleSensor<sup>9+</sup> 3938 3939getSingleSensor(type: SensorId, callback: AsyncCallback<Sensor>): void 3940 3941Obtains information about the sensor of a specific type. This API uses an asynchronous callback to return the result. 3942 3943**System capability**: SystemCapability.Sensors.Sensor 3944 3945**Parameters** 3946 3947| Name | Type | Mandatory| Description | 3948| -------- | --------------------------------------- | ---- | ---------------- | 3949| type | [SensorId](#sensorid9) | Yes | Sensor type. | 3950| callback | AsyncCallback<[Sensor](#sensor9)> | Yes | Callback used to return the sensor information.| 3951 3952**Error codes** 3953 3954For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). 3955 3956| ID| Error Message | 3957| -------- | ------------------ | 3958| 14500101 | Service exception. | 3959 3960**Example** 3961 3962```ts 3963import sensor from '@ohos.sensor'; 3964import BusinessError from '@ohos.base'; 3965 3966try { 3967 sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER, (err: BusinessError.BusinessError, data: sensor.Sensor) => { 3968 if (err) { 3969 console.error(`Failed to get singleSensor. Code: ${err.code}, message: ${err.message}`); 3970 return; 3971 } 3972 console.info('Succeeded in getting sensor: ' + JSON.stringify(data)); 3973 }); 3974} catch (error) { 3975 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 3976 console.error(`Failed to get singleSensor. Code: ${e.code}, message: ${e.message}`); 3977} 3978``` 3979 3980## sensor.getSingleSensor<sup>9+</sup> 3981 3982 getSingleSensor(type: SensorId): Promise<Sensor> 3983 3984Obtains information about the sensor of a specific type. This API uses a promise to return the result. 3985 3986**System capability**: SystemCapability.Sensors.Sensor 3987 3988**Parameters** 3989 3990| Name| Type | Mandatory| Description | 3991| ------ | ---------------------- | ---- | ------------ | 3992| type | [SensorId](#sensorid9) | Yes | Sensor type.| 3993 3994**Return value** 3995 3996| Name | Type | Mandatory| Description | 3997| ------- | --------------------------------- | ---- | ---------------------------- | 3998| promise | Promise<[Sensor](#sensor9)> | Yes | Promise used to return the sensor information.| 3999 4000**Error codes** 4001 4002For details about the following error codes, see [Error Codes of sensor.getSingleSensor](../errorcodes/errorcode-sensor.md). 4003 4004| ID| Error Message | 4005| -------- | ------------------ | 4006| 14500101 | Service exception. | 4007 4008**Example** 4009 4010```ts 4011import sensor from '@ohos.sensor'; 4012import BusinessError from '@ohos.base'; 4013 4014try { 4015 sensor.getSingleSensor(sensor.SensorId.ACCELEROMETER).then((data: sensor.Sensor) => { 4016 console.info('Succeeded in getting sensor: ' + JSON.stringify(data)); 4017 }, (err: BusinessError.BusinessError) => { 4018 console.error(`Failed to get singleSensor . Code: ${err.code}, message: ${err.message}`); 4019 }); 4020} catch (error) { 4021 let e: BusinessError.BusinessError = error as BusinessError.BusinessError; 4022 console.error(`Failed to get singleSensor . Code: ${e.code}, message: ${e.message}`); 4023} 4024``` 4025 4026## SensorId<sup>9+</sup> 4027 4028Enumerates the sensor types. 4029 4030**System capability**: SystemCapability.Sensors.Sensor 4031 4032| Name | Value | Description | 4033| --------------------------- | ---- | ---------------------- | 4034| ACCELEROMETER | 1 | Acceleration sensor. | 4035| GYROSCOPE | 2 | Gyroscope sensor. | 4036| AMBIENT_LIGHT | 5 | Ambient light sensor. | 4037| MAGNETIC_FIELD | 6 | Magnetic field sensor. | 4038| BAROMETER | 8 | Barometer sensor. | 4039| HALL | 10 | Hall effect sensor. | 4040| PROXIMITY | 12 | Proximity sensor. | 4041| HUMIDITY | 13 | Humidity sensor. | 4042| COLOR<sup>10+</sup> | 14 | Color sensor.<br>System API: This is a system API. | 4043| SAR<sup>10+</sup> | 15 | Sodium Adsorption Ratio (SAR) sensor.<br>System API: This is a system API.| 4044| ORIENTATION | 256 | Orientation sensor. | 4045| GRAVITY | 257 | Gravity sensor. | 4046| LINEAR_ACCELEROMETER | 258 | Linear acceleration sensor. | 4047| ROTATION_VECTOR | 259 | Rotation vector sensor. | 4048| AMBIENT_TEMPERATURE | 260 | Ambient temperature sensor. | 4049| MAGNETIC_FIELD_UNCALIBRATED | 261 | Uncalibrated magnetic field sensor. | 4050| GYROSCOPE_UNCALIBRATED | 263 | Uncalibrated gyroscope sensor. | 4051| SIGNIFICANT_MOTION | 264 | Significant motion sensor. | 4052| PEDOMETER_DETECTION | 265 | Pedometer detection sensor. | 4053| PEDOMETER | 266 | Pedometer sensor. | 4054| HEART_RATE | 278 | Heart rate sensor. | 4055| WEAR_DETECTION | 280 | Wear detection sensor. | 4056| ACCELEROMETER_UNCALIBRATED | 281 | Uncalibrated acceleration sensor.| 4057 4058## SensorType<sup>(deprecated)</sup> 4059 4060Enumerates the sensor types. 4061 4062**System capability**: SystemCapability.Sensors.Sensor 4063 4064 4065| Name | Value | Description | 4066| ------------------------------------------ | ---- | ---------------------- | 4067| SENSOR_TYPE_ID_ACCELEROMETER | 1 | Acceleration sensor. | 4068| SENSOR_TYPE_ID_GYROSCOPE | 2 | Gyroscope sensor. | 4069| SENSOR_TYPE_ID_AMBIENT_LIGHT | 5 | Ambient light sensor. | 4070| SENSOR_TYPE_ID_MAGNETIC_FIELD | 6 | Magnetic field sensor. | 4071| SENSOR_TYPE_ID_BAROMETER | 8 | Barometer sensor. | 4072| SENSOR_TYPE_ID_HALL | 10 | Hall effect sensor. | 4073| SENSOR_TYPE_ID_PROXIMITY | 12 | Proximity sensor. | 4074| SENSOR_TYPE_ID_HUMIDITY | 13 | Humidity sensor. | 4075| SENSOR_TYPE_ID_ORIENTATION | 256 | Orientation sensor. | 4076| SENSOR_TYPE_ID_GRAVITY | 257 | Gravity sensor. | 4077| SENSOR_TYPE_ID_LINEAR_ACCELERATION | 258 | Linear acceleration sensor. | 4078| SENSOR_TYPE_ID_ROTATION_VECTOR | 259 | Rotation vector sensor. | 4079| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | 260 | Ambient temperature sensor. | 4080| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261 | Uncalibrated magnetic field sensor. | 4081| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | 263 | Uncalibrated gyroscope sensor. | 4082| SENSOR_TYPE_ID_SIGNIFICANT_MOTION | 264 | Significant motion sensor. | 4083| SENSOR_TYPE_ID_PEDOMETER_DETECTION | 265 | Pedometer detection sensor. | 4084| SENSOR_TYPE_ID_PEDOMETER | 266 | Pedometer sensor. | 4085| SENSOR_TYPE_ID_HEART_RATE | 278 | Heart rate sensor. | 4086| SENSOR_TYPE_ID_WEAR_DETECTION | 280 | Wear detection sensor. | 4087| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281 | Uncalibrated acceleration sensor.| 4088 4089## SensorAccuracy<sup>11+</sup> 4090 4091Enumerates the accuracy levels of sensor data. 4092 4093**System capability**: SystemCapability.Sensors.Sensor 4094 4095| Name | Value| Description | 4096| --------- | ---- | ------------------------ | 4097| ACCURACY_UNRELIABLE | 0 | The sensor data is unreliable.| 4098| ACCURACY_LOW | 1 | The sensor data is at a low accuracy level.| 4099| ACCURACY_MEDIUM | 2 | The sensor data is at a medium accuracy level.| 4100| ACCURACY_HIGH | 3 | The sensor data is at a high accuracy level.| 4101 4102## Response 4103 4104Describes the timestamp of the sensor data. 4105 4106**System capability**: SystemCapability.Sensors.Sensor 4107 4108| Name | Type | Readable| Writable| Description | 4109| --------- | ------ | ---- | ---- | ------------------------ | 4110| timestamp | number | Yes | Yes | Timestamp when the sensor reports data.| 4111| accuracy<sup>11+</sup> | [SensorAccuracy](#sensoraccuracy11)<sup>11+</sup> | Yes | No | Accuracy of the sensor data.| 4112 4113## Sensor<sup>9+</sup> 4114 4115Describes the sensor information. 4116 4117**System capability**: SystemCapability.Sensors.Sensor 4118 4119| Name | Type| Readable| Writable| Description | 4120| --------------- | -------- | ---------------------- | ---------------------- | ---------------------- | 4121| sensorName | string | Yes | No | Sensor name. | 4122| vendorName | string | Yes | No | Vendor of the sensor. | 4123| firmwareVersion | string | Yes | No | Firmware version of the sensor. | 4124| hardwareVersion | string | Yes | No | Hardware version of the sensor. | 4125| sensorId | number | Yes | No | Sensor type ID. | 4126| maxRange | number | Yes | No | Maximum measurement range of the sensor.| 4127| minSamplePeriod | number | Yes | No | Minimum sampling period. | 4128| maxSamplePeriod | number | Yes | No | Maximum sampling period. | 4129| precision | number | Yes | No | Precision of the sensor. | 4130| power | number | Yes | No | Estimated sensor power, in mA. | 4131 4132## ColorResponse<sup>10+</sup> 4133 4134Describes the color sensor data. It extends from [Response](#response). 4135 4136**System capability**: SystemCapability.Sensors.Sensor 4137 4138**System API**: This is a system API. 4139 4140 4141| Name | Type | Readable| Writable| Description | 4142| ---------------- | ------ | ---- | ---- | ----------------------------- | 4143| lightIntensity | number | Yes | Yes | Intensity of light, in lux.| 4144| colorTemperature | number | Yes | Yes | Color temperature, in Kelvin. | 4145 4146## SarResponse<sup>10+</sup> 4147 4148Describes the SAR sensor data. It extends from [Response](#response). 4149 4150**System capability**: SystemCapability.Sensors.Sensor 4151 4152**System API**: This is a system API. 4153 4154 4155| Name | Type | Readable| Writable| Description | 4156| --------------- | ------ | ---- | ---- | ------------------------------- | 4157| absorptionRatio | number | Yes | Yes | Absorption ratio, in W/kg.| 4158 4159## AccelerometerResponse 4160 4161Describes the acceleration sensor data. It extends from [Response](#response). 4162 4163**System capability**: SystemCapability.Sensors.Sensor 4164 4165 4166| Name| Type | Readable| Writable| Description | 4167| ---- | ------ | ---- | ---- | ------------------------------------ | 4168| x | number | Yes | Yes | Acceleration along the x-axis of the device, in m/s².| 4169| y | number | Yes | Yes | Acceleration along the y-axis of the device, in m/s².| 4170| z | number | Yes | Yes | Acceleration along the z-axis of the device, in m/s².| 4171 4172 4173## LinearAccelerometerResponse 4174 4175Describes the linear acceleration sensor data. It extends from [Response](#response). 4176 4177**System capability**: SystemCapability.Sensors.Sensor 4178 4179 4180| Name| Type | Readable| Writable| Description | 4181| ---- | ------ | ---- | ---- | ---------------------------------------- | 4182| x | number | Yes | Yes | Linear acceleration along the x-axis of the device, in m/s².| 4183| y | number | Yes | Yes | Linear acceleration along the y-axis of the device, in m/s².| 4184| z | number | Yes | Yes | Linear acceleration along the z-axis of the device, in m/s².| 4185 4186 4187## AccelerometerUncalibratedResponse 4188 4189Describes the uncalibrated acceleration sensor data. It extends from [Response](#response). 4190 4191**System capability**: SystemCapability.Sensors.Sensor 4192 4193 4194| Name | Type | Readable| Writable| Description | 4195| ----- | ------ | ---- | ---- | ---------------------------------------------- | 4196| x | number | Yes | Yes | Uncalibrated acceleration along the x-axis of the device, in m/s². | 4197| y | number | Yes | Yes | Uncalibrated acceleration along the y-axis of the device, in m/s². | 4198| z | number | Yes | Yes | Uncalibrated acceleration along the z-axis of the device, in m/s². | 4199| biasX | number | Yes | Yes | Uncalibrated acceleration bias along the x-axis of the device, in m/s².| 4200| biasY | number | Yes | Yes | Uncalibrated acceleration bias along the y-axis of the device, in m/s².| 4201| biasZ | number | Yes | Yes | Uncalibrated acceleration bias along the z-axis of the device, in m/s².| 4202 4203 4204## GravityResponse 4205 4206Describes the gravity sensor data. It extends from [Response](#response). 4207 4208**System capability**: SystemCapability.Sensors.Sensor 4209 4210 4211| Name| Type | Readable| Writable| Description | 4212| ---- | ------ | ---- | ---- | ---------------------------------------- | 4213| x | number | Yes | Yes | Gravitational acceleration along the x-axis of the device, in m/s².| 4214| y | number | Yes | Yes | Gravitational acceleration along the y-axis of the device, in m/s².| 4215| z | number | Yes | Yes | Gravitational acceleration along the z-axis of the device, in m/s².| 4216 4217 4218## OrientationResponse 4219 4220Describes the orientation sensor data. It extends from [Response](#response). 4221 4222**System capability**: SystemCapability.Sensors.Sensor 4223 4224 4225| Name | Type | Readable| Writable| Description | 4226| ----- | ------ | ---- | ---- | --------------------------------- | 4227| alpha | number | Yes | Yes | Rotation angle of the device around the z-axis, in degrees.| 4228| beta | number | Yes | Yes | Rotation angle of the device around the x-axis, in degrees.| 4229| gamma | number | Yes | Yes | Rotation angle of the device around the y-axis, in degrees.| 4230 4231 4232## RotationVectorResponse 4233 4234Describes the rotation vector sensor data. It extends from [Response](#response). 4235 4236**System capability**: SystemCapability.Sensors.Sensor 4237 4238 4239| Name| Type | Readable| Writable| Description | 4240| ---- | ------ | ---- | ---- | ----------------- | 4241| x | number | Yes | Yes | X-component of the rotation vector.| 4242| y | number | Yes | Yes | Y-component of the rotation vector.| 4243| z | number | Yes | Yes | Z-component of the rotation vector.| 4244| w | number | Yes | Yes | Scalar. | 4245 4246 4247## GyroscopeResponse 4248 4249Describes the gyroscope sensor data. It extends from [Response](#response). 4250 4251**System capability**: SystemCapability.Sensors.Sensor 4252 4253 4254| Name| Type | Readable| Writable| Description | 4255| ---- | ------ | ---- | ---- | -------------------------------- | 4256| x | number | Yes | Yes | Angular velocity of rotation around the x-axis of the device, in rad/s.| 4257| y | number | Yes | Yes | Angular velocity of rotation around the y-axis of the device, in rad/s.| 4258| z | number | Yes | Yes | Angular velocity of rotation around the z-axis of the device, in rad/s.| 4259 4260 4261## GyroscopeUncalibratedResponse 4262 4263Describes the uncalibrated gyroscope sensor data. It extends from [Response](#response). 4264 4265**System capability**: SystemCapability.Sensors.Sensor 4266 4267 4268| Name | Type | Readable| Writable| Description | 4269| ----- | ------ | ---- | ---- | ------------------------------------------ | 4270| x | number | Yes | Yes | Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s. | 4271| y | number | Yes | Yes | Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s. | 4272| z | number | Yes | Yes | Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s. | 4273| biasX | number | Yes | Yes | Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.| 4274| biasY | number | Yes | Yes | Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.| 4275| biasZ | number | Yes | Yes | Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.| 4276 4277 4278## SignificantMotionResponse 4279 4280Describes the significant motion sensor data. It extends from [Response](#response). 4281 4282**System capability**: SystemCapability.Sensors.Sensor 4283 4284 4285| Name | Type | Readable| Writable| Description | 4286| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 4287| 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 **1** is reported when the device has a significant motion.| 4288 4289 4290## ProximityResponse 4291 4292Describes the proximity sensor data. It extends from [Response](#response). 4293 4294**System capability**: SystemCapability.Sensors.Sensor 4295 4296 4297| Name | Type | Readable| Writable| Description | 4298| -------- | ------ | ---- | ---- | ---------------------------------------------------------- | 4299| 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 a value greater than 0 means that they are far away from each other.| 4300 4301 4302## LightResponse 4303 4304Describes the ambient light sensor data. It extends from [Response](#response). 4305 4306**System capability**: SystemCapability.Sensors.Sensor 4307 4308 4309| Name | Type | Readable| Writable| Description | 4310| --------- | ------ | ---- | ---- | ---------------------- | 4311| intensity | number | Yes | Yes | Illumination, in lux.| 4312 4313 4314## HallResponse 4315 4316Describes the Hall effect sensor data. It extends from [Response](#response). 4317 4318**System capability**: SystemCapability.Sensors.Sensor 4319 4320 4321| Name | Type | Readable| Writable| Description | 4322| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 4323| 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.| 4324 4325 4326## MagneticFieldResponse 4327 4328Describes the magnetic field sensor data. It extends from [Response](#response). 4329 4330**System capability**: SystemCapability.Sensors.Sensor 4331 4332 4333| Name| Type | Readable| Writable| Description | 4334| ---- | ------ | ---- | ---- | ---------------------------- | 4335| x | number | Yes | Yes | Magnetic field strength on the x-axis, in μT.| 4336| y | number | Yes | Yes | Magnetic field strength on the y-axis, in μT.| 4337| z | number | Yes | Yes | Magnetic field strength on the z-axis, in μT.| 4338 4339 4340## MagneticFieldUncalibratedResponse 4341 4342Describes the uncalibrated magnetic field sensor data. It extends from [Response](#response). 4343 4344**System capability**: SystemCapability.Sensors.Sensor 4345 4346 4347| Name | Type | Readable| Writable| Description | 4348| ----- | ------ | ---- | ---- | -------------------------------------- | 4349| x | number | Yes | Yes | Uncalibrated magnetic field strength on the x-axis, in μT. | 4350| y | number | Yes | Yes | Uncalibrated magnetic field strength on the y-axis, in μT. | 4351| z | number | Yes | Yes | Uncalibrated magnetic field strength on the z-axis, in μT. | 4352| biasX | number | Yes | Yes | Bias of the uncalibrated magnetic field strength on the x-axis, in μT.| 4353| biasY | number | Yes | Yes | Bias of the uncalibrated magnetic field strength on the y-axis, in μT.| 4354| biasZ | number | Yes | Yes | Bias of the uncalibrated magnetic field strength on the z-axis, in μT.| 4355 4356 4357## PedometerResponse 4358 4359Describes the pedometer sensor data. It extends from [Response](#response). 4360 4361**System capability**: SystemCapability.Sensors.Sensor 4362 4363 4364| Name | Type | Readable| Writable| Description | 4365| ----- | ------ | ---- | ---- | ---------------- | 4366| steps | number | Yes | Yes | Number of steps a user has walked.| 4367 4368 4369## HumidityResponse 4370 4371Describes the humidity sensor data. It extends from [Response](#response). 4372 4373**System capability**: SystemCapability.Sensors.Sensor 4374 4375 4376| Name | Type | Readable| Writable| Description | 4377| -------- | ------ | ---- | ---- | --------------------------------------------------------- | 4378| humidity | number | Yes | Yes | Ambient relative humidity, in a percentage (%).| 4379 4380 4381## PedometerDetectionResponse 4382 4383Describes the pedometer detection sensor data. It extends from [Response](#response). 4384 4385**System capability**: SystemCapability.Sensors.Sensor 4386 4387 4388| Name | Type | Readable| Writable| Description | 4389| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 4390| 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.| 4391 4392 4393## AmbientTemperatureResponse 4394 4395Describes the ambient temperature sensor data. It extends from [Response](#response). 4396 4397**System capability**: SystemCapability.Sensors.Sensor 4398 4399 4400| Name | Type | Readable| Writable| Description | 4401| ----------- | ------ | ---- | ---- | -------------------------- | 4402| temperature | number | Yes | Yes | Ambient temperature, in degree Celsius.| 4403 4404 4405## BarometerResponse 4406 4407Describes the barometer sensor data. It extends from [Response](#response). 4408 4409**System capability**: SystemCapability.Sensors.Sensor 4410 4411 4412| Name | Type | Readable| Writable| Description | 4413| -------- | ------ | ---- | ---- | ---------------------- | 4414| pressure | number | Yes | Yes | Atmospheric pressure, in units of hPa.| 4415 4416 4417## HeartRateResponse 4418 4419Describes the heart rate sensor data. It extends from [Response](#response). 4420 4421**System capability**: SystemCapability.Sensors.Sensor 4422 4423 4424| Name | Type | Readable| Writable| Description | 4425| --------- | ------ | ---- | ---- | --------------------------------------- | 4426| heartRate | number | Yes | Yes | Heart rate, in beats per minute (bpm).| 4427 4428 4429## WearDetectionResponse 4430 4431Describes the wear detection sensor data. It extends from [Response](#response). 4432 4433**System capability**: SystemCapability.Sensors.Sensor 4434 4435 4436| Name | Type | Readable| Writable| Description | 4437| ----- | ------ | ---- | ---- | ------------------------------------------------ | 4438| 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.| 4439 4440 4441## Options 4442 4443Describes the sensor data reporting frequency. 4444 4445**System capability**: SystemCapability.Sensors.Sensor 4446 4447| Name | Type | Readable| Writable| Description | 4448| -------- | ----------------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | 4449| interval | number/[SensorFrequency](#sensorfrequency11+)<sup>11+</sup> | Yes | Yes | Frequency at which a sensor reports data. The default value is 200,000,000 ns. This attribute has restrictions on the minimum and maximum values, determined by the reporting frequency supported by the hardware.| 4450 4451## SensorFrequency<sup>11+</sup> 4452 4453Defines the reporting frequency mode of the sensor. 4454 4455**System capability**: SystemCapability.Sensors.Sensor 4456 4457| Name | Type | Readable| Writable| Description | 4458| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 4459| game | string | Yes | No | The sensor reports data every 20,000,000 ns. The frequency takes effect when it is within the frequency range supported by the hardware.| 4460| ui | string | Yes | No | The sensor reports data every 60,000,000 ns. The frequency takes effect when it is within the frequency range supported by the hardware.| 4461| normal | string | Yes | No | The sensor reports data every 200,000,000 ns. The frequency takes effect when it is within the frequency range supported by the hardware.| 4462 4463## RotationMatrixResponse 4464 4465Describes the response for setting the rotation matrix. 4466 4467**System capability**: SystemCapability.Sensors.Sensor 4468 4469| Name | Type | Readable| Writable| Description | 4470| ----------- | ------------------- | ---- | ---- | ---------- | 4471| rotation | Array<number> | Yes | Yes | Rotation matrix.| 4472| inclination | Array<number> | Yes | Yes | Inclination matrix.| 4473 4474 4475## CoordinatesOptions 4476 4477Describes the coordinate options. 4478 4479**System capability**: SystemCapability.Sensors.Sensor 4480 4481| Name| Type | Readable| Writable| Description | 4482| ---- | ------ | ---- | ---- | ----------- | 4483| x | number | Yes | Yes | X coordinate direction.| 4484| y | number | Yes | Yes | Y coordinate direction.| 4485 4486 4487## GeomagneticResponse 4488 4489Describes a geomagnetic response object. 4490 4491**System capability**: SystemCapability.Sensors.Sensor 4492 4493| Name | Type | Readable| Writable| Description | 4494| --------------- | ------ | ---- | ---- | -------------------------------------------------- | 4495| x | number | Yes | Yes | North component of the geomagnetic field. | 4496| y | number | Yes | Yes | East component of the geomagnetic field. | 4497| z | number | Yes | Yes | Vertical component of the geomagnetic field. | 4498| geomagneticDip | number | Yes | Yes | Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector. | 4499| 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).| 4500| levelIntensity | number | Yes | Yes | Horizontal intensity of the magnetic field vector field. | 4501| totalIntensity | number | Yes | Yes | Total intensity of the magnetic field vector. | 4502 4503## LocationOptions 4504 4505Describes the geographical location. 4506 4507**System capability**: SystemCapability.Sensors.Sensor 4508 4509| Name | Type | Readable | Writable | Description | 4510| --------- | ------ | -------- | -------- | ----------- | 4511| latitude | number | Yes | Yes | Latitude. | 4512| longitude | number | Yes | Yes | Longitude. | 4513| altitude | number | Yes | Yes | Altitude. | 4514 4515## sensor.on<sup>(deprecated)</sup> 4516 4517### ACCELEROMETER<sup>(deprecated)</sup> 4518 4519on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>,options?: Options): void 4520 4521Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. 4522 4523> **NOTE** 4524> 4525> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER](#accelerometer9)<sup>9+</sup> instead. 4526 4527**Required permissions**: ohos.permission.ACCELEROMETER 4528 4529**System capability**: SystemCapability.Sensors.Sensor 4530 4531**Parameters** 4532 4533| Name | Type | Mandatory | Description | 4534| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4535| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. | 4536| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. | 4537| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4538 4539**Example** 4540 4541```ts 4542import sensor from '@ohos.sensor'; 4543 4544sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => { 4545 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4546 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4547 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4548}, 4549 { interval: 100000000 } 4550); 4551``` 4552 4553### LINEAR_ACCELERATION<sup>(deprecated)</sup> 4554 4555on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>, options?: Options): void 4556 4557Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. 4558 4559> **NOTE** 4560> 4561> This API is deprecated since API version 9. You are advised to use [sensor.on.LINEAR_ACCELEROMETER](#linear_accelerometer9)<sup>9+</sup> instead. 4562 4563**Required permissions**: ohos.permission.ACCELEROMETER 4564 4565**System capability**: SystemCapability.Sensors.Sensor 4566 4567**Parameters** 4568 4569| Name | Type | Mandatory | Description | 4570| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4571| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. | 4572| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. | 4573| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4574 4575### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup> 4576 4577on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>, options?: Options): void 4578 4579Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect. 4580 4581> **NOTE** 4582> 4583> This API is deprecated since API version 9. You are advised to use [sensor.on.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9)<sup>9+</sup> instead. 4584 4585**Required permissions**: ohos.permission.ACCELEROMETER 4586 4587**System capability**: SystemCapability.Sensors.Sensor 4588 4589**Parameters** 4590 4591| Name | Type | Mandatory | Description | 4592| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4593| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. | 4594| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. | 4595| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4596 4597**Example** 4598 4599```ts 4600import sensor from '@ohos.sensor'; 4601 4602sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => { 4603 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4604 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4605 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4606 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 4607 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 4608 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 4609}, 4610 { interval: 100000000 } 4611); 4612 4613``` 4614 4615### GRAVITY<sup>(deprecated)</sup> 4616 4617on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>,options?: Options): void 4618 4619Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect. 4620 4621> **NOTE** 4622> 4623> This API is deprecated since API version 9. You are advised to use [sensor.on.GRAVITY](#gravity9)<sup>9+</sup> instead. 4624 4625**System capability**: SystemCapability.Sensors.Sensor 4626 4627**Parameters** 4628 4629| Name | Type | Mandatory | Description | 4630| -------- | ---------------------------------------------------------- | --------- | ------------------------------------------------------------ | 4631| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. | 4632| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. | 4633| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4634 4635**Example** 4636 4637```ts 4638import sensor from '@ohos.sensor'; 4639 4640sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => { 4641 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4642 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4643 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4644}, 4645 { interval: 100000000 } 4646); 4647``` 4648 4649### GYROSCOPE<sup>(deprecated)</sup> 4650 4651on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>, options?: Options): void 4652 4653Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. 4654 4655> **NOTE** 4656> 4657> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE](#gyroscope9)<sup>9+</sup> instead. 4658 4659**Required permissions**: ohos.permission.GYROSCOPE 4660 4661**System capability**: SystemCapability.Sensors.Sensor 4662 4663**Parameters** 4664 4665| Name | Type | Mandatory | Description | 4666| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4667| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. | 4668| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. | 4669| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4670 4671**Example** 4672 4673```ts 4674import sensor from '@ohos.sensor'; 4675 4676sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => { 4677 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4678 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4679 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4680}, 4681 { interval: 100000000 } 4682); 4683``` 4684 4685### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup> 4686 4687on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<GyroscopeUncalibratedResponse>, options?: Options): void 4688 4689Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect. 4690 4691> **NOTE** 4692> 4693> This API is deprecated since API version 9. You are advised to use [sensor.on.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9)<sup>9+</sup> instead. 4694 4695**Required permissions**: ohos.permission.GYROSCOPE 4696 4697**System capability**: SystemCapability.Sensors.Sensor 4698 4699**Parameters** 4700 4701| Name | Type | Mandatory | Description | 4702| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4703| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. | 4704| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. | 4705| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4706 4707**Example** 4708 4709```ts 4710import sensor from '@ohos.sensor'; 4711 4712sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => { 4713 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4714 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4715 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4716 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 4717 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 4718 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 4719}, 4720 { interval: 100000000 } 4721); 4722``` 4723 4724### SIGNIFICANT_MOTION<sup>(deprecated)</sup> 4725 4726on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>, options?: Options): void 4727 4728Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect. 4729 4730> **NOTE** 4731> 4732> This API is deprecated since API version 9. You are advised to use [sensor.on.SIGNIFICANT_MOTION](#significant_motion9)<sup>9+</sup> instead. 4733 4734**System capability**: SystemCapability.Sensors.Sensor 4735 4736**Parameters** 4737 4738| Name | Type | Mandatory | Description | 4739| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4740| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. | 4741| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. | 4742| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4743 4744**Example** 4745 4746```ts 4747import sensor from '@ohos.sensor'; 4748 4749sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => { 4750 console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); 4751}, 4752 { interval: 100000000 } 4753); 4754``` 4755 4756### PEDOMETER_DETECTION<sup>(deprecated)</sup> 4757 4758on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>, options?: Options): void 4759 4760Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect. 4761 4762> **NOTE** 4763> 4764> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER_DETECTION](#pedometer_detection9)<sup>9+</sup> instead. 4765 4766**Required permissions**: ohos.permission.ACTIVITY_MOTION 4767 4768**System capability**: SystemCapability.Sensors.Sensor 4769 4770**Parameters** 4771 4772| Name | Type | Mandatory | Description | 4773| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4774| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. | 4775| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. | 4776| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4777 4778**Example** 4779 4780```ts 4781import sensor from '@ohos.sensor'; 4782 4783sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => { 4784 console.info('Succeeded in invoking on. Scalar data: ' + data.scalar); 4785}, 4786 { interval: 100000000 } 4787); 4788``` 4789 4790### PEDOMETER<sup>(deprecated)</sup> 4791 4792on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>, options?: Options): void 4793 4794Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect. 4795 4796> **NOTE** 4797> 4798> This API is deprecated since API version 9. You are advised to use [sensor.on.PEDOMETER](#pedometer9)<sup>9+</sup> instead. 4799 4800**Required permissions**: ohos.permission.ACTIVITY_MOTION 4801 4802**System capability**: SystemCapability.Sensors.Sensor 4803 4804**Parameters** 4805 4806| Name | Type | Mandatory | Description | 4807| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4808| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. | 4809| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. | 4810| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4811 4812**Example** 4813 4814```ts 4815import sensor from '@ohos.sensor'; 4816 4817sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => { 4818 console.info('Succeeded in invoking on. Steps: ' + data.steps); 4819}, 4820 { interval: 100000000 } 4821); 4822``` 4823 4824### AMBIENT_TEMPERATURE<sup>(deprecated)</sup> 4825 4826on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<AmbientTemperatureResponse>, options?: Options): void 4827 4828Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect. 4829 4830> **NOTE** 4831> 4832> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_TEMPERATURE](#ambient_temperature9)<sup>9+</sup> instead. 4833 4834**System capability**: SystemCapability.Sensors.Sensor 4835 4836**Parameters** 4837 4838| Name | Type | Mandatory | Description | 4839| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4840| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. | 4841| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. | 4842| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4843 4844**Example** 4845 4846```ts 4847import sensor from '@ohos.sensor'; 4848 4849sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => { 4850 console.info('Succeeded in invoking on. Temperature: ' + data.temperature); 4851}, 4852 { interval: 100000000 } 4853); 4854 4855``` 4856 4857### MAGNETIC_FIELD<sup>(deprecated)</sup> 4858 4859on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>,options?: Options): void 4860 4861Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect. 4862 4863> **NOTE** 4864> 4865> This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD](#magnetic_field9)<sup>9+</sup> instead. 4866 4867**System capability**: SystemCapability.Sensors.Sensor 4868 4869**Parameters** 4870 4871| Name | Type | Mandatory | Description | 4872| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4873| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. | 4874| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. | 4875| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4876 4877**Example** 4878 4879```ts 4880import sensor from '@ohos.sensor'; 4881 4882sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => { 4883 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4884 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4885 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4886}, 4887 { interval: 100000000 } 4888); 4889 4890``` 4891 4892### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup> 4893 4894on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>, options?: Options): void 4895 4896Subscribes 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. 4897 4898> **NOTE** 4899> 4900> This API is deprecated since API version 9. You are advised to use [sensor.on.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9)<sup>9+</sup> instead. 4901 4902**System capability**: SystemCapability.Sensors.Sensor 4903 4904**Parameters** 4905 4906| Name | Type | Mandatory | Description | 4907| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4908| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. | 4909| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. | 4910| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4911 4912**Example** 4913 4914```ts 4915import sensor from '@ohos.sensor'; 4916 4917sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => { 4918 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 4919 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 4920 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 4921 console.info('Succeeded in invoking on. X-coordinate bias: ' + data.biasX); 4922 console.info('Succeeded in invoking on. Y-coordinate bias: ' + data.biasY); 4923 console.info('Succeeded in invoking on. Z-coordinate bias: ' + data.biasZ); 4924}, 4925 { interval: 100000000 } 4926); 4927 4928``` 4929 4930### PROXIMITY<sup>(deprecated)</sup> 4931 4932on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>,options?: Options): void 4933 4934Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect. 4935 4936> **NOTE** 4937> 4938> This API is deprecated since API version 9. You are advised to use [sensor.on.PROXIMITY](#proximity9)<sup>9+</sup> instead. 4939 4940**System capability**: SystemCapability.Sensors.Sensor 4941 4942**Parameters** 4943 4944| Name | Type | Mandatory | Description | 4945| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 4946| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. | 4947| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. | 4948| options | [Options](#options) | No | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when proximity sensor events are frequently triggered. | 4949 4950**Example** 4951 4952```ts 4953import sensor from '@ohos.sensor'; 4954 4955sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => { 4956 console.info('Succeeded in invoking on. Distance: ' + data.distance); 4957}, 4958 { interval: 100000000 } 4959); 4960 4961``` 4962 4963### HUMIDITY<sup>(deprecated)</sup> 4964 4965on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>,options?: Options): void 4966 4967Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect. 4968 4969> **NOTE** 4970> 4971> This API is deprecated since API version 9. You are advised to use [sensor.on.HUMIDITY](#humidity9)<sup>9+</sup> instead. 4972 4973**System capability**: SystemCapability.Sensors.Sensor 4974 4975**Parameters** 4976 4977| Name | Type | Mandatory | Description | 4978| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ | 4979| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. | 4980| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. | 4981| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 4982 4983**Example** 4984 4985```ts 4986import sensor from '@ohos.sensor'; 4987 4988sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => { 4989 console.info('Succeeded in invoking on. Humidity: ' + data.humidity); 4990}, 4991 { interval: 100000000 } 4992); 4993 4994``` 4995 4996### BAROMETER<sup>(deprecated)</sup> 4997 4998on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>,options?: Options): void 4999 5000Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. 5001 5002> **NOTE** 5003> 5004> This API is deprecated since API version 9. You are advised to use [sensor.on.BAROMETER](#barometer9)<sup>9+</sup> instead. 5005 5006**System capability**: SystemCapability.Sensors.Sensor 5007 5008**Parameters** 5009 5010| Name | Type | Mandatory | Description | 5011| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5012| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. | 5013| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. | 5014| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5015 5016**Example** 5017 5018```ts 5019import sensor from '@ohos.sensor'; 5020 5021sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => { 5022 console.info('Succeeded in invoking on. Atmospheric pressure: ' + data.pressure); 5023}, 5024 { interval: 100000000 } 5025); 5026 5027``` 5028 5029### HALL<sup>(deprecated)</sup> 5030 5031on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>, options?: Options): void 5032 5033Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect. 5034 5035> **NOTE** 5036> 5037> This API is deprecated since API version 9. You are advised to use [sensor.on.HALL](#hall9)<sup>9+</sup> instead. 5038 5039**System capability**: SystemCapability.Sensors.Sensor 5040 5041**Parameters** 5042 5043| Name | Type | Mandatory | Description | 5044| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 5045| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. | 5046| callback | Callback<[HallResponse](#hallresponse)> | Yes | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. | 5047| options | [Options](#options) | No | List of optional parameters. The default value is 200,000,000 ns. This parameter is used to set the data reporting frequency when Hall effect events are frequently triggered. | 5048 5049**Example** 5050 5051```ts 5052import sensor from '@ohos.sensor'; 5053 5054sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => { 5055 console.info('Succeeded in invoking on. Status: ' + data.status); 5056}, 5057 { interval: 100000000 } 5058); 5059 5060``` 5061 5062### AMBIENT_LIGHT<sup>(deprecated)</sup> 5063 5064on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>, options?: Options): void 5065 5066Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect. 5067 5068> **NOTE** 5069> 5070> This API is deprecated since API version 9. You are advised to use [sensor.on.AMBIENT_LIGHT](#ambient_light9)<sup>9+</sup> instead. 5071 5072**System capability**: SystemCapability.Sensors.Sensor 5073 5074**Parameters** 5075 5076| Name | Type | Mandatory | Description | 5077| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5078| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. | 5079| callback | Callback<[LightResponse](#lightresponse)> | Yes | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. | 5080| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5081 5082**Example** 5083 5084```ts 5085import sensor from '@ohos.sensor'; 5086 5087sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => { 5088 console.info('Succeeded in invoking on. Illumination: ' + data.intensity); 5089}, 5090 { interval: 100000000 } 5091); 5092 5093``` 5094 5095### ORIENTATION<sup>(deprecated)</sup> 5096 5097on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>, options?: Options): void 5098 5099Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect. 5100 5101> **NOTE** 5102> 5103> This API is deprecated since API version 9. You are advised to use [sensor.on.ORIENTATION](#orientation9)<sup>9+</sup> instead. 5104 5105**System capability**: SystemCapability.Sensors.Sensor 5106 5107**Parameters** 5108 5109| Name | Type | Mandatory | Description | 5110| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5111| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. | 5112| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. | 5113| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5114 5115**Example** 5116 5117```ts 5118import sensor from '@ohos.sensor'; 5119 5120sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => { 5121 console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta); 5122 console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma); 5123 console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha); 5124}, 5125 { interval: 100000000 } 5126); 5127 5128``` 5129 5130### HEART_RATE<sup>(deprecated)</sup> 5131 5132on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>, options?: Options): void 5133 5134Subscribes to data changes of the heart rate sensor. If this API is called multiple times for the same application, the last call takes effect. 5135 5136> **NOTE** 5137> 5138> This API is deprecated since API version 9. You are advised to use [sensor.on.HEART_RATE](#heart_rate9)<sup>9+</sup> instead. 5139 5140**Required permissions**: ohos.permission.HEALTH_DATA 5141 5142**System capability**: SystemCapability.Sensors.Sensor 5143 5144**Parameters** 5145 5146| Name | Type | Mandatory | Description | 5147| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5148| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. | 5149| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | Callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. | 5150| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5151 5152### ROTATION_VECTOR<sup>(deprecated)</sup> 5153 5154on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<RotationVectorResponse>,options?: Options): void 5155 5156Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect. 5157 5158> **NOTE** 5159> 5160> This API is deprecated since API version 9. You are advised to use [sensor.on.ROTATION_VECTOR](#rotation_vector9)<sup>9+</sup> instead. 5161 5162**System capability**: SystemCapability.Sensors.Sensor 5163 5164**Parameters** 5165 5166| Name | Type | Mandatory | Description | 5167| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5168| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. | 5169| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. | 5170| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5171 5172**Example** 5173 5174```ts 5175import sensor from '@ohos.sensor'; 5176 5177sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => { 5178 console.info('Succeeded in invoking on. X-coordinate component: ' + data.x); 5179 console.info('Succeeded in invoking on. Y-coordinate component: ' + data.y); 5180 console.info('Succeeded in invoking on. Z-coordinate component: ' + data.z); 5181 console.info('Succeeded in invoking on. Scalar quantity: ' + data.w); 5182}, 5183 { interval: 100000000 } 5184); 5185 5186``` 5187 5188### WEAR_DETECTION<sup>(deprecated)</sup> 5189 5190on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>,options?: Options): void 5191 5192Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect. 5193 5194> **NOTE** 5195> 5196> This API is deprecated since API version 9. You are advised to use [sensor.on.WEAR_DETECTION](#wear_detection9)<sup>9+</sup> instead. 5197 5198**System capability**: SystemCapability.Sensors.Sensor 5199 5200**Parameters** 5201 5202| Name | Type | Mandatory | Description | 5203| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5204| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. | 5205| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. | 5206| options | [Options](#options) | No | List of optional parameters. This parameter is used to set the data reporting frequency. The default value is 200,000,000 ns. | 5207 5208**Example** 5209 5210```ts 5211import sensor from '@ohos.sensor'; 5212 5213sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => { 5214 console.info('Succeeded in invoking on. Wear status: ' + data.value); 5215}, 5216 { interval: 100000000 } 5217); 5218 5219``` 5220 5221## sensor.once<sup>(deprecated)</sup> 5222 5223### ACCELEROMETER<sup>(deprecated)</sup> 5224 5225once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>): void 5226 5227Subscribes to only one data change of the acceleration sensor. 5228 5229> **NOTE** 5230> 5231> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER](#accelerometer9-1)<sup>9+</sup> instead. 5232 5233**Required permissions**: ohos.permission.ACCELEROMETER 5234 5235**System capability**: SystemCapability.Sensors.Sensor 5236 5237**Parameters** 5238 5239| Name | Type | Mandatory | Description | 5240| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5241| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**. | 5242| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**. | 5243 5244**Example** 5245 5246```ts 5247import sensor from '@ohos.sensor'; 5248 5249sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, (data: sensor.AccelerometerResponse) => { 5250 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5251 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5252 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5253}); 5254 5255``` 5256 5257### LINEAR_ACCELERATION<sup>(deprecated)</sup> 5258 5259once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>): void 5260 5261Subscribes to only one data change of the linear acceleration sensor. 5262 5263> **NOTE** 5264> 5265> This API is deprecated since API version 9. You are advised to use [sensor.once.LINEAR_ACCELEROMETER](#linear_accelerometer9-1)<sup>9+</sup> instead. 5266 5267**Required permissions**: ohos.permission.ACCELERATION 5268 5269**System capability**: SystemCapability.Sensors.Sensor 5270 5271**Parameters** 5272 5273| Name | Type | Mandatory | Description | 5274| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5275| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. | 5276| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**. | 5277 5278### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup> 5279 5280once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>): void 5281 5282Subscribes to only one data change of the uncalibrated acceleration sensor. 5283 5284> **NOTE** 5285> 5286> This API is deprecated since API version 9. You are advised to use [sensor.once.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-1)<sup>9+</sup> instead. 5287 5288**Required permissions**: ohos.permission.ACCELEROMETER 5289 5290**System capability**: SystemCapability.Sensors.Sensor 5291 5292**Parameters** 5293 5294| Name | Type | Mandatory | Description | 5295| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5296| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. | 5297| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**. | 5298 5299**Example** 5300 5301```ts 5302import sensor from '@ohos.sensor'; 5303 5304sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (data: sensor.AccelerometerUncalibratedResponse) => { 5305 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5306 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5307 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5308 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 5309 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 5310 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 5311}); 5312 5313``` 5314 5315### GRAVITY<sup>(deprecated)</sup> 5316 5317once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>): void 5318 5319Subscribes to only one data change of the gravity sensor. 5320 5321> **NOTE** 5322> 5323> This API is deprecated since API version 9. You are advised to use [sensor.once.GRAVITY](#gravity9-1)<sup>9+</sup> instead. 5324 5325**System capability**: SystemCapability.Sensors.Sensor 5326 5327**Parameters** 5328 5329| Name | Type | Mandatory | Description | 5330| -------- | ---------------------------------------------------------- | --------- | ------------------------------------------------------------ | 5331| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**. | 5332| callback | Callback<[GravityResponse](#gravityresponse)> | Yes | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**. | 5333 5334**Example** 5335 5336```ts 5337import sensor from '@ohos.sensor'; 5338 5339sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (data: sensor.GravityResponse) => { 5340 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5341 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5342 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5343 }); 5344 5345``` 5346 5347### GYROSCOPE<sup>(deprecated)</sup> 5348 5349once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>): void 5350 5351Subscribes to only one data change of the gyroscope sensor. 5352 5353> **NOTE** 5354> 5355> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE](#gyroscope9-1)<sup>9+</sup> instead. 5356 5357**Required permissions**: ohos.permission.GYROSCOPE 5358 5359**System capability**: SystemCapability.Sensors.Sensor 5360 5361**Parameters** 5362 5363| Name | Type | Mandatory | Description | 5364| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5365| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**. | 5366| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**. | 5367 5368**Example** 5369 5370```ts 5371import sensor from '@ohos.sensor'; 5372 5373sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, (data: sensor.GyroscopeResponse) => { 5374 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5375 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5376 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5377}); 5378 5379``` 5380 5381### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup> 5382 5383once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback<GyroscopeUncalibratedResponse>): void 5384 5385Subscribes to only one data change of the uncalibrated gyroscope sensor. 5386 5387> **NOTE** 5388> 5389> This API is deprecated since API version 9. You are advised to use [sensor.once.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-1)<sup>9+</sup> instead. 5390 5391**Required permissions**: ohos.permission.GYROSCOPE 5392 5393**System capability**: SystemCapability.Sensors.Sensor 5394 5395**Parameters** 5396 5397| Name | Type | Mandatory | Description | 5398| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5399| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. | 5400| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**. | 5401 5402**Example** 5403 5404```ts 5405import sensor from '@ohos.sensor'; 5406 5407sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (data: sensor.GyroscopeUncalibratedResponse) => { 5408 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5409 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5410 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5411 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 5412 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 5413 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 5414}); 5415 5416``` 5417 5418### SIGNIFICANT_MOTION<sup>(deprecated)</sup> 5419 5420once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<SignificantMotionResponse>): void 5421 5422Subscribes to only one data change of the significant motion sensor. 5423 5424> **NOTE** 5425> 5426> This API is deprecated since API version 9. You are advised to use [sensor.once.SIGNIFICANT_MOTION](#significant_motion9-1)<sup>9+</sup> instead. 5427 5428**System capability**: SystemCapability.Sensors.Sensor 5429 5430**Parameters** 5431 5432| Name | Type | Mandatory | Description | 5433| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5434| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. | 5435| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**. | 5436 5437**Example** 5438 5439```ts 5440import sensor from '@ohos.sensor'; 5441 5442sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (data: sensor.SignificantMotionResponse) => { 5443 console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); 5444}); 5445 5446``` 5447 5448### PEDOMETER_DETECTION<sup>(deprecated)</sup> 5449 5450once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<PedometerDetectionResponse>): void 5451 5452Subscribes to only one data change of the pedometer detection sensor. 5453 5454> **NOTE** 5455> 5456> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER_DETECTION](#pedometer_detection9-1)<sup>9+</sup> instead. 5457 5458**Required permissions**: ohos.permission.ACTIVITY_MOTION 5459 5460**System capability**: SystemCapability.Sensors.Sensor 5461 5462**Parameters** 5463 5464| Name | Type | Mandatory | Description | 5465| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5466| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. | 5467| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**. | 5468 5469**Example** 5470 5471```ts 5472import sensor from '@ohos.sensor'; 5473 5474sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (data: sensor.PedometerDetectionResponse) => { 5475 console.info('Succeeded in invoking once. Scalar data: ' + data.scalar); 5476}); 5477 5478``` 5479 5480### PEDOMETER<sup>(deprecated)</sup> 5481 5482once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>): void 5483 5484Subscribes to only one data change of the pedometer sensor. 5485 5486> **NOTE** 5487> 5488> This API is deprecated since API version 9. You are advised to use [sensor.once.PEDOMETER](#pedometer9-1)<sup>9+</sup> instead. 5489 5490**Required permissions**: ohos.permission.ACTIVITY_MOTION 5491 5492**System capability**: SystemCapability.Sensors.Sensor 5493 5494**Parameters** 5495 5496| Name | Type | Mandatory | Description | 5497| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5498| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**. | 5499| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**. | 5500 5501**Example** 5502 5503```ts 5504import sensor from '@ohos.sensor'; 5505 5506sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (data: sensor.PedometerResponse) => { 5507 console.info('Succeeded in invoking once. Steps: ' + data.steps); 5508}); 5509 5510``` 5511 5512### AMBIENT_TEMPERATURE<sup>(deprecated)</sup> 5513 5514once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<AmbientTemperatureResponse>): void 5515 5516Subscribes to only one data change of the ambient temperature sensor. 5517 5518> **NOTE** 5519> 5520> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_TEMPERATURE](#ambient_temperature9-1)<sup>9+</sup> instead. 5521 5522**System capability**: SystemCapability.Sensors.Sensor 5523 5524**Parameters** 5525 5526| Name | Type | Mandatory | Description | 5527| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5528| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. | 5529| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**. | 5530 5531**Example** 5532 5533```ts 5534import sensor from '@ohos.sensor'; 5535 5536sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (data: sensor.AmbientTemperatureResponse) => { 5537 console.info('Succeeded in invoking once. Temperature: ' + data.temperature); 5538}); 5539 5540``` 5541 5542### MAGNETIC_FIELD<sup>(deprecated)</sup> 5543 5544once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>): void 5545 5546Subscribes to only one data change of the magnetic field sensor. 5547 5548> **NOTE** 5549> 5550> This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD](#magnetic_field9-1)<sup>9+</sup> instead. 5551 5552**System capability**: SystemCapability.Sensors.Sensor 5553 5554**Parameters** 5555 5556| Name | Type | Mandatory | Description | 5557| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5558| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. | 5559| callback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**. | 5560 5561**Example** 5562 5563```ts 5564import sensor from '@ohos.sensor'; 5565 5566sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (data: sensor.MagneticFieldResponse) => { 5567 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5568 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5569 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5570}); 5571 5572``` 5573 5574### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup> 5575 5576once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>): void 5577 5578Subscribes to only one data change of the uncalibrated magnetic field sensor. 5579 5580> **NOTE** 5581> 5582> This API is deprecated since API version 9. You are advised to use [sensor.once.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-1)<sup>9+</sup> instead. 5583 5584**System capability**: SystemCapability.Sensors.Sensor 5585 5586**Parameters** 5587 5588| Name | Type | Mandatory | Description | 5589| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5590| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. | 5591| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**. | 5592 5593**Example** 5594 5595```ts 5596import sensor from '@ohos.sensor'; 5597 5598sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (data: sensor.MagneticFieldUncalibratedResponse) => { 5599 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5600 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5601 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5602 console.info('Succeeded in invoking once. X-coordinate bias: ' + data.biasX); 5603 console.info('Succeeded in invoking once. Y-coordinate bias: ' + data.biasY); 5604 console.info('Succeeded in invoking once. Z-coordinate bias: ' + data.biasZ); 5605}); 5606 5607``` 5608 5609### PROXIMITY<sup>(deprecated)</sup> 5610 5611once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>): void 5612 5613Subscribes to only one data change of the proximity sensor. 5614 5615> **NOTE** 5616> 5617> This API is deprecated since API version 9. You are advised to use [sensor.once.PROXIMITY](#proximity9-1)<sup>9+</sup> instead. 5618 5619**System capability**: SystemCapability.Sensors.Sensor 5620 5621**Parameters** 5622 5623| Name | Type | Mandatory | Description | 5624| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5625| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**. | 5626| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**. | 5627 5628**Example** 5629 5630```ts 5631import sensor from '@ohos.sensor'; 5632 5633sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (data: sensor.ProximityResponse) => { 5634 console.info('Succeeded in invoking once. Distance: ' + data.distance); 5635} 5636); 5637 5638``` 5639 5640### HUMIDITY<sup>(deprecated)</sup> 5641 5642once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>): void 5643 5644Subscribes to only one data change of the humidity sensor. 5645 5646> **NOTE** 5647> 5648> This API is deprecated since API version 9. You are advised to use [sensor.once.HUMIDITY](#humidity9-1)<sup>9+</sup> instead. 5649 5650**System capability**: SystemCapability.Sensors.Sensor 5651 5652**Parameters** 5653 5654| Name | Type | Mandatory | Description | 5655| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ | 5656| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**. | 5657| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**. | 5658 5659**Example** 5660 5661```ts 5662import sensor from '@ohos.sensor'; 5663 5664sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (data: sensor.HumidityResponse) => { 5665 console.info('Succeeded in invoking once. Humidity: ' + data.humidity); 5666}); 5667 5668``` 5669 5670### BAROMETER<sup>(deprecated)</sup> 5671 5672once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>): void 5673 5674Subscribes to only one data change of the barometer sensor. 5675 5676> **NOTE** 5677> 5678> This API is deprecated since API version 9. You are advised to use [sensor.once.BAROMETER](#barometer9-1)<sup>9+</sup> instead. 5679 5680**System capability**: SystemCapability.Sensors.Sensor 5681 5682**Parameters** 5683 5684| Name | Type | Mandatory | Description | 5685| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5686| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**. | 5687| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**. | 5688 5689**Example** 5690 5691```ts 5692import sensor from '@ohos.sensor'; 5693 5694sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (data: sensor.BarometerResponse) => { 5695 console.info('Succeeded in invoking once. Atmospheric pressure: ' + data.pressure); 5696}); 5697 5698``` 5699 5700### HALL<sup>(deprecated)</sup> 5701 5702once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>): void 5703 5704Subscribes to only one data change of the Hall effect sensor. 5705 5706> **NOTE** 5707> 5708> This API is deprecated since API version 9. You are advised to use [sensor.once.HALL](#hall9-1)<sup>9+</sup> instead. 5709 5710**System capability**: SystemCapability.Sensors.Sensor 5711 5712**Parameters** 5713 5714| Name | Type | Mandatory | Description | 5715| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 5716| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**. | 5717| callback | Callback<[HallResponse](#hallresponse)> | Yes | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**. | 5718 5719**Example** 5720 5721```ts 5722import sensor from '@ohos.sensor'; 5723 5724sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, (data: sensor.HallResponse) => { 5725 console.info('Succeeded in invoking once. Status: ' + data.status); 5726}); 5727 5728``` 5729 5730### AMBIENT_LIGHT<sup>(deprecated)</sup> 5731 5732once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>): void 5733 5734Subscribes to only one data change of the ambient light sensor. 5735 5736> **NOTE** 5737> 5738> This API is deprecated since API version 9. You are advised to use [sensor.once.AMBIENT_LIGHT](#ambient_light9-1)<sup>9+</sup> instead. 5739 5740**System capability**: SystemCapability.Sensors.Sensor 5741 5742**Parameters** 5743 5744| Name | Type | Mandatory | Description | 5745| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5746| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. | 5747| callback | Callback<[LightResponse](#lightresponse)> | Yes | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**. | 5748 5749**Example** 5750 5751```ts 5752import sensor from '@ohos.sensor'; 5753 5754sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, (data: sensor.LightResponse) => { 5755 console.info('Succeeded in invoking once. invoking once. Illumination: ' + data.intensity); 5756}); 5757 5758``` 5759 5760### ORIENTATION<sup>(deprecated)</sup> 5761 5762once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>): void 5763 5764Subscribes to only one data change of the orientation sensor. 5765 5766> **NOTE** 5767> 5768> This API is deprecated since API version 9. You are advised to use [sensor.once.ORIENTATION](#orientation9-1)<sup>9+</sup> instead. 5769 5770**System capability**: SystemCapability.Sensors.Sensor 5771 5772**Parameters** 5773 5774| Name | Type | Mandatory | Description | 5775| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5776| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**. | 5777| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**. | 5778 5779**Example** 5780 5781```ts 5782import sensor from '@ohos.sensor'; 5783 5784sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (data: sensor.OrientationResponse) => { 5785 console.info('Succeeded in invoking the device rotateing at an angle around the X axis: ' + data.beta); 5786 console.info('Succeeded in invoking the device rotateing at an angle around the Y axis: ' + data.gamma); 5787 console.info('Succeeded in invoking the device rotateing at an angle around the Z axis: ' + data.alpha); 5788}); 5789 5790``` 5791 5792### ROTATION_VECTOR<sup>(deprecated)</sup> 5793 5794once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<RotationVectorResponse>): void 5795 5796Subscribes to only one data change of the rotation vector sensor. 5797 5798> **NOTE** 5799> 5800> This API is deprecated since API version 9. You are advised to use [sensor.once.ROTATION_VECTOR](#rotation_vector9-1)<sup>9+</sup> instead. 5801 5802**System capability**: SystemCapability.Sensors.Sensor 5803 5804**Parameters** 5805 5806| Name | Type | Mandatory | Description | 5807| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5808| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. | 5809| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**. | 5810 5811**Example** 5812 5813```ts 5814import sensor from '@ohos.sensor'; 5815 5816sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (data: sensor.RotationVectorResponse) => { 5817 console.info('Succeeded in invoking once. X-coordinate component: ' + data.x); 5818 console.info('Succeeded in invoking once. Y-coordinate component: ' + data.y); 5819 console.info('Succeeded in invoking once. Z-coordinate component: ' + data.z); 5820 console.info('Succeeded in invoking once. Scalar quantity: ' + data.w); 5821}); 5822 5823``` 5824 5825### HEART_RATE<sup>(deprecated)</sup> 5826 5827once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>): void 5828 5829Subscribes to only one data change of the heart rate sensor. 5830 5831> **NOTE** 5832> 5833> This API is deprecated since API version 9. You are advised to use [sensor.once.HEART_RATE](#heart_rate9-1)<sup>9+</sup> instead. 5834 5835**Required permissions**: ohos.permission.HEART_RATE 5836 5837**System capability**: SystemCapability.Sensors.Sensor 5838 5839**Parameters** 5840 5841| Name | Type | Mandatory | Description | 5842| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5843| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**. | 5844| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**. | 5845 5846### WEAR_DETECTION<sup>(deprecated)</sup> 5847 5848once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>): void 5849 5850Subscribes to only one data change of the wear detection sensor. 5851 5852> **NOTE** 5853> 5854> This API is deprecated since API version 9. You are advised to use [sensor.once.WEAR_DETECTION](#wear_detection9-1)<sup>9+</sup> instead. 5855 5856**System capability**: SystemCapability.Sensors.Sensor 5857 5858**Parameters** 5859 5860| Name | Type | Mandatory | Description | 5861| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5862| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. | 5863| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**. | 5864 5865**Example** 5866 5867```ts 5868import sensor from '@ohos.sensor'; 5869 5870sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (data: sensor.WearDetectionResponse) => { 5871 console.info("Succeeded in invoking once. Wear status: " + data.value); 5872}); 5873 5874``` 5875 5876## sensor.off<sup>(deprecated)</sup> 5877 5878### ACCELEROMETER<sup>(deprecated)</sup> 5879 5880off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<AccelerometerResponse>): void 5881 5882Unsubscribes from sensor data changes. 5883 5884> **NOTE** 5885> 5886> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER<sup>9+</sup>](#accelerometer9-2) instead. 5887 5888**Required permissions**: ohos.permission.ACCELEROMETER 5889 5890**System capability**: SystemCapability.Sensors.Sensor 5891 5892**Parameters** 5893 5894| Name | Type | Mandatory | Description | 5895| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5896| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**. | 5897| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 5898 5899**Example** 5900 5901```ts 5902import sensor from '@ohos.sensor'; 5903 5904function callback(data: sensor.AccelerometerResponse) { 5905 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 5906 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 5907 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 5908} 5909 5910sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback); 5911 5912``` 5913 5914### ACCELEROMETER_UNCALIBRATED<sup>(deprecated)</sup> 5915 5916off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback<AccelerometerUncalibratedResponse>): void 5917 5918Unsubscribes from sensor data changes. 5919 5920> **NOTE** 5921> 5922> This API is deprecated since API version 9. You are advised to use [sensor.off.ACCELEROMETER_UNCALIBRATED](#accelerometer_uncalibrated9-2)<sup>9+</sup> instead. 5923 5924**Required permissions**: ohos.permission.ACCELEROMETER 5925 5926**System capability**: SystemCapability.Sensors.Sensor 5927 5928**Parameters** 5929 5930| Name | Type | Mandatory | Description | 5931| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5932| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**. | 5933| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 5934 5935**Example** 5936 5937```ts 5938import sensor from '@ohos.sensor'; 5939 5940function callback(data: sensor.AccelerometerUncalibratedResponse) { 5941 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 5942 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 5943 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 5944 console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX); 5945 console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY); 5946 console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ); 5947} 5948 5949sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback); 5950 5951``` 5952 5953### AMBIENT_LIGHT<sup>(deprecated)</sup> 5954 5955off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightResponse>): void 5956 5957Unsubscribes from sensor data changes. 5958 5959> **NOTE** 5960> 5961> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_LIGHT](#ambient_light9-2)<sup>9+</sup> instead. 5962 5963**System capability**: SystemCapability.Sensors.Sensor 5964 5965**Parameters** 5966 5967| Name | Type | Mandatory | Description | 5968| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 5969| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_LIGHT | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**. | 5970| callback | Callback<[LightResponse](#lightresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 5971 5972**Example** 5973 5974```ts 5975import sensor from '@ohos.sensor'; 5976 5977function callback(data: sensor.LightResponse) { 5978 console.info('Succeeded in invoking off. Illumination: ' + data.intensity); 5979} 5980 5981sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback); 5982 5983``` 5984 5985### AMBIENT_TEMPERATURE<sup>(deprecated)</sup> 5986 5987off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatureResponse>): void 5988 5989Unsubscribes from sensor data changes. 5990 5991> **NOTE** 5992> 5993> This API is deprecated since API version 9. You are advised to use [sensor.off.AMBIENT_TEMPERATURE](#ambient_temperature9-2)<sup>9+</sup> instead. 5994 5995**System capability**: SystemCapability.Sensors.Sensor 5996 5997**Parameters** 5998 5999| Name | Type | Mandatory | Description | 6000| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6001| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_AMBIENT_TEMPERATURE | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**. | 6002| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6003 6004**Example** 6005 6006```ts 6007import sensor from '@ohos.sensor'; 6008 6009function callback(data: sensor.AmbientTemperatureResponse) { 6010 console.info('Succeeded in invoking off. Temperature: ' + data.temperature); 6011} 6012 6013sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback); 6014 6015``` 6016 6017### BAROMETER<sup>(deprecated)</sup> 6018 6019off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerResponse>): void 6020 6021Unsubscribes from sensor data changes. 6022 6023> **NOTE** 6024> 6025> This API is deprecated since API version 9. You are advised to use [sensor.off.BAROMETER](#barometer9-2)<sup>9+</sup> instead. 6026 6027**System capability**: SystemCapability.Sensors.Sensor 6028 6029**Parameters** 6030 6031| Name | Type | Mandatory | Description | 6032| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6033| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_BAROMETER | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**. | 6034| callback | Callback<[BarometerResponse](#barometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6035 6036**Example** 6037 6038```ts 6039import sensor from '@ohos.sensor'; 6040 6041function callback(data: sensor.BarometerResponse) { 6042 console.info('Succeeded in invoking off. Atmospheric pressure: ' + data.pressure); 6043} 6044 6045sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback); 6046 6047``` 6048 6049### GRAVITY<sup>(deprecated)</sup> 6050 6051off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityResponse>): void 6052 6053Unsubscribes from sensor data changes. 6054 6055> **NOTE** 6056> 6057> This API is deprecated since API version 9. You are advised to use [sensor.off.GRAVITY](#gravity9-2)<sup>9+</sup> instead. 6058 6059**System capability**: SystemCapability.Sensors.Sensor 6060 6061**Parameters** 6062 6063| Name | Type | Mandatory | Description | 6064| -------- | ---------------------------------------------------------- | --------- | ------------------------------------------------------------ | 6065| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GRAVITY | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**. | 6066| callback | Callback<[GravityResponse](#gravityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6067 6068**Example** 6069 6070```ts 6071import sensor from '@ohos.sensor'; 6072 6073function callback(data: sensor.GravityResponse) { 6074 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6075 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6076 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6077} 6078 6079sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); 6080 6081``` 6082 6083### GYROSCOPE<sup>(deprecated)</sup> 6084 6085off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeResponse>): void 6086 6087Unsubscribes from sensor data changes. 6088 6089> **NOTE** 6090> 6091> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE](#gyroscope9-2)<sup>9+</sup> instead. 6092 6093**Required permissions**: ohos.permission.GYROSCOPE 6094 6095**System capability**: SystemCapability.Sensors.Sensor 6096 6097**Parameters** 6098 6099| Name | Type | Mandatory | Description | 6100| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6101| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**. | 6102| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6103 6104**Example** 6105 6106```ts 6107import sensor from '@ohos.sensor'; 6108 6109function callback(data: sensor.GyroscopeResponse) { 6110 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6111 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6112 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6113} 6114 6115sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback); 6116 6117``` 6118 6119### GYROSCOPE_UNCALIBRATED<sup>(deprecated)</sup> 6120 6121off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncalibratedResponse>): void 6122 6123Unsubscribes from sensor data changes. 6124 6125> **NOTE** 6126> 6127> This API is deprecated since API version 9. You are advised to use [sensor.off.GYROSCOPE_UNCALIBRATED](#gyroscope_uncalibrated9-2)<sup>9+</sup> instead. 6128 6129**Required permissions**: ohos.permission.GYROSCOPE 6130 6131**System capability**: SystemCapability.Sensors.Sensor 6132 6133**Parameters** 6134 6135| Name | Type | Mandatory | Description | 6136| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6137| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**. | 6138| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6139 6140**Example** 6141 6142```ts 6143import sensor from '@ohos.sensor'; 6144 6145function callback(data: sensor.GyroscopeUncalibratedResponse) { 6146 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6147 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6148 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6149} 6150 6151sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback); 6152 6153``` 6154 6155### HALL<sup>(deprecated)</sup> 6156 6157off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>): void 6158 6159Unsubscribes from sensor data changes. 6160 6161> **NOTE** 6162> 6163> This API is deprecated since API version 9. You are advised to use [sensor.off.HALL](#hall9-2)<sup>9+</sup> instead. 6164 6165**System capability**: SystemCapability.Sensors.Sensor 6166 6167**Parameters** 6168 6169| Name | Type | Mandatory | Description | 6170| -------- | ------------------------------------------------------- | --------- | ------------------------------------------------------------ | 6171| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HALL | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**. | 6172| callback | Callback<[HallResponse](#hallresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6173 6174**Example** 6175 6176```ts 6177import sensor from '@ohos.sensor'; 6178 6179function callback(data: sensor.HallResponse) { 6180 console.info('Succeeded in invoking off. Status: ' + data.status); 6181} 6182 6183sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback); 6184 6185``` 6186 6187### HEART_RATE<sup>(deprecated)</sup> 6188 6189off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRateResponse>): void 6190 6191Unsubscribes from sensor data changes. 6192 6193> **NOTE** 6194> 6195> This API is deprecated since API version 9. You are advised to use [sensor.off.HEART_RATE](#heart_rate9-2)<sup>9+</sup> instead. 6196 6197**Required permissions**: ohos.permission.HEALTH_DATA 6198 6199**System capability**: SystemCapability.Sensors.Sensor 6200 6201**Parameters** 6202 6203| Name | Type | Mandatory | Description | 6204| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6205| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HEART_RATE | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**. | 6206| callback | Callback<[HeartRateResponse](#heartrateresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6207 6208**Example** 6209 6210```ts 6211import sensor from '@ohos.sensor'; 6212 6213function callback(data: sensor.HeartRateResponse) { 6214 console.info('Succeeded in invoking off. Humidity: ' + data.heartRate); 6215} 6216 6217sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback); 6218 6219``` 6220 6221### HUMIDITY<sup>(deprecated)</sup> 6222 6223off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityResponse>): void 6224 6225Unsubscribes from sensor data changes. 6226 6227> **NOTE** 6228> 6229> This API is deprecated since API version 9. You are advised to use [sensor.off.HUMIDITY](#humidity9-2)<sup>9+</sup> instead. 6230 6231**System capability**: SystemCapability.Sensors.Sensor 6232 6233**Parameters** 6234 6235| Name | Type | Mandatory | Description | 6236| -------- | ----------------------------------------------------------- | --------- | ------------------------------------------------------------ | 6237| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_HUMIDITY | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**. | 6238| callback | Callback<[HumidityResponse](#humidityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6239 6240**Example** 6241 6242```ts 6243import sensor from '@ohos.sensor'; 6244 6245function callback(data: sensor.HumidityResponse) { 6246 console.info('Succeeded in invoking off. Humidity: ' + data.humidity); 6247} 6248 6249sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback); 6250 6251``` 6252 6253### LINEAR_ACCELERATION<sup>(deprecated)</sup> 6254 6255off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<LinearAccelerometerResponse>): void 6256 6257Unsubscribes from sensor data changes. 6258 6259> **NOTE** 6260> 6261> This API is deprecated since API version 9. You are advised to use [sensor.off.LINEAR_ACCELEROMETER](#linear_accelerometer9-2)<sup>9+</sup> instead. 6262 6263**Required permissions**: ohos.permission.ACCELEROMETER 6264 6265**System capability**: SystemCapability.Sensors.Sensor 6266 6267**Parameters** 6268 6269| Name | Type | Mandatory | Description | 6270| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6271| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_LINEAR_ACCELERATION | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**. | 6272| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6273 6274**Example** 6275 6276```ts 6277import sensor from '@ohos.sensor'; 6278 6279function callback(data: sensor.LinearAccelerometerResponse) { 6280 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6281 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6282 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6283} 6284 6285sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback); 6286 6287``` 6288 6289### MAGNETIC_FIELD<sup>(deprecated)</sup> 6290 6291 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void 6292 6293Unsubscribes from sensor data changes. 6294 6295> **NOTE** 6296> 6297> This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD](#magnetic_field9-2)<sup>9+</sup> instead. 6298 6299**System capability**: SystemCapability.Sensors.Sensor 6300 6301**Parameters** 6302 6303| Name | Type | Mandatory | Description | 6304| ---------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6305| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**. | 6306| callbackcallback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6307 6308**Example** 6309 6310```ts 6311import sensor from '@ohos.sensor'; 6312 6313function callback(data: sensor.MagneticFieldResponse) { 6314 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6315 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6316 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6317} 6318 6319sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); 6320 6321``` 6322 6323### MAGNETIC_FIELD_UNCALIBRATED<sup>(deprecated)</sup> 6324 6325 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void 6326 6327Unsubscribes from sensor data changes. 6328 6329> **NOTE** 6330> 6331> This API is deprecated since API version 9. You are advised to use [sensor.off.MAGNETIC_FIELD_UNCALIBRATED](#magnetic_field_uncalibrated9-2)<sup>9+</sup> instead. 6332 6333**System capability**: SystemCapability.Sensors.Sensor 6334 6335**Parameters** 6336 6337| Name | Type | Mandatory | Description | 6338| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6339| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**. | 6340| callback | Callback<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6341 6342**Example** 6343 6344```ts 6345import sensor from '@ohos.sensor'; 6346 6347function callback(data: sensor.MagneticFieldUncalibratedResponse) { 6348 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6349 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6350 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6351 console.info('Succeeded in invoking off. X-coordinate bias: ' + data.biasX); 6352 console.info('Succeeded in invoking off. Y-coordinate bias: ' + data.biasY); 6353 console.info('Succeeded in invoking off. Z-coordinate bias: ' + data.biasZ); 6354} 6355 6356sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback); 6357 6358``` 6359 6360### ORIENTATION<sup>(deprecated)</sup> 6361 6362 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback<OrientationResponse>): void 6363 6364Unsubscribes from sensor data changes. 6365 6366> **NOTE** 6367> 6368> This API is deprecated since API version 9. You are advised to use [sensor.off.ORIENTATION](#orientation9-2)<sup>9+</sup> instead. 6369 6370**System capability**: SystemCapability.Sensors.Sensor 6371 6372**Parameters** 6373 6374| Name | Type | Mandatory | Description | 6375| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6376| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ORIENTATION | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**. | 6377| callback | Callback<[OrientationResponse](#orientationresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6378 6379**Example** 6380 6381```ts 6382import sensor from '@ohos.sensor'; 6383 6384function callback(data: sensor.OrientationResponse) { 6385 console.info('Succeeded in invoking off. The device rotates at an angle around the X axis: ' + data.beta); 6386 console.info('Succeeded in invoking off. The device rotates at an angle around the Y axis: ' + data.gamma); 6387 console.info('Succeeded in invoking off. The device rotates at an angle around the Z axis: ' + data.alpha); 6388} 6389 6390sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); 6391 6392``` 6393 6394### PEDOMETER<sup>(deprecated)</sup> 6395 6396off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerResponse>): void 6397 6398Unsubscribes from sensor data changes. 6399 6400> **NOTE** 6401> 6402> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER](#pedometer9-2)<sup>9+</sup> instead. 6403 6404**Required permissions**: ohos.permission.ACTIVITY_MOTION 6405 6406**System capability**: SystemCapability.Sensors.Sensor 6407 6408**Parameters** 6409 6410| Name | Type | Mandatory | Description | 6411| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6412| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. | 6413| callback | Callback<[PedometerResponse](#pedometerresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6414 6415**Example** 6416 6417```ts 6418import sensor from '@ohos.sensor'; 6419 6420function callback(data: sensor.PedometerResponse) { 6421 console.info('Succeeded in invoking off. Steps: ' + data.steps); 6422} 6423 6424sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback); 6425 6426``` 6427 6428### PEDOMETER_DETECTION<sup>(deprecated)</sup> 6429 6430off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void 6431 6432Unsubscribes from sensor data changes. 6433 6434> **NOTE** 6435> 6436> This API is deprecated since API version 9. You are advised to use [sensor.off.PEDOMETER_DETECTION](#pedometer_detection9-2)<sup>9+</sup> instead. 6437 6438**Required permissions**: ohos.permission.ACTIVITY_MOTION 6439 6440**System capability**: SystemCapability.Sensors.Sensor 6441 6442**Parameters** 6443 6444| Name | Type | Mandatory | Description | 6445| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6446| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PEDOMETER_DETECTION | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**. | 6447| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6448 6449**Example** 6450 6451```ts 6452import sensor from '@ohos.sensor'; 6453 6454function callback(data: sensor.PedometerDetectionResponse) { 6455 console.info('Succeeded in invoking off. Scalar data: ' + data.scalar); 6456} 6457 6458sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback); 6459 6460``` 6461 6462### PROXIMITY<sup>(deprecated)</sup> 6463 6464off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityResponse>): void 6465 6466Unsubscribes from sensor data changes. 6467 6468> **NOTE** 6469> 6470> This API is deprecated since API version 9. You are advised to use [sensor.off.PROXIMITY](#proximity9-2)<sup>9+</sup> instead. 6471 6472**System capability**: SystemCapability.Sensors.Sensor 6473 6474**Parameters** 6475 6476| Name | Type | Mandatory | Description | 6477| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6478| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_PROXIMITY | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**. | 6479| callback | Callback<[ProximityResponse](#proximityresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6480 6481**Example** 6482 6483```ts 6484import sensor from '@ohos.sensor'; 6485 6486function callback(data: sensor.ProximityResponse) { 6487 console.info('Succeeded in invoking off. Distance: ' + data.distance); 6488} 6489 6490sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback); 6491 6492``` 6493 6494### ROTATION_VECTOR<sup>(deprecated)</sup> 6495 6496off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void 6497 6498Unsubscribes from sensor data changes. 6499 6500> **NOTE** 6501> 6502> This API is deprecated since API version 9. You are advised to use [sensor.off.ROTATION_VECTOR](#rotation_vector9-2)<sup>9+</sup> instead. 6503 6504**System capability**: SystemCapability.Sensors.Sensor 6505 6506**Parameters** 6507 6508| Name | Type | Mandatory | Description | 6509| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6510| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_ROTATION_VECTOR | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**. | 6511| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6512 6513**Example** 6514 6515```ts 6516import sensor from '@ohos.sensor'; 6517 6518function callback(data: sensor.RotationVectorResponse) { 6519 console.info('Succeeded in invoking off. X-coordinate component: ' + data.x); 6520 console.info('Succeeded in invoking off. Y-coordinate component: ' + data.y); 6521 console.info('Succeeded in invoking off. Z-coordinate component: ' + data.z); 6522 console.info('Succeeded in invoking off. Scalar quantity: ' + data.w); 6523} 6524 6525sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); 6526 6527``` 6528 6529### SIGNIFICANT_MOTION<sup>(deprecated)</sup> 6530 6531off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void 6532 6533Unsubscribes from sensor data changes. 6534 6535> **NOTE** 6536> 6537> This API is deprecated since API version 9. You are advised to use [sensor.off.SIGNIFICANT_MOTION](#significant_motion9-2)<sup>9+</sup> instead. 6538 6539**System capability**: SystemCapability.Sensors.Sensor 6540 6541**Parameters** 6542 6543| Name | Type | Mandatory | Description | 6544| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6545| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_SIGNIFICANT_MOTION | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**. | 6546| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6547 6548**Example** 6549 6550```ts 6551import sensor from '@ohos.sensor'; 6552 6553function callback(data: sensor.SignificantMotionResponse) { 6554 console.info('Succeeded in invoking off. Scalar data: ' + data.scalar); 6555} 6556 6557sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback); 6558 6559``` 6560 6561### WEAR_DETECTION<sup>(deprecated)</sup> 6562 6563off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearDetectionResponse>): void 6564 6565Unsubscribes from sensor data changes. 6566 6567> **NOTE** 6568> 6569> This API is deprecated since API version 9. You are advised to use [sensor.off.WEAR_DETECTION](#wear_detection9-2)<sup>9+</sup> instead. 6570 6571**System capability**: SystemCapability.Sensors.Sensor 6572 6573**Parameters** 6574 6575| Name | Type | Mandatory | Description | 6576| -------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6577| type | [SensorType](#sensortypedeprecated).SENSOR_TYPE_ID_WEAR_DETECTION | Yes | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**. | 6578| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified sensor type are unsubscribed from. | 6579 6580**Example** 6581 6582```ts 6583import sensor from '@ohos.sensor'; 6584 6585function accCallback(data: sensor.WearDetectionResponse) { 6586 console.info('Succeeded in invoking off. Wear status: ' + data.value); 6587} 6588 6589sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback); 6590 6591``` 6592 6593## sensor.transformCoordinateSystem<sup>(deprecated)</sup> 6594 6595transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void 6596 6597Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses an asynchronous callback to return the result. 6598 6599> **NOTE** 6600> 6601> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9)<sup>9+</sup> instead. 6602 6603**System capability**: SystemCapability.Sensors.Sensor 6604 6605**Parameters** 6606 6607| Name | Type | Mandatory | Description | 6608| ---------------- | ----------------------------------------- | --------- | ------------------------------------------------------------ | 6609| inRotationVector | Array<number> | Yes | Rotation vector to rotate. | 6610| coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Direction of the coordinate system. | 6611| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation vector after being rotated. | 6612 6613**Example** 6614 6615```ts 6616import sensor from '@ohos.sensor'; 6617import BusinessError from '@ohos.base'; 6618 6619sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 }, 6620 (err: BusinessError.BusinessError, data: Array<number>) => { 6621 if (err) { 6622 console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); 6623 return; 6624 } 6625 console.info("Succeeded in starting Operation. Data obtained: " + data); 6626 for (let i = 0; i < data.length; i++) { 6627 console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]); 6628 } 6629}) 6630 6631``` 6632 6633## sensor.transformCoordinateSystem<sup>(deprecated)</sup> 6634 6635transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions): Promise<Array<number>> 6636 6637Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result. 6638 6639> **NOTE** 6640> 6641> This API is deprecated since API version 9. You are advised to use [sensor.transformRotationMatrix](#sensortransformrotationmatrix9-1)<sup>9+</sup> instead. 6642 6643**System capability**: SystemCapability.Sensors.Sensor 6644 6645**Parameters** 6646 6647| Name | Type | Mandatory | Description | 6648| ---------------- | ----------------------------------------- | --------- | ----------------------------------- | 6649| inRotationVector | Array<number> | Yes | Rotation vector to rotate. | 6650| coordinates | [CoordinatesOptions](#coordinatesoptions) | Yes | Direction of the coordinate system. | 6651 6652**Return value** 6653 6654| Type | Description | 6655| ---------------------------------- | ------------------------------------------------------------ | 6656| Promise<Array<number>> | Promise used to return the rotation vector after being rotated. | 6657 6658**Example** 6659 6660```ts 6661import sensor from '@ohos.sensor'; 6662import BusinessError from '@ohos.base'; 6663 6664const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], { x: 2, y: 3 }); 6665promise.then((data: Array<number>) => { 6666 console.info("Succeeded in starting Operation"); 6667 for (let i = 0; i < data.length; i++) { 6668 console.info("Succeeded in getting transformCoordinateSystem data[ " + i + "] = " + data[i]); 6669 } 6670}).catch((err: BusinessError.BusinessError) => { 6671 console.error(`Failed to operate.`); 6672}) 6673 6674``` 6675 6676## sensor.getGeomagneticField<sup>(deprecated)</sup> 6677 6678getGeomagneticField(locationOptions: LocationOptions, timeMillis: number, callback: AsyncCallback<GeomagneticResponse>): void 6679 6680Obtains the geomagnetic field of a geographic location. This API uses an asynchronous callback to return the result. 6681 6682> **NOTE** 6683> 6684> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9)<sup>9+</sup> instead. 6685 6686**System capability**: SystemCapability.Sensors.Sensor 6687 6688**Parameters** 6689 6690| Name | Type | Mandatory | Description | 6691| --------------- | ------------------------------------------------------------ | --------- | ------------------------------------------------------------ | 6692| locationOptions | [LocationOptions](#locationoptions) | Yes | Geographic location. | 6693| timeMillis | number | Yes | Time for obtaining the magnetic declination, in milliseconds. | 6694| callback | AsyncCallback<[GeomagneticResponse](#geomagneticresponse)> | Yes | Callback used to return the geomagnetic field. | 6695 6696**Example** 6697 6698```ts 6699import sensor from '@ohos.sensor'; 6700import BusinessError from '@ohos.base'; 6701 6702sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000, 6703 (err: BusinessError.BusinessError, data: sensor.GeomagneticResponse) => { 6704 if (err) { 6705 console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); 6706 return; 6707 } 6708 console.info('Succeeded in getting sensor_getGeomagneticField_callback x: ' + data.x + ',y: ' + data.y + ',z: ' + 6709 data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + 6710 ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); 6711}); 6712 6713``` 6714 6715## sensor.getGeomagneticField<sup>(deprecated)</sup> 6716 6717getGeomagneticField(locationOptions: LocationOptions, timeMillis: number): Promise<GeomagneticResponse> 6718 6719Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result. 6720 6721> **NOTE** 6722> 6723> This API is deprecated since API version 9. You are advised to use [sensor.getGeomagneticInfo](#sensorgetgeomagneticinfo9-1)<sup>9+</sup> instead. 6724 6725**System capability**: SystemCapability.Sensors.Sensor 6726 6727**Parameters** 6728 6729| Name | Type | Mandatory | Description | 6730| --------------- | ----------------------------------- | --------- | ------------------------------------------------------------ | 6731| locationOptions | [LocationOptions](#locationoptions) | Yes | Geographic location. | 6732| timeMillis | number | Yes | Time for obtaining the magnetic declination, in milliseconds. | 6733 6734**Return value** 6735 6736| Type | Description | 6737| ---------------------------------------------------------- | --------------------------------------------- | 6738| Promise<[GeomagneticResponse](#geomagneticresponse)> | Promise used to return the geomagnetic field. | 6739 6740**Example** 6741 6742```ts 6743import sensor from '@ohos.sensor'; 6744import BusinessError from '@ohos.base'; 6745 6746const promise = sensor.getGeomagneticField({ latitude: 80, longitude: 0, altitude: 0 }, 1580486400000); 6747promise.then((data: sensor.GeomagneticResponse) => { 6748 console.info('Succeeded in getting sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' + 6749 data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + 6750 ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); 6751}).catch((reason: BusinessError.BusinessError) => { 6752 console.error(`Failed to operate.`); 6753}) 6754 6755``` 6756 6757## sensor.getAltitude<sup>(deprecated)</sup> 6758 6759getAltitude(seaPressure: number, currentPressure: number, callback: AsyncCallback<number>): void 6760 6761Obtains 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. 6762 6763> **NOTE** 6764> 6765> This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9)<sup>9+</sup> instead. 6766 6767**System capability**: SystemCapability.Sensors.Sensor 6768 6769**Parameters** 6770 6771| Name | Type | Mandatory | Description | 6772| --------------- | --------------------------- | --------- | ------------------------------------------------------------ | 6773| seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | 6774| currentPressure | number | Yes | Atmospheric pressure at the altitude where the device is located, in hPa. | 6775| callback | AsyncCallback<number> | Yes | Callback used to return the altitude, in meters. | 6776 6777**Example** 6778 6779```ts 6780import sensor from '@ohos.sensor'; 6781import BusinessError from '@ohos.base'; 6782 6783sensor.getAltitude(0, 200, (err: BusinessError.BusinessError, data: number) => { 6784 if (err) { 6785 console.error(`Failed to operate. Code: ${err.code}, message: ${err.message}`); 6786 return; 6787 } 6788 console.info("Succeeded in getting getAltitude interface get data: " + data); 6789}); 6790 6791``` 6792 6793## sensor.getAltitude<sup>(deprecated)</sup> 6794 6795getAltitude(seaPressure: number, currentPressure: number): Promise<number> 6796 6797Obtains 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. 6798 6799> **NOTE** 6800> 6801> This API is deprecated since API version 9. You are advised to use [sensor.getDeviceAltitude](#sensorgetdevicealtitude9-1)<sup>9+</sup> instead. 6802 6803**System capability**: SystemCapability.Sensors.Sensor 6804 6805**Parameters** 6806 6807| Name | Type | Mandatory | Description | 6808| --------------- | ------ | --------- | ------------------------------------------------------------ | 6809| seaPressure | number | Yes | Sea-level atmospheric pressure, in hPa. | 6810| currentPressure | number | Yes | Atmospheric pressure at the altitude where the device is located, in hPa. | 6811 6812**Return value** 6813 6814| Type | Description | 6815| --------------------- | ----------------------------------------------- | 6816| Promise<number> | Promise used to return the altitude, in meters. | 6817 6818**Example** 6819 6820```ts 6821import sensor from '@ohos.sensor'; 6822import BusinessError from '@ohos.base'; 6823 6824const promise = sensor.getAltitude(0, 200); 6825promise.then((data: number) => { 6826 console.info('Succeeded in getting sensor_getAltitude_Promise success', data); 6827}).catch((err: BusinessError.BusinessError) => { 6828 console.error(`Failed to operate.`); 6829}) 6830 6831``` 6832 6833 6834## sensor.getGeomagneticDip<sup>(deprecated)</sup> 6835 6836getGeomagneticDip(inclinationMatrix: Array<number>, callback: AsyncCallback<number>): void 6837 6838Obtains the magnetic dip based on the inclination matrix. This API uses an asynchronous callback to return the result. 6839 6840> **NOTE** 6841> 6842> This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9)<sup>9+</sup> instead. 6843 6844**System capability**: SystemCapability.Sensors.Sensor 6845 6846**Parameters** 6847 6848| Name | Type | Mandatory | Description | 6849| ----------------- | --------------------------- | --------- | ----------------------------------------------------- | 6850| inclinationMatrix | Array<number> | Yes | Inclination matrix. | 6851| callback | AsyncCallback<number> | Yes | Callback used to return the magnetic dip, in radians. | 6852 6853**Example** 6854 6855```ts 6856import sensor from '@ohos.sensor'; 6857import BusinessError from '@ohos.base'; 6858 6859sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], (err: BusinessError.BusinessError, data: number) => { 6860 if (err) { 6861 console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); 6862 return; 6863 } 6864 console.info("Succeeded in getting getGeomagneticDip interface get data: " + data); 6865}) 6866 6867``` 6868 6869## sensor.getGeomagneticDip<sup>(deprecated)</sup> 6870 6871getGeomagneticDip(inclinationMatrix: Array<number>): Promise<number> 6872 6873Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result. 6874 6875> **NOTE** 6876> 6877> This API is deprecated since API version 9. You are advised to use [sensor.getInclination](#sensorgetinclination9-1)<sup>9+</sup> instead. 6878 6879**System capability**: SystemCapability.Sensors.Sensor 6880 6881**Parameters** 6882 6883| Name | Type | Mandatory | Description | 6884| ----------------- | ------------------- | --------- | ------------------- | 6885| inclinationMatrix | Array<number> | Yes | Inclination matrix. | 6886 6887**Return value** 6888 6889| Type | Description | 6890| --------------------- | ---------------------------------------------------- | 6891| Promise<number> | Promise used to return the magnetic dip, in radians. | 6892 6893**Example** 6894 6895```ts 6896import sensor from '@ohos.sensor'; 6897import BusinessError from '@ohos.base'; 6898 6899const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]); 6900promise.then((data: number) => { 6901 console.info('Succeeded in get GeomagneticDip_promise', data); 6902}).catch((err: BusinessError.BusinessError) => { 6903 console.error(`Failed to operate.`); 6904}) 6905 6906``` 6907 6908## sensor. getAngleModify<sup>(deprecated)</sup> 6909 6910getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void 6911 6912Obtains the angle change between two rotation matrices. This API uses an asynchronous callback to return the result. 6913 6914> **NOTE** 6915> 6916> This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9)<sup>9+</sup> instead. 6917 6918**System capability**: SystemCapability.Sensors.Sensor 6919 6920**Parameters** 6921 6922| Name | Type | Mandatory | Description | 6923| --------------------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 6924| currentRotationMatrix | Array<number> | Yes | Current rotation matrix. | 6925| preRotationMatrix | Array<number> | Yes | The other rotation matrix. | 6926| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the angle change around the z, x, and y axes. | 6927 6928**Example** 6929 6930```ts 6931import sensor from '@ohos.sensor'; 6932import BusinessError from '@ohos.base'; 6933 6934sensor.getAngleModify([1, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], 6935 (err: BusinessError.BusinessError, data: Array<number>) => { 6936 if (err) { 6937 console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); 6938 return; 6939 } 6940 for (let i = 0; i < data.length; i++) { 6941 console.info("data[" + i + "]: " + data[i]); 6942 } 6943}) 6944 6945``` 6946 6947## sensor. getAngleModify<sup>(deprecated)</sup> 6948 6949getAngleModify(currentRotationMatrix: Array<number>, preRotationMatrix: Array<number>): Promise<Array<number>> 6950 6951Obtains the angle change between two rotation matrices. This API uses a promise to return the result. 6952 6953> **NOTE** 6954> 6955> This API is deprecated since API version 9. You are advised to use [sensor.getAngleVariation](#sensorgetanglevariation9-1)<sup>9+</sup> instead. 6956 6957**System capability**: SystemCapability.Sensors.Sensor 6958 6959**Parameters** 6960 6961| Name | Type | Mandatory | Description | 6962| --------------------- | ------------------- | --------- | -------------------------- | 6963| currentRotationMatrix | Array<number> | Yes | Current rotation matrix. | 6964| preRotationMatrix | Array<number> | Yes | The other rotation matrix. | 6965 6966**Return value** 6967 6968| Type | Description | 6969| ---------------------------------- | ------------------------------------------------------------ | 6970| Promise<Array<number>> | Promise used to return the angle change around the z, x, and y axes. | 6971 6972**Example** 6973 6974```ts 6975import sensor from '@ohos.sensor'; 6976import BusinessError from '@ohos.base'; 6977 6978const 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]); 6979promise.then((data: Array<number>) => { 6980 console.info('Succeeded in getting AngleModify_promise.'); 6981 for (let i = 0; i < data.length; i++) { 6982 console.info("Succeeded in getting data[" + i + "]: " + data[i]); 6983 } 6984}).catch((reason: BusinessError.BusinessError) => { 6985 let e: BusinessError.BusinessError = reason as BusinessError.BusinessError; 6986 console.info("Succeeded in getting promise::catch", e); 6987}) 6988 6989``` 6990 6991## sensor.createRotationMatrix<sup>(deprecated)</sup> 6992 6993createRotationMatrix(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void 6994 6995Converts a rotation vector into a rotation matrix. This API uses an asynchronous callback to return the result. 6996 6997> **NOTE** 6998> 6999> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9)<sup>9+</sup> instead. 7000 7001**System capability**: SystemCapability.Sensors.Sensor 7002 7003**Parameters** 7004 7005| Name | Type | Mandatory | Description | 7006| -------------- | ---------------------------------------- | --------- | -------------------------------------------- | 7007| rotationVector | Array<number> | Yes | Rotation vector to convert. | 7008| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation matrix. | 7009 7010**Example** 7011 7012```ts 7013import sensor from '@ohos.sensor'; 7014import BusinessError from '@ohos.base'; 7015 7016sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], 7017 (err: BusinessError.BusinessError, data: Array<number>) => { 7018 if (err) { 7019 console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); 7020 return; 7021 } 7022 for (let i = 0; i < data.length; i++) { 7023 console.info("Succeeded in getting data[" + i + "]: " + data[i]); 7024 } 7025}) 7026 7027``` 7028 7029## sensor.createRotationMatrix<sup>(deprecated)</sup> 7030 7031createRotationMatrix(rotationVector: Array<number>): Promise<Array<number>> 7032 7033Converts a rotation vector into a rotation matrix. This API uses a promise to return the result. 7034 7035> **NOTE** 7036> 7037> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-1)<sup>9+</sup> instead. 7038 7039**System capability**: SystemCapability.Sensors.Sensor 7040 7041**Parameters** 7042 7043| Name | Type | Mandatory | Description | 7044| -------------- | ------------------- | --------- | --------------------------- | 7045| rotationVector | Array<number> | Yes | Rotation vector to convert. | 7046 7047**Return value** 7048 7049| Type | Description | 7050| ---------------------------------- | ------------------------------------------- | 7051| Promise<Array<number>> | Promise used to return the rotation matrix. | 7052 7053**Example** 7054 7055 ```ts 7056import sensor from '@ohos.sensor'; 7057import BusinessError from '@ohos.base'; 7058 7059const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]); 7060promise.then((data: Array<number>) => { 7061 console.info('Succeeded in getting createRotationMatrix_promise'); 7062 for (let i = 0; i < data.length; i++) { 7063 console.info("data[" + i + "]: " + data[i]); 7064 } 7065}).catch((reason: BusinessError.BusinessError) => { 7066 console.info("Succeeded in getting promise::catch", reason); 7067}) 7068 7069 ``` 7070 7071## sensor.createQuaternion<sup>(deprecated)</sup> 7072 7073createQuaternion(rotationVector: Array<number>, callback: AsyncCallback<Array<number>>): void 7074 7075Converts a rotation vector into a quaternion. This API uses an asynchronous callback to return the result. 7076 7077> **NOTE** 7078> 7079> This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9)<sup>9+</sup> instead. 7080 7081**System capability**: SystemCapability.Sensors.Sensor 7082 7083**Parameters** 7084 7085| Name | Type | Mandatory | Description | 7086| -------------- | ---------------------------------------- | --------- | --------------------------------------- | 7087| rotationVector | Array<number> | Yes | Rotation vector to convert. | 7088| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the quaternion. | 7089 7090**Example** 7091 7092```ts 7093import sensor from '@ohos.sensor'; 7094import BusinessError from '@ohos.base'; 7095 7096sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], 7097 (err: BusinessError.BusinessError, data: Array<number>) => { 7098 if (err) { 7099 console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); 7100 return; 7101 } 7102 for (let i = 0; i < data.length; i++) { 7103 console.info("Succeeded in getting data[" + i + "]: " + data[i]); 7104 } 7105}) 7106 7107``` 7108 7109## sensor.createQuaternion<sup>(deprecated)</sup> 7110 7111createQuaternion(rotationVector: Array<number>): Promise<Array<number>> 7112 7113Converts a rotation vector into a quaternion. This API uses a promise to return the result. 7114 7115> **NOTE** 7116> 7117> This API is deprecated since API version 9. You are advised to use [sensor.getQuaternion](#sensorgetquaternion9-1)<sup>9+</sup> instead. 7118 7119**System capability**: SystemCapability.Sensors.Sensor 7120 7121**Parameters** 7122 7123| Name | Type | Mandatory | Description | 7124| -------------- | ------------------- | --------- | --------------------------- | 7125| rotationVector | Array<number> | Yes | Rotation vector to convert. | 7126 7127**Return value** 7128 7129| Type | Description | 7130| ---------------------------------- | -------------------------------------- | 7131| Promise<Array<number>> | Promise used to return the quaternion. | 7132 7133**Example** 7134 7135```ts 7136import sensor from '@ohos.sensor'; 7137import BusinessError from '@ohos.base'; 7138 7139const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]); 7140promise.then((data: Array<number>) => { 7141 console.info('Succeeded in getting createQuaternion_promise'); 7142 for (let i = 0; i < data.length; i++) { 7143 console.info("data[" + i + "]: " + data[i]); 7144 } 7145}).catch((err: BusinessError.BusinessError) => { 7146 console.info(`Failed to get promise.`); 7147}) 7148 7149``` 7150 7151## sensor.getDirection<sup>(deprecated)</sup> 7152 7153getDirection(rotationMatrix: Array<number>, callback: AsyncCallback<Array<number>>): void 7154 7155Obtains the device direction based on the rotation matrix. This API uses an asynchronous callback to return the result. 7156 7157> **NOTE** 7158> 7159> This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9)<sup>9+</sup> instead. 7160 7161**System capability**: SystemCapability.Sensors.Sensor 7162 7163**Parameters** 7164 7165| Name | Type | Mandatory | Description | 7166| -------------- | ---------------------------------------- | --------- | ------------------------------------------------------------ | 7167| rotationMatrix | Array<number> | Yes | The other rotation matrix. | 7168| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the rotation angle around the z, x, and y axes. | 7169 7170**Example** 7171 7172```ts 7173import sensor from '@ohos.sensor'; 7174import BusinessError from '@ohos.base'; 7175 7176sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], (err: BusinessError.BusinessError, data: Array<number>) => { 7177 if (err) { 7178 console.error(`Failed to register data. Code: ${err.code}, message: ${err.message}`); 7179 return; 7180 } 7181 console.info("Succeeded in getting getDirection interface get data: " + data); 7182 for (let i = 1; i < data.length; i++) { 7183 console.info("Succeeded in getting sensor_getDirection_callback" + data[i]); 7184 } 7185}) 7186 7187``` 7188 7189## sensor.getDirection<sup>(deprecated)</sup> 7190 7191getDirection(rotationMatrix: Array<number>): Promise<Array<number>> 7192 7193Obtains the device direction based on the rotation matrix. This API uses a promise to return the result. 7194 7195> **NOTE** 7196> 7197> This API is deprecated since API version 9. You are advised to use [sensor.getOrientation](#sensorgetorientation9-1)<sup>9+</sup> instead. 7198 7199**System capability**: SystemCapability.Sensors.Sensor 7200 7201**Parameters** 7202 7203| Name | Type | Mandatory | Description | 7204| -------------- | ------------------- | --------- | -------------------------- | 7205| rotationMatrix | Array<number> | Yes | The other rotation matrix. | 7206 7207**Return value** 7208 7209| Type | Description | 7210| ---------------------------------- | ------------------------------------------------------------ | 7211| Promise<Array<number>> | Promise used to return the rotation angle around the z, x, and y axes. | 7212 7213**Example** 7214 7215```ts 7216import sensor from '@ohos.sensor'; 7217import BusinessError from '@ohos.base'; 7218 7219const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]); 7220promise.then((data: Array<number>) => { 7221 console.info('Succeeded in getting sensor_getAltitude_Promise', data); 7222 for (let i = 1; i < data.length; i++) { 7223 console.info("Succeeded in getting sensor_getDirection_promise" + data[i]); 7224 } 7225}).catch((err: BusinessError.BusinessError) => { 7226 console.info(`Failed to get promise.`); 7227}) 7228``` 7229 7230## sensor.createRotationMatrix<sup>(deprecated)</sup> 7231 7232createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>, callback: AsyncCallback<RotationMatrixResponse>): void 7233 7234Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses an asynchronous callback to return the result. 7235 7236> **NOTE** 7237> 7238> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-2)<sup>9+</sup> instead. 7239 7240**System capability**: SystemCapability.Sensors.Sensor 7241 7242**Parameters** 7243 7244| Name | Type | Mandatory | Description | 7245| ----------- | ------------------------------------------------------------ | --------- | -------------------------------------------- | 7246| gravity | Array<number> | Yes | Gravity vector. | 7247| geomagnetic | Array<number> | Yes | Geomagnetic vector. | 7248| callback | AsyncCallback<[RotationMatrixResponse](#rotationmatrixresponse)> | Yes | Callback used to return the rotation matrix. | 7249 7250**Example** 7251 7252```ts 7253import sensor from '@ohos.sensor'; 7254import BusinessError from '@ohos.base'; 7255 7256sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], 7257 (err: BusinessError.BusinessError, data: sensor.RotationMatrixResponse) => { 7258 if (err) { 7259 console.error(`Failed to get create rotationMatrix. Code: ${err.code}, message: ${err.message}`); 7260 return; 7261 } 7262 console.info(JSON.stringify(data)); 7263}) 7264 7265``` 7266 7267## sensor.createRotationMatrix<sup>(deprecated)</sup> 7268 7269createRotationMatrix(gravity: Array<number>, geomagnetic: Array<number>): Promise<RotationMatrixResponse> 7270 7271Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result. 7272 7273> **NOTE** 7274> 7275> This API is deprecated since API version 9. You are advised to use [sensor.getRotationMatrix](#sensorgetrotationmatrix9-3)<sup>9+</sup> instead. 7276 7277**System capability**: SystemCapability.Sensors.Sensor 7278 7279**Parameters** 7280 7281| Name | Type | Mandatory | Description | 7282| ----------- | ------------------- | --------- | ------------------- | 7283| gravity | Array<number> | Yes | Gravity vector. | 7284| geomagnetic | Array<number> | Yes | Geomagnetic vector. | 7285 7286**Return value** 7287 7288| Type | Description | 7289| ------------------------------------------------------------ | ------------------------------------------- | 7290| Promise<[RotationMatrixResponse](#rotationmatrixresponse)> | Promise used to return the rotation matrix. | 7291 7292**Example** 7293 7294```ts 7295import sensor from '@ohos.sensor'; 7296import BusinessError from '@ohos.base'; 7297 7298const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]); 7299promise.then((data: sensor.RotationMatrixResponse) => { 7300 console.info(JSON.stringify(data)); 7301}).catch((err: BusinessError.BusinessError) => { 7302 console.info(`Failed to get promise.`); 7303}) 7304```