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