1e41f4b71Sopenharmony_ci# @system.sensor (传感器)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_cisensor模块提供订阅传感器数据基本能力,主要包含查询传感器的列表、订阅/取消传感器的数据、执行控制命令等。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci根据传感器的用途,可以将传感器分为六大类:运动类传感器、环境类传感器、方向类传感器、光线类传感器、健康类传感器、其他类传感器(如霍尔传感器),每一大类传感器包含不同类型的传感器,某种类型的传感器可能是单一的物理传感器,也可能是由多个物理传感器复合而成。
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci> **说明:**
9e41f4b71Sopenharmony_ci>
10e41f4b71Sopenharmony_ci> - 从API Version 8开始,该接口不再维护,推荐使用新接口[`@ohos.sensor`](js-apis-sensor.md)。
11e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
12e41f4b71Sopenharmony_ci> - 该功能使用需要对应硬件支持,仅支持真机调试。
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## 导入模块
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci```
19e41f4b71Sopenharmony_ciimport { Sensor } from '@kit.SensorServiceKit';
20e41f4b71Sopenharmony_ci```
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci## Sensor.subscribeAccelerometer
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci subscribeAccelerometer(options: subscribeAccelerometerOptions): void
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci观察加速度数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACCELEROMETER,该权限为系统权限
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**参数:**
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| 参数名  | 类型                                                         | 必填 | 说明                                       |
35e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
36e41f4b71Sopenharmony_ci| options | [subscribeAccelerometerOptions](#subscribeaccelerometeroptions) | 是   | 监听加速度传感器数据的回调函数的执行频率。 |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**示例:** 
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci```ts
41e41f4b71Sopenharmony_ciimport { Sensor, AccelerometerResponse, subscribeAccelerometerOptions } from '@kit.SensorServiceKit';
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_cilet accelerometerOptions: subscribeAccelerometerOptions = {
44e41f4b71Sopenharmony_ci  interval: 'normal',
45e41f4b71Sopenharmony_ci  success: (ret: AccelerometerResponse) => {
46e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. X-axis data: ' + ret.x);
47e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Y-axis data: ' + ret.y);
48e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Z-axis data: ' + ret.z);
49e41f4b71Sopenharmony_ci  },
50e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
51e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
52e41f4b71Sopenharmony_ci  },
53e41f4b71Sopenharmony_ci};
54e41f4b71Sopenharmony_ciSensor.subscribeAccelerometer(accelerometerOptions);
55e41f4b71Sopenharmony_ci```
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci> **说明:**
58e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci## Sensor.unsubscribeAccelerometer
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciunsubscribeAccelerometer(): void
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci取消订阅加速度数据。
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACCELEROMETER,该权限为系统权限
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**示例:**
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci```ts
73e41f4b71Sopenharmony_ciSensor.unsubscribeAccelerometer();
74e41f4b71Sopenharmony_ci```
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci## Sensor.subscribeCompass
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci subscribeCompass(options: SubscribeCompassOptions): void
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci订阅罗盘数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Sensors.Sensor.Lite
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**参数:**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci| 参数名  | 类型                                                | 必填 | 说明                             |
87e41f4b71Sopenharmony_ci| ------- | --------------------------------------------------- | ---- | -------------------------------- |
88e41f4b71Sopenharmony_ci| options | [SubscribeCompassOptions](#subscribecompassoptions) | 是   | 当罗盘传感器数据发生变化时调用。 |
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**示例:** 
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```ts
93e41f4b71Sopenharmony_ciimport { Sensor, CompassResponse, SubscribeCompassOptions } from '@kit.SensorServiceKit';
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_cilet subscribeCompassOptions: SubscribeCompassOptions = {
96e41f4b71Sopenharmony_ci  success: (ret: CompassResponse) => {
97e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get data direction:' + ret.direction);
98e41f4b71Sopenharmony_ci  },
99e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
100e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
101e41f4b71Sopenharmony_ci  },
102e41f4b71Sopenharmony_ci};
103e41f4b71Sopenharmony_ciSensor.subscribeCompass(subscribeCompassOptions);
104e41f4b71Sopenharmony_ci```
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci> **说明:**
107e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci## Sensor.unsubscribeCompass
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ciunsubscribeCompass(): void
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci取消订阅罗盘。
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**示例:**
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci```ts
120e41f4b71Sopenharmony_ciSensor.unsubscribeCompass();
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci## Sensor.subscribeProximity
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci subscribeProximity(options: SubscribeProximityOptions): void
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci订阅距离感应数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**参数:**
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci| 参数名  | 类型                                                    | 必填 | 说明                             |
134e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------- | ---- | -------------------------------- |
135e41f4b71Sopenharmony_ci| options | [SubscribeProximityOptions](#subscribeproximityoptions) | 是   | 当距离传感器数据发生变化时调用。 |
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**示例:** 
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci```ts
140e41f4b71Sopenharmony_ciimport { Sensor, ProximityResponse, SubscribeProximityOptions } from '@kit.SensorServiceKit';
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_cilet subscribeProximityOptions: SubscribeProximityOptions = {
143e41f4b71Sopenharmony_ci  success: (ret: ProximityResponse) => {
144e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get data distance:' + ret.distance);
145e41f4b71Sopenharmony_ci  },
146e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
147e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
148e41f4b71Sopenharmony_ci  },
149e41f4b71Sopenharmony_ci};
150e41f4b71Sopenharmony_ciSensor.subscribeProximity(subscribeProximityOptions);
151e41f4b71Sopenharmony_ci```
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci> **说明:**
154e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci## Sensor.unsubscribeProximity
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ciunsubscribeProximity(): void
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci取消订阅距离感应。
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**示例:**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci```ts
167e41f4b71Sopenharmony_ciSensor.unsubscribeProximity();
168e41f4b71Sopenharmony_ci```
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci## Sensor.subscribeLight
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci subscribeLight(options: SubscribeLightOptions): void
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci订阅环境光线感应数据变化。再次调用时,会覆盖前一次调用效果,即仅最后一次调用生效。
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**参数:**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci| 参数名  | 类型                                            | 必填 | 说明                               |
181e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------- | ---- | ---------------------------------- |
182e41f4b71Sopenharmony_ci| options | [SubscribeLightOptions](#subscribelightoptions) | 是   | 当环境光传感器数据发生变化时调用。 |
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**示例:** 
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci```ts
187e41f4b71Sopenharmony_ciimport { Sensor, LightResponse, SubscribeLightOptions } from '@kit.SensorServiceKit';
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_cilet subscribeLightOptions: SubscribeLightOptions = {
190e41f4b71Sopenharmony_ci  success: (ret: LightResponse) => {
191e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get data intensity:' + ret.intensity);
192e41f4b71Sopenharmony_ci  },
193e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
194e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
195e41f4b71Sopenharmony_ci  },
196e41f4b71Sopenharmony_ci};
197e41f4b71Sopenharmony_ciSensor.subscribeLight(subscribeLightOptions);
198e41f4b71Sopenharmony_ci```
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci> **说明:**
201e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci## Sensor.unsubscribeLight
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ciunsubscribeLight(): void
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci取消订阅环境光线感应。
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci**示例:** 
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci```ts
214e41f4b71Sopenharmony_ciSensor.unsubscribeLight();
215e41f4b71Sopenharmony_ci```
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci## Sensor.subscribeStepCounter
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci subscribeStepCounter(options: SubscribeStepCounterOptions): void
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci订阅计步传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Sensors.Sensor.Lite
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.ACTIVITY_MOTION
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci**参数:**
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci| 参数名  | 类型                                                        | 必填 | 说明                                   |
230e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------- | ---- | -------------------------------------- |
231e41f4b71Sopenharmony_ci| options | [SubscribeStepCounterOptions](#subscribestepcounteroptions) | 是   | 当步进计数器传感器数据发生变化时调用。 |
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**示例:** 
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci```ts
236e41f4b71Sopenharmony_ciimport { Sensor, StepCounterResponse, SubscribeStepCounterOptions } from '@kit.SensorServiceKit';
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_cilet subscribeStepCounterOptions: SubscribeStepCounterOptions = {
239e41f4b71Sopenharmony_ci  success: (ret: StepCounterResponse) => {
240e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get step value:' + ret.steps);
241e41f4b71Sopenharmony_ci  },
242e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
243e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
244e41f4b71Sopenharmony_ci  },
245e41f4b71Sopenharmony_ci};
246e41f4b71Sopenharmony_ciSensor.subscribeStepCounter(subscribeStepCounterOptions);
247e41f4b71Sopenharmony_ci```
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci> **说明:**
250e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci## Sensor.unsubscribeStepCounter
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ciunsubscribeStepCounter(): void
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci取消订阅计步传感器。
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACTIVITY_MOTION
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci**示例:** 
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci```ts
265e41f4b71Sopenharmony_ciSensor.unsubscribeStepCounter();
266e41f4b71Sopenharmony_ci```
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci## Sensor.subscribeBarometer
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_cisubscribeBarometer(options: SubscribeBarometerOptions): void
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci订阅气压计传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci**参数:**
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci| 参数名  | 类型                                                    | 必填 | 说明                               |
280e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------- | ---- | ---------------------------------- |
281e41f4b71Sopenharmony_ci| options | [SubscribeBarometerOptions](#subscribebarometeroptions) | 是   | 当气压计传感器数据发生变化时调用。 |
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**示例:** 
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci```ts
286e41f4b71Sopenharmony_ciimport { Sensor, BarometerResponse, SubscribeBarometerOptions } from '@kit.SensorServiceKit';
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_cilet subscribeBarometerOptions: SubscribeBarometerOptions = {
289e41f4b71Sopenharmony_ci  success: (ret: BarometerResponse) => {
290e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get data value:' + ret.pressure);
291e41f4b71Sopenharmony_ci  },
292e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
293e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
294e41f4b71Sopenharmony_ci  },
295e41f4b71Sopenharmony_ci};
296e41f4b71Sopenharmony_ciSensor.subscribeBarometer(subscribeBarometerOptions);
297e41f4b71Sopenharmony_ci```
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci> **说明:**
300e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci## Sensor.unsubscribeBarometer
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ciunsubscribeBarometer(): void
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci取消订阅气压计传感器。
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci**示例:** 
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci```ts
314e41f4b71Sopenharmony_ciSensor.unsubscribeBarometer();
315e41f4b71Sopenharmony_ci```
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci## Sensor.subscribeHeartRate
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci subscribeHeartRate(options: SubscribeHeartRateOptions): void
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci订阅心率传感器数据变化。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.READ_HEALTH_DATA
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci**参数:**
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci| 参数名  | 类型                                                    | 必填 | 说明                             |
331e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------- | ---- | -------------------------------- |
332e41f4b71Sopenharmony_ci| options | [SubscribeHeartRateOptions](#subscribeheartrateoptions) | 是   | 当心率传感器数据发生变化时调用。 |
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci**示例:** 
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci```ts
337e41f4b71Sopenharmony_ciimport { Sensor, HeartRateResponse, SubscribeHeartRateOptions } from '@kit.SensorServiceKit';
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_cilet subscribeHeartRateOptions: SubscribeHeartRateOptions = {
340e41f4b71Sopenharmony_ci  success: (ret: HeartRateResponse) => {
341e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get heartrate value:' + ret.heartRate);
342e41f4b71Sopenharmony_ci  },
343e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
344e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
345e41f4b71Sopenharmony_ci  },
346e41f4b71Sopenharmony_ci};
347e41f4b71Sopenharmony_ciSensor.subscribeHeartRate(subscribeHeartRateOptions);
348e41f4b71Sopenharmony_ci```
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci> **说明:**
351e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci## Sensor.unsubscribeHeartRate
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ciunsubscribeHeartRate(): void
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ci取消订阅心率传感器。
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.READ_HEALTH_DATA
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci**示例:** 
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci```ts
367e41f4b71Sopenharmony_ciSensor.unsubscribeHeartRate();
368e41f4b71Sopenharmony_ci```
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci## Sensor.subscribeOnBodyState
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci subscribeOnBodyState(options: SubscribeOnBodyStateOptions): void
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci订阅设备佩戴状态。针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效。
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci**参数:**
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci| 参数名  | 类型                                                        | 必填 | 说明                   |
381e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------- | ---- | ---------------------- |
382e41f4b71Sopenharmony_ci| options | [SubscribeOnBodyStateOptions](#subscribeonbodystateoptions) | 是   | 当穿着状态改变时调用。 |
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci**示例:** 
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci```ts
387e41f4b71Sopenharmony_ciimport { Sensor, OnBodyStateResponse, SubscribeOnBodyStateOptions } from '@kit.SensorServiceKit';
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_cilet subscribeOnBodyStateOptions: SubscribeOnBodyStateOptions = {
390e41f4b71Sopenharmony_ci  success: (ret: OnBodyStateResponse) => {
391e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Get on-body state value:' + ret.value);
392e41f4b71Sopenharmony_ci  },
393e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
394e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
395e41f4b71Sopenharmony_ci  },
396e41f4b71Sopenharmony_ci};
397e41f4b71Sopenharmony_ciSensor.subscribeOnBodyState(subscribeOnBodyStateOptions);
398e41f4b71Sopenharmony_ci```
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci> **说明:**
401e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci## Sensor.unsubscribeOnBodyState
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ciunsubscribeOnBodyState(): void
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci取消订阅设备佩戴状态。
408e41f4b71Sopenharmony_ci
409e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci**示例:** 
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ci```ts
414e41f4b71Sopenharmony_ciSensor.unsubscribeOnBodyState();
415e41f4b71Sopenharmony_ci```
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci## Sensor.getOnBodyState
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci getOnBodyState(options: GetOnBodyStateOptions): void
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci获取设备佩戴状态。
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**参数:** 
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci| 参数名  | 类型                                            | 必填 | 说明                       |
428e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------- | ---- | -------------------------- |
429e41f4b71Sopenharmony_ci| options | [GetOnBodyStateOptions](#getonbodystateoptions) | 是   | 获取传感器磨损状态时调用。 |
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**示例:** 
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci```ts
434e41f4b71Sopenharmony_ciimport { Sensor, OnBodyStateResponse, GetOnBodyStateOptions } from '@kit.SensorServiceKit';
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_cilet getOnBodyStateOptions: GetOnBodyStateOptions = {
437e41f4b71Sopenharmony_ci  success: (ret: OnBodyStateResponse) => {
438e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. On body state: ' + ret.value);
439e41f4b71Sopenharmony_ci  },
440e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
441e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
442e41f4b71Sopenharmony_ci  },
443e41f4b71Sopenharmony_ci};
444e41f4b71Sopenharmony_ciSensor.getOnBodyState(getOnBodyStateOptions);
445e41f4b71Sopenharmony_ci```
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci## Sensor.subscribeDeviceOrientation<sup>6+</sup>
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci subscribeDeviceOrientation(options: SubscribeDeviceOrientationOptions): void
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci观察设备方向传感器数据变化。
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效;针对同一个方法内,不支持多次调用。
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**参数:** 
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci| 参数名  | 类型                                                         | 必填 | 说明                                             |
460e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
461e41f4b71Sopenharmony_ci| options | [SubscribeDeviceOrientationOptions](#subscribedeviceorientationoptions6) | 是   | 用于监听设备方向传感器数据的回调函数的执行频率。 |
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci**示例:** 
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci```ts
466e41f4b71Sopenharmony_ciimport { Sensor, DeviceOrientationResponse, SubscribeDeviceOrientationOptions } from '@kit.SensorServiceKit';
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_cilet subscribeDeviceOrientationOptions: SubscribeDeviceOrientationOptions = {
469e41f4b71Sopenharmony_ci  interval: 'normal',
470e41f4b71Sopenharmony_ci  success: (ret: DeviceOrientationResponse) => {
471e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Alpha data: ' + ret.alpha);
472e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Beta data: ' + ret.beta);
473e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Gamma data: ' + ret.gamma);
474e41f4b71Sopenharmony_ci  },
475e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
476e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
477e41f4b71Sopenharmony_ci  }
478e41f4b71Sopenharmony_ci};
479e41f4b71Sopenharmony_ciSensor.subscribeDeviceOrientation(subscribeDeviceOrientationOptions);
480e41f4b71Sopenharmony_ci```
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci> **说明:**
483e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci## Sensor.unsubscribeDeviceOrientation<sup>6+</sup>
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ciunsubscribeDeviceOrientation(): void
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci取消订阅设备方向传感器数据。
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
492e41f4b71Sopenharmony_ci
493e41f4b71Sopenharmony_ci**示例:**
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci```ts
496e41f4b71Sopenharmony_ciSensor.unsubscribeDeviceOrientation();
497e41f4b71Sopenharmony_ci```
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci## Sensor.subscribeGyroscope<sup>6+</sup>
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci subscribeGyroscope(options: SubscribeGyroscopeOptions): void
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ci观察陀螺仪传感器数据变化。
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci针对同一个应用,多次点击调用时,会覆盖前面的调用效果,即仅最后一次调用生效;针对同一个方法内,不支持多次调用。
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ci**需要权限:** SystemCapability.Sensors.Sensor.Lite
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci**系统能力:** ohos.permission.GYROSCOPE,该权限为系统权限
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ci**参数:** 
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci| 参数名  | 类型                                                     | 必填 | 说明                                           |
514e41f4b71Sopenharmony_ci| ------- | -------------------------------------------------------- | ---- | ---------------------------------------------- |
515e41f4b71Sopenharmony_ci| options | [SubscribeGyroscopeOptions](#subscribegyroscopeoptions6) | 是   | 用于侦听陀螺仪传感器数据的回调函数的执行频率。 |
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ci**示例:** 
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci```ts
520e41f4b71Sopenharmony_ciimport { Sensor, GyroscopeResponse, SubscribeGyroscopeOptions } from '@kit.SensorServiceKit';
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_cilet subscribeGyroscopeOptions: SubscribeGyroscopeOptions = {
523e41f4b71Sopenharmony_ci  interval: 'normal',
524e41f4b71Sopenharmony_ci  success: (ret: GyroscopeResponse) => {
525e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. X-axis data: ' + ret.x);
526e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Y-axis data: ' + ret.y);
527e41f4b71Sopenharmony_ci    console.info('Succeeded in subscribing. Z-axis data: ' + ret.z);
528e41f4b71Sopenharmony_ci  },
529e41f4b71Sopenharmony_ci  fail: (data: string, code: number) => {
530e41f4b71Sopenharmony_ci    console.error(`Failed to subscription. Code: ${code}, data: ${data}`);
531e41f4b71Sopenharmony_ci  }
532e41f4b71Sopenharmony_ci};
533e41f4b71Sopenharmony_ciSensor.subscribeGyroscope(subscribeGyroscopeOptions);
534e41f4b71Sopenharmony_ci```
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci> **说明:**
537e41f4b71Sopenharmony_ci> 建议在页面销毁时,即onDestroy回调中,取消数据订阅,避免不必要的性能开销。
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci## Sensor.unsubscribeGyroscope<sup>6+</sup>
540e41f4b71Sopenharmony_ci
541e41f4b71Sopenharmony_ciunsubscribeGyroscope(): void
542e41f4b71Sopenharmony_ci
543e41f4b71Sopenharmony_ci取消订阅陀螺仪传感器数据。
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GYROSCOPE,该权限为系统权限
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci**示例:** 
550e41f4b71Sopenharmony_ci
551e41f4b71Sopenharmony_ci```ts
552e41f4b71Sopenharmony_ciSensor.unsubscribeGyroscope();
553e41f4b71Sopenharmony_ci```
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ci## subscribeAccelerometerOptions
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ci用于监听加速度传感器数据的回调函数的执行频率。
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACCELEROMETER
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci| 名称     | 类型                                            | 必填 | 说明                                                         |
564e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ |
565e41f4b71Sopenharmony_ci| interval | string                                          | 是   | 频率参数,加速度的回调函数执行频率。<br/>默认为normal,可选值有:<br/>game:极高的回调频率,20ms/次,适用于游戏。<br/>ui:较高的回调频率,60ms/次,适用于UI更新。<br/>normal:普通的回调频率,200ms/次,低功耗。 |
566e41f4b71Sopenharmony_ci| success  | [AccelerometerResponse](#accelerometerresponse) | 是   | 感应到加速度数据变化后的回调函数。                           |
567e41f4b71Sopenharmony_ci| fail     | Function                                        | 否   | 接口调用失败的回调函数。                                     |
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ci## AccelerometerResponse 
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci感应到加速度数据变化后的回调函数。  
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACCELEROMETER
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ci| 名称 | 类型   | 必填 | 说明          |
578e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------- |
579e41f4b71Sopenharmony_ci| x    | number | 是   | x轴的加速度。 |
580e41f4b71Sopenharmony_ci| y    | number | 是   | y轴的加速度。 |
581e41f4b71Sopenharmony_ci| z    | number | 是   | z轴的加速度。 |
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci## SubscribeCompassOptions
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci当罗盘传感器数据发生变化时调用。
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci| 名称    | 类型                                | 必填 | 说明                           |
590e41f4b71Sopenharmony_ci| ------- | ----------------------------------- | ---- | ------------------------------ |
591e41f4b71Sopenharmony_ci| success | [CompassResponse](#compassresponse) | 是   | 罗盘数据改变后触发的回调函数。 |
592e41f4b71Sopenharmony_ci| fail    | Function                            | 否   | 接口调用失败的回调函数。       |
593e41f4b71Sopenharmony_ci
594e41f4b71Sopenharmony_ci## CompassResponse 
595e41f4b71Sopenharmony_ci
596e41f4b71Sopenharmony_ci罗盘数据改变后触发的回调函数。
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci| 名称      | 类型   | 必填 | 说明                 |
601e41f4b71Sopenharmony_ci| --------- | ------ | ---- | -------------------- |
602e41f4b71Sopenharmony_ci| direction | number | 是   | 设备面对的方向度数。 |
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_ci## SubscribeProximityOptions
605e41f4b71Sopenharmony_ci
606e41f4b71Sopenharmony_ci当距离传感器数据发生变化时调用。
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci| 名称    | 类型                                    | 必填 | 说明                               |
611e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | ---------------------------------- |
612e41f4b71Sopenharmony_ci| success | [ProximityResponse](#proximityresponse) | 是   | 距离感应数据改变后调用的回调函数。 |
613e41f4b71Sopenharmony_ci| fail    | Function                                | 否   | 接口调用失败的回调函数。           |
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ci## ProximityResponse 
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci距离感应数据改变后调用的回调函数。
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci| 名称     | 类型   | 必填 | 说明                                       |
622e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------ |
623e41f4b71Sopenharmony_ci| distance | number | 是   | 可见物体相对于设备显示屏的接近或远离状态。 |
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci## SubscribeLightOptions
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci当环境光传感器数据发生变化时调用。
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ci| 名称    | 类型                            | 必填 | 说明                           |
632e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | ------------------------------ |
633e41f4b71Sopenharmony_ci| success | [LightResponse](#lightresponse) | 是   | 光线感应数据改变后的回调函数。 |
634e41f4b71Sopenharmony_ci| fail    | Function                        | 否   | 接口调用失败的回调函数。       |
635e41f4b71Sopenharmony_ci
636e41f4b71Sopenharmony_ci## LightResponse 
637e41f4b71Sopenharmony_ci
638e41f4b71Sopenharmony_ci光线感应数据改变后的回调函数。
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci| 名称      | 类型   | 必填 | 说明                  |
643e41f4b71Sopenharmony_ci| --------- | ------ | ---- | --------------------- |
644e41f4b71Sopenharmony_ci| intensity | number | 是   | 光线强度,单位为lux。 |
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci## SubscribeStepCounterOptions
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci当步进计数器传感器数据发生变化时调用。
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACTIVITY_MOTION
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
653e41f4b71Sopenharmony_ci
654e41f4b71Sopenharmony_ci| 名称    | 类型                                        | 必填 | 说明                             |
655e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | -------------------------------- |
656e41f4b71Sopenharmony_ci| success | [StepCounterResponse](#stepcounterresponse) | 是   | 计步传感器数据改变后的回调函数。 |
657e41f4b71Sopenharmony_ci| fail    | Function                                    | 否   | 接口调用失败的回调函数。         |
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci## StepCounterResponse 
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci计步传感器数据改变后的回调函数。
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.ACTIVITY_MOTION
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci| 名称  | 类型   | 必填 | 说明                             |
668e41f4b71Sopenharmony_ci| ----- | ------ | ---- | -------------------------------- |
669e41f4b71Sopenharmony_ci| steps | number | 是   | 计步传感器重启后累计记录的步数。 |
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci## SubscribeBarometerOptions
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci当气压计传感器数据发生变化时调用。
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ci| 名称    | 类型                                    | 必填 | 说明                             |
678e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | -------------------------------- |
679e41f4b71Sopenharmony_ci| success | [BarometerResponse](#barometerresponse) | 是   | 气压计传感器数据改变后的回调函数。 |
680e41f4b71Sopenharmony_ci| fail    | Function                                | 否   | 接口调用失败的回调函数。         |
681e41f4b71Sopenharmony_ci
682e41f4b71Sopenharmony_ci## BarometerResponse 
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci气压计传感器数据改变后的回调函数。
685e41f4b71Sopenharmony_ci
686e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Sensors.Sensor.Lite
687e41f4b71Sopenharmony_ci
688e41f4b71Sopenharmony_ci| 名称     | 类型   | 必填 | 说明                   |
689e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------- |
690e41f4b71Sopenharmony_ci| pressure | number | 是   | 气压值,单位:帕斯卡。 |
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci## SubscribeHeartRateOptions
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci当心率传感器数据发生变化时调用。
695e41f4b71Sopenharmony_ci
696e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.READ_HEALTH_DATA 
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci| 名称    | 类型                                    | 必填 | 说明                                            |
701e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | ----------------------------------------------- |
702e41f4b71Sopenharmony_ci| success | [HeartRateResponse](#heartrateresponse) | 是   | 心率传感器数据改变后的回调函数,默认频率5s/次。 |
703e41f4b71Sopenharmony_ci| fail    | Function                                | 否   | 接口调用失败的回调函数。                        |
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci## HeartRateResponse 
706e41f4b71Sopenharmony_ci
707e41f4b71Sopenharmony_ci心率传感器数据改变后的回调函数,默认频率5s/次。
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.READ_HEALTH_DATA 
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci| 名称      | 类型   | 必填 | 说明     |
714e41f4b71Sopenharmony_ci| --------- | ------ | ---- | -------- |
715e41f4b71Sopenharmony_ci| heartRate | number | 是   | 心率值。 |
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci## SubscribeOnBodyStateOptions
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci当穿着状态改变时调用。
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci| 名称    | 类型                                        | 必填 | 说明                       |
724e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | -------------------------- |
725e41f4b71Sopenharmony_ci| success | [OnBodyStateResponse](#onbodystateresponse) | 是   | 穿戴状态改变后的回调函数。 |
726e41f4b71Sopenharmony_ci| fail    | Function                                    | 否   | 接口调用失败的回调函数。   |
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ci## OnBodyStateResponse 
729e41f4b71Sopenharmony_ci
730e41f4b71Sopenharmony_ci传感器是否磨损。
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci| 名称  | 类型    | 必填 | 说明         |
735e41f4b71Sopenharmony_ci| ----- | ------- | ---- | ------------ |
736e41f4b71Sopenharmony_ci| value | boolean | 是   | 是否已佩戴。 |
737e41f4b71Sopenharmony_ci
738e41f4b71Sopenharmony_ci## GetOnBodyStateOptions
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ci 获取传感器磨损状态时调用。
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci| 名称     | 类型                                        | 必填 | 说明                     |
745e41f4b71Sopenharmony_ci| -------- | ------------------------------------------- | ---- | ------------------------ |
746e41f4b71Sopenharmony_ci| success  | [OnBodyStateResponse](#onbodystateresponse) | 是   | 接口调用成功的回调函数。 |
747e41f4b71Sopenharmony_ci| fail     | Function                                    | 否   | 接口调用失败的回调函数。 |
748e41f4b71Sopenharmony_ci| complete | Function                                    | 否   | 接口调用结束的回调函数。 |
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci## SubscribeDeviceOrientationOptions<sup>6+</sup>
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ci用于监听设备方向传感器数据的回调函数的执行频率。
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci| 名称     | 类型                                                     | 必填 | 说明                                                         |
757e41f4b71Sopenharmony_ci| -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ |
758e41f4b71Sopenharmony_ci| interval | string                                                   | 是   | 频率参数,设备方向传感器的回调函数执行频率。<br/>默认为normal,可选值有:<br/>-&nbsp;game:极高的回调频率,20ms/次,适用于游戏。<br/>-&nbsp;ui:较高的回调频率,60ms/次,适用于UI更新。<br/>-&nbsp;normal:普通的回调频率,200ms/次,低功耗。 |
759e41f4b71Sopenharmony_ci| success  | [DeviceOrientationResponse](#deviceorientationresponse6) | 是   | 感应到设备方向传感器数据变化后的回调函数。                   |
760e41f4b71Sopenharmony_ci| fail     | Function                                                 | 否   | 接口调用失败的回调函数。                                     |
761e41f4b71Sopenharmony_ci
762e41f4b71Sopenharmony_ci## DeviceOrientationResponse<sup>6+</sup> 
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci感应到设备方向传感器数据变化后的回调函数。
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci| 名称  | 类型   | 必填 | 说明                                                         |
769e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ------------------------------------------------------------ |
770e41f4b71Sopenharmony_ci| alpha | number | 是   | 当设备坐标&nbsp;X/Y&nbsp;和地球&nbsp;X/Y&nbsp;重合时,绕着&nbsp;Z&nbsp;轴转动的夹角为&nbsp;alpha。 |
771e41f4b71Sopenharmony_ci| beta  | number | 是   | 当设备坐标&nbsp;Y/Z&nbsp;和地球&nbsp;Y/Z&nbsp;重合时,绕着&nbsp;X&nbsp;轴转动的夹角为&nbsp;beta。 |
772e41f4b71Sopenharmony_ci| gamma | number | 是   | 当设备&nbsp;X/Z&nbsp;和地球&nbsp;X/Z&nbsp;重合时,绕着&nbsp;Y&nbsp;轴转动的夹角为&nbsp;gamma。 |
773e41f4b71Sopenharmony_ci
774e41f4b71Sopenharmony_ci## SubscribeGyroscopeOptions<sup>6+</sup> 
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci用于侦听陀螺仪传感器数据的回调函数的执行频率。
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GYROSCOPE
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci| 名称     | 类型                                     | 必填 | 说明                                                         |
783e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
784e41f4b71Sopenharmony_ci| interval | string                                   | 是   | 频率参数,陀螺仪的回调函数执行频率。<br/>默认为normal,可选值有:<br/>game:极高的回调频率,20ms/次,适用于游戏。<br/>ui:较高的回调频率,60ms/次,适用于UI更新。<br/>normal:普通的回调频率,200ms/次,低功耗。 |
785e41f4b71Sopenharmony_ci| success  | [GyroscopeResponse](#gyroscoperesponse6) | 是   | 感应到陀螺仪数据变化后的回调函数。                           |
786e41f4b71Sopenharmony_ci| fail     | Function                                 | 否   | 接口调用失败的回调函数。                                     |
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ci## GyroscopeResponse<sup>6+</sup> 
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ci感应到陀螺仪传感器数据变化后的回调函数。
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GYROSCOPE
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Sensors.Sensor.Lite
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_ci| 名称 | 类型   | 必填 | 说明              |
797e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------- |
798e41f4b71Sopenharmony_ci| x    | number | 是   | x轴的旋转角速度。 |
799e41f4b71Sopenharmony_ci| y    | number | 是   | y轴的旋转角速度。 |
800e41f4b71Sopenharmony_ci| z    | number | 是   | z轴的旋转角速度。 |