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 defaultAppMgr from '@ohos.bundle.defaultAppManager'; 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, see [Permission APL](../../security/AccessToken/app-permission-mgmt-overview.md#permission-apl). 24 25## defaultAppMgr.getDefaultApplication 26 27getDefaultApplication(type: string, userId?: number): Promise\<BundleInfo> 28 29Obtains 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. 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#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 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 [Bundle Error Codes](errorcode-bundle.md). 53 54| ID| Error Message | 55| -------- | ----------------------------------------- | 56| 17700004 | The specified user ID is not found. | 57| 17700023 | The specified default app does not exist. | 58| 17700025 | The specified type is invalid. | 59 60**Example** 61 62```ts 63import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 64import { BusinessError } from '@ohos.base'; 65 66defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER) 67 .then((data) => { 68 console.info('Operation successful. bundleInfo: ' + JSON.stringify(data)); 69 }) 70 .catch((error: BusinessError) => { 71 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 72 }); 73 74defaultAppMgr.getDefaultApplication("image/png") 75 .then((data) => { 76 console.info('Operation successful. bundleInfo: ' + JSON.stringify(data)); 77 }) 78 .catch((error: BusinessError) => { 79 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 80 }); 81``` 82 83## defaultAppMgr.getDefaultApplication 84 85getDefaultApplication(type: string, userId: number, callback: AsyncCallback\<BundleInfo>) : void 86 87Obtains 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. 88 89**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION 90 91**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 92 93**System API**: This is a system API. 94 95**Parameters** 96 97| Name | Type | Mandatory | Description | 98| ----------- | ------ | ---- | --------------------------------------- | 99| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 100| userId | number | Yes | User ID. | 101| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the default application. | 102 103**Error codes** 104 105For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 106 107| ID| Error Message | 108| -------- | ----------------------------------------- | 109| 17700004 | The specified user ID is not found. | 110| 17700023 | The specified default app does not exist. | 111| 17700025 | The specified type is invalid. | 112 113**Example** 114 115```ts 116import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 117import { BusinessError } from '@ohos.base'; 118 119let userId = 100; 120defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data) => { 121 if (err) { 122 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 123 return; 124 } 125 console.info('Operation successful. bundleInfo:' + JSON.stringify(data)); 126}); 127 128defaultAppMgr.getDefaultApplication("image/png", userId, (err: BusinessError, data) => { 129 if (err) { 130 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 131 return; 132 } 133 console.info('Operation successful. bundleInfo:' + JSON.stringify(data)); 134}); 135``` 136 137## defaultAppMgr.getDefaultApplication 138 139getDefaultApplication(type: string, callback: AsyncCallback\<BundleInfo>) : void 140 141Obtains 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. 142 143**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION 144 145**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 146 147**System API**: This is a system API. 148 149**Parameters** 150 151| Name | Type | Mandatory | Description | 152| ----------- | ------ | ---- | --------------------------------------- | 153| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 154| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the default application. | 155 156**Error codes** 157 158For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 159 160| ID| Error Message | 161| -------- | ----------------------------------------- | 162| 17700023 | The specified default app does not exist. | 163| 17700025 | The specified type is invalid. | 164 165**Example** 166 167```ts 168import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 169import { BusinessError } from '@ohos.base'; 170 171defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => { 172 if (err) { 173 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 174 return; 175 } 176 console.info('Operation successful. bundleInfo:' + JSON.stringify(data)); 177}); 178defaultAppMgr.getDefaultApplication("image/png", (err: BusinessError, data) => { 179 if (err) { 180 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 181 return; 182 } 183 console.info('Operation successful. bundleInfo:' + JSON.stringify(data)); 184}); 185``` 186 187## defaultAppMgr.getDefaultApplicationSync<sup>10+</sup> 188 189getDefaultApplicationSync(type: string, userId?: number): BundleInfo 190 191Obtains 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. 192 193**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION 194 195**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 196 197**System API**: This is a system API. 198 199**Parameters** 200 201| Name| Type | Mandatory| Description | 202| -------| ------ | ---- | --------------------------------------- | 203| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format.| 204| userId | number | No | User ID. The default value is the user ID of the caller. | 205 206**Return value** 207 208| Type | Description | 209| ------------------------------------------ | -------------------- | 210| [BundleInfo](js-apis-bundle-BundleInfo.md) | Bundle information of the default application.| 211 212**Error codes** 213 214For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 215 216| ID| Error Message | 217| -------- | ----------------------------------------- | 218| 17700004 | The specified user ID is not found. | 219| 17700023 | The specified default app does not exist. | 220| 17700025 | The specified type is invalid. | 221 222**Example** 223 224```ts 225import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 226try { 227 let data = defaultAppMgr.getDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER) 228 console.info('Operation successful. bundleInfo: ' + JSON.stringify(data)); 229} catch(error) { 230 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 231}; 232 233try { 234 let data = defaultAppMgr.getDefaultApplicationSync("image/png") 235 console.info('Operation successful. bundleInfo: ' + JSON.stringify(data)); 236} catch(error) { 237 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 238}; 239``` 240 241## defaultAppMgr.setDefaultApplication 242 243setDefaultApplication(type: string, elementName: ElementName, userId?: number): Promise\<void> 244 245Sets 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. 246 247**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 248 249**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 250 251**System API**: This is a system API. 252 253**Parameters** 254 255| Name | Type | Mandatory | Description | 256| ----------- | ------ | ---- | --------------------------------------- | 257| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 258| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application. | 259| userId | number | No | User ID. The default value is the user ID of the caller. | 260 261**Return value** 262 263| Type | Description | 264| -------------- | ---------------------------------- | 265| Promise\<void> | Promise that returns no value.| 266 267**Error codes** 268 269For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 270 271| ID| Error Message | 272| -------- | ---------------------------------------------- | 273| 17700004 | The specified user ID is not found. | 274| 17700025 | The specified type is invalid. | 275| 17700028 | The specified ability does not match the type. | 276 277**Example** 278 279```ts 280import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 281import { BusinessError } from '@ohos.base'; 282 283defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, { 284 bundleName: "com.example.myapplication", 285 moduleName: "module01", 286 abilityName: "EntryAbility" 287}).then((data) => { 288 console.info('Operation successful.'); 289}).catch((error: BusinessError) => { 290 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 291}); 292 293let userId = 100; 294defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, { 295 bundleName: "com.example.myapplication", 296 moduleName: "module01", 297 abilityName: "EntryAbility" 298}, userId).then((data) => { 299 console.info('Operation successful.'); 300}).catch((error: BusinessError) => { 301 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 302}); 303 304defaultAppMgr.setDefaultApplication("image/png", { 305 bundleName: "com.example.myapplication", 306 moduleName: "module01", 307 abilityName: "EntryAbility" 308}, userId).then((data) => { 309 console.info('Operation successful.'); 310}).catch((error: BusinessError) => { 311 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 312}); 313``` 314 315## defaultAppMgr.setDefaultApplication 316 317setDefaultApplication(type: string, elementName: ElementName, userId: number, callback: AsyncCallback\<void>) : void 318 319Sets 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. 320 321**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 322 323**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 324 325**System API**: This is a system API. 326 327**Parameters** 328 329| Name | Type | Mandatory | Description | 330| ----------- | ------ | ---- | --------------------------------------- | 331| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 332| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application. | 333| userId | number | Yes | User ID. | 334| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 335 336**Error codes** 337 338For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 339 340| ID| Error Message | 341| -------- | ---------------------------------------------- | 342| 17700004 | The specified user ID is not found. | 343| 17700025 | The specified type is invalid. | 344| 17700028 | The specified ability does not match the type. | 345 346**Example** 347 348```ts 349import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 350import { BusinessError } from '@ohos.base'; 351 352let userId = 100; 353defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, { 354 bundleName: "com.example.myapplication", 355 moduleName: "module01", 356 abilityName: "EntryAbility" 357}, userId, (err: BusinessError, data) => { 358 if (err) { 359 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 360 return; 361 } 362 console.info('Operation successful.'); 363}); 364 365defaultAppMgr.setDefaultApplication("image/png", { 366 bundleName: "com.example.myapplication", 367 moduleName: "module01", 368 abilityName: "EntryAbility" 369}, userId, (err: BusinessError, data) => { 370 if (err) { 371 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 372 return; 373 } 374 console.info('Operation successful.'); 375}); 376``` 377 378## defaultAppMgr.setDefaultApplication 379 380setDefaultApplication(type: string, elementName: ElementName, callback: AsyncCallback\<void>) : void 381 382Sets 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. 383 384**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 385 386**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 387 388**System API**: This is a system API. 389 390**Parameters** 391 392| Name | Type | Mandatory | Description | 393| ----------- | ------ | ---- | --------------------------------------- | 394| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 395| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application. | 396| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 397 398**Error codes** 399 400For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 401 402| ID| Error Message | 403| -------- | ---------------------------------------------- | 404| 17700025 | The specified type is invalid. | 405| 17700028 | The specified ability does not match the type. | 406 407**Example** 408 409```ts 410import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 411import { BusinessError } from '@ohos.base'; 412 413defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, { 414 bundleName: "com.example.myapplication", 415 moduleName: "module01", 416 abilityName: "EntryAbility" 417}, (err: BusinessError, data) => { 418 if (err) { 419 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 420 return; 421 } 422 console.info('Operation successful.'); 423}); 424 425defaultAppMgr.setDefaultApplication("image/png", { 426 bundleName: "com.example.myapplication", 427 moduleName: "module01", 428 abilityName: "EntryAbility" 429}, (err: BusinessError, data) => { 430 if (err) { 431 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 432 return; 433 } 434 console.info('Operation successful.'); 435}); 436``` 437 438## defaultAppMgr.setDefaultApplicationSync<sup>10+</sup> 439 440setDefaultApplicationSync(type: string, elementName: ElementName, userId?: number): void 441 442Sets 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. 443 444**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 445 446**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 447 448**System API**: This is a system API. 449 450**Parameters** 451 452| Name | Type | Mandatory| Description | 453| ----------- | ------ | ---- | --------------------------------------- | 454| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format.| 455| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes| Information about the element to be set as the default application. | 456| userId | number | No | User ID. The default value is the user ID of the caller. | 457 458**Error codes** 459 460For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 461 462| ID| Error Message | 463| -------- | ---------------------------------------------- | 464| 17700004 | The specified user ID is not found. | 465| 17700025 | The specified type is invalid. | 466| 17700028 | The specified ability does not match the type. | 467 468**Example** 469 470```ts 471import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 472try { 473 defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, { 474 bundleName: "com.example.myapplication", 475 moduleName: "module01", 476 abilityName: "EntryAbility" 477}); 478 console.info('Operation successful.'); 479} catch(error) { 480 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 481}; 482 483let userId = 100; 484try { 485 defaultAppMgr.setDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, { 486 bundleName: "com.example.myapplication", 487 moduleName: "module01", 488 abilityName: "EntryAbility" 489}, userId); 490 console.info('Operation successful.'); 491} catch(error) { 492 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 493}; 494 495try { 496 defaultAppMgr.setDefaultApplicationSync("image/png", { 497 bundleName: "com.example.myapplication", 498 moduleName: "module01", 499 abilityName: "EntryAbility" 500}, userId); 501 console.info('Operation successful.'); 502} catch(error) { 503 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 504}; 505``` 506 507## defaultAppMgr.resetDefaultApplication 508 509resetDefaultApplication(type: string, userId?: number): Promise\<void> 510 511Resets 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. 512 513**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 514 515**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 516 517**System API**: This is a system API. 518 519**Parameters** 520 521| Name | Type | Mandatory | Description | 522| ----------- | ------ | ---- | --------------------------------------- | 523| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 524| userId | number | No | User ID. The default value is the user ID of the caller. | 525 526**Error codes** 527 528For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 529 530| ID| Error Message | 531| -------- | ----------------------------------- | 532| 17700004 | The specified user ID is not found. | 533| 17700025 | The specified type is invalid. | 534 535**Example** 536 537```ts 538import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 539import { BusinessError } from '@ohos.base'; 540 541let userId = 100; 542defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId) 543 .then((data) => { 544 console.info('Operation successful.'); 545 }) 546 .catch((error: BusinessError) => { 547 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 548 }); 549 550defaultAppMgr.resetDefaultApplication("image/png", userId) 551 .then((data) => { 552 console.info('Operation successful.'); 553 }) 554 .catch((error: BusinessError) => { 555 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 556 }); 557``` 558 559## defaultAppMgr.resetDefaultApplication 560 561resetDefaultApplication(type: string, userId: number, callback: AsyncCallback\<void>) : void 562 563Resets 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. 564 565**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 566 567**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 568 569**System API**: This is a system API. 570 571**Parameters** 572 573| Name | Type | Mandatory | Description | 574| ----------- | ------ | ---- | --------------------------------------- | 575| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 576| userId | number | Yes | User ID. | 577| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 578 579**Error codes** 580 581For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 582 583| ID| Error Message | 584| -------- | ----------------------------------- | 585| 17700004 | The specified user ID is not found. | 586| 17700025 | The specified type is invalid. | 587 588**Example** 589 590```ts 591import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 592import { BusinessError } from '@ohos.base'; 593 594let userId = 100; 595defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err: BusinessError, data) => { 596 if (err) { 597 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 598 return; 599 } 600 console.info('Operation successful.'); 601}); 602 603defaultAppMgr.resetDefaultApplication("image/png", userId, (err: BusinessError, data) => { 604 if (err) { 605 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 606 return; 607 } 608 console.info('Operation successful.'); 609}); 610``` 611 612## defaultAppMgr.resetDefaultApplication 613 614resetDefaultApplication(type: string, callback: AsyncCallback\<void>) : void 615 616Resets 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. 617 618**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 619 620**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 621 622**System API**: This is a system API. 623 624**Parameters** 625 626| Name | Type | Mandatory | Description | 627| ----------- | ------ | ---- | --------------------------------------- | 628| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format. | 629| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 630 631**Error codes** 632 633For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 634 635| ID| Error Message | 636| -------- | ----------------------------------- | 637| 17700025 | The specified type is invalid. | 638 639**Example** 640 641```ts 642import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 643import { BusinessError } from '@ohos.base'; 644 645defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err: BusinessError, data) => { 646 if (err) { 647 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 648 return; 649 } 650 console.info('Operation successful.'); 651}); 652 653defaultAppMgr.resetDefaultApplication("image/png", (err: BusinessError, data) => { 654 if (err) { 655 console.error('Operation failed. Cause: ' + JSON.stringify(err)); 656 return; 657 } 658 console.info('Operation successful.'); 659}); 660``` 661 662## defaultAppMgr.resetDefaultApplicationSync<sup>10+</sup> 663 664resetDefaultApplicationSync(type: string, userId?: number): void 665 666Resets 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. 667 668**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION 669 670**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp 671 672**System API**: This is a system API. 673 674**Parameters** 675 676| Name| Type | Mandatory| Description | 677| ------ | ------ | ---- | --------------------------------------- | 678| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](js-apis-defaultAppManager.md#defaultappmgrapplicationtype) or a file type that complies with the media type format.| 679| userId | number | No | User ID. The default value is the user ID of the caller. | 680 681**Error codes** 682 683For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md). 684 685| ID| Error Message | 686| -------- | ----------------------------------- | 687| 17700004 | The specified user ID is not found. | 688| 17700025 | The specified type is invalid. | 689 690**Example** 691 692```ts 693import defaultAppMgr from '@ohos.bundle.defaultAppManager'; 694 695let userId = 100; 696try { 697 defaultAppMgr.resetDefaultApplicationSync(defaultAppMgr.ApplicationType.BROWSER, userId); 698 console.info('Operation successful.'); 699} catch(error) { 700 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 701}; 702 703try { 704 defaultAppMgr.resetDefaultApplicationSync("image/png", userId); 705 console.info('Operation successful.'); 706} catch(error) { 707 console.error('Operation failed. Cause: ' + JSON.stringify(error)); 708}; 709``` 710