1# @ohos.bundle.defaultAppManager (Default Application Management) (System API)
2
3The **DefaultAppManager** module provides APIs to query whether the current application is the default application of a specific type.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.bundle.defaultAppManager](js-apis-defaultAppManager.md).
10
11## Modules to Import
12
13```ts
14import { defaultAppManager } from '@kit.AbilityKit';
15```
16
17## Required Permissions
18
19| Permission                                   | APL   | Description            |
20| --------------------------------------- | ----------- | ---------------- |
21| ohos.permission.GET_DEFAULT_APPLICATION | system_core | Permission related to the default application. |
22
23For details about the APL, see [Basic Concepts in the Permission Mechanism](../../security/AccessToken/app-permission-mgmt-overview.md#basic-concepts-in-the-permission-mechanism).
24
25## defaultAppManager.getDefaultApplication
26
27getDefaultApplication(type: string, userId?: number): Promise\<BundleInfo>
28
29Obtains the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses a promise to return the result.
30
31**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
32
33**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
34
35**System API**: This is a system API.
36
37**Parameters**
38
39| Name        | Type    | Mandatory  | Description                                     |
40| ----------- | ------ | ---- | --------------------------------------- |
41| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
42| userId  | number | No   | User ID. The default value is the user ID of the caller.                        |
43
44**Return value**
45
46| Type                       | Description                |
47| ------------------------- | ------------------ |
48| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise used to return the default application. |
49
50**Error codes**
51
52For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
53
54| ID | Error Message                                 |
55| -------- | ----------------------------------------- |
56| 201 | Permission denied. |
57| 202 | Permission denied, non-system app called system api. |
58| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
59| 801 | Capability not supported. |
60| 17700004 | The specified user ID is not found.       |
61| 17700023 | The specified default app does not exist. |
62| 17700025 | The specified type is invalid.            |
63
64**Example**
65
66```ts
67import { defaultAppManager } from '@kit.AbilityKit';
68import { BusinessError } from '@kit.BasicServicesKit';
69import { uniformTypeDescriptor } from '@kit.ArkData';
70
71defaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER)
72  .then((data) => {
73    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
74  })
75  .catch((error: BusinessError) => {
76    console.error('Operation failed. Cause: ' + JSON.stringify(error));
77  });
78
79defaultAppManager.getDefaultApplication("image/png")
80  .then((data) => {
81    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
82  })
83  .catch((error: BusinessError) => {
84    console.error('Operation failed. Cause: ' + JSON.stringify(error));
85  });
86
87defaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI)
88  .then((data) => {
89    console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
90  })
91  .catch((error: BusinessError) => {
92    console.error('Operation failed. Cause: ' + JSON.stringify(error));
93  });
94```
95
96## defaultAppManager.getDefaultApplication
97
98getDefaultApplication(type: string, userId: number, callback: AsyncCallback\<BundleInfo>) : void
99
100Obtains the default application of a user based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
101
102**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
103
104**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
105
106**System API**: This is a system API.
107
108**Parameters**
109
110| Name        | Type    | Mandatory  | Description                                     |
111| ----------- | ------ | ---- | --------------------------------------- |
112| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
113| userId  | number | Yes   | User ID.                          |
114| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes   | Callback used to return the default application.                   |
115
116**Error codes**
117
118For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
119
120| ID | Error Message                                 |
121| -------- | ----------------------------------------- |
122| 201 | Permission denied. |
123| 202 | Permission denied, non-system app called system api. |
124| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
125| 801 | Capability not supported. |
126| 17700004 | The specified user ID is not found.       |
127| 17700023 | The specified default app does not exist. |
128| 17700025 | The specified type is invalid.            |
129
130**Example**
131
132```ts
133import { defaultAppManager } from '@kit.AbilityKit';
134import { BusinessError } from '@kit.BasicServicesKit';
135import { uniformTypeDescriptor } from '@kit.ArkData';
136
137let userId = 100;
138defaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
139  if (err) {
140    console.error('Operation failed. Cause: ' + JSON.stringify(err));
141    return;
142  }
143  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
144});
145
146defaultAppManager.getDefaultApplication("image/png", userId, (err: BusinessError, data) => {
147  if (err) {
148    console.error('Operation failed. Cause: ' + JSON.stringify(err));
149    return;
150  }
151  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
152});
153
154defaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId, (err: BusinessError, data) => {
155  if (err) {
156    console.error('Operation failed. Cause: ' + JSON.stringify(err));
157    return;
158  }
159  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
160});
161```
162
163## defaultAppManager.getDefaultApplication
164
165getDefaultApplication(type: string, callback: AsyncCallback\<BundleInfo>) : void
166
167Obtains the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
168
169**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
170
171**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
172
173**System API**: This is a system API.
174
175**Parameters**
176
177| Name        | Type    | Mandatory  | Description                                     |
178| ----------- | ------ | ---- | --------------------------------------- |
179| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
180| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes   | Callback used to return the default application.                   |
181
182**Error codes**
183
184For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
185
186| ID | Error Message                                 |
187| -------- | ----------------------------------------- |
188| 201 | Permission denied. |
189| 202 | Permission denied, non-system app called system api. |
190| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
191| 801 | Capability not supported. |
192| 17700023 | The specified default app does not exist. |
193| 17700025 | The specified type is invalid.            |
194
195**Example**
196
197```ts
198import { defaultAppManager } from '@kit.AbilityKit';
199import { BusinessError } from '@kit.BasicServicesKit';
200import { uniformTypeDescriptor } from '@kit.ArkData';
201
202defaultAppManager.getDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
203  if (err) {
204    console.error('Operation failed. Cause: ' + JSON.stringify(err));
205    return;
206  }
207  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
208});
209
210defaultAppManager.getDefaultApplication("image/png", (err: BusinessError, data) => {
211  if (err) {
212    console.error('Operation failed. Cause: ' + JSON.stringify(err));
213    return;
214  }
215  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
216});
217
218defaultAppManager.getDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, (err: BusinessError, data) => {
219  if (err) {
220    console.error('Operation failed. Cause: ' + JSON.stringify(err));
221    return;
222  }
223  console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
224});
225```
226
227## defaultAppManager.getDefaultApplicationSync<sup>10+</sup>
228
229getDefaultApplicationSync(type: string, userId?: number): BundleInfo
230
231Obtains the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API returns the result synchronously.
232
233**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
234
235**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
236
237**System API**: This is a system API.
238
239**Parameters**
240
241| Name | Type  | Mandatory | Description                                   |
242| -------| ------ | ---- | --------------------------------------- |
243| type   | string | Yes  | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).|
244| userId | number | No  | User ID. The default value is the user ID of the caller.         |
245
246**Return value**
247
248| Type                                      | Description                |
249| ------------------------------------------ | -------------------- |
250| [BundleInfo](js-apis-bundle-BundleInfo.md) | Bundle information of the default application.|
251
252**Error codes**
253
254For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
255
256| ID | Error Message                                 |
257| -------- | ----------------------------------------- |
258| 201 | Permission denied. |
259| 202 | Permission denied, non-system app called system api. |
260| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
261| 801 | Capability not supported. |
262| 17700004 | The specified user ID is not found.       |
263| 17700023 | The specified default app does not exist. |
264| 17700025 | The specified type is invalid.            |
265
266**Example**
267
268```ts
269import { defaultAppManager } from '@kit.AbilityKit';
270import { uniformTypeDescriptor } from '@kit.ArkData';
271
272try {
273  let data = defaultAppManager.getDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER)
274  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
275} catch(error) {
276  console.error('Operation failed. Cause: ' + JSON.stringify(error));
277};
278
279try {
280  let data = defaultAppManager.getDefaultApplicationSync("image/png")
281  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
282} catch(error) {
283  console.error('Operation failed. Cause: ' + JSON.stringify(error));
284};
285
286try {
287  let data = defaultAppManager.getDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI)
288  console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
289} catch(error) {
290  console.error('Operation failed. Cause: ' + JSON.stringify(error));
291};
292```
293
294## defaultAppManager.setDefaultApplication
295
296setDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise\<void>
297
298Sets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses a promise to return the result.
299
300**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
301
302**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
303
304**System API**: This is a system API.
305
306**Parameters**
307
308| Name        | Type    | Mandatory  | Description                                     |
309| ----------- | ------ | ---- | --------------------------------------- |
310| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
311| elementName  | [ElementName](js-apis-bundle-ElementName.md) | Yes   | Information about the element to be set as the default application.                          |
312| userId  | number | No   | User ID. The default value is the user ID of the caller.                           |
313
314**Return value**
315
316| Type          | Description                              |
317| -------------- | ---------------------------------- |
318| Promise\<void> | Promise that returns no value. |
319
320**Error codes**
321
322For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
323
324| ID | Error Message                                      |
325| -------- | ---------------------------------------------- |
326| 201 | Permission denied. |
327| 202 | Permission denied, non-system app called system api. |
328| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
329| 801 | Capability not supported. |
330| 17700004 | The specified user ID is not found.            |
331| 17700025 | The specified type is invalid.                 |
332| 17700028 | The specified ability does not match the type. |
333
334**Example**
335
336```ts
337import { defaultAppManager } from '@kit.AbilityKit';
338import { BusinessError } from '@kit.BasicServicesKit';
339import { uniformTypeDescriptor } from '@kit.ArkData';
340
341defaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
342  bundleName: "com.example.myapplication",
343  moduleName: "module01",
344  abilityName: "EntryAbility"
345}).then((data) => {
346  console.info('Operation successful.');
347}).catch((error: BusinessError) => {
348  console.error('Operation failed. Cause: ' + JSON.stringify(error));
349});
350
351let userId = 100;
352defaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
353  bundleName: "com.example.myapplication",
354  moduleName: "module01",
355  abilityName: "EntryAbility"
356}, userId).then((data) => {
357  console.info('Operation successful.');
358}).catch((error: BusinessError) => {
359  console.error('Operation failed. Cause: ' + JSON.stringify(error));
360});
361
362defaultAppManager.setDefaultApplication("image/png", {
363  bundleName: "com.example.myapplication",
364  moduleName: "module01",
365  abilityName: "EntryAbility"
366}, userId).then((data) => {
367  console.info('Operation successful.');
368}).catch((error: BusinessError) => {
369  console.error('Operation failed. Cause: ' + JSON.stringify(error));
370});
371
372defaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
373  bundleName: "com.example.myapplication",
374  moduleName: "module01",
375  abilityName: "EntryAbility"
376}, userId).then((data) => {
377  console.info('Operation successful.');
378}).catch((error: BusinessError) => {
379  console.error('Operation failed. Cause: ' + JSON.stringify(error));
380});
381```
382
383## defaultAppManager.setDefaultApplication
384
385setDefaultApplication(type: string, elementName: ElementName, userId: number, callback: AsyncCallback\<void>) : void
386
387Sets the default application for a user based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
388
389**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
390
391**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
392
393**System API**: This is a system API.
394
395**Parameters**
396
397| Name        | Type    | Mandatory  | Description                                     |
398| ----------- | ------ | ---- | --------------------------------------- |
399| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
400| elementName  | [ElementName](js-apis-bundle-ElementName.md) | Yes   | Information about the element to be set as the default application.                          |
401| userId  | number | Yes   | User ID.                          |
402| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result.                   |
403
404**Error codes**
405
406For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
407
408| ID | Error Message                                      |
409| -------- | ---------------------------------------------- |
410| 201 | Permission denied. |
411| 202 | Permission denied, non-system app called system api. |
412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
413| 801 | Capability not supported. |
414| 17700004 | The specified user ID is not found.            |
415| 17700025 | The specified type is invalid.                 |
416| 17700028 | The specified ability does not match the type. |
417
418**Example**
419
420```ts
421import { defaultAppManager } from '@kit.AbilityKit';
422import { BusinessError } from '@kit.BasicServicesKit';
423import { uniformTypeDescriptor } from '@kit.ArkData';
424
425let userId = 100;
426defaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
427  bundleName: "com.example.myapplication",
428  moduleName: "module01",
429  abilityName: "EntryAbility"
430}, userId, (err: BusinessError, data) => {
431  if (err) {
432    console.error('Operation failed. Cause: ' + JSON.stringify(err));
433    return;
434  }
435  console.info('Operation successful.');
436});
437
438defaultAppManager.setDefaultApplication("image/png", {
439  bundleName: "com.example.myapplication",
440  moduleName: "module01",
441  abilityName: "EntryAbility"
442}, userId, (err: BusinessError, data) => {
443  if (err) {
444    console.error('Operation failed. Cause: ' + JSON.stringify(err));
445    return;
446  }
447  console.info('Operation successful.');
448});
449
450defaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
451  bundleName: "com.example.myapplication",
452  moduleName: "module01",
453  abilityName: "EntryAbility"
454}, userId, (err: BusinessError, data) => {
455  if (err) {
456    console.error('Operation failed. Cause: ' + JSON.stringify(err));
457    return;
458  }
459  console.info('Operation successful.');
460});
461```
462
463## defaultAppManager.setDefaultApplication
464
465setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback\<void>) : void
466
467Sets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
468
469**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
470
471**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
472
473**System API**: This is a system API.
474
475**Parameters**
476
477| Name        | Type    | Mandatory  | Description                                     |
478| ----------- | ------ | ---- | --------------------------------------- |
479| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
480| elementName  | [ElementName](js-apis-bundle-ElementName.md) | Yes   | Information about the element to be set as the default application.                          |
481| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result.                   |
482
483**Error codes**
484
485For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
486
487| ID | Error Message                                      |
488| -------- | ---------------------------------------------- |
489| 201 | Permission denied. |
490| 202 | Permission denied, non-system app called system api. |
491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
492| 801 | Capability not supported. |
493| 17700025 | The specified type is invalid.                 |
494| 17700028 | The specified ability does not match the type. |
495
496**Example**
497
498```ts
499import { defaultAppManager } from '@kit.AbilityKit';
500import { BusinessError } from '@kit.BasicServicesKit';
501import { uniformTypeDescriptor } from '@kit.ArkData';
502
503defaultAppManager.setDefaultApplication(defaultAppManager.ApplicationType.BROWSER, {
504  bundleName: "com.example.myapplication",
505  moduleName: "module01",
506  abilityName: "EntryAbility"
507}, (err: BusinessError, data) => {
508  if (err) {
509    console.error('Operation failed. Cause: ' + JSON.stringify(err));
510    return;
511  }
512  console.info('Operation successful.');
513});
514
515defaultAppManager.setDefaultApplication("image/png", {
516  bundleName: "com.example.myapplication",
517  moduleName: "module01",
518  abilityName: "EntryAbility"
519}, (err: BusinessError, data) => {
520  if (err) {
521    console.error('Operation failed. Cause: ' + JSON.stringify(err));
522    return;
523  }
524  console.info('Operation successful.');
525});
526
527defaultAppManager.setDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, {
528  bundleName: "com.example.myapplication",
529  moduleName: "module01",
530  abilityName: "EntryAbility"
531}, (err: BusinessError, data) => {
532  if (err) {
533    console.error('Operation failed. Cause: ' + JSON.stringify(err));
534    return;
535  }
536  console.info('Operation successful.');
537});
538```
539
540## defaultAppManager.setDefaultApplicationSync<sup>10+</sup>
541
542setDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void
543
544Sets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API returns the result synchronously.
545
546**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
547
548**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
549
550**System API**: This is a system API.
551
552**Parameters**
553
554| Name     | Type  | Mandatory | Description                                     |
555| ----------- | ------ | ---- | --------------------------------------- |
556| type        | string | Yes  | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).|
557| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application.                          |
558| userId      | number | No  | User ID. The default value is the user ID of the caller.                           |
559
560**Error codes**
561
562For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
563
564| ID | Error Message                                      |
565| -------- | ---------------------------------------------- |
566| 201 | Permission denied. |
567| 202 | Permission denied, non-system app called system api. |
568| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
569| 801 | Capability not supported. |
570| 17700004 | The specified user ID is not found.            |
571| 17700025 | The specified type is invalid.                 |
572| 17700028 | The specified ability does not match the type. |
573
574**Example**
575
576```ts
577import { defaultAppManager } from '@kit.AbilityKit';
578import { uniformTypeDescriptor } from '@kit.ArkData';
579
580try {
581  defaultAppManager.setDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, {
582  bundleName: "com.example.myapplication",
583  moduleName: "module01",
584  abilityName: "EntryAbility"
585});
586  console.info('Operation successful.');
587} catch(error) {
588  console.error('Operation failed. Cause: ' + JSON.stringify(error));
589};
590
591let userId = 100;
592try {
593  defaultAppManager.setDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, {
594  bundleName: "com.example.myapplication",
595  moduleName: "module01",
596  abilityName: "EntryAbility"
597}, userId);
598  console.info('Operation successful.');
599} catch(error) {
600  console.error('Operation failed. Cause: ' + JSON.stringify(error));
601};
602
603try {
604  defaultAppManager.setDefaultApplicationSync("image/png", {
605  bundleName: "com.example.myapplication",
606  moduleName: "module01",
607  abilityName: "EntryAbility"
608}, userId);
609  console.info('Operation successful.');
610} catch(error) {
611  console.error('Operation failed. Cause: ' + JSON.stringify(error));
612};
613
614try {
615  defaultAppManager.setDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI, {
616  bundleName: "com.example.myapplication",
617  moduleName: "module01",
618  abilityName: "EntryAbility"
619}, userId);
620  console.info('Operation successful.');
621} catch(error) {
622  console.error('Operation failed. Cause: ' + JSON.stringify(error));
623};
624```
625
626## defaultAppManager.resetDefaultApplication
627
628resetDefaultApplication(type: string, userId?: number): Promise\<void>
629
630Resets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses a promise to return the result.
631
632**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
633
634**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
635
636**System API**: This is a system API.
637
638**Parameters**
639
640| Name        | Type    | Mandatory  | Description                                     |
641| ----------- | ------ | ---- | --------------------------------------- |
642| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
643| userId  | number | No   | User ID. The default value is the user ID of the caller.                           |
644
645**Error codes**
646
647For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
648
649| ID | Error Message                           |
650| -------- | ----------------------------------- |
651| 201 | Permission denied. |
652| 202 | Permission denied, non-system app called system api. |
653| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
654| 801 | Capability not supported. |
655| 17700004 | The specified user ID is not found. |
656| 17700025 | The specified type is invalid.      |
657
658**Example**
659
660```ts
661import { defaultAppManager } from '@kit.AbilityKit';
662import { BusinessError } from '@kit.BasicServicesKit';
663import { uniformTypeDescriptor } from '@kit.ArkData';
664
665let userId = 100;
666defaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId)
667  .then((data) => {
668    console.info('Operation successful.');
669  })
670  .catch((error: BusinessError) => {
671    console.error('Operation failed. Cause: ' + JSON.stringify(error));
672  });
673
674defaultAppManager.resetDefaultApplication("image/png", userId)
675  .then((data) => {
676    console.info('Operation successful.');
677  })
678  .catch((error: BusinessError) => {
679    console.error('Operation failed. Cause: ' + JSON.stringify(error));
680  });
681
682defaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId)
683  .then((data) => {
684    console.info('Operation successful.');
685  })
686  .catch((error: BusinessError) => {
687    console.error('Operation failed. Cause: ' + JSON.stringify(error));
688  });
689```
690
691## defaultAppManager.resetDefaultApplication
692
693resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<void>) : void
694
695Resets the default application for a user based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
696
697**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
698
699**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
700
701**System API**: This is a system API.
702
703**Parameters**
704
705| Name        | Type    | Mandatory  | Description                                     |
706| ----------- | ------ | ---- | --------------------------------------- |
707| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
708| userId  | number | Yes   | User ID.                         |
709| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result.                   |
710
711**Error codes**
712
713For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
714
715| ID | Error Message                           |
716| -------- | ----------------------------------- |
717| 201 | Permission denied. |
718| 202 | Permission denied, non-system app called system api. |
719| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
720| 801 | Capability not supported. |
721| 17700004 | The specified user ID is not found. |
722| 17700025 | The specified type is invalid.      |
723
724**Example**
725
726```ts
727import { defaultAppManager } from '@kit.AbilityKit';
728import { BusinessError } from '@kit.BasicServicesKit';
729import { uniformTypeDescriptor } from '@kit.ArkData';
730
731let userId = 100;
732defaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, userId, (err: BusinessError, data) => {
733  if (err) {
734    console.error('Operation failed. Cause: ' + JSON.stringify(err));
735    return;
736  }
737  console.info('Operation successful.');
738});
739
740defaultAppManager.resetDefaultApplication("image/png", userId, (err: BusinessError, data) => {
741  if (err) {
742    console.error('Operation failed. Cause: ' + JSON.stringify(err));
743    return;
744  }
745  console.info('Operation successful.');
746});
747
748defaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, userId, (err: BusinessError, data) => {
749  if (err) {
750    console.error('Operation failed. Cause: ' + JSON.stringify(err));
751    return;
752  }
753  console.info('Operation successful.');
754});
755```
756
757## defaultAppManager.resetDefaultApplication
758
759resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void
760
761Resets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API uses an asynchronous callback to return the result.
762
763**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
764
765**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
766
767**System API**: This is a system API.
768
769**Parameters**
770
771| Name        | Type    | Mandatory  | Description                                     |
772| ----------- | ------ | ---- | --------------------------------------- |
773| type  | string | Yes   | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).      |
774| callback    | AsyncCallback\<void> | Yes   | Callback used to return the result.                   |
775
776**Error codes**
777
778For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
779
780| ID | Error Message                           |
781| -------- | ----------------------------------- |
782| 201 | Permission denied. |
783| 202 | Permission denied, non-system app called system api. |
784| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
785| 801 | Capability not supported. |
786| 17700025 | The specified type is invalid.      |
787
788**Example**
789
790```ts
791import { defaultAppManager } from '@kit.AbilityKit';
792import { BusinessError } from '@kit.BasicServicesKit';
793import { uniformTypeDescriptor } from '@kit.ArkData';
794
795defaultAppManager.resetDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => {
796  if (err) {
797    console.error('Operation failed. Cause: ' + JSON.stringify(err));
798    return;
799  }
800  console.info('Operation successful.');
801});
802
803defaultAppManager.resetDefaultApplication("image/png", (err: BusinessError, data) => {
804  if (err) {
805    console.error('Operation failed. Cause: ' + JSON.stringify(err));
806    return;
807  }
808  console.info('Operation successful.');
809});
810
811defaultAppManager.resetDefaultApplication(uniformTypeDescriptor.UniformDataType.AVI, (err: BusinessError, data) => {
812  if (err) {
813    console.error('Operation failed. Cause: ' + JSON.stringify(err));
814    return;
815  }
816  console.info('Operation successful.');
817});
818```
819
820## defaultAppManager.resetDefaultApplicationSync<sup>10+</sup>
821
822resetDefaultApplicationSync(type: string, userId?: number): void
823
824Resets the default application based on a system-defined application type, a file type that complies with the media type format (either specified by **type** or **subtype**), or a [uniform data type](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md). This API returns the result synchronously.
825
826**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
827
828**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
829
830**System API**: This is a system API.
831
832**Parameters**
833
834| Name | Type  | Mandatory | Description                                   |
835| ------ | ------ | ---- | --------------------------------------- |
836| type   | string | Yes  | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmanagerapplicationtype), a file type that complies with the media type format, or a value defined by [UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md).|
837| userId | number | No  | User ID. The default value is the user ID of the caller.                           |
838
839**Error codes**
840
841For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
842
843| ID | Error Message                           |
844| -------- | ----------------------------------- |
845| 201 | Permission denied. |
846| 202 | Permission denied, non-system app called system api. |
847| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
848| 801 | Capability not supported. |
849| 17700004 | The specified user ID is not found. |
850| 17700025 | The specified type is invalid.      |
851
852**Example**
853
854```ts
855import { defaultAppManager } from '@kit.AbilityKit';
856import { uniformTypeDescriptor } from '@kit.ArkData';
857
858let userId = 100;
859try {
860  defaultAppManager.resetDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER, userId);
861  console.info('Operation successful.');
862} catch(error) {
863  console.error('Operation failed. Cause: ' + JSON.stringify(error));
864};
865
866try {
867  defaultAppManager.resetDefaultApplicationSync("image/png", userId);
868  console.info('Operation successful.');
869} catch(error) {
870  console.error('Operation failed. Cause: ' + JSON.stringify(error));
871};
872
873try {
874  defaultAppManager.resetDefaultApplicationSync(uniformTypeDescriptor.UniformDataType.AVI, userId);
875  console.info('Operation successful.');
876} catch(error) {
877  console.error('Operation failed. Cause: ' + JSON.stringify(error));
878};
879```
880