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

W
wusongqing 已提交
3
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
W
wusongqing 已提交
4
> 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 已提交
5

W
wusongqing 已提交
6 7

## Modules to Import
Z
zengyawen 已提交
8 9 10 11 12

```
import sensor from '@ohos.sensor';
```

W
wusongqing 已提交
13

W
wusongqing 已提交
14
## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
W
wusongqing 已提交
15

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

W
wusongqing 已提交
18
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 已提交
19

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

W
wusongqing 已提交
22
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
23

W
wusongqing 已提交
24

W
wusongqing 已提交
25 26 27 28 29 30
**Parameters**
| 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 已提交
31

W
wusongqing 已提交
32
**Example**
W
wusongqing 已提交
33
  ```
W
wusongqing 已提交
34
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
W
wusongqing 已提交
35 36 37 38
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
39
      {interval: 10000000}
W
wusongqing 已提交
40 41
  );
  ```
Z
zengyawen 已提交
42 43


W
wusongqing 已提交
44
## sensor.on(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
Z
zengyawen 已提交
45

W
wusongqing 已提交
46
on(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>, options?: Options): void
Z
zengyawen 已提交
47 48 49

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 已提交
50 51 52 53
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
54 55 56 57 58 59
**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<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | 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 已提交
60

W
wusongqing 已提交
61
**Example**
W
wusongqing 已提交
62
  ```
W
wusongqing 已提交
63
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,function(data){
W
wusongqing 已提交
64 65 66 67
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
68
      {interval: 10000000}
W
wusongqing 已提交
69 70
  );
  ```
Z
zengyawen 已提交
71 72


W
wusongqing 已提交
73
## sensor.on(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
Z
zengyawen 已提交
74

W
wusongqing 已提交
75
on(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>, options?: Options): void
Z
zengyawen 已提交
76 77 78

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 已提交
79 80 81 82
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
83 84 85 86 87 88
**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<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | 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 已提交
89

W
wusongqing 已提交
90
**Example**
W
wusongqing 已提交
91
  ```
W
wusongqing 已提交
92
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,function(data){
W
wusongqing 已提交
93 94 95 96 97 98 99
      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 已提交
100
      {interval: 10000000}
W
wusongqing 已提交
101 102
  );
  ```
Z
zengyawen 已提交
103 104


W
wusongqing 已提交
105
## sensor.on(SensorType.SENSOR_TYPE_ID_GRAVITY)
Z
zengyawen 已提交
106

W
wusongqing 已提交
107
on(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>,options?: Options): void
Z
zengyawen 已提交
108

W
wusongqing 已提交
109
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 已提交
110

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

W
wusongqing 已提交
113 114 115 116 117 118
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.  |
| callback | Callback<[GravityResponse](#gravityresponse)> | 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 已提交
119

W
wusongqing 已提交
120
**Example**
W
wusongqing 已提交
121
  ```
W
wusongqing 已提交
122
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY,function(data){
W
wusongqing 已提交
123 124 125 126
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
127
      {interval: 10000000}
W
wusongqing 已提交
128 129
  );
  ```
Z
zengyawen 已提交
130 131


W
wusongqing 已提交
132
## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE)
Z
zengyawen 已提交
133

W
wusongqing 已提交
134
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>, options?: Options): void
Z
zengyawen 已提交
135

W
wusongqing 已提交
136
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 已提交
137

W
wusongqing 已提交
138 139 140 141
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
142 143 144 145 146 147
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.  |
| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | 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 已提交
148

W
wusongqing 已提交
149
**Example**
W
wusongqing 已提交
150
  ```
W
wusongqing 已提交
151
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE,function(data){
W
wusongqing 已提交
152 153 154 155
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
156
      {interval: 10000000}
W
wusongqing 已提交
157 158
  );
  ```
Z
zengyawen 已提交
159 160


W
wusongqing 已提交
161
## sensor.on(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
Z
zengyawen 已提交
162

W
wusongqing 已提交
163
on(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback:Callback<GyroscopeUncalibratedResponse>, options?: Options): void
Z
zengyawen 已提交
164 165 166

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 已提交
167 168 169 170
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
171 172 173 174 175 176
**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<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | 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 已提交
177

W
wusongqing 已提交
178
**Example**
W
wusongqing 已提交
179
  ```
W
wusongqing 已提交
180
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,function(data){
W
wusongqing 已提交
181 182 183 184 185 186 187
      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 已提交
188
      {interval: 10000000}
W
wusongqing 已提交
189 190
  );
  ```
Z
zengyawen 已提交
191 192


W
wusongqing 已提交
193
## sensor.on(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
Z
zengyawen 已提交
194

W
wusongqing 已提交
195
on(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback: Callback<SignificantMotionResponse>, options?: Options): void
Z
zengyawen 已提交
196 197 198

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 已提交
199 200
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
201 202 203 204 205 206
**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<[SignificantMotionResponse](#significantmotionresponse)> | 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 已提交
207

W
wusongqing 已提交
208
**Example**
W
wusongqing 已提交
209
  ```
W
wusongqing 已提交
210
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,function(data){
W
wusongqing 已提交
211 212 213 214 215
      console.info('Scalar data: ' + data.scalar);
  },
      {interval: 10000000}
  );
  ```
Z
zengyawen 已提交
216 217


W
wusongqing 已提交
218
## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
Z
zengyawen 已提交
219

W
wusongqing 已提交
220
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback: Callback<PedometerDetectionResponse>, options?: Options): void
Z
zengyawen 已提交
221 222 223

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 已提交
224 225 226 227
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
228 229 230 231 232 233
**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<[PedometerDetectionResponse](#pedometerdetectionresponse)> | 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 已提交
234

W
wusongqing 已提交
235
**Example**
W
wusongqing 已提交
236
  ```
W
wusongqing 已提交
237
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,function(data){
W
wusongqing 已提交
238 239
      console.info('Scalar data: ' + data.scalar);
  },
Z
zengyawen 已提交
240
      {interval: 10000000}
W
wusongqing 已提交
241 242
  );
  ```
Z
zengyawen 已提交
243 244


W
wusongqing 已提交
245
## sensor.on(SensorType.SENSOR_TYPE_ID_PEDOMETER)
Z
zengyawen 已提交
246

W
wusongqing 已提交
247
on(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>, options?: Options): void
Z
zengyawen 已提交
248

W
wusongqing 已提交
249
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 已提交
250

W
wusongqing 已提交
251 252 253 254
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
255 256 257 258 259 260
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.  |
| callback | Callback<[PedometerResponse](#pedometerresponse)> | 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 已提交
261

W
wusongqing 已提交
262
**Example**
W
wusongqing 已提交
263
  ```
W
wusongqing 已提交
264
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER,function(data){
W
wusongqing 已提交
265 266
      console.info('Steps: ' + data.steps);
  },
Z
zengyawen 已提交
267
      {interval: 10000000}
W
wusongqing 已提交
268 269
  );
  ```
Z
zengyawen 已提交
270 271


W
wusongqing 已提交
272
## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
Z
zengyawen 已提交
273

W
wusongqing 已提交
274
on(type:SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback:Callback<AmbientTemperatureResponse>,  options?: Options): void
Z
zengyawen 已提交
275 276 277

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 已提交
278 279
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
280 281 282 283 284 285
**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<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | 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 已提交
286

W
wusongqing 已提交
287
**Example**
W
wusongqing 已提交
288
  ```
W
wusongqing 已提交
289
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,function(data){
W
wusongqing 已提交
290 291
      console.info('Temperature: ' + data.temperature);
  },
Z
zengyawen 已提交
292
      {interval: 10000000}
W
wusongqing 已提交
293 294
  );
  ```
Z
zengyawen 已提交
295 296


W
wusongqing 已提交
297
## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
Z
zengyawen 已提交
298

W
wusongqing 已提交
299
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>,options?: Options): void
Z
zengyawen 已提交
300 301 302

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 已提交
303 304
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
305 306 307 308 309 310
**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<[MagneticFieldResponse](#magneticfieldresponse)> | 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 已提交
311

W
wusongqing 已提交
312
**Example**
W
wusongqing 已提交
313
  ```
W
wusongqing 已提交
314
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD,function(data){
W
wusongqing 已提交
315 316 317 318
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
  },
Z
zengyawen 已提交
319
      {interval: 10000000}
W
wusongqing 已提交
320 321
  );
  ```
Z
zengyawen 已提交
322 323


W
wusongqing 已提交
324
## sensor.on(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
Z
zengyawen 已提交
325

W
wusongqing 已提交
326
on(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>, options?: Options): void
Z
zengyawen 已提交
327 328 329

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 已提交
330 331
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
332 333 334 335 336 337
**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<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | 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 已提交
338

W
wusongqing 已提交
339
**Example**
W
wusongqing 已提交
340
  ```
W
wusongqing 已提交
341
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,function(data){
W
wusongqing 已提交
342 343 344 345 346 347 348 349 350 351
      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 已提交
352 353


W
wusongqing 已提交
354
## sensor.on(SensorType.SENSOR_TYPE_ID_PROXIMITY)
Z
zengyawen 已提交
355

W
wusongqing 已提交
356
on(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>,options?: Options): void
Z
zengyawen 已提交
357

W
wusongqing 已提交
358
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 已提交
359

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

W
wusongqing 已提交
362 363 364 365 366 367
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.  |
| callback | Callback<[ProximityResponse](#proximityresponse)> | 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 已提交
368

W
wusongqing 已提交
369
**Example**
W
wusongqing 已提交
370
  ```
W
wusongqing 已提交
371
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY,function(data){
W
wusongqing 已提交
372 373
      console.info('Distance: ' + data.distance);
  },
Z
zengyawen 已提交
374
      {interval: 10000000}
W
wusongqing 已提交
375 376
  );
  ```
Z
zengyawen 已提交
377 378


W
wusongqing 已提交
379
## sensor.on(SensorType.SENSOR_TYPE_ID_HUMIDITY)
Z
zengyawen 已提交
380

W
wusongqing 已提交
381
on(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>,options?: Options): void
Z
zengyawen 已提交
382

W
wusongqing 已提交
383
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 已提交
384

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

W
wusongqing 已提交
387 388 389 390 391 392
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                    |
| -------- | ---------------------------------------- | ---- | -------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
| callback | Callback<[HumidityResponse](#humidityresponse)> | 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 已提交
393

W
wusongqing 已提交
394
**Example**
W
wusongqing 已提交
395
  ```
W
wusongqing 已提交
396
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY,function(data){
W
wusongqing 已提交
397 398
      console.info('Humidity: ' + data.humidity);
  },
Z
zengyawen 已提交
399
      {interval: 10000000}
W
wusongqing 已提交
400 401
  );
  ```
Z
zengyawen 已提交
402 403


W
wusongqing 已提交
404
## sensor.on(SensorType.SENSOR_TYPE_ID_BAROMETER)
Z
zengyawen 已提交
405

W
wusongqing 已提交
406
on(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>,options?: Options): void
Z
zengyawen 已提交
407

W
wusongqing 已提交
408
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 已提交
409

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

W
wusongqing 已提交
412 413 414 415 416 417
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.  |
| callback | Callback<[BarometerResponse](#barometerresponse)> | 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 已提交
418

W
wusongqing 已提交
419
**Example**
W
wusongqing 已提交
420
  ```
W
wusongqing 已提交
421
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER,function(data){
W
wusongqing 已提交
422 423
      console.info('Atmospheric pressure: ' + data.pressure);
  },
Z
zengyawen 已提交
424
      {interval: 10000000}
W
wusongqing 已提交
425 426
  );
  ```
Z
zengyawen 已提交
427 428


W
wusongqing 已提交
429
## sensor.on(SensorType.SENSOR_TYPE_ID_HALL)
Z
zengyawen 已提交
430

W
wusongqing 已提交
431
on(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>, options?: Options): void
Z
zengyawen 已提交
432 433 434

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 已提交
435 436
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
437 438 439 440 441 442
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
| callback | Callback<[HallResponse](#hallresponse)> | 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 已提交
443

W
wusongqing 已提交
444
**Example**
W
wusongqing 已提交
445
  ```
W
wusongqing 已提交
446
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL,function(data){
W
wusongqing 已提交
447 448
      console.info('Status: ' + data.status);
  },
Z
zengyawen 已提交
449
      {interval: 10000000}
W
wusongqing 已提交
450 451
  );
  ```
Z
zengyawen 已提交
452 453


W
wusongqing 已提交
454
## sensor.on(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)
Z
zengyawen 已提交
455

W
wusongqing 已提交
456
on(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>, options?: Options): void
Z
zengyawen 已提交
457 458 459

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 已提交
460 461
**System capability**: SystemCapability.Sensors.Sensor

W
wusongqing 已提交
462 463 464 465 466 467
**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<[LightResponse](#lightresponse)> | 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 已提交
468

W
wusongqing 已提交
469
**Example**
W
wusongqing 已提交
470
  ```
W
wusongqing 已提交
471
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT,function(data){
W
wusongqing 已提交
472 473
      console.info(' Illumination: ' + data.intensity);
  },
Z
zengyawen 已提交
474
      {interval: 10000000}
W
wusongqing 已提交
475 476
  );
  ```
Z
zengyawen 已提交
477 478


W
wusongqing 已提交
479
## sensor.on(SensorType.SENSOR_TYPE_ID_ORIENTATION)
Z
zengyawen 已提交
480

W
wusongqing 已提交
481
on(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>, options?: Options): void
Z
zengyawen 已提交
482

W
wusongqing 已提交
483
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 已提交
484

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

W
wusongqing 已提交
487 488 489 490 491 492
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.  |
| callback | Callback<[OrientationResponse](#orientationresponse)> | 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 已提交
493

W
wusongqing 已提交
494
**Example**
W
wusongqing 已提交
495
  ```
W
wusongqing 已提交
496 497 498 499
  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 已提交
500
  },
Z
zengyawen 已提交
501
      {interval: 10000000}
W
wusongqing 已提交
502 503
  );
  ```
Z
zengyawen 已提交
504

W
wusongqing 已提交
505 506 507 508 509 510 511 512 513 514
## sensor.on(SensorType.SENSOR_TYPE_ID_HEART_RATE)

on(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>, 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

W
wusongqing 已提交
515
**Parameters**
W
wusongqing 已提交
516

W
wusongqing 已提交
517 518 519 520
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HEART_RATE**.  |
| callback | Callback<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
521

W
wusongqing 已提交
522
**Example**
Z
zengyawen 已提交
523

W
wusongqing 已提交
524 525 526 527 528 529 530
```
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE,function(data){
    console.info("Heart rate: " + data.heartRate);
},
    {interval: 10000000}
);
```
Z
zengyawen 已提交
531

W
wusongqing 已提交
532 533 534
## sensor.on(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)

on(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,callback: Callback<RotationVectorResponse>,options?: Options): void
Z
zengyawen 已提交
535

W
wusongqing 已提交
536
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 已提交
537

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

W
wusongqing 已提交
540 541 542 543 544 545
**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<[RotationVectorResponse](#rotationvectorresponse)> | 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 已提交
546

W
wusongqing 已提交
547
**Example**
W
wusongqing 已提交
548
  ```
W
wusongqing 已提交
549
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR,function(data){
W
wusongqing 已提交
550 551 552
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
W
wusongqing 已提交
553
      console.info('Scalar quantity: ' + data.w);
W
wusongqing 已提交
554
  },
Z
zengyawen 已提交
555
      {interval: 10000000}
W
wusongqing 已提交
556 557
  );
  ```
Z
zengyawen 已提交
558 559


W
wusongqing 已提交
560
## sensor.on(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
Z
zengyawen 已提交
561

W
wusongqing 已提交
562
on(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>,options?: Options): void
Z
zengyawen 已提交
563

W
wusongqing 已提交
564
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 已提交
565

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

W
wusongqing 已提交
568 569 570 571 572 573
**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<[WearDetectionResponse](#weardetectionresponse)> | 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 已提交
574

W
wusongqing 已提交
575
**Example**
W
wusongqing 已提交
576
  ```
W
wusongqing 已提交
577
  sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION,function(data){
W
wusongqing 已提交
578 579
      console.info('Wear status: ' + data.value);
  },
Z
zengyawen 已提交
580
      {interval: 10000000}
W
wusongqing 已提交
581 582
  );
  ```
Z
zengyawen 已提交
583 584


W
wusongqing 已提交
585
## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)
Z
zengyawen 已提交
586

W
wusongqing 已提交
587
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback: Callback<AccelerometerResponse>): void
Z
zengyawen 已提交
588

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

W
wusongqing 已提交
591 592 593 594
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
595 596 597 598 599
**Parameters**
| 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   | One-shot callback used to return the acceleration sensor data. The reported data type in the callback is **AccelerometerResponse**.|
W
wusongqing 已提交
600

W
wusongqing 已提交
601
**Example**
W
wusongqing 已提交
602
  ```
W
wusongqing 已提交
603
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER,function(data){
W
wusongqing 已提交
604 605 606 607 608 609
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
610 611


W
wusongqing 已提交
612
## sensor.once(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
Z
zengyawen 已提交
613

W
wusongqing 已提交
614
once(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION,callback:Callback<LinearAccelerometerResponse>): void
Z
zengyawen 已提交
615 616 617

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

W
wusongqing 已提交
618 619 620 621
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
622 623 624 625 626
**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<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes   | One-shot callback used to return the linear acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
W
wusongqing 已提交
627

W
wusongqing 已提交
628
**Example**
W
wusongqing 已提交
629
  ```
W
wusongqing 已提交
630
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function(data) {
W
wusongqing 已提交
631 632 633 634 635 636
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
637 638


W
wusongqing 已提交
639
## sensor.once(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)
Z
zengyawen 已提交
640

W
wusongqing 已提交
641
once(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED,callback: Callback<AccelerometerUncalibratedResponse>): void
Z
zengyawen 已提交
642 643 644

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

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

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

W
wusongqing 已提交
649 650 651 652 653
**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<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
W
wusongqing 已提交
654

W
wusongqing 已提交
655
**Example**
W
wusongqing 已提交
656
  ```
W
wusongqing 已提交
657
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function(data) {
W
wusongqing 已提交
658 659 660 661 662 663 664 665 666 667 668
      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 已提交
669
## sensor.once(SensorType.SENSOR_TYPE_ID_GRAVITY)
W
wusongqing 已提交
670

W
wusongqing 已提交
671
once(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback: Callback<GravityResponse>): void
W
wusongqing 已提交
672 673 674

Subscribes to only one data change of the gravity sensor.

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

W
wusongqing 已提交
677 678 679 680 681
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GRAVITY**.        |
| callback | Callback<[GravityResponse](#gravityresponse)> | Yes   | One-shot callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
W
wusongqing 已提交
682

W
wusongqing 已提交
683
**Example**
W
wusongqing 已提交
684
  ```
W
wusongqing 已提交
685
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function(data) {
W
wusongqing 已提交
686 687 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);
    }
  );
  ```


W
wusongqing 已提交
694
## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE)
W
wusongqing 已提交
695

W
wusongqing 已提交
696
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback: Callback<GyroscopeResponse>): void
W
wusongqing 已提交
697 698 699

Subscribes to only one data change of the gyroscope sensor.

W
wusongqing 已提交
700 701 702 703
**Required permissions**: ohos.permission.GYROSCOPE (a system permission)

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

W
wusongqing 已提交
704 705 706 707 708
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_GYROSCOPE**.      |
| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes   | One-shot callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
W
wusongqing 已提交
709

W
wusongqing 已提交
710
**Example**
W
wusongqing 已提交
711
  ```
W
wusongqing 已提交
712
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, function(data) {
W
wusongqing 已提交
713 714 715 716 717 718
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
719 720


W
wusongqing 已提交
721
## sensor.once(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)
Z
zengyawen 已提交
722

W
wusongqing 已提交
723
once(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED,callback: Callback<GyroscopeUncalibratedResponse>): void
Z
zengyawen 已提交
724 725 726

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

W
wusongqing 已提交
727 728 729 730
**Required permissions**: ohos.permission.GYROSCOPE (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_GYROSCOPE_UNCALIBRATED**.|
| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
736

W
wusongqing 已提交
737
**Example**
W
wusongqing 已提交
738
  ```
W
wusongqing 已提交
739
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function(data) {
W
wusongqing 已提交
740 741 742 743 744 745 746 747 748
      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 已提交
749 750


W
wusongqing 已提交
751
## sensor.once(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
Z
zengyawen 已提交
752

W
wusongqing 已提交
753
once(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION,callback: Callback<SignificantMotionResponse>): void
Z
zengyawen 已提交
754 755 756

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

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

W
wusongqing 已提交
759 760 761 762 763
**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<[SignificantMotionResponse](#significantmotionresponse)> | Yes   | One-shot callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
W
wusongqing 已提交
764

W
wusongqing 已提交
765
**Example**
W
wusongqing 已提交
766
  ```
W
wusongqing 已提交
767
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function(data) {
W
wusongqing 已提交
768 769 770 771
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
Z
zengyawen 已提交
772 773


W
wusongqing 已提交
774
## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)
Z
zengyawen 已提交
775

W
wusongqing 已提交
776
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION,callback: Callback<PedometerDetectionResponse>): void
Z
zengyawen 已提交
777 778 779

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

W
wusongqing 已提交
780 781 782 783
**Required permissions**: ohos.permission.ACTIVITY_MOTION

**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_PEDOMETER_DETECTION**.|
| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes   | One-shot callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
W
wusongqing 已提交
789

W
wusongqing 已提交
790
**Example**
W
wusongqing 已提交
791
  ```
W
wusongqing 已提交
792
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function(data) {
W
wusongqing 已提交
793 794 795 796
      console.info('Scalar data: ' + data.scalar);
    }
  );
  ```
Z
zengyawen 已提交
797 798


W
wusongqing 已提交
799
## sensor.once(SensorType.SENSOR_TYPE_ID_PEDOMETER)
Z
zengyawen 已提交
800

W
wusongqing 已提交
801
once(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback: Callback<PedometerResponse>): void
Z
zengyawen 已提交
802

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

W
wusongqing 已提交
805 806 807 808
**Required permissions**: ohos.permission.ACTIVITY_MOTION

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

W
wusongqing 已提交
809 810 811 812 813
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PEDOMETER**.       |
| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes   | One-shot callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
814

W
wusongqing 已提交
815
**Example**
W
wusongqing 已提交
816
  ```
W
wusongqing 已提交
817
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function(data) {
W
wusongqing 已提交
818 819 820 821
      console.info('Steps: ' + data.steps);
    }
  );
  ```
Z
zengyawen 已提交
822 823


W
wusongqing 已提交
824
## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)
Z
zengyawen 已提交
825

W
wusongqing 已提交
826
once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE,callback: Callback<AmbientTemperatureResponse>): void
Z
zengyawen 已提交
827 828 829

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

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

W
wusongqing 已提交
832 833 834 835 836
**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<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes   | One-shot callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
W
wusongqing 已提交
837

W
wusongqing 已提交
838
**Example**
W
wusongqing 已提交
839
  ```
W
wusongqing 已提交
840
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function(data) {
W
wusongqing 已提交
841 842 843 844
      console.info('Temperature: ' + data.temperature);
    }
  );
  ```
Z
zengyawen 已提交
845 846


W
wusongqing 已提交
847
## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
Z
zengyawen 已提交
848

W
wusongqing 已提交
849
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback: Callback<MagneticFieldResponse>): void
Z
zengyawen 已提交
850 851 852

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

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

W
wusongqing 已提交
855 856 857 858 859
**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<[MagneticFieldResponse](#magneticfieldresponse)> | Yes   | One-shot callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
860

W
wusongqing 已提交
861
**Example**
W
wusongqing 已提交
862
  ```
W
wusongqing 已提交
863
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function(data) {
W
wusongqing 已提交
864 865 866 867 868 869
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
    }
  );
  ```
Z
zengyawen 已提交
870 871


W
wusongqing 已提交
872
## sensor.once(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
Z
zengyawen 已提交
873

W
wusongqing 已提交
874
once(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED,callback: Callback<MagneticFieldUncalibratedResponse>): void
Z
zengyawen 已提交
875 876 877

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

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

W
wusongqing 已提交
880 881 882 883 884
**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<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes   | One-shot callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
W
wusongqing 已提交
885

W
wusongqing 已提交
886
**Example**
W
wusongqing 已提交
887
  ```
W
wusongqing 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
  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);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_PROXIMITY)

once(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback: Callback<ProximityResponse>): void

Subscribes to only one data change of the proximity sensor.

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

W
wusongqing 已提交
908 909 910 911 912
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_PROXIMITY**.      |
| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes   | One-shot callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
W
wusongqing 已提交
913

W
wusongqing 已提交
914
**Example**
W
wusongqing 已提交
915 916
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function(error, data) {
W
wusongqing 已提交
917 918 919
      if (error) {
          console.error("Subscription failed. Error code: " + error.code + "; message: " + error.message);
          return;
Z
zengyawen 已提交
920
      }
W
wusongqing 已提交
921 922 923 924 925 926 927 928 929 930 931 932 933 934
      console.info('Distance: ' + data.distance);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_HUMIDITY)

once(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback: Callback<HumidityResponse>): void

Subscribes to only one data change of the humidity sensor.

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

W
wusongqing 已提交
935 936 937 938 939
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HUMIDITY**.        |
| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes   | One-shot callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
940

W
wusongqing 已提交
941
**Example**
W
wusongqing 已提交
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function(data) {
      console.info('Humidity: ' + data.humidity);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_BAROMETER)

once(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback: Callback<BarometerResponse>): void

Subscribes to only one data change of the barometer sensor.

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

W
wusongqing 已提交
958 959 960 961 962
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_BAROMETER**.      |
| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes   | One-shot callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
W
wusongqing 已提交
963

W
wusongqing 已提交
964
**Example**
W
wusongqing 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function(data) {
      console.info('Atmospheric pressure: ' + data.pressure);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_HALL)

once(type: SensorType.SENSOR_TYPE_ID_HALL, callback: Callback<HallResponse>): void

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

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

W
wusongqing 已提交
981 982 983 984 985
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                  |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_HALL**.        |
| callback | Callback<[HallResponse](#hallresponse)> | Yes   | One-shot callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
986

W
wusongqing 已提交
987
**Example**
W
wusongqing 已提交
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, function(data) {
      console.info('Status: ' + data.status);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)

once(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback: Callback<LightResponse>): void

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

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

W
wusongqing 已提交
1004 1005 1006 1007 1008
**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<[LightResponse](#lightresponse)> | Yes   | One-shot callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.|
W
wusongqing 已提交
1009

W
wusongqing 已提交
1010
**Example**
W
wusongqing 已提交
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, function(data) {
      console.info(' Illumination: ' + data.intensity);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_ORIENTATION)

once(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback: Callback<OrientationResponse>): void

Subscribes to only one data change of the orientation sensor.

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

W
wusongqing 已提交
1027 1028 1029 1030 1031
**Parameters**
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to subscribe to, which is **SENSOR_TYPE_ID_ORIENTATION**.     |
| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes   | One-shot callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
W
wusongqing 已提交
1032

W
wusongqing 已提交
1033
**Example**
W
wusongqing 已提交
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
  ```
  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);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)

once(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback: Callback<RotationVectorResponse>): void

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

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

W
wusongqing 已提交
1052 1053 1054 1055 1056
**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<[RotationVectorResponse](#rotationvectorresponse)> | Yes   | One-shot callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
W
wusongqing 已提交
1057

W
wusongqing 已提交
1058
**Example**
W
wusongqing 已提交
1059 1060
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function(data) {
W
wusongqing 已提交
1061 1062 1063
      console.info('X-coordinate component: ' + data.x);
      console.info('Y-coordinate component: ' + data.y);
      console.info('Z-coordinate component: ' + data.z);
W
wusongqing 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
      console.info('Scalar quantity: ' + data.w);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_HEART_RATE)

once(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback: Callback<HeartRateResponse>): void

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

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

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

W
wusongqing 已提交
1080 1081 1082 1083 1084
**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<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1085

W
wusongqing 已提交
1086
**Example**
W
wusongqing 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function(data) {
      console.info("Heart rate: " + data.heartRate);
    }
  );
  ```


## sensor.once(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)

once(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback: Callback<WearDetectionResponse>): void

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

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

W
wusongqing 已提交
1103 1104 1105 1106 1107
**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<[WearDetectionResponse](#weardetectionresponse)> | Yes   | One-shot callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
W
wusongqing 已提交
1108

W
wusongqing 已提交
1109
**Example**
W
wusongqing 已提交
1110 1111 1112
  ```
  sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function(data) {
      console.info("Wear status: "+ data.value);
W
wusongqing 已提交
1113 1114 1115
    }
  );
  ```
Z
zengyawen 已提交
1116

W
wusongqing 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER)

off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback?: Callback<AccelerometerResponse>): void

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1127
**Parameters**
W
wusongqing 已提交
1128

W
wusongqing 已提交
1129 1130 1131 1132
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, 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**.|
W
wusongqing 已提交
1133

W
wusongqing 已提交
1134
**Example**
W
wusongqing 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154

```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED)

off(type: SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, callback?: Callback<AccelerometerUncalibratedResponse>): void

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1155
**Parameters**
W
wusongqing 已提交
1156

W
wusongqing 已提交
1157 1158 1159 1160
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED**.|
| callback | Callback<[AccelerometerUncalibratedResponse](#accelerometeruncalibratedresponse)> | Yes   | Callback used to return the uncalibrated acceleration sensor data. The reported data type in the callback is **AccelerometerUncalibratedResponse**.|
W
wusongqing 已提交
1161

W
wusongqing 已提交
1162
**Example**
W
wusongqing 已提交
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183

```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT)

off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback?: Callback<LightResponse>): void

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1184
**Parameters**
W
wusongqing 已提交
1185

W
wusongqing 已提交
1186 1187 1188 1189
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_LIGHT**.|
| callback | Callback<[LightResponse](#lightresponse)> | Yes   | Callback used to return the ambient light sensor data. The reported data type in the callback is **LightResponse**.  |
W
wusongqing 已提交
1190

W
wusongqing 已提交
1191
**Example**
W
wusongqing 已提交
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

```
function callback(data) {
    console.info(' Illumination: ' + data.intensity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)

off(type: SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback?: Callback<AmbientTemperatureResponse>): void

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1208
**Parameters**
W
wusongqing 已提交
1209

W
wusongqing 已提交
1210 1211 1212 1213
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_AMBIENT_TEMPERATURE**.|
| callback | Callback<[AmbientTemperatureResponse](#ambienttemperatureresponse)> | Yes   | Callback used to return the ambient temperature sensor data. The reported data type in the callback is **AmbientTemperatureResponse**.|
W
wusongqing 已提交
1214

W
wusongqing 已提交
1215
**Example**
W
wusongqing 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231

```
function callback(data) {
     console.info('Temperature: ' + data.temperature);
}
sensor.off( sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE)

off(type: SensorType.SENSOR_TYPE_ID_BAROMETER, callback?: Callback<BarometerResponse>): void

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1234 1235 1236 1237
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_BAROMETER**.|
| callback | Callback<[BarometerResponse](#barometerresponse)> | Yes   | Callback used to return the barometer sensor data. The reported data type in the callback is **BarometerResponse**.|
W
wusongqing 已提交
1238

W
wusongqing 已提交
1239
**Example**
W
wusongqing 已提交
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255

```
function callback(data) {
     console.info('Atmospheric pressure: ' + data.pressure);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_GRAVITY)

off(type: SensorType.SENSOR_TYPE_ID_GRAVITY, callback?: Callback<GravityResponse>): void

Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1256
**Parameters**
W
wusongqing 已提交
1257

W
wusongqing 已提交
1258 1259 1260 1261
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GRAVITY**.   |
| callback | Callback<[GravityResponse](#gravityresponse)> | Yes   | Callback used to return the gravity sensor data. The reported data type in the callback is **GravityResponse**.|
W
wusongqing 已提交
1262

W
wusongqing 已提交
1263
**Example**
W
wusongqing 已提交
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283

```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE)

off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback?: Callback<GyroscopeResponse>): void

Unsubscribes from sensor data changes.

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

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

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

W
wusongqing 已提交
1286 1287 1288 1289
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE**.|
| callback | Callback<[GyroscopeResponse](#gyroscoperesponse)> | Yes   | Callback used to return the gyroscope sensor data. The reported data type in the callback is **GyroscopeResponse**.|
W
wusongqing 已提交
1290

W
wusongqing 已提交
1291
**Example**
W
wusongqing 已提交
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303

```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED)

W
wusongqing 已提交
1304
off(type: SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, callback?: Callback<GyroscopeUncalibratedResponse>): void
W
wusongqing 已提交
1305 1306 1307 1308 1309 1310 1311

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1312
**Parameters**
W
wusongqing 已提交
1313

W
wusongqing 已提交
1314 1315 1316 1317
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED**.|
| callback | Callback<[GyroscopeUncalibratedResponse](#gyroscopeuncalibratedresponse)> | Yes   | Callback used to return the uncalibrated gyroscope sensor data. The reported data type in the callback is **GyroscopeUncalibratedResponse**.|
W
wusongqing 已提交
1318

W
wusongqing 已提交
1319
**Example**
W
wusongqing 已提交
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337

```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_HALL)

off(type: SensorType.SENSOR_TYPE_ID_HALL, callback?: Callback<HallResponse>): void

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1340 1341 1342 1343
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HALL**.      |
| callback | Callback<[HallResponse](#hallresponse)> | Yes   | Callback used to return the Hall effect sensor data. The reported data type in the callback is **HallResponse**.|
W
wusongqing 已提交
1344

W
wusongqing 已提交
1345
**Example**
W
wusongqing 已提交
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363

```
function callback(data) {
    console.info('Status: ' + data.status);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_HEART_RATE)

off(type: SensorType.SENSOR_TYPE_ID_HEART_RATE, callback?: Callback<HeartRateResponse>): void

Unsubscribes from sensor data changes.

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

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

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

W
wusongqing 已提交
1366 1367 1368 1369
| 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<[HeartRateResponse](#heartrateresponse)> | Yes   | One-shot callback used to return the heart rate sensor data. The reported data type in the callback is **HeartRateResponse**.|
W
wusongqing 已提交
1370

W
wusongqing 已提交
1371
**Example**
W
wusongqing 已提交
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389

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

## sensor.off(SensorType.SENSOR_TYPE_ID_HUMIDITY)

off(type: SensorType.SENSOR_TYPE_ID_HUMIDITY, callback?: Callback<HumidityResponse>): void

Unsubscribes from sensor data changes.

**Required permission**: ohos.permission.READ_HEALTH_DATA (a system permission)

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

W
wusongqing 已提交
1390
**Parameters**
W
wusongqing 已提交
1391

W
wusongqing 已提交
1392 1393 1394 1395
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_HUMIDITY**.  |
| callback | Callback<[HumidityResponse](#humidityresponse)> | Yes   | Callback used to return the humidity sensor data. The reported data type in the callback is **HumidityResponse**.|
W
wusongqing 已提交
1396

W
wusongqing 已提交
1397
**Example**
W
wusongqing 已提交
1398 1399 1400 1401 1402 1403 1404 1405 1406

```
function callback(data) {
    console.info('Humidity: ' + data.humidity);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION)
Z
zengyawen 已提交
1407

W
wusongqing 已提交
1408
off(type: SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, callback?: Callback<LinearAccelerometerResponse>): void
Z
zengyawen 已提交
1409

W
wusongqing 已提交
1410
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1411

W
wusongqing 已提交
1412 1413 1414
**Required permissions**: ohos.permission.ACCELEROMETER (a system permission)

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

W
wusongqing 已提交
1416
**Parameters**
W
wusongqing 已提交
1417

W
wusongqing 已提交
1418 1419 1420 1421
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_LINEAR_ACCELERATION**.|
| callback | Callback<[LinearAccelerometerResponse](#linearaccelerometerresponse)> | Yes   | Callback used to return the acceleration sensor data. The reported data type in the callback is **LinearAccelerometerResponse**.|
W
wusongqing 已提交
1422

W
wusongqing 已提交
1423
**Example**
Z
zengyawen 已提交
1424

W
wusongqing 已提交
1425 1426 1427 1428 1429 1430 1431 1432
```
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 已提交
1433

W
wusongqing 已提交
1434
## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD)
Z
zengyawen 已提交
1435

W
wusongqing 已提交
1436
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback?: Callback<MagneticFieldResponse>): void
Z
zengyawen 已提交
1437

W
wusongqing 已提交
1438 1439 1440 1441 1442
Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1444
**Parameters**
W
wusongqing 已提交
1445

W
wusongqing 已提交
1446 1447 1448 1449
| Name             | Type                                      | Mandatory  | Description                                      |
| ---------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type             | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_MAGNETIC_FIELD**.|
| callbackcallback | Callback<[MagneticFieldResponse](#magneticfieldresponse)> | Yes   | Callback used to return the magnetic field sensor data. The reported data type in the callback is **MagneticFieldResponse**.|
W
wusongqing 已提交
1450

W
wusongqing 已提交
1451
**Example**
W
wusongqing 已提交
1452

W
wusongqing 已提交
1453 1454 1455 1456 1457 1458 1459 1460
```
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 已提交
1461

W
wusongqing 已提交
1462
## sensor.off(SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED)
W
wusongqing 已提交
1463

W
wusongqing 已提交
1464
 off(type: SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, callback?: Callback<MagneticFieldUncalibratedResponse>): void
W
wusongqing 已提交
1465

W
wusongqing 已提交
1466 1467 1468
Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1470
**Parameters**
W
wusongqing 已提交
1471

W
wusongqing 已提交
1472 1473 1474 1475
| 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<[MagneticFieldUncalibratedResponse](#magneticfielduncalibratedresponse)> | Yes   | Callback used to return the uncalibrated magnetic field sensor data. The reported data type in the callback is **MagneticFieldUncalibratedResponse**.|
W
wusongqing 已提交
1476

W
wusongqing 已提交
1477
**Example**
Z
zengyawen 已提交
1478

W
wusongqing 已提交
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
```
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);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_ORIENTATION)
Z
zengyawen 已提交
1492

W
wusongqing 已提交
1493
 off(type: SensorType.SENSOR_TYPE_ID_ORIENTATION, callback?: Callback<OrientationResponse>): void
Z
zengyawen 已提交
1494

W
wusongqing 已提交
1495
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1496

W
wusongqing 已提交
1497
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1498

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

W
wusongqing 已提交
1501 1502 1503 1504
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ORIENTATION**.|
| callback | Callback<[OrientationResponse](#orientationresponse)> | Yes   | Callback used to return the orientation sensor data. The reported data type in the callback is **OrientationResponse**.|
W
wusongqing 已提交
1505

W
wusongqing 已提交
1506
**Example**
Z
zengyawen 已提交
1507

W
wusongqing 已提交
1508 1509 1510 1511 1512 1513 1514 1515
```
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 已提交
1516

W
wusongqing 已提交
1517
## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER)
Z
zengyawen 已提交
1518

W
wusongqing 已提交
1519
off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER, callback?: Callback<PedometerResponse>): void
Z
zengyawen 已提交
1520

W
wusongqing 已提交
1521 1522 1523
Unsubscribes from sensor data changes.

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

W
wusongqing 已提交
1525
**Parameters**
W
wusongqing 已提交
1526

W
wusongqing 已提交
1527 1528 1529 1530
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER**. |
| callback | Callback<[PedometerResponse](#pedometerresponse)> | Yes   | Callback used to return the pedometer sensor data. The reported data type in the callback is **PedometerResponse**.|
W
wusongqing 已提交
1531

W
wusongqing 已提交
1532
**Return value**
W
wusongqing 已提交
1533

W
wusongqing 已提交
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
```
function callback(data) {
    console.info('Steps: ' + data.steps);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION)

off(type: SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback?: Callback<PedometerDetectionResponse>): void
W
wusongqing 已提交
1544

W
wusongqing 已提交
1545
Unsubscribes from sensor data changes.
W
wusongqing 已提交
1546

W
wusongqing 已提交
1547
**Required permissions**: ohos.permission.ACTIVITY_MOTION
W
wusongqing 已提交
1548

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

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

W
wusongqing 已提交
1553 1554 1555 1556
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PEDOMETER_DETECTION**.|
| callback | Callback<[PedometerDetectionResponse](#pedometerdetectionresponse)> | Yes   | Callback used to return the pedometer detection sensor data. The reported data type in the callback is **PedometerDetectionResponse**.|
W
wusongqing 已提交
1557

W
wusongqing 已提交
1558
**Example**
Z
zengyawen 已提交
1559

W
wusongqing 已提交
1560 1561 1562 1563 1564 1565 1566 1567
```
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_PROXIMITY)
Z
zengyawen 已提交
1568

W
wusongqing 已提交
1569
off(type: SensorType.SENSOR_TYPE_ID_PROXIMITY, callback?: Callback<ProximityResponse>): void
Z
zengyawen 已提交
1570

W
wusongqing 已提交
1571
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1572

W
wusongqing 已提交
1573
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1574

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

W
wusongqing 已提交
1577 1578 1579 1580
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_PROXIMITY**.|
| callback | Callback<[ProximityResponse](#proximityresponse)> | Yes   | Callback used to return the proximity sensor data. The reported data type in the callback is **ProximityResponse**.|
W
wusongqing 已提交
1581

W
wusongqing 已提交
1582
**Example**
Z
zengyawen 已提交
1583

W
wusongqing 已提交
1584 1585 1586 1587 1588 1589 1590 1591
```
function callback(data) {
    console.info('Distance: ' + data.distance);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, callback);
```

## sensor.off(SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR)
Z
zengyawen 已提交
1592

W
wusongqing 已提交
1593
off(type: SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback?: Callback<RotationVectorResponse>): void
Z
zengyawen 已提交
1594

W
wusongqing 已提交
1595
Unsubscribes from sensor data changes.
Z
zengyawen 已提交
1596

W
wusongqing 已提交
1597
**System capability**: SystemCapability.Sensors.Sensor
Z
zengyawen 已提交
1598

W
wusongqing 已提交
1599
**Parameters**
W
wusongqing 已提交
1600

W
wusongqing 已提交
1601 1602 1603 1604
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_ROTATION_VECTOR**.|
| callback | Callback<[RotationVectorResponse](#rotationvectorresponse)> | Yes   | Callback used to return the rotation vector sensor data. The reported data type in the callback is **RotationVectorResponse**.|
W
wusongqing 已提交
1605

W
wusongqing 已提交
1606
**Example**
Z
zengyawen 已提交
1607

W
wusongqing 已提交
1608 1609 1610 1611 1612 1613 1614 1615 1616
```
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 已提交
1617

W
wusongqing 已提交
1618
## sensor.off(SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION)
Z
zengyawen 已提交
1619

W
wusongqing 已提交
1620
off(type: SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback?: Callback<SignificantMotionResponse>): void
Z
zengyawen 已提交
1621

W
wusongqing 已提交
1622 1623 1624
Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1628 1629 1630 1631
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_SIGNIFICANT_MOTION**.|
| callback | Callback<[SignificantMotionResponse](#significantmotionresponse)> | Yes   | Callback used to return the significant motion sensor data. The reported data type in the callback is **SignificantMotionResponse**.|
W
wusongqing 已提交
1632

W
wusongqing 已提交
1633
**Example**
Z
zengyawen 已提交
1634

W
wusongqing 已提交
1635 1636 1637 1638 1639 1640
```
function callback(data) {
    console.info('Scalar data: ' + data.scalar);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, callback);
```
Z
zengyawen 已提交
1641

W
wusongqing 已提交
1642
## sensor.off(SensorType.SENSOR_TYPE_ID_WEAR_DETECTION)
Z
zengyawen 已提交
1643

W
wusongqing 已提交
1644
off(type: SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, callback?: Callback<WearDetectionResponse>): void
Z
zengyawen 已提交
1645 1646 1647

Unsubscribes from sensor data changes.

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

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

W
wusongqing 已提交
1652 1653 1654 1655
| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type     | [SensorType](#sensortype)                | Yes   | Type of the sensor to unsubscribe from, which is **SENSOR_TYPE_ID_WEAR_DETECTION**.|
| callback | Callback<[WearDetectionResponse](#weardetectionresponse)> | Yes   | Callback used to return the wear detection sensor data. The reported data type in the callback is **WearDetectionResponse**.|
W
wusongqing 已提交
1656

W
wusongqing 已提交
1657
**Example**
W
wusongqing 已提交
1658 1659 1660 1661 1662 1663 1664

```
function accCallback(data) {
    console.info('Wear status: ' + data.value);
}
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, accCallback);
```
W
wusongqing 已提交
1665

W
wusongqing 已提交
1666 1667 1668 1669
## sensor.transformCoordinateSystem

transformCoordinateSystem(inRotationVector: Array<number>, coordinates: CoordinatesOptions, callback: AsyncCallback<Array<number>>): void

W
wusongqing 已提交
1670 1671 1672
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 已提交
1673

W
wusongqing 已提交
1674
**Parameters**
W
wusongqing 已提交
1675

W
wusongqing 已提交
1676 1677 1678 1679 1680
| Name             | Type                                      | Mandatory  | Description         |
| ---------------- | ---------------------------------------- | ---- | ----------- |
| inRotationVector | Array<number>                      | Yes   | Rotation vector to rotate.    |
| coordinates      | [CoordinatesOptions](#coordinatesoptions) | Yes   | Direction of the coordinate system.   |
| callback         | AsyncCallback<Array<number>> | Yes   | Callback used to return the rotation vector after being rotated.|
W
wusongqing 已提交
1681

W
wusongqing 已提交
1682
**Example**
W
wusongqing 已提交
1683

W
wusongqing 已提交
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
```
sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3}, function(err, data) {
    if (err) {
        console.error("Operation failed. Error code: " + err.code + ", message: " + err.message);
        return;
    }
    console.info("Operation successed. Data obtained: " + data.x);
    for (var i=0; i < data.length; i++) {
        console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
    }
 })
```
W
wusongqing 已提交
1696 1697 1698 1699
## sensor.transformCoordinateSystem

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

W
wusongqing 已提交
1700 1701 1702
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 已提交
1703

W
wusongqing 已提交
1704
**Parameters**
W
wusongqing 已提交
1705

W
wusongqing 已提交
1706 1707 1708 1709
| 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 已提交
1710

W
wusongqing 已提交
1711
**Return value**
W
wusongqing 已提交
1712

W
wusongqing 已提交
1713 1714 1715
| Type                                | Description         |
| ---------------------------------- | ----------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation vector after being rotated.|
W
wusongqing 已提交
1716

W
wusongqing 已提交
1717
**Example**
W
wusongqing 已提交
1718

W
wusongqing 已提交
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
```
const promise = sensor.transformCoordinateSystem([1, 0, 0, 0, 1, 0, 0, 0, 1], {'axisX':2, 'axisY':3});
    promise.then((data) => {
        console.info("Operation successed.");
        for (var i=0; i < data.length; i++) {
            console.info("transformCoordinateSystem data[ " + i + "] = " + data[i]);
        }
    }).catch((err) => {
           console.info("Operation failed");
})
```
W
wusongqing 已提交
1730 1731 1732 1733 1734

## sensor.getGeomagneticField

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

W
wusongqing 已提交
1735 1736 1737
Obtains the geomagnetic field of a geographic location. This API uses a callback to return the result.

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

W
wusongqing 已提交
1739 1740 1741 1742 1743 1744
**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 已提交
1745

W
wusongqing 已提交
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
**Example**
```
sensor.getGeomagneticField([80, 0, 0], 1580486400000, function(err, data)  {
    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 已提交
1758 1759 1760 1761
## sensor.getGeomagneticField

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

W
wusongqing 已提交
1762 1763 1764
Obtains the geomagnetic field of a geographic location. This API uses a promise to return the result.

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

W
wusongqing 已提交
1766 1767 1768 1769 1770
**Parameters**
| Name            | Type                                 | Mandatory  | Description               |
| --------------- | ----------------------------------- | ---- | ----------------- |
| locationOptions | [LocationOptions](#locationoptions) | Yes   | Geographic location.            |
| timeMillis      | number                              | Yes   | Time for obtaining the magnetic declination, in milliseconds.|
Z
zengyawen 已提交
1771

W
wusongqing 已提交
1772 1773 1774 1775
**Return value**
| Type                                      | Description     |
| ---------------------------------------- | ------- |
| Promise&lt;[GeomagneticResponse](#geomagneticresponse)&gt; | Promise used to return the geomagnetic field.|
Z
zengyawen 已提交
1776

W
wusongqing 已提交
1777
**Return value**
W
wusongqing 已提交
1778
  ```
W
wusongqing 已提交
1779
  const promise = sensor.getGeomagneticField([80, 0, 0], 1580486400000);
W
wusongqing 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788
      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 已提交
1789 1790 1791 1792
## sensor.getAltitude

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

W
wusongqing 已提交
1793 1794 1795
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 已提交
1796

W
wusongqing 已提交
1797
**Parameters**
W
wusongqing 已提交
1798

W
wusongqing 已提交
1799 1800 1801 1802 1803
| 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 已提交
1804

W
wusongqing 已提交
1805
**Return value**
W
wusongqing 已提交
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821

  ```
  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 已提交
1822 1823 1824
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 已提交
1825

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

W
wusongqing 已提交
1828 1829 1830 1831
| 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 已提交
1832

W
wusongqing 已提交
1833
**Return value**
W
wusongqing 已提交
1834

W
wusongqing 已提交
1835 1836 1837
| Type                   | Description                |
| --------------------- | ------------------ |
| Promise&lt;number&gt; | Promise used to return the altitude, in meters.|
W
wusongqing 已提交
1838

W
wusongqing 已提交
1839
**Return value**
W
wusongqing 已提交
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854

  ```
  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 已提交
1855 1856 1857
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 已提交
1858

W
wusongqing 已提交
1859
**Parameters**
W
wusongqing 已提交
1860

W
wusongqing 已提交
1861 1862 1863 1864
| 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 已提交
1865

W
wusongqing 已提交
1866
**Return value**
W
wusongqing 已提交
1867 1868 1869 1870 1871 1872 1873 1874

  ```
  sensor.getGeomagneticDip([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
W
wusongqing 已提交
1875
          console.info("Successed to get getGeomagneticDip interface get data: " + data);
W
wusongqing 已提交
1876 1877 1878 1879 1880 1881 1882
  })
  ```

## sensor.getGeomagneticDip

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

W
wusongqing 已提交
1883 1884 1885
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 已提交
1886

W
wusongqing 已提交
1887
**Parameters**
W
wusongqing 已提交
1888

W
wusongqing 已提交
1889 1890 1891
| Name              | Type                 | Mandatory  | Description     |
| ----------------- | ------------------- | ---- | ------- |
| inclinationMatrix | Array&lt;number&gt; | Yes   | Inclination matrix.|
W
wusongqing 已提交
1892

W
wusongqing 已提交
1893
**Return value**
W
wusongqing 已提交
1894

W
wusongqing 已提交
1895 1896 1897
| Type                   | Description            |
| --------------------- | -------------- |
| Promise&lt;number&gt; | Promise used to return the magnetic dip, in radians.|
W
wusongqing 已提交
1898

W
wusongqing 已提交
1899
**Return value**
W
wusongqing 已提交
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913

  ```
  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 已提交
1914 1915 1916
Obtains the angle change between two rotation matrices. This API uses a callback to return the result.

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

W
wusongqing 已提交
1918
**Parameters**
W
wusongqing 已提交
1919

W
wusongqing 已提交
1920 1921 1922 1923 1924
| 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 已提交
1925

W
wusongqing 已提交
1926
**Return value**
W
wusongqing 已提交
1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946

  ```
  sensor. getAngleModify([1,0,0,0,1,0,0,0,1], [1, 0, 0, 0, 0.87, -0.50, 0, 0.50, 0.87], function(err, data)  {
      if (err) {
          console.error(LABEL + 'Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get  getAngleModifiy interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor. getAngleModify

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

W
wusongqing 已提交
1947 1948 1949
Obtains the angle change between two rotation matrices. This API uses a promise to return the result.

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

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

W
wusongqing 已提交
1953 1954 1955 1956
| Name                  | Type                 | Mandatory  | Description       |
| --------------------- | ------------------- | ---- | --------- |
| currentRotationMatrix | Array&lt;number&gt; | Yes   | Current rotation matrix.|
| preRotationMatrix     | Array&lt;number&gt; | Yes   | Rotation matrix.  |
W
wusongqing 已提交
1957

W
wusongqing 已提交
1958
**Return value**
W
wusongqing 已提交
1959

W
wusongqing 已提交
1960 1961 1962
| 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 已提交
1963

W
wusongqing 已提交
1964
**Return value**
W
wusongqing 已提交
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982

  ```
  const promise = sensor.getAngleModify([1,0,0,0,1,0,0,0,1], [1,0,0,0,0.87,-0.50,0,0.50,0.87]);
      promise.then((data) => {
          console.info(LABEL + 'getAngleModifiy_promise success');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info(LABEL + "promise::catch", reason);
  })
  ```


## sensor.createRotationMatrix

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

W
wusongqing 已提交
1983 1984 1985
Converts a rotation vector into a rotation matrix. This API uses a callback to return the result.

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

W
wusongqing 已提交
1987
**Parameters**
W
wusongqing 已提交
1988

W
wusongqing 已提交
1989 1990 1991 1992
| 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 已提交
1993

W
wusongqing 已提交
1994
**Return value**
W
wusongqing 已提交
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014

  ```
  sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data) {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor.createRotationMatrix

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

W
wusongqing 已提交
2015 2016 2017
Converts a rotation vector into a rotation matrix. This API uses a promise to return the result.

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

W
wusongqing 已提交
2019
**Parameters**
W
wusongqing 已提交
2020

W
wusongqing 已提交
2021 2022 2023
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
W
wusongqing 已提交
2024

W
wusongqing 已提交
2025
**Return value**
W
wusongqing 已提交
2026

W
wusongqing 已提交
2027 2028 2029
| Type                                | Description     |
| ---------------------------------- | ------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
2030

W
wusongqing 已提交
2031
**Return value**
W
wusongqing 已提交
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049

  ```
  const promise = sensor.createRotationMatrix([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info(LABEL + 'createRotationMatrix_promise success');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((reason) => {
          console.info(LABEL + "promise::catch", reason);
  })	
  ```


## sensor.createQuaternion

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

W
wusongqing 已提交
2050 2051 2052
Converts a rotation vector into a quaternion. This API uses a callback to return the result.

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

W
wusongqing 已提交
2054
**Parameters**
W
wusongqing 已提交
2055

W
wusongqing 已提交
2056 2057 2058 2059
| 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 已提交
2060

W
wusongqing 已提交
2061
**Return value**
W
wusongqing 已提交
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081

  ```
  sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' + 
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get  createQuaternion interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i]);
      }
  })
  ```


## sensor.createQuaternion

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

W
wusongqing 已提交
2082 2083 2084
Converts a rotation vector into a quaternion. This API uses a promise to return the result.

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

W
wusongqing 已提交
2086
**Parameters**
W
wusongqing 已提交
2087

W
wusongqing 已提交
2088 2089 2090
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationVector | Array&lt;number&gt; | Yes   | Rotation vector to convert.|
W
wusongqing 已提交
2091

W
wusongqing 已提交
2092
**Return value**
W
wusongqing 已提交
2093

W
wusongqing 已提交
2094 2095 2096
| Type                                | Description    |
| ---------------------------------- | ------ |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the quaternion.|
W
wusongqing 已提交
2097

W
wusongqing 已提交
2098
**Return value**
W
wusongqing 已提交
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116

  ```
  const promise = sensor.createQuaternion([0.20046076, 0.21907, 0.73978853, 0.60376877]);
      promise.then((data) => {
          console.info('createQuaternion_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).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 已提交
2117 2118 2119
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 已提交
2120

W
wusongqing 已提交
2121
**Parameters**
W
wusongqing 已提交
2122

W
wusongqing 已提交
2123 2124 2125 2126
| 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 已提交
2127

W
wusongqing 已提交
2128
**Return value**
W
wusongqing 已提交
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148

  ```
  sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info(LABEL + "SensorJsAPI--->Successed to get getDirection interface get data: " + data.x);
      for (var i = 1; i < data.length; i++) {
          console.info(TAG +"sensor_getDirection_callback" + data[i]);
      }
  })
  ```


## sensor.getDirection

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

W
wusongqing 已提交
2149 2150 2151
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 已提交
2152

W
wusongqing 已提交
2153
**Parameters**
W
wusongqing 已提交
2154

W
wusongqing 已提交
2155 2156 2157
| Name           | Type                 | Mandatory  | Description     |
| -------------- | ------------------- | ---- | ------- |
| rotationMatrix | Array&lt;number&gt; | Yes   | Rotation matrix.|
W
wusongqing 已提交
2158

W
wusongqing 已提交
2159
**Return value**
W
wusongqing 已提交
2160

W
wusongqing 已提交
2161 2162 2163
| 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 已提交
2164

W
wusongqing 已提交
2165
**Return value**
W
wusongqing 已提交
2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183

  ```
  const promise = sensor.getDirection([1, 0, 0, 0, 1, 0, 0, 0, 1]);
      promise.then((data) => {
          console.info(' sensor_getAltitude_Promise success', data.x);
          for (var i = 1; i < data.length; i++) {
              console.info(TAG +"sensor_getDirection_promise" + data[i]);
          }
      }).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 已提交
2184 2185 2186
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 已提交
2187

W
wusongqing 已提交
2188
**Parameters**
W
wusongqing 已提交
2189

W
wusongqing 已提交
2190 2191 2192 2193 2194
| 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 已提交
2195

W
wusongqing 已提交
2196
**Return value**
W
wusongqing 已提交
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216

  ```
  sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444], function(err, data)  {
      if (err) {
          console.error(LABEL + 'SensorJsAPI--->Failed to register data, error code is: ' + err.code + ', message: ' +
                        err.message);
          return;
      }
      console.info("SensorJsAPI--->Successed to get createRotationMatrix interface get data: " + data.x);
      for (var i=0; i < data.length; i++) {
          console.info(LABEL + "data[" + i + "]: " + data[i])
      }
  })
  ```


## sensor.createRotationMatrix

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

W
wusongqing 已提交
2217 2218 2219
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 已提交
2220

W
wusongqing 已提交
2221
**Parameters**
W
wusongqing 已提交
2222

W
wusongqing 已提交
2223 2224 2225 2226
| Name        | Type                 | Mandatory  | Description     |
| ----------- | ------------------- | ---- | ------- |
| gravity     | Array&lt;number&gt; | Yes   | Gravity vector.|
| geomagnetic | Array&lt;number&gt; | Yes   | Geomagnetic vector.|
W
wusongqing 已提交
2227

W
wusongqing 已提交
2228
**Return value**
W
wusongqing 已提交
2229

W
wusongqing 已提交
2230 2231 2232
| Type                                      | Description     |
| ---------------------------------------- | ------- |
| Promise&lt;[RotationMatrixResponse](#rotationmatrixresponse)&gt; | Promise used to return the rotation matrix.|
W
wusongqing 已提交
2233

W
wusongqing 已提交
2234
**Return value**
W
wusongqing 已提交
2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247

  ```
  const promise = sensor.createRotationMatrix([-0.27775216, 0.5351276, 9.788099], [210.87253, -78.6096, -111.44444]);
      promise.then((data) => {
          console.info(LABEL + 'createRotationMatrix_promise successed');
          for (var i=0; i < data.length; i++) {
              console.info(LABEL + "data[" + i + "]: " + data[i]);
          }
      }).catch((err) => {
          console.info(LABEL + 'promise failed');
  })
  ```

W
wusongqing 已提交
2248 2249

## SensorType
Z
zengyawen 已提交
2250 2251 2252

Enumerates the sensor types.

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

W
wusongqing 已提交
2255

W
wusongqing 已提交
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
| Name                                      | Default Value | Description         |
| ---------------------------------------- | ---- | ----------- |
| SENSOR_TYPE_ID_ACCELEROMETER             | 1    | Acceleration sensor.    |
| SENSOR_TYPE_ID_GYROSCOPE                 | 2    | Gyroscope sensor.    |
| SENSOR_TYPE_ID_AMBIENT_LIGHT             | 5    | Ambient light sensor.    |
| SENSOR_TYPE_ID_MAGNETIC_FIELD            | 6    | Magnetic field sensor.     |
| SENSOR_TYPE_ID_BAROMETER                 | 8    | Barometer sensor.    |
| SENSOR_TYPE_ID_HALL                      | 10   | Hall effect sensor.     |
| SENSOR_TYPE_ID_PROXIMITY                 | 12   | Proximity sensor.    |
| SENSOR_TYPE_ID_HUMIDITY                  | 13   | Humidity sensor.     |
| SENSOR_TYPE_ID_ORIENTATION               | 256  | Orientation sensor.     |
| SENSOR_TYPE_ID_GRAVITY                   | 257  | Gravity sensor.     |
| SENSOR_TYPE_ID_LINEAR_ACCELERATION       | 258  | Linear acceleration sensor.  |
| SENSOR_TYPE_ID_ROTATION_VECTOR           | 259  | Rotation vector sensor.   |
| SENSOR_TYPE_ID_AMBIENT_TEMPERATURE       | 260  | Ambient temperature sensor.   |
| SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED | 261  | Uncalibrated magnetic field sensor.  |
| SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED    | 263  | Uncalibrated gyroscope sensor. |
| SENSOR_TYPE_ID_SIGNIFICANT_MOTION        | 264  | Significant motion sensor.   |
| SENSOR_TYPE_ID_PEDOMETER_DETECTION       | 265  | Pedometer detection sensor.   |
| SENSOR_TYPE_ID_PEDOMETER                 | 266  | Pedometer sensor.     |
| SENSOR_TYPE_ID_HEART_RATE                | 278  | Heart rate sensor.     |
| SENSOR_TYPE_ID_WEAR_DETECTION            | 280  | Wear detection sensor.   |
| SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED | 281  | Uncalibrated acceleration sensor.|
W
wusongqing 已提交
2279 2280 2281 2282 2283 2284


## Response

Describes the timestamp of the sensor data.

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

W
wusongqing 已提交
2287 2288 2289
| Name       | Type  | Readable  | Writable  | Description          |
| --------- | ------ | ---- | ---- | ------------ |
| timestamp | number | Yes   | Yes   | Timestamp when the sensor reports data.|
W
wusongqing 已提交
2290 2291 2292 2293 2294 2295


## AccelerometerResponse

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

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

W
wusongqing 已提交
2298

W
wusongqing 已提交
2299 2300 2301 2302 2303
| 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 已提交
2304 2305 2306 2307 2308 2309


## LinearAccelerometerResponse

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

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

W
wusongqing 已提交
2312

W
wusongqing 已提交
2313 2314 2315 2316 2317
| 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 已提交
2318 2319 2320 2321 2322 2323


## AccelerometerUncalibratedResponse

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

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

W
wusongqing 已提交
2326

W
wusongqing 已提交
2327 2328 2329 2330 2331 2332 2333 2334
| 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 已提交
2335 2336 2337 2338 2339 2340


## GravityResponse

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

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

W
wusongqing 已提交
2343

W
wusongqing 已提交
2344 2345 2346 2347 2348
| 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 已提交
2349 2350 2351 2352 2353 2354


## OrientationResponse

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

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

W
wusongqing 已提交
2357

W
wusongqing 已提交
2358 2359 2360 2361 2362
| Name   | Type  | Readable  | Writable  | Description                      |
| ----- | ------ | ---- | ---- | ------------------------ |
| alpha | number | Yes   | Yes   | Rotation angle of the device around the z-axis, in rad.|
| beta  | number | Yes   | Yes   | Rotation angle of the device around the x-axis, in rad. |
| gamma | number | Yes   | Yes   | Rotation angle of the device around the y-axis, in rad. |
W
wusongqing 已提交
2363 2364 2365 2366 2367 2368


## RotationVectorResponse

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

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

W
wusongqing 已提交
2371

W
wusongqing 已提交
2372 2373 2374 2375 2376 2377
| 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 已提交
2378 2379 2380 2381 2382 2383


## GyroscopeResponse

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

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

W
wusongqing 已提交
2386

W
wusongqing 已提交
2387 2388 2389 2390 2391
| 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 已提交
2392 2393 2394 2395 2396 2397


## GyroscopeUncalibratedResponse

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

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

W
wusongqing 已提交
2400

W
wusongqing 已提交
2401 2402 2403 2404 2405 2406 2407 2408
| 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 已提交
2409 2410 2411 2412 2413 2414


## SignificantMotionResponse

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

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

W
wusongqing 已提交
2417

W
wusongqing 已提交
2418 2419 2420
| 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 已提交
2421 2422 2423 2424 2425 2426


## ProximityResponse

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

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

W
wusongqing 已提交
2429

W
wusongqing 已提交
2430 2431 2432
| 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 已提交
2433 2434 2435 2436 2437 2438


## LightResponse

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

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

W
wusongqing 已提交
2441

W
wusongqing 已提交
2442 2443 2444
| Name       | Type  | Readable  | Writable  | Description         |
| --------- | ------ | ---- | ---- | ----------- |
| intensity | number | Yes   | Yes   | Illumination, in lux.|
W
wusongqing 已提交
2445 2446 2447 2448 2449 2450


## HallResponse

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

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

W
wusongqing 已提交
2453

W
wusongqing 已提交
2454 2455 2456
| 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 已提交
2457 2458 2459 2460 2461 2462


## MagneticFieldResponse

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

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

W
wusongqing 已提交
2465

W
wusongqing 已提交
2466 2467 2468 2469 2470
| 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 已提交
2471 2472 2473 2474 2475 2476


## MagneticFieldUncalibratedResponse

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

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

W
wusongqing 已提交
2479

W
wusongqing 已提交
2480 2481 2482 2483 2484 2485 2486 2487
| 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 已提交
2488 2489 2490 2491 2492 2493


## PedometerResponse

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

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

W
wusongqing 已提交
2496

W
wusongqing 已提交
2497 2498 2499
| Name   | Type  | Readable  | Writable  | Description      |
| ----- | ------ | ---- | ---- | -------- |
| steps | number | Yes   | Yes   | Number of steps a user has walked.|
W
wusongqing 已提交
2500 2501 2502 2503 2504 2505


## HumidityResponse

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

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

W
wusongqing 已提交
2508

W
wusongqing 已提交
2509 2510 2511
| Name      | Type  | Readable  | Writable  | Description                                  |
| -------- | ------ | ---- | ---- | ------------------------------------ |
| humidity | number | Yes   | Yes   | Ambient relative humidity, in a percentage (%).|
W
wusongqing 已提交
2512 2513


W
wusongqing 已提交
2514
## PedometerDetectionResponse
W
wusongqing 已提交
2515 2516 2517

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

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

W
wusongqing 已提交
2520

W
wusongqing 已提交
2521 2522 2523
| 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 已提交
2524 2525 2526 2527 2528 2529


## AmbientTemperatureResponse

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

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

W
wusongqing 已提交
2532

W
wusongqing 已提交
2533 2534 2535
| Name         | Type  | Readable  | Writable  | Description           |
| ----------- | ------ | ---- | ---- | ------------- |
| temperature | number | Yes   | Yes   | Ambient temperature, in degree Celsius.|
W
wusongqing 已提交
2536 2537 2538 2539 2540 2541


## BarometerResponse

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

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

W
wusongqing 已提交
2544

W
wusongqing 已提交
2545 2546 2547
| Name      | Type  | Readable  | Writable  | Description          |
| -------- | ------ | ---- | ---- | ------------ |
| pressure | number | Yes   | Yes   | Atmospheric pressure, in pascal.|
W
wusongqing 已提交
2548 2549 2550 2551 2552 2553


## HeartRateResponse

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

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

W
wusongqing 已提交
2556

W
wusongqing 已提交
2557 2558 2559
| Name       | Type  | Readable  | Writable  | Description                   |
| --------- | ------ | ---- | ---- | --------------------- |
| heartRate | number | Yes   | Yes   | Heart rate, in beats per minute (bpm).|
W
wusongqing 已提交
2560 2561 2562 2563 2564 2565


## WearDetectionResponse

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

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

W
wusongqing 已提交
2568

W
wusongqing 已提交
2569 2570 2571
| 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 已提交
2572 2573 2574


## Options
Z
zengyawen 已提交
2575 2576 2577

Describes the sensor data reporting frequency.

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

W
wusongqing 已提交
2580 2581
| Name      | Type  | Description                         |
| -------- | ------ | --------------------------- |
W
wusongqing 已提交
2582 2583
| interval | number | Frequency at which a sensor reports data. The default value is 200,000,000 ns.|

W
wusongqing 已提交
2584 2585 2586 2587
## RotationMatrixResponse

Describes the response for setting the rotation matrix.

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

W
wusongqing 已提交
2590 2591 2592 2593
| 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 已提交
2594 2595 2596 2597 2598 2599


## CoordinatesOptions

Describes the coordinate options.

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

W
wusongqing 已提交
2602 2603 2604 2605
| Name  | Type  | Readable  | Writable  | Description    |
| ---- | ------ | ---- | ---- | ------ |
| x    | number | Yes   | Yes   | X coordinate direction.|
| y    | number | Yes   | Yes   | Y coordinate direction.|
W
wusongqing 已提交
2606

W
wusongqing 已提交
2607 2608 2609 2610 2611

## GeomagneticResponse

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

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

W
wusongqing 已提交
2614 2615 2616 2617 2618 2619 2620 2621 2622
| 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 已提交
2623 2624

## LocationOptions
Z
zengyawen 已提交
2625

W
wusongqing 已提交
2626 2627 2628 2629
Describes the geographical location.

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

W
wusongqing 已提交
2630 2631 2632 2633 2634
| Name       | Type  | Readable  | Writable  | Description   |
| --------- | ------ | ---- | ---- | ----- |
| latitude  | number | Yes   | Yes   | Latitude.  |
| longitude | number | Yes   | Yes   | Longitude.  |
| altitude  | number | Yes   | Yes   | Altitude.|