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