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