1e41f4b71Sopenharmony_ci# @ohos.bundle.defaultAppManager (默认应用管理) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供查询默认应用的能力,支持查询当前应用是否是默认应用。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## defaultAppManager.ApplicationType 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci默认应用的应用类型。 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 22e41f4b71Sopenharmony_ci| -------- | -------------------------------------- | -------------------------------------- | 23e41f4b71Sopenharmony_ci| BROWSER | 'Web Browser' | 默认浏览器。 | 24e41f4b71Sopenharmony_ci| IMAGE | 'Image Gallery' | 默认图片查看器。 | 25e41f4b71Sopenharmony_ci| AUDIO | 'Audio Player' | 默认音频播放器。 | 26e41f4b71Sopenharmony_ci| VIDEO | 'Video Player' | 默认视频播放器。 | 27e41f4b71Sopenharmony_ci| PDF | 'PDF Viewer' | 默认PDF文档查看器。 | 28e41f4b71Sopenharmony_ci| WORD | 'Word Viewer' | 默认WORD文档查看器。 | 29e41f4b71Sopenharmony_ci| EXCEL | 'Excel Viewer' | 默认EXCEL文档查看器。 | 30e41f4b71Sopenharmony_ci| PPT | 'PPT Viewer' | 默认PPT文档查看器。 | 31e41f4b71Sopenharmony_ci| EMAIL<sup>12+</sup> | 'Email' | 默认邮件。 | 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci## defaultAppManager.isDefaultApplication 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciisDefaultApplication(type: string): Promise\<boolean> 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型判断当前应用是否是该类型的默认应用,使用Promise形式返回结果。 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**参数:** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 44e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | --------------------------------------- | 45e41f4b71Sopenharmony_ci| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmanagerapplicationtype)或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型中的值。 | 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**返回值:** 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci| 类型 | 说明 | 50e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | 51e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise形式返回当前应用是否是默认应用,true表示是默认应用,false表示不是默认应用。 | 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**错误码:** 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 58e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------------- | 59e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 60e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**示例:** 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci```ts 65e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit'; 66e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_cidefaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER) 69e41f4b71Sopenharmony_ci .then((data) => { 70e41f4b71Sopenharmony_ci console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data)); 71e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 72e41f4b71Sopenharmony_ci console.error('Operation failed. Cause: ' + JSON.stringify(error)); 73e41f4b71Sopenharmony_ci }); 74e41f4b71Sopenharmony_ci``` 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci## defaultAppManager.isDefaultApplication 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciisDefaultApplication(type: string, callback: AsyncCallback\<boolean>): void 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci以异步方法根据系统已定义的应用类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型判断当前应用是否是该类型的默认应用,使用callback形式返回结果。 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**参数:** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 87e41f4b71Sopenharmony_ci| ----------- | ------------------------------- | ---- | --------------------------------------- | 88e41f4b71Sopenharmony_ci| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmanagerapplicationtype)或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型中的值。 | 89e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | 是 | 程序启动作为入参的回调函数,返回当前应用是否是默认应用,true表示是默认应用,false表示不是默认应用。 | 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**错误码:** 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 96e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------------- | 97e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 98e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**示例:** 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci```ts 103e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit'; 104e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_cidefaultAppManager.isDefaultApplication(defaultAppManager.ApplicationType.BROWSER, (err: BusinessError, data) => { 107e41f4b71Sopenharmony_ci if (err) { 108e41f4b71Sopenharmony_ci console.error('Operation failed. Cause: ' + JSON.stringify(err)); 109e41f4b71Sopenharmony_ci return; 110e41f4b71Sopenharmony_ci } 111e41f4b71Sopenharmony_ci console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data)); 112e41f4b71Sopenharmony_ci}); 113e41f4b71Sopenharmony_ci``` 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## defaultAppManager.isDefaultApplicationSync<sup>10+</sup> 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ciisDefaultApplicationSync(type: string): boolean 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci以同步方法根据系统已定义的应用类型或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型判断当前应用是否是该类型的默认应用,使用boolean形式返回结果。 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.DefaultApp 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**参数:** 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 126e41f4b71Sopenharmony_ci| -------| ------ | ---- | --------------------------------------- | 127e41f4b71Sopenharmony_ci| type | string | 是 | 要查询的应用类型,取[ApplicationType](#defaultappmanagerapplicationtype)或者[UniformDataType](../apis-arkdata/js-apis-data-uniformTypeDescriptor.md)类型中的值。 | 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**返回值:** 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci| 类型 | 说明 | 132e41f4b71Sopenharmony_ci| ------- | -------------------- | 133e41f4b71Sopenharmony_ci| boolean | 返回当前应用是否是默认应用,true表示是默认应用,false表示不是默认应用。 | 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**错误码:** 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 140e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------------------- | 141e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 142e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**示例:** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci```ts 147e41f4b71Sopenharmony_ciimport { defaultAppManager } from '@kit.AbilityKit'; 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_citry { 150e41f4b71Sopenharmony_ci let data = defaultAppManager.isDefaultApplicationSync(defaultAppManager.ApplicationType.BROWSER) 151e41f4b71Sopenharmony_ci console.info('Operation successful. IsDefaultApplicationSync ? ' + JSON.stringify(data)); 152e41f4b71Sopenharmony_ci} catch(error) { 153e41f4b71Sopenharmony_ci console.error('Operation failed. Cause: ' + JSON.stringify(error)); 154e41f4b71Sopenharmony_ci}; 155e41f4b71Sopenharmony_ci```