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

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

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

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

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

W
wusongqing 已提交
18 19

## Modules to Import
Z
zengyawen 已提交
20

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

W
wusongqing 已提交
25
## sensor.on
W
wusongqing 已提交
26

W
wusongqing 已提交
27
### ACCELEROMETER
W
wusongqing 已提交
28

W
wusongqing 已提交
29
on(type:  SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>,options?: Options): void
W
wusongqing 已提交
30

W
wusongqing 已提交
31
Subscribes to data changes of the acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
32

W
wusongqing 已提交
33
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)
Z
zengyawen 已提交
34

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

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

W
wusongqing 已提交
39 40 41 42 43
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
| callback | Callback<[AccelerometerResponse](#accelerometerresponse)> | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
44

W
wusongqing 已提交
45
**Example**
W
wusongqing 已提交
46
  ```js
W
wusongqing 已提交
47
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
W
wusongqing 已提交
48 49 50 51
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
52
      {interval: 10000000}
W
wusongqing 已提交
53 54
  );
  ```
Z
zengyawen 已提交
55

W
wusongqing 已提交
56
### LINEAR_ACCELERATION<sup>deprecated</sup>
Z
zengyawen 已提交
57

W
wusongqing 已提交
58
on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;, options?: Options): void
Z
zengyawen 已提交
59 60 61

Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

W
wusongqing 已提交
62 63
This API is deprecated since API version 9. You are advised to use **Sensor.on.LINEAR_ACCELEROMETER<sup>9+</sup>** instead.

W
wusongqing 已提交
64 65 66 67
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
68 69 70 71 72 73
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes   | Callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
74

W
wusongqing 已提交
75
**Example**
W
wusongqing 已提交
76
  ```js
W
wusongqing 已提交
77
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){
W
wusongqing 已提交
78 79 80 81
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
82
      {interval: 10000000}
W
wusongqing 已提交
83 84
  );
  ```
Z
zengyawen 已提交
85

W
wusongqing 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
### LINEAR_ACCELEROMETER<sup>9+</sup>

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

Subscribes to data changes of the linear acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.


**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

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

**Example**
  ```js
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,function(data){
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
      {interval: 10000000}
  );
  ```

W
wusongqing 已提交
115
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
116

W
wusongqing 已提交
117
on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
118 119 120

Subscribes to data changes of the uncalibrated acceleration sensor. If this API is called multiple times for the same application, the last call takes effect.

W
wusongqing 已提交
121 122 123 124
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
125 126 127 128 129 130
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
131

W
wusongqing 已提交
132
**Example**
W
wusongqing 已提交
133
  ```js
W
wusongqing 已提交
134
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
W
wusongqing 已提交
135 136 137 138 139 140 141
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
  },
Z
zengyawen 已提交
142
      {interval: 10000000}
W
wusongqing 已提交
143 144
  );
  ```
Z
zengyawen 已提交
145

W
wusongqing 已提交
146
### GRAVITY
Z
zengyawen 已提交
147

W
wusongqing 已提交
148
on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
149

W
wusongqing 已提交
150
Subscribes to data changes of the gravity sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
151

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

W
wusongqing 已提交
154 155 156 157 158 159
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.  |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes   | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.       |
W
wusongqing 已提交
160

W
wusongqing 已提交
161
**Example**
W
wusongqing 已提交
162
  ```js
W
wusongqing 已提交
163
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
W
wusongqing 已提交
164 165 166 167
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
168
      {interval: 10000000}
W
wusongqing 已提交
169 170
  );
  ```
Z
zengyawen 已提交
171

W
wusongqing 已提交
172
### GYROSCOPE
Z
zengyawen 已提交
173

W
wusongqing 已提交
174
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;, options?: Options): void
Z
zengyawen 已提交
175

W
wusongqing 已提交
176
Subscribes to data changes of the gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
177

W
wusongqing 已提交
178 179 180 181
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
182 183 184 185 186 187
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.  |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes   | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
188

W
wusongqing 已提交
189
**Example**
W
wusongqing 已提交
190
  ```js
W
wusongqing 已提交
191
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
W
wusongqing 已提交
192 193 194 195
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
196
      {interval: 10000000}
W
wusongqing 已提交
197 198
  );
  ```
Z
zengyawen 已提交
199

W
wusongqing 已提交
200
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
201

W
wusongqing 已提交
202
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback&lt;GyroscopeUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
203 204 205

Subscribes to data changes of the uncalibrated gyroscope sensor. If this API is called multiple times for the same application, the last call takes effect.

W
wusongqing 已提交
206 207 208 209
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
210 211 212 213 214 215
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data.                          |
W
wusongqing 已提交
216

W
wusongqing 已提交
217
**Example**
W
wusongqing 已提交
218
  ```js
W
wusongqing 已提交
219
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
W
wusongqing 已提交
220 221 222 223 224 225 226
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
  },
Z
zengyawen 已提交
227
      {interval: 10000000}
W
wusongqing 已提交
228 229
  );
  ```
Z
zengyawen 已提交
230

W
wusongqing 已提交
231
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
232

W
wusongqing 已提交
233
on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback&lt;SignificantMotionResponse&gt;, options?: Options): void
Z
zengyawen 已提交
234 235 236

Subscribes to data changes of the significant motion sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
239 240 241 242 243 244
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes   | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
245

W
wusongqing 已提交
246
**Example**
W
wusongqing 已提交
247
  ```js
W
wusongqing 已提交
248
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
W
wusongqing 已提交
249 250 251 252 253
      console.info('Scalar data: ' + data.scalar);
  },
      {interval: 10000000}
  );
  ```
Z
zengyawen 已提交
254

W
wusongqing 已提交
255
### PEDOMETER_DETECTION
Z
zengyawen 已提交
256

W
wusongqing 已提交
257
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback&lt;PedometerDetectionResponse&gt;, options?: Options): void
Z
zengyawen 已提交
258 259 260

Subscribes to data changes of the pedometer detection sensor. If this API is called multiple times for the same application, the last call takes effect.

W
wusongqing 已提交
261 262 263 264
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
265 266 267 268 269 270
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes   | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
271

W
wusongqing 已提交
272
**Example**
W
wusongqing 已提交
273
  ```js
W
wusongqing 已提交
274
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
W
wusongqing 已提交
275 276
      console.info('Scalar data: ' + data.scalar);
  },
Z
zengyawen 已提交
277
      {interval: 10000000}
W
wusongqing 已提交
278 279
  );
  ```
Z
zengyawen 已提交
280

W
wusongqing 已提交
281
### PEDOMETER
Z
zengyawen 已提交
282

W
wusongqing 已提交
283
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;, options?: Options): void
Z
zengyawen 已提交
284

W
wusongqing 已提交
285
Subscribes to data changes of the pedometer sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
286

W
wusongqing 已提交
287 288 289 290
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
291 292 293 294 295 296
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.  |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes   | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.         |
W
wusongqing 已提交
297

W
wusongqing 已提交
298
**Example**
W
wusongqing 已提交
299
  ```js
W
wusongqing 已提交
300
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
W
wusongqing 已提交
301 302
      console.info('Steps: ' + data.steps);
  },
Z
zengyawen 已提交
303
      {interval: 10000000}
W
wusongqing 已提交
304 305
  );
  ```
Z
zengyawen 已提交
306

W
wusongqing 已提交
307
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
308

W
wusongqing 已提交
309
on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback&lt;AmbientTemperatureResponse&gt;,  options?: Options): void
Z
zengyawen 已提交
310 311 312

Subscribes to data changes of the ambient temperature sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
315 316 317 318 319 320
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes   | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
321

W
wusongqing 已提交
322
**Example**
W
wusongqing 已提交
323
  ```js
W
wusongqing 已提交
324
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
W
wusongqing 已提交
325 326
      console.info('Temperature: ' + data.temperature);
  },
Z
zengyawen 已提交
327
      {interval: 10000000}
W
wusongqing 已提交
328 329
  );
  ```
Z
zengyawen 已提交
330

W
wusongqing 已提交
331
### MAGNETIC_FIELD
Z
zengyawen 已提交
332

W
wusongqing 已提交
333
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;,options?: Options): void
Z
zengyawen 已提交
334 335 336

Subscribes to data changes of the magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
339 340 341 342 343 344
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.|
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes   | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
345

W
wusongqing 已提交
346
**Example**
W
wusongqing 已提交
347
  ```js
W
wusongqing 已提交
348
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
W
wusongqing 已提交
349 350 351 352
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
353
      {interval: 10000000}
W
wusongqing 已提交
354 355
  );
  ```
Z
zengyawen 已提交
356

W
wusongqing 已提交
357
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
358

W
wusongqing 已提交
359
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;, options?: Options): void
Z
zengyawen 已提交
360 361 362

Subscribes to data changes of the uncalibrated magnetic field sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
365 366 367 368 369 370
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
371

W
wusongqing 已提交
372
**Example**
W
wusongqing 已提交
373
  ```js
W
wusongqing 已提交
374
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
W
wusongqing 已提交
375 376 377 378 379 380 381 382 383 384
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
  },
      {interval: 10000000}
  );
  ```
Z
zengyawen 已提交
385

W
wusongqing 已提交
386
### PROXIMITY
Z
zengyawen 已提交
387

W
wusongqing 已提交
388
on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
389

W
wusongqing 已提交
390
Subscribes to data changes of the proximity sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
391

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

W
wusongqing 已提交
394 395 396 397 398 399
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.  |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes   | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
400

W
wusongqing 已提交
401
**Example**
W
wusongqing 已提交
402
  ```js
W
wusongqing 已提交
403
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
W
wusongqing 已提交
404 405
      console.info('Distance: ' + data.distance);
  },
Z
zengyawen 已提交
406
      {interval: 10000000}
W
wusongqing 已提交
407 408
  );
  ```
Z
zengyawen 已提交
409

W
wusongqing 已提交
410
### HUMIDITY
Z
zengyawen 已提交
411

W
wusongqing 已提交
412
on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;,options?: Options): void
Z
zengyawen 已提交
413

W
wusongqing 已提交
414
Subscribes to data changes of the humidity sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
415

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

W
wusongqing 已提交
418 419 420 421 422 423
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                    |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes   | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.        |
W
wusongqing 已提交
424

W
wusongqing 已提交
425
**Example**
W
wusongqing 已提交
426
  ```js
W
wusongqing 已提交
427
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
W
wusongqing 已提交
428 429
      console.info('Humidity: ' + data.humidity);
  },
Z
zengyawen 已提交
430
      {interval: 10000000}
W
wusongqing 已提交
431 432
  );
  ```
Z
zengyawen 已提交
433

W
wusongqing 已提交
434
### BAROMETER
Z
zengyawen 已提交
435

W
wusongqing 已提交
436
on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;,options?: Options): void
Z
zengyawen 已提交
437

W
wusongqing 已提交
438
Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
439

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

W
wusongqing 已提交
442 443 444 445 446 447
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.  |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes   | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
448

W
wusongqing 已提交
449
**Example**
W
wusongqing 已提交
450
  ```js
W
wusongqing 已提交
451
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
W
wusongqing 已提交
452 453
      console.info('Atmospheric pressure: ' + data.pressure);
  },
Z
zengyawen 已提交
454
      {interval: 10000000}
W
wusongqing 已提交
455 456
  );
  ```
Z
zengyawen 已提交
457

W
wusongqing 已提交
458
### HALL
Z
zengyawen 已提交
459

W
wusongqing 已提交
460
on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;, options?: Options): void
Z
zengyawen 已提交
461 462 463

Subscribes to data changes of the Hall effect sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
466 467 468 469 470 471
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes   | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
472

W
wusongqing 已提交
473
**Example**
W
wusongqing 已提交
474
  ```js
W
wusongqing 已提交
475
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
W
wusongqing 已提交
476 477
      console.info('Status: ' + data.status);
  },
Z
zengyawen 已提交
478
      {interval: 10000000}
W
wusongqing 已提交
479 480
  );
  ```
Z
zengyawen 已提交
481

W
wusongqing 已提交
482
### AMBIENT_LIGHT
Z
zengyawen 已提交
483

W
wusongqing 已提交
484
on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;, options?: Options): void
Z
zengyawen 已提交
485 486 487

Subscribes to data changes of the ambient light sensor. If this API is called multiple times for the same application, the last call takes effect.

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

W
wusongqing 已提交
490 491 492 493 494 495
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes   | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.    |
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
496

W
wusongqing 已提交
497
**Example**
W
wusongqing 已提交
498
  ```js
W
wusongqing 已提交
499
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
W
wusongqing 已提交
500 501
      console.info(' Illumination: ' + data.intensity);
  },
Z
zengyawen 已提交
502
      {interval: 10000000}
W
wusongqing 已提交
503 504
  );
  ```
Z
zengyawen 已提交
505

W
wusongqing 已提交
506
### ORIENTATION
Z
zengyawen 已提交
507

W
wusongqing 已提交
508
on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;, options?: Options): void
Z
zengyawen 已提交
509

W
wusongqing 已提交
510
Subscribes to data changes of the orientation sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
511

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

W
wusongqing 已提交
514 515 516 517 518 519
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.  |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes   | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
520

W
wusongqing 已提交
521
**Example**
W
wusongqing 已提交
522
  ```js
W
wusongqing 已提交
523 524 525 526
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION,function(data){
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
W
wusongqing 已提交
527
  },
Z
zengyawen 已提交
528
      {interval: 10000000}
W
wusongqing 已提交
529 530
  );
  ```
Z
zengyawen 已提交
531

W
wusongqing 已提交
532
### HEART_RATE<sup>deprecated</sup>
W
wusongqing 已提交
533 534 535 536 537

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

Subscribes to only one data change of the heart rate sensor.

W
wusongqing 已提交
538 539
This API is deprecated since API version 9. You are advised to use **sensor.on.HEART_BEAT_RATE<sup>9+</sup>** instead.

W
wusongqing 已提交
540 541 542 543
**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

W
wusongqing 已提交
544
**Parameters**
W
wusongqing 已提交
545

W
wusongqing 已提交
546 547 548 549
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.  |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
550

W
wusongqing 已提交
551
**Example**
Z
zengyawen 已提交
552

W
wusongqing 已提交
553
```js
W
wusongqing 已提交
554 555 556 557 558 559
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);
```
Z
zengyawen 已提交
560

W
wusongqing 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
### HEART_BEAT_RATE<sup>9+</sup>

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

Subscribes to only one data change of the heart rate sensor.

**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**.  |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|

**Example**

```js
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);
```

W
wusongqing 已提交
588
### ROTATION_VECTOR
W
wusongqing 已提交
589 590

on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback&lt;RotationVectorResponse&gt;,options?: Options): void
Z
zengyawen 已提交
591

W
wusongqing 已提交
592
Subscribes to data changes of the rotation vector sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
593

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

W
wusongqing 已提交
596 597 598 599 600 601
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes   | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
602

W
wusongqing 已提交
603
**Example**
W
wusongqing 已提交
604
  ```js
W
wusongqing 已提交
605
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
W
wusongqing 已提交
606 607 608
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
W
wusongqing 已提交
609
      console.info('Scalar quantity: ' + data.w);
W
wusongqing 已提交
610
  },
Z
zengyawen 已提交
611
      {interval: 10000000}
W
wusongqing 已提交
612 613
  );
  ```
Z
zengyawen 已提交
614

W
wusongqing 已提交
615
### WEAR_DETECTION
Z
zengyawen 已提交
616

W
wusongqing 已提交
617
on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;,options?: Options): void
Z
zengyawen 已提交
618

W
wusongqing 已提交
619
Subscribes to data changes of the wear detection sensor. If this API is called multiple times for the same application, the last call takes effect.
Z
zengyawen 已提交
620

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

W
wusongqing 已提交
623 624 625 626 627 628
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes   | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
| options  | [Options](#options)                      | No   | Interval at which the callback is invoked to return the sensor data. The default value is 200,000,000 ns.          |
W
wusongqing 已提交
629

W
wusongqing 已提交
630
**Example**
W
wusongqing 已提交
631
  ```js
W
wusongqing 已提交
632
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
W
wusongqing 已提交
633 634
      console.info('Wear status: ' + data.value);
  },
Z
zengyawen 已提交
635
      {interval: 10000000}
W
wusongqing 已提交
636 637
  );
  ```
Z
zengyawen 已提交
638

W
wusongqing 已提交
639
## sensor.once
Z
zengyawen 已提交
640

W
wusongqing 已提交
641
### ACCELEROMETER
Z
zengyawen 已提交
642

W
wusongqing 已提交
643
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback&lt;AccelerometerResponse&gt;): void
Z
zengyawen 已提交
644

W
wusongqing 已提交
645
Subscribes to only one data change of the acceleration sensor.
Z
zengyawen 已提交
646

W
wusongqing 已提交
647 648 649 650
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
651 652 653 654 655
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER**.  |
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes   | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
W
wusongqing 已提交
656

W
wusongqing 已提交
657
**Example**
W
wusongqing 已提交
658
  ```js
W
wusongqing 已提交
659
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
W
wusongqing 已提交
660 661 662 663 664 665
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
666

W
wusongqing 已提交
667
### LINEAR_ACCELERATION<sup>deprecated</sup>
Z
zengyawen 已提交
668

W
wusongqing 已提交
669
once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
670 671 672

Subscribes to only one data change of the linear acceleration sensor.

W
wusongqing 已提交
673 674
This API is deprecated since API version 9. You are advised to use **sensor.once.LINEAR_ACCELEROMETER<sup>9+</sup>** instead.

W
wusongqing 已提交
675 676 677 678
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
679 680 681 682 683
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes   | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
W
wusongqing 已提交
684

W
wusongqing 已提交
685
**Example**
W
wusongqing 已提交
686
  ```js
W
wusongqing 已提交
687
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) {
W
wusongqing 已提交
688 689 690 691 692 693
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
694

W
wusongqing 已提交
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
### LINEAR_ACCELEROMETER<sup>9+</sup>

once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER,callback:Callback&lt;LinearAccelerometerResponse&gt;): void

Subscribes to only one data change of the linear acceleration sensor.

**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

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

**Example**
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```

W
wusongqing 已提交
721
### ACCELEROMETER_UNCALIBRATED
Z
zengyawen 已提交
722

W
wusongqing 已提交
723
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback&lt;AccelerometerUncalibratedResponse&gt;): void
Z
zengyawen 已提交
724 725 726

Subscribes to only one data change of the uncalibrated acceleration sensor.

W
wusongqing 已提交
727 728 729 730
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
731 732 733 734 735
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes   | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
W
wusongqing 已提交
736

W
wusongqing 已提交
737
**Example**
W
wusongqing 已提交
738
  ```
W
wusongqing 已提交
739
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
W
wusongqing 已提交
740 741 742 743 744 745 746 747 748 749
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
    }
  );
  ```

W
wusongqing 已提交
750
### GRAVITY
W
wusongqing 已提交
751

W
wusongqing 已提交
752
once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback&lt;GravityResponse&gt;): void
W
wusongqing 已提交
753 754 755

Subscribes to only one data change of the gravity sensor.

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

W
wusongqing 已提交
758 759 760 761 762
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.        |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes   | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
W
wusongqing 已提交
763

W
wusongqing 已提交
764
**Example**
W
wusongqing 已提交
765
  ```js
W
wusongqing 已提交
766
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
W
wusongqing 已提交
767 768 769 770 771 772 773
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```

W
wusongqing 已提交
774
### GYROSCOPE
W
wusongqing 已提交
775

W
wusongqing 已提交
776
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback&lt;GyroscopeResponse&gt;): void
W
wusongqing 已提交
777 778 779

Subscribes to only one data change of the gyroscope sensor.

W
wusongqing 已提交
780 781 782 783
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
784 785 786 787 788
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.      |
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes   | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
W
wusongqing 已提交
789

W
wusongqing 已提交
790
**Example**
W
wusongqing 已提交
791
  ```js
W
wusongqing 已提交
792
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
W
wusongqing 已提交
793 794 795 796 797 798
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
799

W
wusongqing 已提交
800
### GYROSCOPE_UNCALIBRATED
Z
zengyawen 已提交
801

W
wusongqing 已提交
802
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
Z
zengyawen 已提交
803 804 805

Subscribes to only one data change of the uncalibrated gyroscope sensor.

W
wusongqing 已提交
806 807 808 809
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
810 811 812 813 814
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes   | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
815

W
wusongqing 已提交
816
**Example**
W
wusongqing 已提交
817
  ```js
W
wusongqing 已提交
818
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
W
wusongqing 已提交
819 820 821 822 823 824 825 826 827
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
    }
  );
  ```
Z
zengyawen 已提交
828

W
wusongqing 已提交
829
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
830

W
wusongqing 已提交
831
once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
832 833 834

Subscribes to only one data change of the significant motion sensor.

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

W
wusongqing 已提交
837 838 839 840 841
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes   | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
W
wusongqing 已提交
842

W
wusongqing 已提交
843
**Example**
W
wusongqing 已提交
844
  ```js
W
wusongqing 已提交
845
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
W
wusongqing 已提交
846 847 848 849
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
Z
zengyawen 已提交
850

W
wusongqing 已提交
851
### PEDOMETER_DETECTION
Z
zengyawen 已提交
852

W
wusongqing 已提交
853
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback&lt;PedometerDetectionResponse&gt;): void
Z
zengyawen 已提交
854 855 856

Subscribes to only one data change of the pedometer detection sensor.

W
wusongqing 已提交
857 858 859 860
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
861 862 863 864 865
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes   | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
W
wusongqing 已提交
866

W
wusongqing 已提交
867
**Example**
W
wusongqing 已提交
868
  ```js
W
wusongqing 已提交
869
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
W
wusongqing 已提交
870 871 872 873
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
Z
zengyawen 已提交
874

W
wusongqing 已提交
875
### PEDOMETER
Z
zengyawen 已提交
876

W
wusongqing 已提交
877
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
878

W
wusongqing 已提交
879
Subscribes to only one data change of the pedometer sensor.
Z
zengyawen 已提交
880

W
wusongqing 已提交
881 882 883 884
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
885 886 887 888 889
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.       |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes   | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
890

W
wusongqing 已提交
891
**Example**
W
wusongqing 已提交
892
  ```js
W
wusongqing 已提交
893
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
W
wusongqing 已提交
894 895 896 897
      console.info('Steps: ' + data.steps);
    }
  );
  ```
Z
zengyawen 已提交
898

W
wusongqing 已提交
899
### AMBIENT_TEMPERATURE
Z
zengyawen 已提交
900

W
wusongqing 已提交
901
once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback&lt;AmbientTemperatureResponse&gt;): void
Z
zengyawen 已提交
902 903 904

Subscribes to only one data change of the ambient temperature sensor.

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

W
wusongqing 已提交
907 908 909 910 911
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes   | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
W
wusongqing 已提交
912

W
wusongqing 已提交
913
**Example**
W
wusongqing 已提交
914
  ```js
W
wusongqing 已提交
915
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
W
wusongqing 已提交
916 917 918 919
      console.info('Temperature: ' + data.temperature);
    }
  );
  ```
Z
zengyawen 已提交
920

W
wusongqing 已提交
921
### MAGNETIC_FIELD
Z
zengyawen 已提交
922

W
wusongqing 已提交
923
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback&lt;MagneticFieldResponse&gt;): void
Z
zengyawen 已提交
924 925 926

Subscribes to only one data change of the magnetic field sensor.

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

W
wusongqing 已提交
929 930 931 932 933
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.  |
| callback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes   | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
934

W
wusongqing 已提交
935
**Example**
W
wusongqing 已提交
936
  ```js
W
wusongqing 已提交
937
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
W
wusongqing 已提交
938 939 940 941 942 943
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
944

W
wusongqing 已提交
945
### MAGNETIC_FIELD_UNCALIBRATED
Z
zengyawen 已提交
946

W
wusongqing 已提交
947
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
Z
zengyawen 已提交
948 949 950

Subscribes to only one data change of the uncalibrated magnetic field sensor.

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

W
wusongqing 已提交
953 954 955 956 957
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes   | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
W
wusongqing 已提交
958

W
wusongqing 已提交
959
**Example**
W
wusongqing 已提交
960
  ```js
W
wusongqing 已提交
961 962 963 964 965 966 967 968 969 970 971
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function(data) {
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
      console.info('X-coordinate bias: ' + data.biasX);
      console.info('Y-coordinate bias: ' + data.biasY);
      console.info('Z-coordinate bias: ' + data.biasZ);
    }
  );
  ```

W
wusongqing 已提交
972
### PROXIMITY
W
wusongqing 已提交
973 974 975 976 977 978 979

once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback&lt;ProximityResponse&gt;): void

Subscribes to only one data change of the proximity sensor.

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

W
wusongqing 已提交
980 981 982 983 984
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.      |
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes   | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
W
wusongqing 已提交
985

W
wusongqing 已提交
986
**Example**
W
wusongqing 已提交
987
  ```js
W
wusongqing 已提交
988
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(data) {
W
wusongqing 已提交
989 990 991 992 993
      console.info('Distance: ' + data.distance);
    }
  );
  ```

W
wusongqing 已提交
994
### HUMIDITY
W
wusongqing 已提交
995 996 997 998 999 1000 1001

once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback&lt;HumidityResponse&gt;): void

Subscribes to only one data change of the humidity sensor.

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

W
wusongqing 已提交
1002 1003 1004 1005 1006
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.        |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes   | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
1007

W
wusongqing 已提交
1008
**Example**
W
wusongqing 已提交
1009
  ```js
W
wusongqing 已提交
1010 1011 1012 1013 1014 1015
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
  ```

W
wusongqing 已提交
1016
### BAROMETER
W
wusongqing 已提交
1017 1018 1019 1020 1021 1022 1023

once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback&lt;BarometerResponse&gt;): void

Subscribes to only one data change of the barometer sensor.

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

W
wusongqing 已提交
1024 1025 1026 1027 1028
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.      |
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes   | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
W
wusongqing 已提交
1029

W
wusongqing 已提交
1030
**Example**
W
wusongqing 已提交
1031
  ```js
W
wusongqing 已提交
1032 1033 1034 1035 1036 1037
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
  ```

W
wusongqing 已提交
1038
### HALL
W
wusongqing 已提交
1039 1040 1041 1042 1043 1044 1045

once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback&lt;HallResponse&gt;): void

Subscribes to only one data change of the Hall effect sensor.

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

W
wusongqing 已提交
1046 1047 1048 1049 1050
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes   | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
1051

W
wusongqing 已提交
1052
**Example**
W
wusongqing 已提交
1053
  ```js
W
wusongqing 已提交
1054 1055 1056 1057 1058 1059
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
  ```

W
wusongqing 已提交
1060
### AMBIENT_LIGHT
W
wusongqing 已提交
1061 1062 1063 1064 1065 1066 1067

once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback&lt;LightResponse&gt;): void

Subscribes to only one data change of the ambient light sensor.

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

W
wusongqing 已提交
1068 1069 1070 1071 1072
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                    |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes   | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
W
wusongqing 已提交
1073

W
wusongqing 已提交
1074
**Example**
W
wusongqing 已提交
1075
  ```js
W
wusongqing 已提交
1076 1077 1078 1079 1080 1081
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
      console.info(' Illumination: ' + data.intensity);
    }
  );
  ```

W
wusongqing 已提交
1082
### ORIENTATION
W
wusongqing 已提交
1083 1084 1085 1086 1087 1088 1089

once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback&lt;OrientationResponse&gt;): void

Subscribes to only one data change of the orientation sensor.

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

W
wusongqing 已提交
1090 1091 1092 1093 1094
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.     |
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes   | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
W
wusongqing 已提交
1095

W
wusongqing 已提交
1096
**Example**
W
wusongqing 已提交
1097
  ```js
W
wusongqing 已提交
1098 1099 1100 1101 1102 1103 1104 1105
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function(data) {
      console.info('The device rotates at an angle around the X axis: ' + data.beta);
      console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
      console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
    }
  );
  ```

W
wusongqing 已提交
1106
### ROTATION_VECTOR
W
wusongqing 已提交
1107 1108 1109 1110 1111 1112 1113

once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback&lt;RotationVectorResponse&gt;): void

Subscribes to only one data change of the rotation vector sensor.

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

W
wusongqing 已提交
1114 1115 1116 1117 1118
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes   | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
W
wusongqing 已提交
1119

W
wusongqing 已提交
1120
**Example**
W
wusongqing 已提交
1121
  ```js
W
wusongqing 已提交
1122
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
W
wusongqing 已提交
1123 1124 1125
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
W
wusongqing 已提交
1126 1127 1128 1129 1130
      console.info('Scalar quantity: ' + data.w);
    }
  );
  ```

W
wusongqing 已提交
1131
### HEART_RATE<sup>deprecated</sup>
W
wusongqing 已提交
1132 1133 1134 1135 1136

once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback&lt;HeartRateResponse&gt;): void

Subscribes to only one data change of the heart rate sensor.

W
wusongqing 已提交
1137 1138
This API is deprecated since API version 9. You are advised to use **sensor.once.HEART_BEAT_RATE<sup>9+</sup>** instead.

W
wusongqing 已提交
1139 1140 1141 1142
**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

W
wusongqing 已提交
1143 1144 1145 1146 1147
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.      |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1148

W
wusongqing 已提交
1149
**Example**
W
wusongqing 已提交
1150
  ```js
W
wusongqing 已提交
1151 1152 1153 1154 1155 1156
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
      console.info("Heart rate: " + data.heartRate);
    }
  );
  ```

W
wusongqing 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
### HEART_BEAT_RATE<sup>9+</sup>

once(type: SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback: Callback&lt;HeartRateResponse&gt;): void

Subscribes to only one data change of the heart rate sensor.

**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**.      |
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|

**Example**
  ```js
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, function(data) {
      console.info("Heart rate: " + data.heartRate);
    }
  );
  ```

W
wusongqing 已提交
1181
### WEAR_DETECTION
W
wusongqing 已提交
1182 1183 1184 1185 1186 1187 1188

once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback&lt;WearDetectionResponse&gt;): void

Subscribes to only one data change of the wear detection sensor.

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

W
wusongqing 已提交
1189 1190 1191 1192 1193
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes   | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
W
wusongqing 已提交
1194

W
wusongqing 已提交
1195
**Example**
W
wusongqing 已提交
1196
  ```js
W
wusongqing 已提交
1197 1198
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
W
wusongqing 已提交
1199 1200 1201
    }
  );
  ```
Z
zengyawen 已提交
1202

W
wusongqing 已提交
1203 1204 1205
## sensor.off

### ACCELEROMETER
W
wusongqing 已提交
1206 1207 1208 1209 1210 1211 1212 1213 1214

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
1215
**Parameters**
W
wusongqing 已提交
1216

W
wusongqing 已提交
1217 1218 1219 1220
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER**.|
| callback | Callback&lt;[AccelerometerResponse](#accelerometerresponse)&gt; | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
W
wusongqing 已提交
1221

W
wusongqing 已提交
1222
**Example**
W
wusongqing 已提交
1223

W
wusongqing 已提交
1224
```js
W
wusongqing 已提交
1225 1226 1227 1228 1229 1230 1231 1232
function callback(data) {
    console.info('x-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
```

W
wusongqing 已提交
1233
### ACCELEROMETER_UNCALIBRATED
W
wusongqing 已提交
1234 1235 1236 1237 1238 1239 1240 1241 1242

off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback&lt;AccelerometerUncalibratedResponse&gt;): void

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
1243
**Parameters**
W
wusongqing 已提交
1244

W
wusongqing 已提交
1245 1246 1247 1248
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback&lt;[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
W
wusongqing 已提交
1249

W
wusongqing 已提交
1250
**Example**
W
wusongqing 已提交
1251

W
wusongqing 已提交
1252
```js
W
wusongqing 已提交
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback);
```

W
wusongqing 已提交
1264
### AMBIENT_LIGHT
W
wusongqing 已提交
1265 1266 1267 1268 1269 1270 1271

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

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1272
**Parameters**
W
wusongqing 已提交
1273

W
wusongqing 已提交
1274 1275 1276 1277
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
| callback | Callback&lt;[LightResponse](#lightresponse)&gt; | Yes   | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.  |
W
wusongqing 已提交
1278

W
wusongqing 已提交
1279
**Example**
W
wusongqing 已提交
1280

W
wusongqing 已提交
1281
```js
W
wusongqing 已提交
1282 1283 1284 1285 1286 1287
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

W
wusongqing 已提交
1288
### AMBIENT_TEMPERATURE
W
wusongqing 已提交
1289 1290 1291 1292 1293 1294 1295

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

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1296
**Parameters**
W
wusongqing 已提交
1297

W
wusongqing 已提交
1298 1299 1300 1301
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
| callback | Callback&lt;[AmbientTemperatureResponse](#ambienttemperatureresponse)&gt; | Yes   | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
W
wusongqing 已提交
1302

W
wusongqing 已提交
1303
**Example**
W
wusongqing 已提交
1304

W
wusongqing 已提交
1305
```js
W
wusongqing 已提交
1306 1307 1308 1309 1310 1311
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

W
wusongqing 已提交
1312
### AMBIENT_TEMPERATURE
W
wusongqing 已提交
1313 1314 1315 1316 1317 1318 1319

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

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1320
**Parameters**
W
wusongqing 已提交
1321

W
wusongqing 已提交
1322 1323 1324 1325
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**.|
| callback | Callback&lt;[BarometerResponse](#barometerresponse)&gt; | Yes   | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
W
wusongqing 已提交
1326

W
wusongqing 已提交
1327
**Example**
W
wusongqing 已提交
1328

W
wusongqing 已提交
1329
```js
W
wusongqing 已提交
1330 1331 1332 1333 1334 1335
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

W
wusongqing 已提交
1336
### GRAVITY
W
wusongqing 已提交
1337 1338 1339 1340 1341 1342 1343

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

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1346 1347 1348 1349
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**.   |
| callback | Callback&lt;[GravityResponse](#gravityresponse)&gt; | Yes   | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
W
wusongqing 已提交
1350

W
wusongqing 已提交
1351
**Example**
W
wusongqing 已提交
1352

W
wusongqing 已提交
1353
```js
W
wusongqing 已提交
1354 1355 1356 1357 1358 1359 1360 1361
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback);
```

W
wusongqing 已提交
1362
### GYROSCOPE
W
wusongqing 已提交
1363 1364 1365 1366 1367 1368 1369 1370 1371

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
1372
**Parameters**
W
wusongqing 已提交
1373

W
wusongqing 已提交
1374 1375 1376 1377
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**.|
| callback | Callback&lt;[GyroscopeResponse](#gyroscoperesponse)&gt; | Yes   | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
W
wusongqing 已提交
1378

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

W
wusongqing 已提交
1381
```js
W
wusongqing 已提交
1382 1383 1384 1385 1386 1387 1388 1389
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
```

W
wusongqing 已提交
1390
### GYROSCOPE_UNCALIBRATED
W
wusongqing 已提交
1391

W
wusongqing 已提交
1392
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback&lt;GyroscopeUncalibratedResponse&gt;): void
W
wusongqing 已提交
1393 1394 1395 1396 1397 1398 1399

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
1400
**Parameters**
W
wusongqing 已提交
1401

W
wusongqing 已提交
1402 1403 1404 1405
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
| callback | Callback&lt;[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
1406

W
wusongqing 已提交
1407
**Example**
W
wusongqing 已提交
1408

W
wusongqing 已提交
1409
```js
W
wusongqing 已提交
1410 1411 1412 1413 1414 1415 1416 1417
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback);
```

W
wusongqing 已提交
1418
### HALL
W
wusongqing 已提交
1419 1420 1421 1422 1423 1424 1425

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

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1428 1429 1430 1431
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**.      |
| callback | Callback&lt;[HallResponse](#hallresponse)&gt; | Yes   | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
1432

W
wusongqing 已提交
1433
**Example**
W
wusongqing 已提交
1434

W
wusongqing 已提交
1435
```js
W
wusongqing 已提交
1436 1437 1438 1439 1440 1441
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

W
wusongqing 已提交
1442
### HEART_RATE<sup>deprecated</sup>
W
wusongqing 已提交
1443 1444 1445 1446 1447

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

Unsubscribes from sensor data changes.

W
wusongqing 已提交
1448 1449
This API is deprecated since API version 9. You are advised to use **sensor.off.HEART_BEAT_RATE<sup>9+</sup>** instead.

W
wusongqing 已提交
1450 1451 1452 1453
**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

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

W
wusongqing 已提交
1456 1457 1458 1459
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)[SensorType](#sensortype) | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_RATE**.|
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1460

W
wusongqing 已提交
1461
**Example**
W
wusongqing 已提交
1462

W
wusongqing 已提交
1463
```js
W
wusongqing 已提交
1464 1465 1466 1467 1468 1469
function callback(data) {
    console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, callback);
```

W
wusongqing 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
### HEART_BEAT_RATE<sup>9+</sup>

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.READ_HEALTH_DATA

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

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)[SensorType](#sensortype) | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HEART_BEAT_RATE**.|
| callback | Callback&lt;[HeartRateResponse](#heartrateresponse)&gt; | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|

**Example**

```js
function callback(data) {
    console.info("Heart rate: " + data.heartRate);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_BEAT_RATE, callback);
```

W
wusongqing 已提交
1496
### HUMIDITY
W
wusongqing 已提交
1497 1498 1499 1500 1501 1502 1503

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

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1504
**Parameters**
W
wusongqing 已提交
1505

W
wusongqing 已提交
1506 1507 1508 1509
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
| callback | Callback&lt;[HumidityResponse](#humidityresponse)&gt; | Yes   | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
1510

W
wusongqing 已提交
1511
**Example**
W
wusongqing 已提交
1512

W
wusongqing 已提交
1513
```js
W
wusongqing 已提交
1514 1515 1516 1517 1518 1519
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

W
wusongqing 已提交
1520
### LINEAR_ACCELERATION<sup>deprecated</sup>
Z
zengyawen 已提交
1521

W
wusongqing 已提交
1522
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback&lt;LinearAccelerometerResponse&gt;): void
Z
zengyawen 已提交
1523

W
wusongqing 已提交
1524
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1525

W
wusongqing 已提交
1526 1527
This API is deprecated since API version 9. You are advised to use **sensor.off.LINEAR_ACCELEROMETER<sup>9+</sup>** instead.

W
wusongqing 已提交
1528 1529 1530
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
1532
**Parameters**
W
wusongqing 已提交
1533

W
wusongqing 已提交
1534 1535 1536 1537
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
W
wusongqing 已提交
1538

W
wusongqing 已提交
1539
**Example**
Z
zengyawen 已提交
1540

W
wusongqing 已提交
1541
```js
W
wusongqing 已提交
1542 1543 1544 1545 1546 1547 1548
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback);
```
Z
zengyawen 已提交
1549

W
wusongqing 已提交
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
### LINEAR_ACCELEROMETER<sup>9+</sup>

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

Unsubscribes from sensor data changes.

**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELEROMETER**.|
| callback | Callback&lt;[LinearAccelerometerResponse](#linearaccelerometerresponse)&gt; | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|

**Example**

```js
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELEROMETER, callback);
```

W
wusongqing 已提交
1578
### MAGNETIC_FIELD
Z
zengyawen 已提交
1579

W
wusongqing 已提交
1580
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback&lt;MagneticFieldResponse&gt;): void
Z
zengyawen 已提交
1581

W
wusongqing 已提交
1582 1583 1584
Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1586
**Parameters**
W
wusongqing 已提交
1587

W
wusongqing 已提交
1588 1589 1590 1591
| Name             | Type                                      | Mandatory  | Description                                      |
| ---------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type             | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.|
| callbackcallback | Callback&lt;[MagneticFieldResponse](#magneticfieldresponse)&gt; | Yes   | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
1592

W
wusongqing 已提交
1593
**Example**
W
wusongqing 已提交
1594

W
wusongqing 已提交
1595
```js
W
wusongqing 已提交
1596 1597 1598 1599 1600 1601 1602
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback);
```
W
wusongqing 已提交
1603

W
wusongqing 已提交
1604
### MAGNETIC_FIELD_UNCALIBRATED
W
wusongqing 已提交
1605

W
wusongqing 已提交
1606
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback&lt;MagneticFieldUncalibratedResponse&gt;): void
W
wusongqing 已提交
1607

W
wusongqing 已提交
1608 1609 1610
Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1614 1615 1616 1617
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED**.|
| callback | Callback&lt;[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)&gt; | Yes   | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
W
wusongqing 已提交
1618

W
wusongqing 已提交
1619
**Example**
Z
zengyawen 已提交
1620

W
wusongqing 已提交
1621
```js
W
wusongqing 已提交
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('X-coordinate bias: ' + data.biasX);
    console.info('Y-coordinate bias: ' + data.biasY);
    console.info('Z-coordinate bias: ' + data.biasZ);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback);
```

W
wusongqing 已提交
1633
### ORIENTATION
Z
zengyawen 已提交
1634

W
wusongqing 已提交
1635
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback&lt;OrientationResponse&gt;): void
Z
zengyawen 已提交
1636

W
wusongqing 已提交
1637
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1638

W
wusongqing 已提交
1639
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1640

W
wusongqing 已提交
1641
**Parameters**
W
wusongqing 已提交
1642

W
wusongqing 已提交
1643 1644 1645 1646
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**.|
| callback | Callback&lt;[OrientationResponse](#orientationresponse)&gt; | Yes   | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
W
wusongqing 已提交
1647

W
wusongqing 已提交
1648
**Example**
Z
zengyawen 已提交
1649

W
wusongqing 已提交
1650
```js
W
wusongqing 已提交
1651 1652 1653 1654 1655 1656 1657
function callback(data) {
    console.info('The device rotates at an angle around the X axis: ' + data.beta);
    console.info('The device rotates at an angle around the Y axis: ' + data.gamma);
    console.info('The device rotates at an angle around the Z axis: ' + data.alpha);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback);
```
Z
zengyawen 已提交
1658

W
wusongqing 已提交
1659
### PEDOMETER
Z
zengyawen 已提交
1660

W
wusongqing 已提交
1661
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback&lt;PedometerResponse&gt;): void
Z
zengyawen 已提交
1662

W
wusongqing 已提交
1663 1664
Unsubscribes from sensor data changes.

W
wusongqing 已提交
1665 1666
**Required permissions**: ohos.permission.ACTIVITY_MOTION

W
wusongqing 已提交
1667
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1668

W
wusongqing 已提交
1669
**Parameters**
W
wusongqing 已提交
1670

W
wusongqing 已提交
1671 1672 1673 1674
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback&lt;[PedometerResponse](#pedometerresponse)&gt; | Yes   | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
1675

W
wusongqing 已提交
1676
**Example**
W
wusongqing 已提交
1677

W
wusongqing 已提交
1678
```js
W
wusongqing 已提交
1679 1680 1681 1682 1683 1684
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

W
wusongqing 已提交
1685
### PEDOMETER_DETECTION
W
wusongqing 已提交
1686 1687

off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback&lt;PedometerDetectionResponse&gt;): void
W
wusongqing 已提交
1688

W
wusongqing 已提交
1689
Unsubscribes from sensor data changes.
W
wusongqing 已提交
1690

W
wusongqing 已提交
1691
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1692

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

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

W
wusongqing 已提交
1697 1698 1699 1700
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
| callback | Callback&lt;[PedometerDetectionResponse](#pedometerdetectionresponse)&gt; | Yes   | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
W
wusongqing 已提交
1701

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

W
wusongqing 已提交
1704
```js
W
wusongqing 已提交
1705 1706 1707 1708 1709 1710
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

W
wusongqing 已提交
1711
### PROXIMITY
Z
zengyawen 已提交
1712

W
wusongqing 已提交
1713
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback&lt;ProximityResponse&gt;): void
Z
zengyawen 已提交
1714

W
wusongqing 已提交
1715
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1716

W
wusongqing 已提交
1717
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1718

W
wusongqing 已提交
1719
**Parameters**
W
wusongqing 已提交
1720

W
wusongqing 已提交
1721 1722 1723 1724
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**.|
| callback | Callback&lt;[ProximityResponse](#proximityresponse)&gt; | Yes   | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
W
wusongqing 已提交
1725

W
wusongqing 已提交
1726
**Example**
Z
zengyawen 已提交
1727

W
wusongqing 已提交
1728
```js
W
wusongqing 已提交
1729 1730 1731 1732 1733 1734
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```

W
wusongqing 已提交
1735
### ROTATION_VECTOR
Z
zengyawen 已提交
1736

W
wusongqing 已提交
1737
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback&lt;RotationVectorResponse&gt;): void
Z
zengyawen 已提交
1738

W
wusongqing 已提交
1739
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1740

W
wusongqing 已提交
1741
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1742

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

W
wusongqing 已提交
1745 1746 1747 1748
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
| callback | Callback&lt;[RotationVectorResponse](#rotationvectorresponse)&gt; | Yes   | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
W
wusongqing 已提交
1749

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

W
wusongqing 已提交
1752
```js
W
wusongqing 已提交
1753 1754 1755 1756 1757 1758 1759 1760
function callback(data) {
    console.info('X-coordinate component: ' + data.x);
    console.info('Y-coordinate component: ' + data.y);
    console.info('Z-coordinate component: ' + data.z);
    console.info('Scalar quantity: ' + data.w);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback);
```
Z
zengyawen 已提交
1761

W
wusongqing 已提交
1762
### SIGNIFICANT_MOTION
Z
zengyawen 已提交
1763

W
wusongqing 已提交
1764
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback&lt;SignificantMotionResponse&gt;): void
Z
zengyawen 已提交
1765

W
wusongqing 已提交
1766 1767 1768
Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1770
**Parameters**
W
wusongqing 已提交
1771

W
wusongqing 已提交
1772 1773 1774 1775
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
| callback | Callback&lt;[SignificantMotionResponse](#significantmotionresponse)&gt; | Yes   | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
W
wusongqing 已提交
1776

W
wusongqing 已提交
1777
**Example**
Z
zengyawen 已提交
1778

W
wusongqing 已提交
1779
```js
W
wusongqing 已提交
1780 1781 1782 1783 1784
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
Z
zengyawen 已提交
1785

W
wusongqing 已提交
1786
### WEAR_DETECTION
Z
zengyawen 已提交
1787

W
wusongqing 已提交
1788
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback&lt;WearDetectionResponse&gt;): void
Z
zengyawen 已提交
1789 1790 1791

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1794
**Parameters**
W
wusongqing 已提交
1795

W
wusongqing 已提交
1796 1797 1798 1799
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
| callback | Callback&lt;[WearDetectionResponse](#weardetectionresponse)&gt; | Yes   | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
W
wusongqing 已提交
1800

W
wusongqing 已提交
1801
**Example**
W
wusongqing 已提交
1802

W
wusongqing 已提交
1803
```js
W
wusongqing 已提交
1804 1805 1806 1807 1808
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
W
wusongqing 已提交
1809

W
wusongqing 已提交
1810 1811 1812 1813
## sensor.transformCoordinateSystem

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

W
wusongqing 已提交
1814 1815 1816
Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a callback to return the result.

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

W
wusongqing 已提交
1818
**Parameters**
W
wusongqing 已提交
1819

W
wusongqing 已提交
1820 1821 1822 1823 1824
| Name             | Type                                      | Mandatory  | Description         |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to rotate.    |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.   |
| callback         | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the rotation vector after being rotated.|
W
wusongqing 已提交
1825

W
wusongqing 已提交
1826
**Example**
W
wusongqing 已提交
1827

W
wusongqing 已提交
1828 1829
```js
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3}, function(err, data) {
W
wusongqing 已提交
1830 1831 1832 1833
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
W
wusongqing 已提交
1834
    console.info("Operation successed. Data obtained: " + data);
W
wusongqing 已提交
1835 1836 1837 1838 1839
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
W
wusongqing 已提交
1840 1841 1842 1843
## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array&lt;number&gt;, coordinates: CoordinatesOptions): Promise&lt;Array&lt;number&gt;&gt;

W
wusongqing 已提交
1844 1845 1846
Rotates a rotation vector so that it can represent the coordinate system in different ways. This API uses a promise to return the result.

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

W
wusongqing 已提交
1848
**Parameters**
W
wusongqing 已提交
1849

W
wusongqing 已提交
1850 1851 1852 1853
| Name             | Type                                      | Mandatory  | Description      |
| ---------------- | ---------------------------------------- | ---- | -------- |
| inRotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to rotate. |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.|
W
wusongqing 已提交
1854

W
wusongqing 已提交
1855
**Return value**
W
wusongqing 已提交
1856

W
wusongqing 已提交
1857 1858 1859
| Type                                | Description         |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|
W
wusongqing 已提交
1860

W
wusongqing 已提交
1861
**Example**
W
wusongqing 已提交
1862

W
wusongqing 已提交
1863 1864
```js
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {x:2, y:3});
W
wusongqing 已提交
1865 1866 1867 1868 1869 1870 1871 1872 1873
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
```
W
wusongqing 已提交
1874 1875 1876 1877 1878

## sensor.getGeomagneticField

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

W
wusongqing 已提交
1879 1880 1881
Obtains the geomagnetic field of a geographic location. This API uses a callback to return the result.

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

W
wusongqing 已提交
1883 1884 1885 1886 1887 1888
**Parameters**
| Name            | Type                                      | Mandatory  | Description               |
| --------------- | ---------------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions)      | Yes   | Geographic location.            |
| timeMillis      | number                                   | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
| callback        | AsyncCallback&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Yes   | Callback used to return the geomagnetic field.          |
W
wusongqing 已提交
1889

W
wusongqing 已提交
1890
**Example**
W
wusongqing 已提交
1891 1892
```js
sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000, function(err, data)  {
W
wusongqing 已提交
1893 1894 1895 1896 1897 1898 1899 1900 1901
    if (err) {
        console.error('Operation failed. Error code: ' + err.code + '; message: ' + err.message);
        return;
    }
    console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
});
```
W
wusongqing 已提交
1902 1903 1904 1905
## sensor.getGeomagneticField

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

W
wusongqing 已提交
1906 1907 1908
Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.

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

W
wusongqing 已提交
1910 1911 1912 1913 1914
**Parameters**
| Name            | Type                                 | Mandatory  | Description               |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | Yes   | Geographic location.            |
| timeMillis      | number                              | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
Z
zengyawen 已提交
1915

W
wusongqing 已提交
1916 1917 1918
**Return value**
| Type                                      | Description     |
| ---------------------------------------- | ------- |
W
wusongqing 已提交
1919
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|
Z
zengyawen 已提交
1920

W
wusongqing 已提交
1921 1922 1923
**Example**
  ```js
  const promise = sensor.getGeomagneticField({latitude:80, longitude:0, altitude:0}, 1580486400000);
W
wusongqing 已提交
1924 1925 1926 1927 1928 1929 1930 1931 1932
      promise.then((data) => {
          console.info('sensor_getGeomagneticField_promise x: ' + data.x + ',y: ' + data.y + ',z: ' +
  	             data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle +
  		     ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity);
      }).catch((reason) => {
          console.info('Operation failed.');
  })
  ```

W
wusongqing 已提交
1933 1934 1935 1936
## sensor.getAltitude

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

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

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

W
wusongqing 已提交
1941
**Parameters**
W
wusongqing 已提交
1942

W
wusongqing 已提交
1943 1944 1945 1946 1947
| Name            | Type                         | Mandatory  | Description                  |
| --------------- | --------------------------- | ---- | -------------------- |
| seaPressure     | number                      | Yes   | Sea-level atmospheric pressure, in hPa.    |
| currentPressure | number                      | Yes   | Atmospheric pressure at the altitude where the device is located, in hPa.|
| callback        | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the altitude, in meters.   |
W
wusongqing 已提交
1948

W
wusongqing 已提交
1949
**Example**
W
wusongqing 已提交
1950

W
wusongqing 已提交
1951
  ```js
W
wusongqing 已提交
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965
  sensor.getAltitude(0, 200, function(err, data)  {
      if (err) {
          console.error(
  "Operation failed. Error code: " + err.code + ", message: " + err.message);
          return;
      }
          console.info("Successed to get getAltitude interface get data: " + data);
  });
  ```

## sensor.getAltitude

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

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

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

W
wusongqing 已提交
1970
**Parameters**
W
wusongqing 已提交
1971

W
wusongqing 已提交
1972 1973 1974 1975
| Name            | Type    | Mandatory  | Description                  |
| --------------- | ------ | ---- | -------------------- |
| seaPressure     | number | Yes   | Sea-level atmospheric pressure, in hPa.    |
| currentPressure | number | Yes   | Atmospheric pressure at the altitude where the device is located, in hPa.|
W
wusongqing 已提交
1976

W
wusongqing 已提交
1977
**Return value**
W
wusongqing 已提交
1978

W
wusongqing 已提交
1979 1980 1981
| Type                   | Description                |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|
W
wusongqing 已提交
1982

W
wusongqing 已提交
1983
**Example**
W
wusongqing 已提交
1984

W
wusongqing 已提交
1985
  ```js
W
wusongqing 已提交
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
  const promise = sensor.getAltitude(0, 200);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data);
      }).catch((err) => {
          console.error("Operation failed");
  })
  ```


## sensor.getGeomagneticDip

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

W
wusongqing 已提交
1999 2000 2001
Obtains the magnetic dip based on the inclination matrix. This API uses a callback to return the result.

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

W
wusongqing 已提交
2003
**Parameters**
W
wusongqing 已提交
2004

W
wusongqing 已提交
2005 2006 2007 2008
| Name              | Type                         | Mandatory  | Description            |
| ----------------- | --------------------------- | ---- | -------------- |
| inclinationMatrix | Array&lt;number&gt;         | Yes   | Inclination matrix.       |
| callback          | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the magnetic dip, in radians.|
W
wusongqing 已提交
2009

W
wusongqing 已提交
2010
**Example**
W
wusongqing 已提交
2011

W
wusongqing 已提交
2012
  ```js
W
wusongqing 已提交
2013 2014
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
W
wusongqing 已提交
2015
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
W
wusongqing 已提交
2016 2017 2018
                        err.message);
          return;
      }
W
wusongqing 已提交
2019
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
W
wusongqing 已提交
2020 2021 2022 2023 2024 2025 2026
  })
  ```

## sensor.getGeomagneticDip

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

W
wusongqing 已提交
2027 2028 2029
Obtains the magnetic dip based on the inclination matrix. This API uses a promise to return the result.

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

W
wusongqing 已提交
2031
**Parameters**
W
wusongqing 已提交
2032

W
wusongqing 已提交
2033 2034 2035
| Name              | Type                 | Mandatory  | Description     |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | Yes   | Inclination matrix.|
W
wusongqing 已提交
2036

W
wusongqing 已提交
2037
**Return value**
W
wusongqing 已提交
2038

W
wusongqing 已提交
2039 2040 2041
| Type                   | Description            |
| --------------------- | -------------- |
| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|
W
wusongqing 已提交
2042

W
wusongqing 已提交
2043
**Example**
W
wusongqing 已提交
2044

W
wusongqing 已提交
2045
  ```js
W
wusongqing 已提交
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
  const promise = sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info(' getGeomagneticDip_promise successed', data);
      }).catch((err) => {
           console.error("Operation failed");
  })
  ```

## sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

W
wusongqing 已提交
2058 2059 2060
Obtains the angle change between two rotation matrices. This API uses a callback to return the result.

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

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

W
wusongqing 已提交
2064 2065 2066 2067 2068
| Name                  | Type                                      | Mandatory  | Description                |
| --------------------- | ---------------------------------------- | ---- | ------------------ |
| currentRotationMatrix | Array&lt;number&gt;                      | Yes   | Current rotation matrix.         |
| preRotationMatrix     | Array&lt;number&gt;                      | Yes   | The other rotation matrix.           |
| callback              | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the angle change around the z, x, and y axes.|
W
wusongqing 已提交
2069

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

W
wusongqing 已提交
2072
  ```js
W
wusongqing 已提交
2073 2074
  sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
      if (err) {
W
wusongqing 已提交
2075
          console.error('Failed to register data, error code is: ' + err.code + ', message: ' + 
W
wusongqing 已提交
2076 2077 2078 2079
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2080
          console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2081 2082 2083 2084 2085 2086 2087 2088 2089
      }
  })
  ```


## sensor. getAngleModify

getAngleModify(currentRotationMatrix: Array&lt;number&gt;, preRotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

W
wusongqing 已提交
2090 2091 2092
Obtains the angle change between two rotation matrices. This API uses a promise to return the result.

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

W
wusongqing 已提交
2094
**Parameters**
W
wusongqing 已提交
2095

W
wusongqing 已提交
2096 2097 2098 2099
| Name                  | Type                 | Mandatory  | Description       |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | Yes   | Current rotation matrix.|
| preRotationMatrix     | Array&lt;number&gt; | Yes   | Rotation matrix.  |
W
wusongqing 已提交
2100

W
wusongqing 已提交
2101
**Return value**
W
wusongqing 已提交
2102

W
wusongqing 已提交
2103 2104 2105
| Type                                | Description                |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the angle change around the z, x, and y axes.|
W
wusongqing 已提交
2106

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

W
wusongqing 已提交
2109
  ```js
W
wusongqing 已提交
2110 2111
  const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
      promise.then((data) => {
W
wusongqing 已提交
2112
          console.info('getAngleModifiy_promise success');
W
wusongqing 已提交
2113
          for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2114
              console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2115 2116
          }
      }).catch((reason) => {
W
wusongqing 已提交
2117
          console.info("promise::catch", reason);
W
wusongqing 已提交
2118 2119 2120 2121 2122 2123 2124 2125
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

W
wusongqing 已提交
2126 2127 2128
Converts a rotation vector into a rotation matrix. This API uses a callback to return the result.

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

W
wusongqing 已提交
2130
**Parameters**
W
wusongqing 已提交
2131

W
wusongqing 已提交
2132 2133 2134 2135
| Name           | Type                                      | Mandatory  | Description     |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to convert.|
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the rotation matrix.|
W
wusongqing 已提交
2136

W
wusongqing 已提交
2137
**Example**
W
wusongqing 已提交
2138

W
wusongqing 已提交
2139
  ```js
W
wusongqing 已提交
2140 2141
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
W
wusongqing 已提交
2142
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
W
wusongqing 已提交
2143 2144 2145 2146
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2147
          console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2148 2149 2150 2151 2152 2153 2154 2155 2156
      }
  })
  ```


## sensor.createRotationMatrix

createRotationMatrix(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

W
wusongqing 已提交
2157 2158 2159
Converts a rotation vector into a rotation matrix. This API uses a promise to return the result.

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

W
wusongqing 已提交
2161
**Parameters**
W
wusongqing 已提交
2162

W
wusongqing 已提交
2163 2164 2165
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
W
wusongqing 已提交
2166

W
wusongqing 已提交
2167
**Return value**
W
wusongqing 已提交
2168

W
wusongqing 已提交
2169 2170 2171
| Type                                | Description     |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
2172

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

W
wusongqing 已提交
2175
  ```js
W
wusongqing 已提交
2176 2177
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
W
wusongqing 已提交
2178
          console.info('createRotationMatrix_promise success');
W
wusongqing 已提交
2179
          for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2180
              console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2181 2182
          }
      }).catch((reason) => {
W
wusongqing 已提交
2183
          console.info("promise::catch", reason);
W
wusongqing 已提交
2184 2185 2186 2187 2188 2189 2190 2191
  })	
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

W
wusongqing 已提交
2192 2193 2194
Converts a rotation vector into a quaternion. This API uses a callback to return the result.

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

W
wusongqing 已提交
2196
**Parameters**
W
wusongqing 已提交
2197

W
wusongqing 已提交
2198 2199 2200 2201
| Name           | Type                                      | Mandatory  | Description     |
| -------------- | ---------------------------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt;                      | Yes   | Rotation vector to convert.|
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the quaternion. |
W
wusongqing 已提交
2202

W
wusongqing 已提交
2203
**Example**
W
wusongqing 已提交
2204

W
wusongqing 已提交
2205
  ```js
W
wusongqing 已提交
2206 2207
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
W
wusongqing 已提交
2208
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
W
wusongqing 已提交
2209 2210 2211 2212
                        err.message);
          return;
      }
      for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2213
          console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2214 2215 2216 2217 2218 2219 2220 2221 2222
      }
  })
  ```


## sensor.createQuaternion

createQuaternion(rotationVector: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

W
wusongqing 已提交
2223 2224 2225
Converts a rotation vector into a quaternion. This API uses a promise to return the result.

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

W
wusongqing 已提交
2227
**Parameters**
W
wusongqing 已提交
2228

W
wusongqing 已提交
2229 2230 2231
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
W
wusongqing 已提交
2232

W
wusongqing 已提交
2233
**Return value**
W
wusongqing 已提交
2234

W
wusongqing 已提交
2235 2236 2237
| Type                                | Description    |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
W
wusongqing 已提交
2238

W
wusongqing 已提交
2239
**Example**
W
wusongqing 已提交
2240

W
wusongqing 已提交
2241
  ```js
W
wusongqing 已提交
2242 2243 2244 2245
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
W
wusongqing 已提交
2246
              console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;, callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void

W
wusongqing 已提交
2258 2259 2260
Obtains the device direction based on the rotation matrix. This API uses a callback to return the result.

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

W
wusongqing 已提交
2262
**Parameters**
W
wusongqing 已提交
2263

W
wusongqing 已提交
2264 2265 2266 2267
| Name           | Type                                      | Mandatory  | Description                |
| -------------- | ---------------------------------------- | ---- | ------------------ |
| rotationMatrix | Array&lt;number&gt;                      | Yes   | Rotation matrix.           |
| callback       | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes   | Callback used to return the rotation angle around the z, x, and y axes.|
W
wusongqing 已提交
2268

W
wusongqing 已提交
2269
**Example**
W
wusongqing 已提交
2270

W
wusongqing 已提交
2271
  ```js
W
wusongqing 已提交
2272 2273
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
W
wusongqing 已提交
2274
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
W
wusongqing 已提交
2275 2276 2277
                        err.message);
          return;
      }
W
wusongqing 已提交
2278
      console.info("SensorJsAPI--->Successed to get getDirection interface get data: " + data);
W
wusongqing 已提交
2279
      for (var i = 1; i < data.length; i++) {
W
wusongqing 已提交
2280
          console.info("sensor_getDirection_callback" + data[i]);
W
wusongqing 已提交
2281 2282 2283 2284 2285 2286 2287 2288 2289
      }
  })
  ```


## sensor.getDirection

getDirection(rotationMatrix: Array&lt;number&gt;): Promise&lt;Array&lt;number&gt;&gt;

W
wusongqing 已提交
2290 2291 2292
Obtains the device direction based on the rotation matrix. This API uses a promise to return the result.

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

W
wusongqing 已提交
2294
**Parameters**
W
wusongqing 已提交
2295

W
wusongqing 已提交
2296 2297 2298
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | Yes   | Rotation matrix.|
W
wusongqing 已提交
2299

W
wusongqing 已提交
2300
**Return value**
W
wusongqing 已提交
2301

W
wusongqing 已提交
2302 2303 2304
| Type                                | Description                |
| ---------------------------------- | ------------------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation angle around the z, x, and y axes.|
W
wusongqing 已提交
2305

W
wusongqing 已提交
2306
**Example**
W
wusongqing 已提交
2307

W
wusongqing 已提交
2308
  ```js
W
wusongqing 已提交
2309 2310
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
W
wusongqing 已提交
2311
          console.info('sensor_getAltitude_Promise success', data);
W
wusongqing 已提交
2312
          for (var i = 1; i < data.length; i++) {
W
wusongqing 已提交
2313
              console.info("sensor_getDirection_promise" + data[i]);
W
wusongqing 已提交
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324
          }
      }).catch((err) => {
          console.info('promise failed');
  })
  ```


## sensor.createRotationMatrix

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

W
wusongqing 已提交
2325 2326 2327
Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a callback to return the result.

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

W
wusongqing 已提交
2329
**Parameters**
W
wusongqing 已提交
2330

W
wusongqing 已提交
2331 2332 2333 2334 2335
| Name        | Type                                      | Mandatory  | Description     |
| ----------- | ---------------------------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt;                      | Yes   | Gravity vector.|
| geomagnetic | Array&lt;number&gt;                      | Yes   | Geomagnetic vector.|
| callback    | AsyncCallback&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Yes   | Callback used to return the rotation matrix.|
W
wusongqing 已提交
2336

W
wusongqing 已提交
2337
**Example**
W
wusongqing 已提交
2338

W
wusongqing 已提交
2339
  ```js
W
wusongqing 已提交
2340 2341
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
W
wusongqing 已提交
2342
          console.error('SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
W
wusongqing 已提交
2343 2344 2345
                        err.message);
          return;
      }
W
wusongqing 已提交
2346
      for (var i=0; i < data.rotation.length; i++) {
W
wusongqing 已提交
2347
          console.info("data[" + i + "]: " + data[i])
W
wusongqing 已提交
2348 2349 2350 2351 2352 2353 2354 2355 2356
      }
  })
  ```


## sensor.createRotationMatrix

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

W
wusongqing 已提交
2357 2358 2359
Creates a rotation matrix based on the gravity vector and geomagnetic vector. This API uses a promise to return the result.

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

W
wusongqing 已提交
2361
**Parameters**
W
wusongqing 已提交
2362

W
wusongqing 已提交
2363 2364 2365 2366
| Name        | Type                 | Mandatory  | Description     |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | Yes   | Gravity vector.|
| geomagnetic | Array&lt;number&gt; | Yes   | Geomagnetic vector.|
W
wusongqing 已提交
2367

W
wusongqing 已提交
2368
**Return value**
W
wusongqing 已提交
2369

W
wusongqing 已提交
2370 2371 2372
| Type                                      | Description     |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
2373

W
wusongqing 已提交
2374
**Example**
W
wusongqing 已提交
2375

W
wusongqing 已提交
2376
  ```js
W
wusongqing 已提交
2377 2378
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
W
wusongqing 已提交
2379
          console.info('createRotationMatrix_promise successed');
W
wusongqing 已提交
2380
          for (var i=0; i < data.rotation.length; i++) {
W
wusongqing 已提交
2381
              console.info("data[" + i + "]: " + data[i]);
W
wusongqing 已提交
2382 2383
          }
      }).catch((err) => {
W
wusongqing 已提交
2384
          console.info('promise failed');
W
wusongqing 已提交
2385 2386 2387
  })
  ```

W
wusongqing 已提交
2388 2389

## SensorType
Z
zengyawen 已提交
2390 2391 2392

Enumerates the sensor types.

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

W
wusongqing 已提交
2395

W
wusongqing 已提交
2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407
| Name                                      | Default Value | Description         |
| ---------------------------------------- | ---- | ----------- |
| SENSOR_TYPE_ID_ACCELEROMETER             | 1    | Acceleration sensor.    |
| SENSOR_TYPE_ID_GYROSCOPE                 | 2    | Gyroscope sensor.    |
| SENSOR_TYPE_ID_AMBIENT_LIGHT             | 5    | Ambient light sensor.    |
| SENSOR_TYPE_ID_MAGNETIC_FIELD            | 6    | Magnetic field sensor.     |
| SENSOR_TYPE_ID_BAROMETER                 | 8    | Barometer sensor.    |
| SENSOR_TYPE_ID_HALL                      | 10   | Hall effect sensor.     |
| SENSOR_TYPE_ID_PROXIMITY                 | 12   | Proximity sensor.    |
| SENSOR_TYPE_ID_HUMIDITY                  | 13   | Humidity sensor.     |
| SENSOR_TYPE_ID_ORIENTATION               | 256  | Orientation sensor.     |
| SENSOR_TYPE_ID_GRAVITY                   | 257  | Gravity sensor.     |
W
wusongqing 已提交
2408 2409
| SENSOR_TYPE_ID_LINEAR_ACCELERATION<sup>deprecated</sup>       | 258  | Linear acceleration sensor.  |
| SENSOR_TYPE_ID_LINEAR_ACCELEROMETER       | 258  | Linear acceleration sensor.  |
W
wusongqing 已提交
2410 2411 2412 2413 2414 2415 2416
| SENSOR_TYPE_ID_ROTATION_VECTOR           | 259  | Rotation vector sensor.   |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE       | 260  | Ambient temperature sensor.   |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | Uncalibrated magnetic field sensor.  |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED    | 263  | Uncalibrated gyroscope sensor. |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION        | 264  | Significant motion sensor.   |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION       | 265  | Pedometer detection sensor.   |
| SENSOR_TYPE_ID_PEDOMETER                 | 266  | Pedometer sensor.     |
W
wusongqing 已提交
2417 2418
| SENSOR_TYPE_ID_HEART_RATE<sup>deprecated</sup>                | 278  | Heart rate sensor.     |
| SENSOR_TYPE_ID_HEART_BEAT_RATE                | 278  | Heart rate sensor.     |
W
wusongqing 已提交
2419 2420
| SENSOR_TYPE_ID_WEAR_DETECTION            | 280  | Wear detection sensor.   |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281  | Uncalibrated acceleration sensor.|
W
wusongqing 已提交
2421 2422 2423 2424 2425 2426


## Response

Describes the timestamp of the sensor data.

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

W
wusongqing 已提交
2429 2430 2431
| Name       | Type  | Readable  | Writable  | Description          |
| --------- | ------ | ---- | ---- | ------------ |
| timestamp | number | Yes   | Yes   | Timestamp when the sensor reports data.|
W
wusongqing 已提交
2432 2433 2434 2435 2436 2437


## AccelerometerResponse

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

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

W
wusongqing 已提交
2440

W
wusongqing 已提交
2441 2442 2443 2444 2445
| Name  | Type  | Readable  | Writable  | Description                    |
| ---- | ------ | ---- | ---- | ---------------------- |
| x    | number | Yes   | Yes   | Acceleration along the x-axis of the device, in m/s2.|
| y    | number | Yes   | Yes   | Acceleration along the y-axis of the device, in m/s2.|
| z    | number | Yes   | Yes   | Acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
2446 2447 2448 2449 2450 2451


## LinearAccelerometerResponse

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

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

W
wusongqing 已提交
2454

W
wusongqing 已提交
2455 2456 2457 2458 2459
| Name  | Type  | Readable  | Writable  | Description                      |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | Yes   | Yes   | Linear acceleration along the x-axis of the device, in m/s2.|
| y    | number | Yes   | Yes   | Linear acceleration along the y-axis of the device, in m/s2.|
| z    | number | Yes   | Yes   | Linear acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
2460 2461 2462 2463 2464 2465


## AccelerometerUncalibratedResponse

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

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

W
wusongqing 已提交
2468

W
wusongqing 已提交
2469 2470 2471 2472 2473 2474 2475 2476
| Name   | Type  | Readable  | Writable  | Description                          |
| ----- | ------ | ---- | ---- | ---------------------------- |
| x     | number | Yes   | Yes   | Uncalibrated acceleration along the x-axis of the device, in m/s2.   |
| y     | number | Yes   | Yes   | Uncalibrated acceleration along the y-axis of the device, in m/s2.   |
| z     | number | Yes   | Yes   | Uncalibrated acceleration along the z-axis of the device, in m/s2.   |
| biasX | number | Yes   | Yes   | Uncalibrated acceleration bias along the x-axis of the device, in m/s2. |
| biasY | number | Yes   | Yes   | Uncalibrated acceleration bias along the y-axis of the device, in m/s2.|
| biasZ | number | Yes   | Yes   | Uncalibrated acceleration bias along the z-axis of the device, in m/s2. |
W
wusongqing 已提交
2477 2478 2479 2480 2481 2482


## GravityResponse

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

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

W
wusongqing 已提交
2485

W
wusongqing 已提交
2486 2487 2488 2489 2490
| Name  | Type  | Readable  | Writable  | Description                      |
| ---- | ------ | ---- | ---- | ------------------------ |
| x    | number | Yes   | Yes   | Gravitational acceleration along the x-axis of the device, in m/s2.|
| y    | number | Yes   | Yes   | Gravitational acceleration along the y-axis of the device, in m/s2.|
| z    | number | Yes   | Yes   | Gravitational acceleration along the z-axis of the device, in m/s2.|
W
wusongqing 已提交
2491 2492 2493 2494 2495 2496


## OrientationResponse

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

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

W
wusongqing 已提交
2499

W
wusongqing 已提交
2500 2501
| Name   | Type  | Readable  | Writable  | Description               |
| ----- | ------ | ---- | ---- | ----------------- |
W
wusongqing 已提交
2502
| alpha | number | Yes   | Yes   | Rotation angle of the device around the z-axis, in degrees.|
W
wusongqing 已提交
2503 2504
| beta  | number | Yes   | Yes   | Rotation angle of the device around the x-axis, in degrees.|
| gamma | number | Yes   | Yes   | Rotation angle of the device around the y-axis, in degrees.|
W
wusongqing 已提交
2505 2506 2507 2508 2509 2510


## RotationVectorResponse

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

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

W
wusongqing 已提交
2513

W
wusongqing 已提交
2514 2515 2516 2517 2518 2519
| Name  | Type  | Readable  | Writable  | Description       |
| ---- | ------ | ---- | ---- | --------- |
| x    | number | Yes   | Yes   | X-component of the rotation vector.|
| y    | number | Yes   | Yes   | Y-component of the rotation vector.|
| z    | number | Yes   | Yes   | Z-component of the rotation vector.|
| w    | number | Yes   | Yes   | Scalar.      |
W
wusongqing 已提交
2520 2521 2522 2523 2524 2525


## GyroscopeResponse

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

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

W
wusongqing 已提交
2528

W
wusongqing 已提交
2529 2530 2531 2532 2533
| Name  | Type  | Readable  | Writable  | Description                 |
| ---- | ------ | ---- | ---- | ------------------- |
| x    | number | Yes   | Yes   | Angular velocity of rotation around the x-axis of the device, in rad/s.|
| y    | number | Yes   | Yes   | Angular velocity of rotation around the y-axis of the device, in rad/s.|
| z    | number | Yes   | Yes   | Angular velocity of rotation around the z-axis of the device, in rad/s.|
W
wusongqing 已提交
2534 2535 2536 2537 2538 2539


## GyroscopeUncalibratedResponse

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

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

W
wusongqing 已提交
2542

W
wusongqing 已提交
2543 2544 2545 2546 2547 2548 2549 2550
| Name   | Type  | Readable  | Writable  | Description                      |
| ----- | ------ | ---- | ---- | ------------------------ |
| x     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the x-axis of the device, in rad/s.  |
| y     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the y-axis of the device, in rad/s.  |
| z     | number | Yes   | Yes   | Uncalibrated angular velocity of rotation around the z-axis of the device, in rad/s.  |
| biasX | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the x-axis of the device, in rad/s.|
| biasY | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the y-axis of the device, in rad/s.|
| biasZ | number | Yes   | Yes   | Uncalibrated angular velocity bias of rotation around the z-axis of the device, in rad/s.|
W
wusongqing 已提交
2551 2552 2553 2554 2555 2556


## SignificantMotionResponse

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

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

W
wusongqing 已提交
2559

W
wusongqing 已提交
2560 2561 2562
| Name    | Type  | Readable  | Writable  | Description                                      |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| scalar | number | Yes   | Yes   | Intensity of a motion. This parameter specifies whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.|
W
wusongqing 已提交
2563 2564 2565 2566 2567 2568


## ProximityResponse

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

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

W
wusongqing 已提交
2571

W
wusongqing 已提交
2572 2573 2574
| Name      | Type  | Readable  | Writable  | Description                          |
| -------- | ------ | ---- | ---- | ---------------------------- |
| distance | number | Yes   | Yes   | Proximity between the visible object and the device monitor. The value **0** means the two are close to each other, and **1** means that they are far away from each other.|
W
wusongqing 已提交
2575 2576 2577 2578 2579 2580


## LightResponse

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

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

W
wusongqing 已提交
2583

W
wusongqing 已提交
2584 2585 2586
| Name       | Type  | Readable  | Writable  | Description         |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | Yes   | Yes   | Illumination, in lux.|
W
wusongqing 已提交
2587 2588 2589 2590 2591 2592


## HallResponse

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

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

W
wusongqing 已提交
2595

W
wusongqing 已提交
2596 2597 2598
| Name    | Type  | Readable  | Writable  | Description                               |
| ------ | ------ | ---- | ---- | --------------------------------- |
| status | number | Yes   | Yes   | Hall effect sensor status. This parameter specifies whether a magnetic field exists around a device. The value **0** means that a magnetic field exists around the device, and **1** means the opposite.|
W
wusongqing 已提交
2599 2600 2601 2602 2603 2604


## MagneticFieldResponse

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

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

W
wusongqing 已提交
2607

W
wusongqing 已提交
2608 2609 2610 2611 2612
| Name| Type| Readable| Writable| Description                        |
| ---- | -------- | ---- | ---- | ---------------------------- |
| x    | number   | Yes  | Yes  | Magnetic field strength on the x-axis, in μT.|
| y    | number   | Yes  | Yes  | Magnetic field strength on the y-axis, in μT.|
| z    | number   | Yes  | Yes  | Magnetic field strength on the z-axis, in μT.|
W
wusongqing 已提交
2613 2614 2615 2616 2617 2618


## MagneticFieldUncalibratedResponse

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

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

W
wusongqing 已提交
2621

W
wusongqing 已提交
2622 2623 2624 2625 2626 2627 2628 2629
| Name   | Type  | Readable  | Writable  | Description                    |
| ----- | ------ | ---- | ---- | ---------------------- |
| x     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the x-axis, in μT.  |
| y     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the y-axis, in μT.  |
| z     | number | Yes   | Yes   | Uncalibrated magnetic field strength on the z-axis, in μT.  |
| biasX | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the x-axis, in μT.|
| biasY | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the y-axis, in μT.|
| biasZ | number | Yes   | Yes   | Bias of the uncalibrated magnetic field strength on the z-axis, in μT.|
W
wusongqing 已提交
2630 2631 2632 2633 2634 2635


## PedometerResponse

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

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

W
wusongqing 已提交
2638

W
wusongqing 已提交
2639 2640 2641
| Name   | Type  | Readable  | Writable  | Description      |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | Yes   | Yes   | Number of steps a user has walked.|
W
wusongqing 已提交
2642 2643 2644 2645 2646 2647


## HumidityResponse

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

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

W
wusongqing 已提交
2650

W
wusongqing 已提交
2651 2652 2653
| Name      | Type  | Readable  | Writable  | Description                                  |
| -------- | ------ | ---- | ---- | ------------------------------------ |
| humidity | number | Yes   | Yes   | Ambient relative humidity, in a percentage (%).|
W
wusongqing 已提交
2654 2655


W
wusongqing 已提交
2656
## PedometerDetectionResponse
W
wusongqing 已提交
2657 2658 2659

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

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

W
wusongqing 已提交
2662

W
wusongqing 已提交
2663 2664 2665
| Name    | Type  | Readable  | Writable  | Description                                      |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| scalar | number | Yes   | Yes   | Pedometer detection. This parameter specifies whether a user takes a step. The value **0** means that the user does not take a step, and **1** means that the user takes a step.|
W
wusongqing 已提交
2666 2667 2668 2669 2670 2671


## AmbientTemperatureResponse

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

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

W
wusongqing 已提交
2674

W
wusongqing 已提交
2675 2676 2677
| Name         | Type  | Readable  | Writable  | Description           |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | Yes   | Yes   | Ambient temperature, in degree Celsius.|
W
wusongqing 已提交
2678 2679 2680 2681 2682 2683


## BarometerResponse

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

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

W
wusongqing 已提交
2686

W
wusongqing 已提交
2687 2688 2689
| Name      | Type  | Readable  | Writable  | Description          |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | Yes   | Yes   | Atmospheric pressure, in pascal.|
W
wusongqing 已提交
2690 2691 2692 2693 2694 2695


## HeartRateResponse

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

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

W
wusongqing 已提交
2698

W
wusongqing 已提交
2699 2700 2701
| Name       | Type  | Readable  | Writable  | Description                   |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | Yes   | Yes   | Heart rate, in beats per minute (bpm).|
W
wusongqing 已提交
2702 2703 2704 2705 2706 2707


## WearDetectionResponse

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

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

W
wusongqing 已提交
2710

W
wusongqing 已提交
2711 2712 2713
| Name   | Type  | Readable  | Writable  | Description                       |
| ----- | ------ | ---- | ---- | ------------------------- |
| value | number | Yes   | Yes   | Whether the device is being worn. The value **1** means that the device is being worn, and **0** means the opposite.|
W
wusongqing 已提交
2714 2715 2716


## Options
Z
zengyawen 已提交
2717 2718 2719

Describes the sensor data reporting frequency.

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

W
wusongqing 已提交
2722 2723
| Name      | Type  | Description                         |
| -------- | ------ | --------------------------- |
W
wusongqing 已提交
2724 2725
| interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.|

W
wusongqing 已提交
2726 2727 2728 2729
## RotationMatrixResponse

Describes the response for setting the rotation matrix.

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

W
wusongqing 已提交
2732 2733 2734 2735
| Name         | Type               | Readable  | Writable  | Description   |
| ----------- | ------------------- | ---- | ---- | ----- |
| rotation    | Array&lt;number&gt; | Yes   | Yes   | Rotation matrix.|
| inclination | Array&lt;number&gt; | Yes   | Yes   | Inclination matrix.|
W
wusongqing 已提交
2736 2737 2738 2739 2740 2741


## CoordinatesOptions

Describes the coordinate options.

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

W
wusongqing 已提交
2744 2745 2746 2747
| Name  | Type  | Readable  | Writable  | Description    |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | Yes   | Yes   | X coordinate direction.|
| y    | number | Yes   | Yes   | Y coordinate direction.|
W
wusongqing 已提交
2748

W
wusongqing 已提交
2749 2750 2751 2752 2753

## GeomagneticResponse

Describes a geomagnetic response object. It extends from [Response](#response).

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

W
wusongqing 已提交
2756 2757 2758 2759 2760 2761 2762 2763 2764
| Name             | Type  | Readable  | Writable  | Description                       |
| --------------- | ------ | ---- | ---- | ------------------------- |
| x               | number | Yes   | Yes   | North component of the geomagnetic field.                 |
| y               | number | Yes   | Yes   | East component of the geomagnetic field.                 |
| z               | number | Yes   | Yes   | Vertical component of the geomagnetic field.                |
| geomagneticDip  | number | Yes   | Yes   | Magnetic dip, also called magnetic inclination, which is the angle measured from the horizontal plane to the magnetic field vector.      |
| deflectionAngle | number | Yes   | Yes   | Magnetic declination, which is the angle between true north (geographic north) and the magnetic north (the horizontal component of the field).|
| levelIntensity  | number | Yes   | Yes   | Horizontal intensity of the magnetic field vector field.                |
| totalIntensity  | number | Yes   | Yes   | Total intensity of the magnetic field vector.                 |
W
wusongqing 已提交
2765 2766

## LocationOptions
Z
zengyawen 已提交
2767

W
wusongqing 已提交
2768 2769 2770 2771
Describes the geographical location.

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

W
wusongqing 已提交
2772 2773 2774 2775 2776
| Name       | Type  | Readable  | Writable  | Description   |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | Yes   | Yes   | Latitude.  |
| longitude | number | Yes   | Yes   | Longitude.  |
| altitude  | number | Yes   | Yes   | Altitude.|