• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.stationary (设备状态感知框架)
2<!--Kit: Multimodal Awareness Kit-->
3<!--Subsystem: MultimodalAwareness-->
4<!--Owner: @dilligencer-->
5<!--Designer: @zou_ye-->
6<!--Tester: @judan-->
7<!--Adviser: @hu-zhiqiong-->
8
9设备状态感知框架提供设备状态感知能力,包括绝对静止和相对静止。
10
11> **说明:**
12>
13> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块不支持x86模拟器。
16
17## 导入模块
18
19```ts
20import { stationary } from '@kit.MultimodalAwarenessKit';
21```
22
23## ActivityResponse
24
25服务响应抽象接口。
26
27**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
28
29| 名称 | 类型 | 只读 | 可选 | 说明 |
30| -------- | -------- | -------- | -------- | -------- |
31| state | [ActivityState](#activitystate) | 否 | 否 | 设备状态变化返回值。 |
32
33## ActivityType
34
35type ActivityType = 'still' | 'relativeStill'
36
37设备状态类型。
38
39**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
40
41| 类型 | 说明 |
42| -------- | -------- |
43| 'still' | 绝对静止。 |
44| 'relativeStill' | 相对静止。 |
45
46## ActivityEvent
47
48设备状态事件。
49
50**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
51
52| 名称                             | 值    | 说明                                       |
53| ------------------------------ | ---- | ---------------------------------------- |
54| ENTER         | 1    | 进入。   |
55| EXIT | 2   | 退出。 |
56| ENTER_EXIT | 3   | 进入和退出。 |
57
58## ActivityState
59
60设备状态返回值。
61
62**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
63
64| 名称                             | 值    | 说明                                       |
65| ------------------------------ | ---- | ---------------------------------------- |
66| ENTER         | 1    | 进入。   |
67| EXIT | 2   | 退出。 |
68
69## stationary.on('still' | 'relativeStill')
70
71on(activity: ActivityType, event: ActivityEvent, reportLatencyNs: number, callback: Callback&lt;ActivityResponse&gt;): void
72
73设备状态管理,订阅设备状态服务。
74
75**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
76
77**参数:**
78
79| 参数名                  | 类型                                               | 必填 | 说明                          |
80| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
81| activity  | [ActivityType](#activitytype)  | 是   | 设备状态能力类型。              |
82| event  | [ActivityEvent](#activityevent)  | 是   | 事件类型。              |
83| reportLatencyNs  | number  | 是   | 报告延时(取值范围1000000000-3000000000)。              |
84| callback             | Callback<[ActivityResponse](#activityresponse)\>  | 是   | 回调函数,接收上报状态变化事件。    |
85
86**示例:**
87
88```ts
89let reportLatencyNs = 1000000000;
90stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => {
91    console.log('data='+ JSON.stringify(data));
92})
93```
94
95## stationary.once('still' | 'relativeStill')
96
97once(activity: ActivityType, callback: Callback&lt;ActivityResponse&gt;): void
98
99设备状态管理,查询设备状态。
100
101**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
102
103**参数:**
104
105| 参数名                  | 类型                                               | 必填 | 说明                          |
106| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
107| activity  | [ActivityType](#activitytype)  | 是   | 设备状态能力类型。              |
108| callback             | Callback<[ActivityResponse](#activityresponse)\>  | 是   | 回调函数,接收上报状态变化事件。    |
109
110**示例:**
111
112```ts
113stationary.once('still', (data) => {
114    console.log("data="+ JSON.stringify(data));
115})
116```
117
118## stationary.off('still' | 'relativeStill')
119
120off(activity: ActivityType, event: ActivityEvent, callback?: Callback&lt;ActivityResponse&gt;): void
121
122设备状态管理,取消订阅设备状态服务。
123
124**系统能力**:SystemCapability.Msdp.DeviceStatus.Stationary
125
126**参数:**
127
128| 参数名                  | 类型                                               | 必填 | 说明                          |
129| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
130| activity  | [ActivityType](#activitytype)  | 是   | 设备状态能力类型。              |
131| event  | [ActivityEvent](#activityevent)  | 是   | 事件类型。              |
132| callback | Callback<[ActivityResponse](#activityresponse)\>  | 否   | 回调函数,接收上报状态变化事件,如果没有传递callback参数或者传递的类型是undefined,会移除该进程下订阅该类型得所有callback。  |
133
134**示例:**
135
136```ts
137stationary.off('still', stationary.ActivityEvent.ENTER);
138```
139