1e41f4b71Sopenharmony_ci# @ohos.bundle.defaultAppManager (默认应用管理)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci本模块提供查询默认应用的能力,支持查询当前应用是否是默认应用。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> 当前页面仅包含本模块的系统接口,其他公开接口参见[`@ohos.bundle.defaultAppManager`](js-apis-defaultAppManager.md)。
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## 导入模块
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```ts
14e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## 权限列表
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| 权限                                    | 权限等级    | 描述             |
20e41f4b71Sopenharmony_ci| --------------------------------------- | ----------- | ---------------- |
21e41f4b71Sopenharmony_ci| ohos.permission.GET_DEFAULT_APPLICATION | system_core | 默认应用相关权限。 |
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci权限等级参考[权限APL等级说明](../../security/AccessToken/app-permission-mgmt-overview.md#权限机制中的基本概念)。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## defaultAppManager.getDefaultApplication
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_cigetDefaultApplication(type: string, userId?: number): Promise\<BundleInfo>
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型获取默认应用信息,使用Promise形式返回结果。
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**参数:**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
40e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
41e41f4b71Sopenharmony_ci| type  | string | 是    | 要查询的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
42e41f4b71Sopenharmony_ci| userId  | number | 否    | 用户ID。默认值:调用方所在用户。                        |
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**返回值:**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| 类型                        | 说明                 |
47e41f4b71Sopenharmony_ci| ------------------------- | ------------------ |
48e41f4b71Sopenharmony_ci| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise形式返回默认应用包信息。 |
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**错误码:**
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                  |
55e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
56e41f4b71Sopenharmony_ci| 201 | Permission denied. |
57e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
58e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
59e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
60e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.       |
61e41f4b71Sopenharmony_ci| 17700023 | The specified default app does not exist. |
62e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.            |
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**示例:**
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci```ts
67e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
68e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
69e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER)
72e41f4b71Sopenharmony_ci  .then((data) => {
73e41f4b71Sopenharmony_ci    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
74e41f4b71Sopenharmony_ci  })
75e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
76e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
77e41f4b71Sopenharmony_ci  });
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication("image/png")
80e41f4b71Sopenharmony_ci  .then((data) => {
81e41f4b71Sopenharmony_ci    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
82e41f4b71Sopenharmony_ci  })
83e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
84e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
85e41f4b71Sopenharmony_ci  });
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI)
88e41f4b71Sopenharmony_ci  .then((data) => {
89e41f4b71Sopenharmony_ci    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
90e41f4b71Sopenharmony_ci  })
91e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
92e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
93e41f4b71Sopenharmony_ci  });
94e41f4b71Sopenharmony_ci```
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci## defaultAppManager.getDefaultApplication
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_cigetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<BundleInfo>) : void
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型获取默认应用信息,使用callback形式返回结果。
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**参数:**
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
111e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
112e41f4b71Sopenharmony_ci| type  | string | 是    | 要查询的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
113e41f4b71Sopenharmony_ci| userId  | number | 是    | 用户ID。                           |
114e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | 是    | 程序启动作为入参的回调函数,返回包信息。                    |
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**错误码:**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                  |
121e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
122e41f4b71Sopenharmony_ci| 201 | Permission denied. |
123e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
124e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
125e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
126e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.       |
127e41f4b71Sopenharmony_ci| 17700023 | The specified default app does not exist. |
128e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.            |
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**示例:**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```ts
133e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
134e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
135e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_cilet userId = 100;
138e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
139e41f4b71Sopenharmony_ci  if (err) {
140e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
141e41f4b71Sopenharmony_ci    return;
142e41f4b71Sopenharmony_ci  }
143e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
144e41f4b71Sopenharmony_ci});
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication("image/png", userId, (err: BusinessError, data) => {
147e41f4b71Sopenharmony_ci  if (err) {
148e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
149e41f4b71Sopenharmony_ci    return;
150e41f4b71Sopenharmony_ci  }
151e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
152e41f4b71Sopenharmony_ci});
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId, (err: BusinessError, data) => {
155e41f4b71Sopenharmony_ci  if (err) {
156e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
157e41f4b71Sopenharmony_ci    return;
158e41f4b71Sopenharmony_ci  }
159e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
160e41f4b71Sopenharmony_ci});
161e41f4b71Sopenharmony_ci```
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci## defaultAppManager.getDefaultApplication
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_cigetDefaultApplication(type: string, callback: AsyncCallback\<BundleInfo>) : void
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型获取默认应用信息,使用callback形式返回结果。
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci**参数:**
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
178e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
179e41f4b71Sopenharmony_ci| type  | string | 是    | 要查询的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
180e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | 是    | 程序启动作为入参的回调函数,返回包信息。                    |
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci**错误码:**
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                  |
187e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
188e41f4b71Sopenharmony_ci| 201 | Permission denied. |
189e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
190e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
191e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
192e41f4b71Sopenharmony_ci| 17700023 | The specified default app does not exist. |
193e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.            |
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**示例:**
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci```ts
198e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
199e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
200e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
203e41f4b71Sopenharmony_ci  if (err) {
204e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
205e41f4b71Sopenharmony_ci    return;
206e41f4b71Sopenharmony_ci  }
207e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
208e41f4b71Sopenharmony_ci});
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication("image/png", (err: BusinessError, data) => {
211e41f4b71Sopenharmony_ci  if (err) {
212e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
213e41f4b71Sopenharmony_ci    return;
214e41f4b71Sopenharmony_ci  }
215e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
216e41f4b71Sopenharmony_ci});
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_cidefaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, (err: BusinessError, data) => {
219e41f4b71Sopenharmony_ci  if (err) {
220e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
221e41f4b71Sopenharmony_ci    return;
222e41f4b71Sopenharmony_ci  }
223e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
224e41f4b71Sopenharmony_ci});
225e41f4b71Sopenharmony_ci```
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci## defaultAppManager.getDefaultApplicationSync<sup>10+</sup>
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_cigetDefaultApplicationSync(type: string, userId?: number): BundleInfo
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci以同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型获取默认应用信息,使用BundleInfo返回结果。
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_DEFAULT_APPLICATION
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**参数:**
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                                    |
242e41f4b71Sopenharmony_ci| -------| ------ | ---- | --------------------------------------- |
243e41f4b71Sopenharmony_ci| type   | string | 是   | 要查询的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。|
244e41f4b71Sopenharmony_ci| userId | number | 否   | 用户ID。默认值:调用方所在用户。         |
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**返回值:**
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci| 类型                                       | 说明                 |
249e41f4b71Sopenharmony_ci| ------------------------------------------ | -------------------- |
250e41f4b71Sopenharmony_ci| [BundleInfo](js-apis-bundle-BundleInfo.md) | 返回的默认应用包信息。|
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**错误码:**
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                  |
257e41f4b71Sopenharmony_ci| -------- | ----------------------------------------- |
258e41f4b71Sopenharmony_ci| 201 | Permission denied. |
259e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
260e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
261e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
262e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.       |
263e41f4b71Sopenharmony_ci| 17700023 | The specified default app does not exist. |
264e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.            |
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci**示例:**
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci```ts
269e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
270e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_citry {
273e41f4b71Sopenharmony_ci  let data = defaultAppManager.getDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER)
274e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
275e41f4b71Sopenharmony_ci} catch(error) {
276e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
277e41f4b71Sopenharmony_ci};
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_citry {
280e41f4b71Sopenharmony_ci  let data = defaultAppManager.getDefaultApplicationSync("image/png")
281e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
282e41f4b71Sopenharmony_ci} catch(error) {
283e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
284e41f4b71Sopenharmony_ci};
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_citry {
287e41f4b71Sopenharmony_ci  let data = defaultAppManager.getDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI)
288e41f4b71Sopenharmony_ci  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
289e41f4b71Sopenharmony_ci} catch(error) {
290e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
291e41f4b71Sopenharmony_ci};
292e41f4b71Sopenharmony_ci```
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci## defaultAppManager.setDefaultApplication
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_cisetDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise\<void>
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型设置默认应用,使用Promise形式返回结果。
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci**参数:**
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
309e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
310e41f4b71Sopenharmony_ci| type  | string | 是    | 要设置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
311e41f4b71Sopenharmony_ci| elementName  | [ElementName](js-apis-bundle-ElementName.md) | 是    | 要设置为默认应用的组件信息。                           |
312e41f4b71Sopenharmony_ci| userId  | number | 否    | 用户ID。默认值:调用方所在用户。                           |
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**返回值:**
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci| 类型           | 说明                               |
317e41f4b71Sopenharmony_ci| -------------- | ---------------------------------- |
318e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象,无返回结果的Promise对象。 |
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**错误码:**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                       |
325e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- |
326e41f4b71Sopenharmony_ci| 201 | Permission denied. |
327e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
328e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
329e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
330e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.            |
331e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.                 |
332e41f4b71Sopenharmony_ci| 17700028 | The specified ability does not match the type. |
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci**示例:**
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci```ts
337e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
338e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
339e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
342e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
343e41f4b71Sopenharmony_ci  moduleName: "module01",
344e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
345e41f4b71Sopenharmony_ci}).then((data) => {
346e41f4b71Sopenharmony_ci  console.info('Operation successful.');
347e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
348e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
349e41f4b71Sopenharmony_ci});
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_cilet userId = 100;
352e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
353e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
354e41f4b71Sopenharmony_ci  moduleName: "module01",
355e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
356e41f4b71Sopenharmony_ci}, userId).then((data) => {
357e41f4b71Sopenharmony_ci  console.info('Operation successful.');
358e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
359e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
360e41f4b71Sopenharmony_ci});
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication("image/png", {
363e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
364e41f4b71Sopenharmony_ci  moduleName: "module01",
365e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
366e41f4b71Sopenharmony_ci}, userId).then((data) => {
367e41f4b71Sopenharmony_ci  console.info('Operation successful.');
368e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
369e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
370e41f4b71Sopenharmony_ci});
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
373e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
374e41f4b71Sopenharmony_ci  moduleName: "module01",
375e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
376e41f4b71Sopenharmony_ci}, userId).then((data) => {
377e41f4b71Sopenharmony_ci  console.info('Operation successful.');
378e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => {
379e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
380e41f4b71Sopenharmony_ci});
381e41f4b71Sopenharmony_ci```
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci## defaultAppManager.setDefaultApplication
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_cisetDefaultApplication(type: string, elementName: ElementName, userId: number, callback: AsyncCallback\<void>) : void
386e41f4b71Sopenharmony_ci
387e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型设置默认应用,使用callback形式返回结果。
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_ci**参数:**
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
398e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
399e41f4b71Sopenharmony_ci| type  | string | 是    | 要设置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
400e41f4b71Sopenharmony_ci| elementName  | [ElementName](js-apis-bundle-ElementName.md) | 是    | 要设置为默认应用的组件信息。                           |
401e41f4b71Sopenharmony_ci| userId  | number | 是    | 用户ID。                           |
402e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<void> | 是    | 程序启动作为入参的回调函数。                    |
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci**错误码:**
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                       |
409e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- |
410e41f4b71Sopenharmony_ci| 201 | Permission denied. |
411e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
412e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
413e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
414e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.            |
415e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.                 |
416e41f4b71Sopenharmony_ci| 17700028 | The specified ability does not match the type. |
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci**示例:**
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ci```ts
421e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
422e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
423e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_cilet userId = 100;
426e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
427e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
428e41f4b71Sopenharmony_ci  moduleName: "module01",
429e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
430e41f4b71Sopenharmony_ci}, userId, (err: BusinessError, data) => {
431e41f4b71Sopenharmony_ci  if (err) {
432e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
433e41f4b71Sopenharmony_ci    return;
434e41f4b71Sopenharmony_ci  }
435e41f4b71Sopenharmony_ci  console.info('Operation successful.');
436e41f4b71Sopenharmony_ci});
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication("image/png", {
439e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
440e41f4b71Sopenharmony_ci  moduleName: "module01",
441e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
442e41f4b71Sopenharmony_ci}, userId, (err: BusinessError, data) => {
443e41f4b71Sopenharmony_ci  if (err) {
444e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
445e41f4b71Sopenharmony_ci    return;
446e41f4b71Sopenharmony_ci  }
447e41f4b71Sopenharmony_ci  console.info('Operation successful.');
448e41f4b71Sopenharmony_ci});
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
451e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
452e41f4b71Sopenharmony_ci  moduleName: "module01",
453e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
454e41f4b71Sopenharmony_ci}, userId, (err: BusinessError, data) => {
455e41f4b71Sopenharmony_ci  if (err) {
456e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
457e41f4b71Sopenharmony_ci    return;
458e41f4b71Sopenharmony_ci  }
459e41f4b71Sopenharmony_ci  console.info('Operation successful.');
460e41f4b71Sopenharmony_ci});
461e41f4b71Sopenharmony_ci```
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci## defaultAppManager.setDefaultApplication
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_cisetDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback\<void>) : void
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型设置默认应用,使用callback形式返回结果。
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
474e41f4b71Sopenharmony_ci
475e41f4b71Sopenharmony_ci**参数:**
476e41f4b71Sopenharmony_ci
477e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
478e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
479e41f4b71Sopenharmony_ci| type  | string | 是    | 要设置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
480e41f4b71Sopenharmony_ci| elementName  | [ElementName](js-apis-bundle-ElementName.md) | 是    | 要设置为默认应用的组件信息。                           |
481e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<void> | 是    | 程序启动作为入参的回调函数。                    |
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci**错误码:**
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                       |
488e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- |
489e41f4b71Sopenharmony_ci| 201 | Permission denied. |
490e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
491e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
492e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
493e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.                 |
494e41f4b71Sopenharmony_ci| 17700028 | The specified ability does not match the type. |
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**示例:**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci```ts
499e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
500e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
501e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
504e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
505e41f4b71Sopenharmony_ci  moduleName: "module01",
506e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
507e41f4b71Sopenharmony_ci}, (err: BusinessError, data) => {
508e41f4b71Sopenharmony_ci  if (err) {
509e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
510e41f4b71Sopenharmony_ci    return;
511e41f4b71Sopenharmony_ci  }
512e41f4b71Sopenharmony_ci  console.info('Operation successful.');
513e41f4b71Sopenharmony_ci});
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication("image/png", {
516e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
517e41f4b71Sopenharmony_ci  moduleName: "module01",
518e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
519e41f4b71Sopenharmony_ci}, (err: BusinessError, data) => {
520e41f4b71Sopenharmony_ci  if (err) {
521e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
522e41f4b71Sopenharmony_ci    return;
523e41f4b71Sopenharmony_ci  }
524e41f4b71Sopenharmony_ci  console.info('Operation successful.');
525e41f4b71Sopenharmony_ci});
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_cidefaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
528e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
529e41f4b71Sopenharmony_ci  moduleName: "module01",
530e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
531e41f4b71Sopenharmony_ci}, (err: BusinessError, data) => {
532e41f4b71Sopenharmony_ci  if (err) {
533e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
534e41f4b71Sopenharmony_ci    return;
535e41f4b71Sopenharmony_ci  }
536e41f4b71Sopenharmony_ci  console.info('Operation successful.');
537e41f4b71Sopenharmony_ci});
538e41f4b71Sopenharmony_ci```
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ci## defaultAppManager.setDefaultApplicationSync<sup>10+</sup>
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_cisetDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci以同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型设置默认应用。
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci**参数:**
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ci| 参数名      | 类型   | 必填 | 说明                                      |
555e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
556e41f4b71Sopenharmony_ci| type        | string | 是   | 要设置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。|
557e41f4b71Sopenharmony_ci| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 要设置为默认应用的组件信息。                           |
558e41f4b71Sopenharmony_ci| userId      | number | 否   | 用户ID。默认值:调用方所在用户。                           |
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci**错误码:**
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
563e41f4b71Sopenharmony_ci
564e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                       |
565e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- |
566e41f4b71Sopenharmony_ci| 201 | Permission denied. |
567e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
568e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
569e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
570e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.            |
571e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.                 |
572e41f4b71Sopenharmony_ci| 17700028 | The specified ability does not match the type. |
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ci**示例:**
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci```ts
577e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
578e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_citry {
581e41f4b71Sopenharmony_ci  defaultAppManager.setDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, {
582e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
583e41f4b71Sopenharmony_ci  moduleName: "module01",
584e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
585e41f4b71Sopenharmony_ci});
586e41f4b71Sopenharmony_ci  console.info('Operation successful.');
587e41f4b71Sopenharmony_ci} catch(error) {
588e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
589e41f4b71Sopenharmony_ci};
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_cilet userId = 100;
592e41f4b71Sopenharmony_citry {
593e41f4b71Sopenharmony_ci  defaultAppManager.setDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, {
594e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
595e41f4b71Sopenharmony_ci  moduleName: "module01",
596e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
597e41f4b71Sopenharmony_ci}, userId);
598e41f4b71Sopenharmony_ci  console.info('Operation successful.');
599e41f4b71Sopenharmony_ci} catch(error) {
600e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
601e41f4b71Sopenharmony_ci};
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_citry {
604e41f4b71Sopenharmony_ci  defaultAppManager.setDefaultApplicationSync("image/png", {
605e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
606e41f4b71Sopenharmony_ci  moduleName: "module01",
607e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
608e41f4b71Sopenharmony_ci}, userId);
609e41f4b71Sopenharmony_ci  console.info('Operation successful.');
610e41f4b71Sopenharmony_ci} catch(error) {
611e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
612e41f4b71Sopenharmony_ci};
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_citry {
615e41f4b71Sopenharmony_ci  defaultAppManager.setDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI, {
616e41f4b71Sopenharmony_ci  bundleName: "com.example.myapplication",
617e41f4b71Sopenharmony_ci  moduleName: "module01",
618e41f4b71Sopenharmony_ci  abilityName: "EntryAbility"
619e41f4b71Sopenharmony_ci}, userId);
620e41f4b71Sopenharmony_ci  console.info('Operation successful.');
621e41f4b71Sopenharmony_ci} catch(error) {
622e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
623e41f4b71Sopenharmony_ci};
624e41f4b71Sopenharmony_ci```
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ci## defaultAppManager.resetDefaultApplication
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ciresetDefaultApplication(type: string, userId?: number): Promise\<void>
629e41f4b71Sopenharmony_ci
630e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型重置默认应用,使用Promise形式返回结果。
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
635e41f4b71Sopenharmony_ci
636e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
637e41f4b71Sopenharmony_ci
638e41f4b71Sopenharmony_ci**参数:**
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
641e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
642e41f4b71Sopenharmony_ci| type  | string | 是    | 要重置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
643e41f4b71Sopenharmony_ci| userId  | number | 否    | 用户ID。默认值:调用方所在用户。                           |
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci**错误码:**
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                            |
650e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
651e41f4b71Sopenharmony_ci| 201 | Permission denied. |
652e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
653e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
654e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
655e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
656e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.      |
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ci**示例:**
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci```ts
661e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
662e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
663e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_cilet userId = 100;
666e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId)
667e41f4b71Sopenharmony_ci  .then((data) => {
668e41f4b71Sopenharmony_ci    console.info('Operation successful.');
669e41f4b71Sopenharmony_ci  })
670e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
671e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
672e41f4b71Sopenharmony_ci  });
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication("image/png", userId)
675e41f4b71Sopenharmony_ci  .then((data) => {
676e41f4b71Sopenharmony_ci    console.info('Operation successful.');
677e41f4b71Sopenharmony_ci  })
678e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
679e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
680e41f4b71Sopenharmony_ci  });
681e41f4b71Sopenharmony_ci
682e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId)
683e41f4b71Sopenharmony_ci  .then((data) => {
684e41f4b71Sopenharmony_ci    console.info('Operation successful.');
685e41f4b71Sopenharmony_ci  })
686e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
687e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(error));
688e41f4b71Sopenharmony_ci  });
689e41f4b71Sopenharmony_ci```
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci## defaultAppManager.resetDefaultApplication
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ciresetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<void>) : void
694e41f4b71Sopenharmony_ci
695e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型重置默认应用,使用callback形式返回结果。
696e41f4b71Sopenharmony_ci
697e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
700e41f4b71Sopenharmony_ci
701e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**参数:**
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
706e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
707e41f4b71Sopenharmony_ci| type  | string | 是    | 要重置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
708e41f4b71Sopenharmony_ci| userId  | number | 是    | 用户ID。                          |
709e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<void> | 是    | 程序启动作为入参的回调函数。                    |
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ci**错误码:**
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                            |
716e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
717e41f4b71Sopenharmony_ci| 201 | Permission denied. |
718e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
719e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
720e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
721e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
722e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.      |
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci**示例:**
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci```ts
727e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
728e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
729e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_cilet userId = 100;
732e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
733e41f4b71Sopenharmony_ci  if (err) {
734e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
735e41f4b71Sopenharmony_ci    return;
736e41f4b71Sopenharmony_ci  }
737e41f4b71Sopenharmony_ci  console.info('Operation successful.');
738e41f4b71Sopenharmony_ci});
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication("image/png", userId, (err: BusinessError, data) => {
741e41f4b71Sopenharmony_ci  if (err) {
742e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
743e41f4b71Sopenharmony_ci    return;
744e41f4b71Sopenharmony_ci  }
745e41f4b71Sopenharmony_ci  console.info('Operation successful.');
746e41f4b71Sopenharmony_ci});
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId, (err: BusinessError, data) => {
749e41f4b71Sopenharmony_ci  if (err) {
750e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
751e41f4b71Sopenharmony_ci    return;
752e41f4b71Sopenharmony_ci  }
753e41f4b71Sopenharmony_ci  console.info('Operation successful.');
754e41f4b71Sopenharmony_ci});
755e41f4b71Sopenharmony_ci```
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci## defaultAppManager.resetDefaultApplication
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_ciresetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型重置默认应用,使用callback形式返回结果。
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_ci**参数:**
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci| 参数名         | 类型     | 必填   | 说明                                      |
772e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- |
773e41f4b71Sopenharmony_ci| type  | string | 是    | 要重置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。       |
774e41f4b71Sopenharmony_ci| callback    | AsyncCallback\<void> | 是    | 程序启动作为入参的回调函数。                    |
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci**错误码:**
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                            |
781e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
782e41f4b71Sopenharmony_ci| 201 | Permission denied. |
783e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
784e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
785e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
786e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.      |
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ci**示例:**
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ci```ts
791e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
792e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
793e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
796e41f4b71Sopenharmony_ci  if (err) {
797e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
798e41f4b71Sopenharmony_ci    return;
799e41f4b71Sopenharmony_ci  }
800e41f4b71Sopenharmony_ci  console.info('Operation successful.');
801e41f4b71Sopenharmony_ci});
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication("image/png", (err: BusinessError, data) => {
804e41f4b71Sopenharmony_ci  if (err) {
805e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
806e41f4b71Sopenharmony_ci    return;
807e41f4b71Sopenharmony_ci  }
808e41f4b71Sopenharmony_ci  console.info('Operation successful.');
809e41f4b71Sopenharmony_ci});
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_cidefaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, (err: BusinessError, data) => {
812e41f4b71Sopenharmony_ci  if (err) {
813e41f4b71Sopenharmony_ci    console.error('Operation failed. Cause: ' + JSON.stringify(err));
814e41f4b71Sopenharmony_ci    return;
815e41f4b71Sopenharmony_ci  }
816e41f4b71Sopenharmony_ci  console.info('Operation successful.');
817e41f4b71Sopenharmony_ci});
818e41f4b71Sopenharmony_ci```
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_ci## defaultAppManager.resetDefaultApplicationSync<sup>10+</sup>
821e41f4b71Sopenharmony_ci
822e41f4b71Sopenharmony_ciresetDefaultApplicationSync(type: string, userId?: number): void
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci以同步方法根据系统已定义的应用类型或者符合媒体类型格式(type/subtype)的文件类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型重置默认应用。
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.SET_DEFAULT_APPLICATION
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci**系统接口:**  此接口为系统接口。
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci**参数:**
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ci| 参数名 | 类型   | 必填 | 说明                                    |
835e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
836e41f4b71Sopenharmony_ci| type   | string | 是   | 要重置的应用类型,取[ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype)中的值,或者符合媒体类型格式的文件类型,或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型。|
837e41f4b71Sopenharmony_ci| userId | number | 否   | 用户ID。默认值:调用方所在用户。                           |
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_ci**错误码:**
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                            |
844e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
845e41f4b71Sopenharmony_ci| 201 | Permission denied. |
846e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. |
847e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
848e41f4b71Sopenharmony_ci| 801 | Capability not supported. |
849e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
850e41f4b71Sopenharmony_ci| 17700025 | The specified type is invalid.      |
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ci**示例:**
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci```ts
855e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit';
856e41f4b71Sopenharmony_ciimport { uniformTypeDescriptor } from '@kit.ArkData';
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_cilet userId = 100;
859e41f4b71Sopenharmony_citry {
860e41f4b71Sopenharmony_ci  defaultAppManager.resetDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, userId);
861e41f4b71Sopenharmony_ci  console.info('Operation successful.');
862e41f4b71Sopenharmony_ci} catch(error) {
863e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
864e41f4b71Sopenharmony_ci};
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_citry {
867e41f4b71Sopenharmony_ci  defaultAppManager.resetDefaultApplicationSync("image/png", userId);
868e41f4b71Sopenharmony_ci  console.info('Operation successful.');
869e41f4b71Sopenharmony_ci} catch(error) {
870e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
871e41f4b71Sopenharmony_ci};
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_citry {
874e41f4b71Sopenharmony_ci  defaultAppManager.resetDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI, userId);
875e41f4b71Sopenharmony_ci  console.info('Operation successful.');
876e41f4b71Sopenharmony_ci} catch(error) {
877e41f4b71Sopenharmony_ci  console.error('Operation failed. Cause: ' + JSON.stringify(error));
878e41f4b71Sopenharmony_ci};
879e41f4b71Sopenharmony_ci```