• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.distributedDeviceManager (设备管理)(系统接口)
2
3本模块提供分布式设备管理能力。
4
5应用可调用接口实现如下功能:
6
7- 注册和解除注册设备上下线变化监听
8- 发现周边不可信设备
9- 认证和取消认证设备
10- 查询可信设备列表
11- 查询本地设备信息,包括设备名称,设备类型和设备标识等。
12
13
14> **说明:**
15>
16> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
17> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.distributedDeviceManager (设备管理)](js-apis-distributedDeviceManager.md)。
18
19
20## 导入模块
21
22```ts
23import { distributedDeviceManager } from '@kit.DistributedServiceKit';
24```
25
26### replyUiAction
27
28replyUiAction(action: number, actionResult: string): void;
29
30回复用户UI操作行为。此接口只能被devicemanager的PIN码hap使用。
31
32**需要权限**:ohos.permission.ACCESS_SERVICE_DM
33
34**系统能力**:SystemCapability.DistributedHardware.DeviceManager
35
36**系统API**: 此接口为系统接口。
37
38**参数:**
39
40  | 参数名       | 类型            | 必填  | 说明                |
41  | ------------- | --------------- | ---- | ------------------- |
42  | action        | number          | 是    | 用户操作动作。       |
43  | actionResult        | string          | 是    | 表示用户操作结果。 |
44
45**错误码:**
46
47以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)
48
49| 错误码ID | 错误信息                                                        |
50| -------- | --------------------------------------------------------------- |
51| 201 | Permission verification failed. The application does not have the permission required to call the API.                                            |
52| 202 | Permission verification failed. A non-system application calls a system API.                              |
53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified actionResult is greater than 255. |
54
55**示例:**
56
57示例中`dmInstance`的初始化请参见[创建一个设备管理实例](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager)。
58<!--code_no_check-->
59  ```ts
60  import { BusinessError } from '@kit.BasicServicesKit';
61
62 try {
63    /*
64      action = 0 - 允许授权
65      action = 1 - 取消授权
66      action = 2 - 授权框用户操作超时
67      action = 3 - 取消pin码框展示
68      action = 4 - 取消pin码输入框展示
69      action = 5 - pin码输入框确定操作
70    */
71    let operation = 0;
72    dmInstance.replyUiAction(operation, 'extra');
73  } catch (err) {
74    let e: BusinessError = err as BusinessError;
75    console.error('replyUiAction errCode:' + e.code + ',errMessage:' + e.message);
76  }
77  ```
78
79### on('replyResult')
80
81on(type: 'replyResult', callback: Callback&lt;{ param: string;}&gt;): void;
82
83回复UI操作结果回调。
84
85**需要权限**:ohos.permission.ACCESS_SERVICE_DM
86
87**系统能力**:SystemCapability.DistributedHardware.DeviceManager
88
89**系统API**: 此接口为系统接口。
90
91**参数:**
92
93  | 参数名      | 类型                             | 必填 | 说明                            |
94  | -------- | ------------------------------------ | ---- | ------------------------------ |
95  | type     | string                                | 是  | 注册的设备管理器 UI 状态回调,以便在状态改变时通知应用,固定为replyResult。 |
96  | callback | Callback&lt;{&nbsp;param:&nbsp;string;}&gt; | 是  | 指示要注册的设备管理器 UI 状态回调,返回UI状态。        |
97
98**错误码:**
99
100以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)
101
102| 错误码ID | 错误信息                                                        |
103| -------- | --------------------------------------------------------------- |
104| 202 | Permission verification failed. A non-system application calls a system API.                            |
105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
106
107**示例:**
108
109示例中`dmInstance`的初始化请参见[创建一个设备管理实例](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager)。
110<!--code_no_check-->
111  ```ts
112  import { BusinessError } from '@kit.BasicServicesKit';
113
114  class Data {
115    param: string = '';
116  }
117
118  interface TmpStr {
119    verifyFailed: boolean;
120  }
121
122  try {
123    dmInstance.on('replyResult', (data: Data) => {
124      console.log('replyResult executed, dialog closed' + JSON.stringify(data));
125      let tmpStr: TmpStr = JSON.parse(data.param);
126      let isShow = tmpStr.verifyFailed;
127      console.log('replyResult executed, dialog closed' + isShow);
128    });
129  } catch (err) {
130    let e: BusinessError = err as BusinessError;
131    console.error('replyResult errCode:' + e.code + ',errMessage:' + e.message);
132  }
133  ```
134
135### off('replyResult')
136
137off(type: 'replyResult', callback?: Callback&lt;{ param: string;}&gt;): void;
138
139取消回复UI操作结果回调。
140
141**需要权限**:ohos.permission.ACCESS_SERVICE_DM
142
143**系统能力**:SystemCapability.DistributedHardware.DeviceManager
144
145**系统API**: 此接口为系统接口。
146
147**参数:**
148
149  | 参数名      | 类型                              | 必填 | 说明                            |
150  | -------- | ------------------------------------- | ---- | ------------------------------ |
151  | type     | string                                | 是   | 取消注册的设备管理器 UI 状态回调,固定为replyResult。 |
152  | callback | Callback&lt;{&nbsp;param:&nbsp;string;}&gt; | 否   | 指示要取消注册的设备管理器 UI 状态,返回UI状态。 |
153
154**错误码:**
155
156以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)
157
158| 错误码ID | 错误信息                                                        |
159| -------- | --------------------------------------------------------------- |
160| 202 | Permission verification failed. A non-system application calls a system API.                              |
161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. |
162
163**示例:**
164
165示例中`dmInstance`的初始化请参见[创建一个设备管理实例](js-apis-distributedDeviceManager.md#distributeddevicemanagercreatedevicemanager)。
166<!--code_no_check-->
167  ```ts
168  import { BusinessError } from '@kit.BasicServicesKit';
169
170  try {
171    dmInstance.off('replyResult');
172  } catch (err) {
173    let e: BusinessError = err as BusinessError;
174    console.error('replyResult errCode:' + e.code + ',errMessage:' + e.message);
175  }
176  ```
177
178