1# @ohos.bundle.bundleManager (bundleManager模块) 2 3本模块提供应用信息查询能力,支持BundleInfo、ApplicationInfo、Ability、ExtensionAbility等信息的查询 4 5> **说明:** 6> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7 8## 导入模块 9 10```ts 11import bundleManager from '@ohos.bundle.bundleManager'; 12``` 13 14## 权限列表 15 16| 权限 | 权限等级 | 描述 | 17| ------------------------------------------ | ------------ | ------------------| 18| ohos.permission.GET_BUNDLE_INFO | normal | 查询指定应用信息。 | 19| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 可查询所有应用信息。 | 20| ohos.permission.REMOVE_CACHE_FILES | system_basic | 清理应用缓存。 | 21|ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | 设置禁用使能所需的权限。 | 22 23权限等级参考[权限等级说明](../../security/accesstoken-overview.md#权限等级说明)。 24 25## 枚举 26 27### BundleFlag 28 29包信息标志,指示需要获取的包信息的内容。 30 31 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 32 33| 名称 | 值 | 说明 | 34| ----------------------------------------- | ---------- | ------------------------------------------------------------ | 35| GET_BUNDLE_INFO_DEFAULT | 0x00000000 | 用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 36| GET_BUNDLE_INFO_WITH_APPLICATION | 0x00000001 | 用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 37| GET_BUNDLE_INFO_WITH_HAP_MODULE | 0x00000002 | 用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。 | 38| GET_BUNDLE_INFO_WITH_ABILITY | 0x00000004 | 用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 39| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY | 0x00000008 | 用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 40| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | 用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。 | 41| GET_BUNDLE_INFO_WITH_METADATA | 0x00000020 | 用于获取applicationInfo、moduleInfo和abilityInfo中包含的metadata。它不能单独使用,它需要与GET_BUNDLE_INFO_WITH_APPLICATION、GET_BUNDLE_INFO_WITH_HAP_MODULE、GET_BUNDLE_INFO_WITH_ABILITY、GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY一起使用。 | 42| GET_BUNDLE_INFO_WITH_DISABLE | 0x00000040 | 用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 43| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 0x00000080 | 用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。 | 44 45### ApplicationFlag 46 47应用信息标志,指示需要获取的应用信息的内容。 48 49 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 50 51 **系统接口:** 系统接口,不支持三方应用调用。 52 53| 名称 | 值 | 说明 | 54| ------------------------------------ | ---------- | ------------------------------------------------------------ | 55| GET_APPLICATION_INFO_DEFAULT | 0x00000000 | 用于获取默认的applicationInfo,获取的applicationInfo不包含permission和metadata信息。 | 56| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的applicationInfo。 | 57| GET_APPLICATION_INFO_WITH_METADATA | 0x00000002 | 用于获取包含metadata的applicationInfo。 | 58| GET_APPLICATION_INFO_WITH_DISABLE | 0x00000004 | 用于获取包含禁用应用程序的applicationInfo。 | 59 60### AbilityFlag 61 62Ability组件信息标志,指示需要获取的Ability组件信息的内容。 63 64 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 65 66 **系统接口:** 系统接口,不支持三方应用调用。 67 68| 名称 | 值 | 说明 | 69| --------------------------------- | ---------- | ------------------------------------------------------------ | 70| GET_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认abilityInfo,获取的abilityInfo不包含permission、metadata和禁用的abilityInfo。 | 71| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的abilityInfo。 | 72| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的abilityInfo。 | 73| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的abilityInfo。 | 74| GET_ABILITY_INFO_WITH_DISABLE | 0x00000008 | 用于获取包含禁用的abilityInfo的abilityInfo。 | 75| GET_ABILITY_INFO_ONLY_SYSTEM_APP | 0x00000010 | 用于仅为系统应用程序获取abilityInfo。 | 76 77### ExtensionAbilityFlag 78 79扩展组件信息标志,指示需要获取的扩展组件信息的内容。 80 81 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 82 83 **系统接口:** 系统接口,不支持三方应用调用。 84 85| 名称 | 值 | 说明 | 86| ------------------------------------------- | ---------- | ------------------------------------------------------------ | 87| GET_EXTENSION_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认extensionAbilityInfo。获取的extensionAbilityInfo不包含permission、metadata 和禁用的abilityInfo。 | 88| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的extensionAbilityInfo。 | 89| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的extensionAbilityInfo。 | 90| GET_EXTENSION_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的extensionAbilityInfo。 | 91 92### ExtensionAbilityType 93 94指示扩展组件的类型。 95 96 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 97 98| 名称 | 值 | 说明 | 99|:----------------:|:---:|-----| 100| FORM | 0 | [FormExtensionAbility](../../application-models/widget-development-stage.md):卡片扩展能力,提供卡片开发能力。 | 101| WORK_SCHEDULER | 1 | [WorkSchedulerExtensionAbility](../../task-management/work-scheduler-dev-guide.md):延时任务扩展能力,允许应用在系统闲时执行实时性不高的任务。 | 102| INPUT_METHOD | 2 | [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md):输入法扩展能力,用于开发输入法应用。 | 103| SERVICE | 3 | [ServiceExtensionAbility](../../application-models/serviceextensionability.md):后台服务扩展能力,提供后台运行并对外提供相应能力。 | 104| ACCESSIBILITY | 4 | [AccessibilityExtensionAbility](js-apis-application-accessibilityExtensionAbility.md):无障碍服务扩展能力,支持访问与操作前台界面。 | 105| DATA_SHARE | 5 | [DataShareExtensionAbility](../../database/database-datashare-guidelines.md):数据共享扩展能力,用于对外提供数据读写服务。 | 106| FILE_SHARE | 6 | FileShareExtensionAbility:文件共享扩展能力,用于应用间的文件分享。预留能力,当前暂未支持。 | 107| STATIC_SUBSCRIBER| 7 | [StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md):静态广播扩展能力,用于处理静态事件,比如开机事件。 | 108| WALLPAPER | 8 | WallpaperExtensionAbility:壁纸扩展能力,用于实现桌面壁纸。预留能力,当前暂未支持。 | 109| BACKUP | 9 | BackupExtensionAbility:数据备份扩展能力,提供应用数据和公共数据备份回复能力。预留能力,当前暂未支持。 | 110| WINDOW | 10 | [WindowExtensionAbility](js-apis-application-windowExtensionAbility.md):界面组合扩展能力,允许系统应用进行跨应用的界面拉起和嵌入。 | 111| ENTERPRISE_ADMIN | 11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md):企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。 | 112| THUMBNAIL | 13 | ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,当前暂未支持。 | 113| PREVIEW | 14 | PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,当前暂未支持。 | 114| UNSPECIFIED | 255 | 不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。 | 115 116 117### PermissionGrantState 118 119指示权限授予状态。 120 121 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 122 123| 名称 | 值 | 说明 | 124|:----------------:|:---:|:---:| 125| PERMISSION_DENIED| -1 | 拒绝授予权限。 | 126| PERMISSION_GRANTED | 0 | 授予权限。 | 127 128### SupportWindowMode 129 130标识该组件所支持的窗口模式。 131 132 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 133 134| 名称 | 值 | 说明 | 135|:----------------:|:---:|:---:| 136| FULL_SCREEN | 0 | 窗口支持全屏显示。 | 137| SPLIT | 1 | 窗口支持分屏显示。 | 138| FLOATING | 2 | 支持窗口化显示。 | 139 140### LaunchType 141 142指示组件的启动方式。 143 144 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 145 146| 名称 | 值 | 说明 | 147|:----------------:|:---:|:---:| 148| SINGLETON | 0 | ability的启动模式,表示单实例。 | 149| MULTITON | 1 | ability的启动模式,表示普通多实例。 | 150| SPECIFIED | 2 | ability的启动模式,表示该ability内部根据业务自己置顶多实例。 | 151 152### AbilityType 153 154指示Ability组件的类型。 155 156 **模型约束:** 仅可在FA模型下使用 157 158 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 159 160| 名称 | 值 | 说明 | 161| :-----: | ---- | :--------------------------------------------------------: | 162| PAGE | 1 | 表示基于Page模板开发的FA,用于提供与用户交互的能力。 | 163| SERVICE | 2 | 表示基于Service模板开发的PA,用于提供后台运行任务的能力。 | 164| DATA | 3 | 表示基于Data模板开发的PA,用于对外部提供统一的数据访问对象。 | 165 166### DisplayOrientation 167 168标识该Ability的显示模式。该标签仅适用于page类型的Ability。 169 170 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 171 172| 名称 |值 |说明 | 173|:----------------------------------|---|---| 174| UNSPECIFIED |0 |表示未定义方向模式,由系统判定。 | 175| LANDSCAPE |1 |表示横屏显示模式。 | 176| PORTRAIT |2 |表示竖屏显示模式。 | 177| FOLLOW_RECENT |3 |表示跟随上一个显示模式。 | 178| LANDSCAPE_INVERTED |4 |表示反向横屏显示模式。 | 179| PORTRAIT_INVERTED |5 |表示反向竖屏显示模式。 | 180| AUTO_ROTATION |6 |表示传感器自动旋转模式。 | 181| AUTO_ROTATION_LANDSCAPE |7 |表示传感器自动横向旋转模式。 | 182| AUTO_ROTATION_PORTRAIT |8 |表示传感器自动竖向旋转模式。 | 183| AUTO_ROTATION_RESTRICTED |9 |表示受开关控制的自动旋转模式。 | 184| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|表述受开关控制的自动横向旋转模式。| 185| AUTO_ROTATION_PORTRAIT_RESTRICTED |11|表示受开关控制的自动竖向旋转模式。| 186| LOCKED |12|表示锁定模式。| 187 188### ModuleType 189 190标识模块类型。 191 192 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core 193 194| 名称 | 值 | 说明 | 195| ------- | ---- | -------------------- | 196| ENTRY | 1 | 应用的主模块。 | 197| FEATURE | 2 | 应用的动态特性模块。 | 198| SHARED | 3 | 应用的动态共享库模块。 | 199 200### BundleType 201 202标识应用的类型。 203 204 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core 205 206| 名称 | 值 | 说明 | 207| -------------- | ---- | --------------- | 208| APP | 0 | 该Bundle是普通应用程序。 | 209| ATOMIC_SERVICE | 1 | 该Bundle是原子化服务。 | 210 211## 接口 212 213### bundleManager.getBundleInfoForSelf 214 215getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 216 217以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用Promise形式返回结果。 218 219**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 220 221**参数:** 222 223| 参数名 | 类型 | 必填 | 说明 | 224| ----------- | ------ | ---- | --------------------- | 225| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 226 227**返回值:** 228 229| 类型 | 说明 | 230| ----------------------------------------------------------- | ------------------------------------- | 231| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回当前应用的BundleInfo。| 232 233**示例:** 234 235```ts 236import bundleManager from '@ohos.bundle.bundleManager'; 237import hilog from '@ohos.hilog'; 238let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 239try { 240 bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { 241 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); 242 }).catch(err => { 243 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); 244 }); 245} catch (err) { 246 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message); 247} 248``` 249 250### bundleManager.getBundleInfoForSelf 251 252getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void; 253 254以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用callback形式返回结果。 255 256**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 257 258**参数:** 259 260| 参数名 | 类型 | 必填 | 说明 | 261| ----------- | ------ | ---- | --------------------- | 262| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 263| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的当前应用的BundleInfo;否则为错误对象。 | 264 265**示例:** 266 267```ts 268import bundleManager from '@ohos.bundle.bundleManager'; 269import hilog from '@ohos.hilog'; 270let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 271 272try { 273 bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => { 274 if (err) { 275 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message); 276 } else { 277 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data)); 278 } 279 }); 280} catch (err) { 281 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message); 282} 283``` 284 285### bundleManager.getBundleInfo 286 287getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void; 288 289以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用callback形式返回结果。 290 291获取调用方自己的信息时不需要权限。 292 293**系统接口:** 此接口为系统接口。 294 295**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 296 297**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 298 299**参数:** 300 301| 参数名 | 类型 | 必填 | 说明 | 302| ----------- | ------ | ---- | ---------------------------- | 303| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 304| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| 305| userId | number | 是 | 表示用户ID。 | 306| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。 | 307 308**错误码:** 309 310以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 311 312| 错误码ID | 错误信息 | 313| -------- | ------------------------------------- | 314| 17700001 | The specified bundleName is not found. | 315| 17700004 | The specified user ID is not found. | 316| 17700026 | The specified bundle is disabled. | 317 318**示例:** 319 320```ts 321// 额外获取AbilityInfo 322import bundleManager from '@ohos.bundle.bundleManager'; 323import hilog from '@ohos.hilog'; 324let bundleName = 'com.example.myapplication'; 325let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY; 326let userId = 100; 327 328try { 329 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 330 if (err) { 331 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 332 } else { 333 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 334 } 335 }); 336} catch (err) { 337 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 338} 339``` 340 341```ts 342// 额外获取ApplicationInfo中的metadata 343import bundleManager from '@ohos.bundle.bundleManager'; 344import hilog from '@ohos.hilog'; 345let bundleName = 'com.example.myapplication'; 346let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; 347let userId = 100; 348 349try { 350 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 351 if (err) { 352 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 353 } else { 354 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 355 } 356 }); 357} catch (err) { 358 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 359} 360``` 361 362### bundleManager.getBundleInfo 363 364getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void; 365 366以异步方法根据给定的bundleName和bundleFlags获取BundleInfo,使用callback形式返回结果。 367 368获取调用方自己的信息时不需要权限。 369 370**系统接口:** 此接口为系统接口。 371 372**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 373 374**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 375 376**参数:** 377 378| 参数名 | 类型 | 必填 | 说明 | 379| ----------- | ------ | ---- | ---------------------------- | 380| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 381| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| 382| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 383 384**错误码:** 385 386以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 387 388| 错误码ID | 错误信息 | 389| -------- | ------------------------------------- | 390| 17700001 | The specified bundleName is not found. | 391| 17700004 | The specified user ID is not found. | 392| 17700026 | The specified bundle is disabled. | 393 394**示例:** 395 396```ts 397// 额外获取extensionAbility 398import bundleManager from '@ohos.bundle.bundleManager'; 399import hilog from '@ohos.hilog'; 400let bundleName = 'com.example.myapplication'; 401let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 402 403try { 404 bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => { 405 if (err) { 406 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 407 } else { 408 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 409 } 410 }); 411} catch (err) { 412 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 413} 414``` 415 416### bundleManager.getBundleInfo 417 418getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: number): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 419 420以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用Promise形式返回结果。 421 422获取调用方自己的信息时不需要权限。 423 424**系统接口:** 此接口为系统接口。 425 426**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 427 428**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 429 430**参数:** 431 432| 参数名 | 类型 | 必填 | 说明 | 433| ----------- | ------ | ---- | ---------------------------- | 434| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 435| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 436| userId | number | 否 | 表示用户ID。 | 437 438**返回值:** 439 440| 类型 | 说明 | 441| ----------------------------------------------------------- | --------------------------- | 442| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 443 444**错误码:** 445 446以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 447 448| 错误码ID | 错误信息 | 449| -------- | --------------------------------------| 450| 17700001 | The specified bundleName is not found. | 451| 17700004 | The specified user ID is not found. | 452| 17700026 | The specified bundle is disabled. | 453 454**示例:** 455 456```ts 457// 额外获取ApplicationInfo和SignatureInfo 458import bundleManager from '@ohos.bundle.bundleManager'; 459import hilog from '@ohos.hilog'; 460let bundleName = 'com.example.myapplication'; 461let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; 462let userId = 100; 463 464try { 465 bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => { 466 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 467 }).catch(err => { 468 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 469 }); 470} catch (err) { 471 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 472} 473``` 474 475```ts 476import bundleManager from '@ohos.bundle.bundleManager'; 477import hilog from '@ohos.hilog'; 478let bundleName = 'com.example.myapplication'; 479let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 480 481try { 482 bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => { 483 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 484 }).catch(err => { 485 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 486 }); 487} catch (err) { 488 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 489} 490 491``` 492 493### bundleManager.getApplicationInfo 494 495getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void; 496 497以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用callback形式返回结果。 498 499获取调用方自己的信息时不需要权限。 500 501**系统接口:** 此接口为系统接口。 502 503**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 504 505**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 506 507**参数:** 508 509| 参数名 | 类型 | 必填 | 说明 | 510| ---------- | ------ | ---- | ---------------------------- | 511| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 512| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 513| userId | number | 是 | 表示用户ID。 | 514| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 515 516**错误码:** 517 518以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 519 520| 错误码ID | 错误信息 | 521| -------- | --------------------------------------| 522| 17700001 | The specified bundleName is not found. | 523| 17700004 | The specified user ID is not found. | 524| 17700026 | The specified bundle is disabled. | 525 526**示例:** 527 528```ts 529import bundleManager from '@ohos.bundle.bundleManager'; 530import hilog from '@ohos.hilog'; 531let bundleName = 'com.example.myapplication'; 532let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 533let userId = 100; 534 535try { 536 bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => { 537 if (err) { 538 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 539 } else { 540 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 541 } 542 }); 543} catch (err) { 544 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 545} 546``` 547 548### bundleManager.getApplicationInfo 549 550getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void; 551 552以异步方法根据给定的bundleName和appFlags获取ApplicationInfo,使用callback形式返回结果。 553 554获取调用方自己的信息时不需要权限。 555 556**系统接口:** 此接口为系统接口。 557 558**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 559 560**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 561 562**参数:** 563 564| 参数名 | 类型 | 必填 | 说明 | 565| ---------- | ------ | ---- | ---------------------------- | 566| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 567| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 568| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 569 570**错误码:** 571 572以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 573 574| 错误码ID | 错误信息 | 575| -------- | --------------------------------------| 576| 17700001 | The specified bundleName is not found. | 577| 17700004 | The specified user ID is not found. | 578| 17700026 | The specified bundle is disabled. | 579 580**示例:** 581 582```ts 583import bundleManager from '@ohos.bundle.bundleManager'; 584import hilog from '@ohos.hilog'; 585let bundleName = 'com.example.myapplication'; 586let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 587 588try { 589 bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => { 590 if (err) { 591 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 592 } else { 593 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 594 } 595 }); 596} catch (err) { 597 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 598} 599``` 600 601### bundleManager.getApplicationInfo 602 603getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId?: number): Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>; 604 605以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用Promise形式返回结果。 606 607获取调用方自己的信息时不需要权限。 608 609**系统接口:** 此接口为系统接口。 610 611**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 612 613**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 614 615**参数:** 616 617| 参数名 | 类型 | 必填 | 说明 | 618| ---------- | ------ | ---- | ---------------------------- | 619| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 620| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 621| userId | number | 否 | 表示用户ID。 | 622 623**返回值:** 624 625| 类型 | 说明 | 626| ------------------------------------------------------------ | -------------------------------- | 627| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise对象,返回ApplicationInfo。 | 628 629**错误码:** 630 631以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 632 633| 错误码ID | 错误信息 | 634| -------- | ------------------------------------- | 635| 17700001 | The specified bundleName is not found. | 636| 17700004 | The specified user ID is not found. | 637| 17700026 | The specified bundle is disabled. | 638 639**示例:** 640 641```ts 642import bundleManager from '@ohos.bundle.bundleManager'; 643import hilog from '@ohos.hilog'; 644let bundleName = 'com.example.myapplication'; 645let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 646let userId = 100; 647 648try { 649 bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => { 650 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 651 }).catch(err => { 652 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message); 653 }); 654} catch (err) { 655 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message); 656} 657``` 658 659### bundleManager.getAllBundleInfo 660 661getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void; 662 663以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。 664 665**系统接口:** 此接口为系统接口。 666 667**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 668 669**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 670 671**参数:** 672 673| 参数名 | 类型 | 必填 | 说明 | 674| ----------- | ------ | ---- | -------------------------------------------------- | 675| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 676| userId | number | 是 | 表示用户ID。 | 677| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 678 679**错误码:** 680 681以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 682 683| 错误码ID | 错误信息 | 684| -------- | --------------------------------- | 685| 17700004 | The specified user ID is not found. | 686 687**示例:** 688 689```ts 690import bundleManager from '@ohos.bundle.bundleManager'; 691import hilog from '@ohos.hilog'; 692let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 693let userId = 100; 694 695try { 696 bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => { 697 if (err) { 698 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 699 } else { 700 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 701 } 702 }); 703} catch (err) { 704 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 705} 706``` 707 708### bundleManager.getAllBundleInfo 709 710getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void; 711 712以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。 713 714**系统接口:** 此接口为系统接口。 715 716**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 717 718**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 719 720**参数:** 721 722| 参数名 | 类型 | 必填 | 说明 | 723| ----------- | ------ | ---- | -------------------------------------------------- | 724| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 725| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 726 727**错误码:** 728 729错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 730 731| 错误码ID | 错误信息 | 732| -------- | ---------------------------------- | 733| 17700004 | The specified user ID is not found. | 734 735**示例:** 736 737```ts 738import bundleManager from '@ohos.bundle.bundleManager'; 739import hilog from '@ohos.hilog'; 740let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 741 742try { 743 bundleManager.getAllBundleInfo(bundleFlags, (err, data) => { 744 if (err) { 745 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 746 } else { 747 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 748 } 749 }); 750} catch (err) { 751 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 752} 753``` 754 755### bundleManager.getAllBundleInfo 756 757getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>; 758 759以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。 760 761**系统接口:** 此接口为系统接口。 762 763**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 764 765**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 766 767**参数:** 768 769| 参数名 | 类型 | 必填 | 说明 | 770| ----------- | ------ | ---- | -------------------------------------------------- | 771| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 772| userId | number | 否 | 表示用户ID。 | 773 774**返回值:** 775 776| 类型 | 说明 | 777| ------------------------------------------------------------ | ----------------------------------- | 778| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise对象,返回Array\<BundleInfo>。 | 779 780**错误码:** 781 782以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 783 784| 错误码ID | 错误信息 | 785| -------- | ---------------------------------- | 786| 17700004 | The specified user ID is not found. | 787 788**示例:** 789 790```ts 791import bundleManager from '@ohos.bundle.bundleManager'; 792import hilog from '@ohos.hilog'; 793let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 794 795try { 796 bundleManager.getAllBundleInfo(bundleFlags).then((data) => { 797 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 798 }).catch(err => { 799 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message); 800 }); 801} catch (err) { 802 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message); 803} 804``` 805 806### bundleManager.getAllApplicationInfo 807 808getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void; 809 810以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。 811 812**系统接口:** 此接口为系统接口。 813 814**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 815 816**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 817 818**参数:** 819 820| 参数名 | 类型 | 必填 | 说明 | 821| -------- | ------ | ---- | ----------------------------------------------------------- | 822| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 823| userId | number | 是 | 表示用户ID。 | 824| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 825 826**错误码:** 827 828以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 829 830| 错误码ID | 错误信息 | 831| -------- | ---------------------------------- | 832| 17700004 | The specified user ID is not found. | 833 834**示例:** 835 836```ts 837import bundleManager from '@ohos.bundle.bundleManager'; 838import hilog from '@ohos.hilog'; 839let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 840let userId = 100; 841 842try { 843 bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => { 844 if (err) { 845 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 846 } else { 847 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 848 } 849 }); 850} catch (err) { 851 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 852} 853``` 854 855### bundleManager.getAllApplicationInfo 856 857getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void; 858 859以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。 860 861**系统接口:** 此接口为系统接口。 862 863**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 864 865**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 866 867**参数:** 868 869| 参数名 | 类型 | 必填 | 说明 | 870| -------- | ------ | ---- | ----------------------------------------------------------- | 871| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 872| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 873 874**错误码:** 875 876错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 877 878| 错误码ID | 错误信息 | 879| -------- | ---------------------------------- | 880| 17700004 | The specified user ID is not found. | 881 882**示例:** 883 884```ts 885import bundleManager from '@ohos.bundle.bundleManager'; 886import hilog from '@ohos.hilog'; 887let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 888 889try { 890 bundleManager.getAllApplicationInfo(appFlags, (err, data) => { 891 if (err) { 892 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 893 } else { 894 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 895 } 896 }); 897} catch (err) { 898 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 899} 900``` 901 902### bundleManager.getAllApplicationInfo 903 904getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>; 905 906以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。 907 908**系统接口:** 此接口为系统接口。 909 910**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 911 912**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 913 914**参数:** 915 916| 参数名 | 类型 | 必填 | 说明 | 917| -------- | ------ | ---- | ---------------------------------------------------------- | 918| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 919| userId | number | 否 | 表示用户ID。 | 920 921**返回值:** 922 923| 类型 | 说明 | 924| ------------------------------------------------------------ | ---------------------------------------- | 925| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise对象,返回Array\<ApplicationInfo>。 | 926 927**错误码:** 928 929以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 930 931| 错误码ID | 错误信息 | 932| -------- | ---------------------------------- | 933| 17700004 | The specified user ID is not found. | 934 935**示例:** 936 937```ts 938import bundleManager from '@ohos.bundle.bundleManager'; 939import hilog from '@ohos.hilog'; 940let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 941 942try { 943 bundleManager.getAllApplicationInfo(appFlags).then((data) => { 944 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 945 }).catch(err => { 946 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message); 947 }); 948} catch (err) { 949 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message); 950} 951 952``` 953 954### bundleManager.queryAbilityInfo 955 956queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: number, callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void; 957 958以异步方法根据给定的want、abilityFlags和userId获取多个AbilityInfo,使用callback形式返回结果。 959 960**系统接口:** 此接口为系统接口。 961 962**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 963 964**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 965 966**参数:** 967 968| 参数名 | 类型 | 必填 | 说明 | 969| ------------ | ------ | ---- | ------------------------------------------------------- | 970| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 971| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 972| userId | number | 是 | 表示用户ID。 | 973| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 974 975**错误码:** 976 977以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 978 979| 错误码ID | 错误信息 | 980| -------- | -------------------------------------- | 981| 17700001 | The specified bundleName is not found. | 982| 17700003 | The specified ability is not found. | 983| 17700004 | The specified userId is invalid. | 984| 17700026 | The specified bundle is disabled. | 985| 17700029 | The specified ability is disabled. | 986 987**示例:** 988 989```ts 990import bundleManager from '@ohos.bundle.bundleManager'; 991import hilog from '@ohos.hilog'; 992let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 993let userId = 100; 994let want = { 995 bundleName : "com.example.myapplication", 996 abilityName : "com.example.myapplication.MainAbility" 997}; 998 999try { 1000 bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => { 1001 if (err) { 1002 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1003 } else { 1004 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1005 } 1006 }); 1007} catch (err) { 1008 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1009} 1010``` 1011 1012### bundleManager.queryAbilityInfo 1013 1014queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void; 1015 1016以异步方法根据给定的want和abilityFlags获取一个或多个AbilityInfo,使用callback形式返回结果。 1017 1018**系统接口:** 此接口为系统接口。 1019 1020**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1021 1022**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1023 1024**参数:** 1025 1026| 参数名 | 类型 | 必填 | 说明 | 1027| ------------ | ------ | ---- | -------------------------------------------------------| 1028| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1029| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 1030| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 1031 1032**错误码:** 1033 1034以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1035 1036| 错误码ID | 错误信息 | 1037| -------- | -------------------------------------- | 1038| 17700001 | The specified bundleName is not found. | 1039| 17700003 | The specified ability is not found. | 1040| 17700004 | The specified userId is invalid. | 1041| 17700026 | The specified bundle is disabled. | 1042| 17700029 | The specified ability is disabled. | 1043 1044**示例:** 1045 1046```ts 1047import bundleManager from '@ohos.bundle.bundleManager'; 1048import hilog from '@ohos.hilog'; 1049let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1050let want = { 1051 bundleName : "com.example.myapplication", 1052 abilityName : "com.example.myapplication.MainAbility" 1053}; 1054 1055try { 1056 bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => { 1057 if (err) { 1058 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1059 } else { 1060 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1061 } 1062 }); 1063} catch (err) { 1064 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1065} 1066``` 1067 1068### bundleManager.queryAbilityInfo 1069 1070queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>; 1071 1072以异步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise形式返回结果。 1073 1074**系统接口:** 此接口为系统接口。 1075 1076**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1077 1078**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1079 1080**参数:** 1081 1082| 参数名 | 类型 | 必填 | 说明 | 1083| ------------ | ------ | ---- | ------------------------------------------------------- | 1084| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1085| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1086| userId | number | 否 | 表示用户ID。 | 1087 1088**返回值:** 1089 1090| 类型 | 说明 | 1091| ------------------------------------------------------------ | ------------------------------------ | 1092| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise对象,返回Array\<AbilityInfo>。 | 1093 1094**错误码:** 1095 1096以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1097 1098| 错误码ID | 错误信息 | 1099| -------- | ------------------------------------- | 1100| 17700001 | The specified bundleName is not found. | 1101| 17700003 | The specified ability is not found. | 1102| 17700004 | The specified userId is invalid. | 1103| 17700026 | The specified bundle is disabled. | 1104| 17700029 | The specified ability is disabled. | 1105 1106**示例:** 1107 1108```ts 1109import bundleManager from '@ohos.bundle.bundleManager'; 1110import hilog from '@ohos.hilog'; 1111let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1112let userId = 100; 1113let want = { 1114 bundleName : "com.example.myapplication", 1115 abilityName : "com.example.myapplication.MainAbility" 1116}; 1117 1118try { 1119 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => { 1120 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1121 }).catch(err => { 1122 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1123 }); 1124} catch (err) { 1125 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1126} 1127``` 1128 1129```ts 1130import bundleManager from '@ohos.bundle.bundleManager'; 1131import hilog from '@ohos.hilog'; 1132let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1133let want = { 1134 bundleName : "com.example.myapplication", 1135 abilityName : "com.example.myapplication.MainAbility" 1136}; 1137 1138try { 1139 bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => { 1140 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1141 }).catch(err => { 1142 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1143 }) 1144} catch (err) { 1145 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1146} 1147``` 1148 1149### bundleManager.queryExtensionAbilityInfo 1150 1151queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId: number, callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void; 1152 1153以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。 1154 1155**系统接口:** 此接口为系统接口。 1156 1157**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1158 1159**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1160 1161**参数:** 1162 1163| 参数名 | 类型 | 必填 | 说明 | 1164| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1165| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1166| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1167| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1168| userId | number | 是 | 表示用户ID。 | 1169| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1170 1171**错误码:** 1172 1173以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1174 1175| 错误码ID | 错误信息 | 1176| -------- | ------------------------------------------- | 1177| 17700001 | The specified bundleName is not found. | 1178| 17700003 | The specified extensionAbility is not found. | 1179| 17700004 | The specified userId is invalid. | 1180| 17700026 | The specified bundle is disabled. | 1181 1182**示例:** 1183 1184```ts 1185import bundleManager from '@ohos.bundle.bundleManager'; 1186import hilog from '@ohos.hilog'; 1187let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1188let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1189let userId = 100; 1190let want = { 1191 bundleName : "com.example.myapplication", 1192 abilityName : "com.example.myapplication.MainAbility" 1193}; 1194 1195try { 1196 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => { 1197 if (err) { 1198 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1199 } else { 1200 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1201 } 1202 }); 1203} catch (err) { 1204 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1205} 1206``` 1207 1208### bundleManager.queryExtensionAbilityInfo 1209 1210queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void; 1211 1212以异步方法根据给定的want、extensionAbilityType和extensionAbilityFlags获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。 1213 1214**系统接口:** 此接口为系统接口。 1215 1216**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1217 1218**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1219 1220**参数:** 1221 1222| 参数名 | 类型 | 必填 | 说明 | 1223| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1224| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1225| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1226| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1227| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1228 1229**错误码:** 1230 1231以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1232 1233| 错误码ID | 错误信息 | 1234| -------- | -------------------------------------------- | 1235| 17700001 | The specified bundleName is not found. | 1236| 17700003 | The specified extensionAbility is not found. | 1237| 17700004 | The specified userId is invalid. | 1238| 17700026 | The specified bundle is disabled. | 1239 1240**示例:** 1241 1242```ts 1243import bundleManager from '@ohos.bundle.bundleManager'; 1244import hilog from '@ohos.hilog'; 1245let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1246let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1247let want = { 1248 bundleName : "com.example.myapplication", 1249 abilityName : "com.example.myapplication.MainAbility" 1250}; 1251 1252try { 1253 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => { 1254 if (err) { 1255 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1256 } else { 1257 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1258 } 1259 }); 1260} catch (err) { 1261 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1262} 1263``` 1264 1265### bundleManager.queryExtensionAbilityInfo 1266 1267queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>; 1268 1269以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用Promise形式返回结果。 1270 1271**系统接口:** 此接口为系统接口。 1272 1273**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1274 1275**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1276 1277**参数:** 1278 1279| 参数名 | 类型 | 必填 | 说明 | 1280| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1281| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1282| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1283| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1284| userId | number | 否 | 表示用户ID。 | 1285 1286**返回值:** 1287 1288| 类型 | 说明 | 1289| ------------------------------------------------------------ | --------------------------------------------- | 1290| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise对象,返回Array\<ExtensionAbilityInfo>。 | 1291 1292**错误码:** 1293 1294以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1295 1296| 错误码ID | 错误信息 | 1297| -------- | --------------------------------------| 1298| 17700001 | The specified bundleName is not found. | 1299| 17700003 | The specified extensionAbility is not found. | 1300| 17700004 | The specified userId is invalid. | 1301| 17700026 | The specified bundle is disabled. | 1302 1303**示例:** 1304 1305```ts 1306import bundleManager from '@ohos.bundle.bundleManager'; 1307import hilog from '@ohos.hilog'; 1308 1309let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1310let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1311let userId = 100; 1312let want = { 1313 bundleName : "com.example.myapplication", 1314 abilityName : "com.example.myapplication.MainAbility" 1315}; 1316 1317try { 1318 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => { 1319 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1320 }).catch(err => { 1321 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1322 }); 1323} catch (err) { 1324 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1325} 1326``` 1327 1328```ts 1329import bundleManager from '@ohos.bundle.bundleManager'; 1330import hilog from '@ohos.hilog'; 1331let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1332let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1333let want = { 1334 bundleName : "com.example.myapplication", 1335 abilityName : "com.example.myapplication.MainAbility" 1336}; 1337 1338try { 1339 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => { 1340 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1341 }).catch(err => { 1342 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1343 }) 1344} catch (err) { 1345 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1346} 1347``` 1348 1349### bundleManager.getBundleNameByUid 1350 1351getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void; 1352 1353以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。 1354 1355**系统接口:** 此接口为系统接口。 1356 1357**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1358 1359**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1360 1361**参数:** 1362 1363| 参数名 | 类型 | 必填 | 说明 | 1364| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1365| uid | number | 是 | 表示应用程序的UID。 | 1366| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleName;否则为错误对象。 | 1367 1368**错误码:** 1369 1370以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1371 1372| 错误码ID | 错误信息 | 1373| -------- | --------------------- | 1374| 17700021 | The uid is not found. | 1375 1376**示例:** 1377 1378```ts 1379import bundleManager from '@ohos.bundle.bundleManager'; 1380import hilog from '@ohos.hilog'; 1381let uid = 20010005; 1382try { 1383 bundleManager.getBundleNameByUid(uid, (err, data) => { 1384 if (err) { 1385 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message); 1386 } else { 1387 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data)); 1388 } 1389 }); 1390} catch (err) { 1391 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message); 1392} 1393``` 1394 1395### bundleManager.getBundleNameByUid 1396 1397getBundleNameByUid(uid: number): Promise\<string>; 1398 1399以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。 1400 1401**系统接口:** 此接口为系统接口。 1402 1403**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1404 1405**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1406 1407**参数:** 1408 1409| 参数名 | 类型 | 必填 | 说明 | 1410| ---- | ------ | ---- | ------------------ | 1411| uid | number | 是 | 表示应用程序的UID。 | 1412 1413**返回值:** 1414 1415| 类型 | 说明 | 1416| ---------------- | --------------------------- | 1417| Promise\<string> | Promise对象,返回bundleName。 | 1418 1419**错误码:** 1420 1421以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1422 1423| 错误码ID | 错误信息 | 1424| -------- | ---------------------| 1425| 17700021 | The uid is not found. | 1426 1427**示例:** 1428 1429```ts 1430import bundleManager from '@ohos.bundle.bundleManager'; 1431import hilog from '@ohos.hilog'; 1432let uid = 20010005; 1433try { 1434 bundleManager.getBundleNameByUid(uid).then((data) => { 1435 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data)); 1436 }).catch(err => { 1437 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message); 1438 }); 1439} catch (err) { 1440 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message); 1441} 1442``` 1443 1444### bundleManager.getBundleArchiveInfo 1445 1446getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void; 1447 1448以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用callback形式返回结果。 1449 1450**系统接口:** 此接口为系统接口。 1451 1452**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1453 1454**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1455 1456**参数:** 1457 1458| 参数名 | 类型 | 必填 | 说明 | 1459| ----------- | ------ | ---- | ----------------------------------------------------------- | 1460| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1461| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1462| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 1463 1464**错误码:** 1465 1466以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1467 1468| 错误码ID | 错误信息 | 1469| -------- | --------------------------- | 1470| 17700022 | The hapFilePath is invalid. | 1471 1472**示例:** 1473 1474```ts 1475import bundleManager from '@ohos.bundle.bundleManager'; 1476import hilog from '@ohos.hilog'; 1477let hapFilePath = "/data/xxx/test.hap"; 1478let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1479 1480try { 1481 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => { 1482 if (err) { 1483 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1484 } else { 1485 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data)); 1486 } 1487 }); 1488} catch (err) { 1489 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1490} 1491``` 1492 1493### bundleManager.getBundleArchiveInfo 1494 1495getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 1496 1497以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用Promise形式返回结果。 1498 1499**系统接口:** 此接口为系统接口。 1500 1501**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1502 1503**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1504 1505**参数:** 1506 1507| 参数名 | 类型 | 必填 | 说明 | 1508| ----------- | ------ | ---- | ------------------------------------------------------------ | 1509| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1510| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1511 1512**返回值:** 1513 1514| 类型 | 说明 | 1515| ----------------------------------------------------------- | --------------------------- | 1516| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 1517 1518**错误码:** 1519 1520以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1521 1522| 错误码ID | 错误信息 | 1523| -------- | -------------------------- | 1524| 17700022 | The hapFilePath is invalid. | 1525 1526**示例:** 1527 1528```ts 1529import bundleManager from '@ohos.bundle.bundleManager'; 1530import hilog from '@ohos.hilog'; 1531let hapFilePath = "/data/xxx/test.hap"; 1532let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1533 1534try { 1535 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => { 1536 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data)); 1537 }).catch(err => { 1538 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1539 }); 1540} catch (err) { 1541 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1542} 1543``` 1544 1545### bundleManager.cleanBundleCacheFiles 1546 1547cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void; 1548 1549以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。 1550 1551**系统接口:** 此接口为系统接口。 1552 1553**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1554 1555**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1556 1557**参数:** 1558 1559| 参数名 | 类型 | 必填 | 说明 | 1560| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 1561| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 1562| callback | AsyncCallback\<void> | 是 | 回调函数,当清理应用缓存目录数据成功,err为null,否则为错误对象。 | 1563 1564**错误码:** 1565 1566以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1567 1568| 错误码ID | 错误信息 | 1569| -------- | ------------------------------------------------------------ | 1570| 17700001 | The specified bundleName is not found. | 1571| 17700030 | The specified bundle does not support clearing of cache files. | 1572 1573**示例:** 1574 1575```ts 1576import bundleManager from '@ohos.bundle.bundleManager'; 1577import hilog from '@ohos.hilog'; 1578let bundleName = "com.ohos.myapplication"; 1579 1580try { 1581 bundleManager.cleanBundleCacheFiles(bundleName, err => { 1582 if (err) { 1583 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1584 } else { 1585 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1586 } 1587 }); 1588} catch (err) { 1589 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1590} 1591``` 1592 1593### bundleManager.cleanBundleCacheFiles 1594 1595cleanBundleCacheFiles(bundleName: string): Promise\<void>; 1596 1597以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。 1598 1599**系统接口:** 此接口为系统接口。 1600 1601**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1602 1603**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1604 1605**参数:** 1606 1607| 参数名 | 类型 | 必填 | 说明 | 1608| ---------- | ------ | ---- | ------------------------------------------ | 1609| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 1610 1611**返回值:** 1612 1613| 类型 | 说明 | 1614| -------------- | ------------------------------------------------------------ | 1615| Promise\<void> | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 | 1616 1617**错误码:** 1618 1619以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1620 1621| 错误码ID | 错误信息 | 1622| -------- | ---------------------------------------------------------- | 1623| 17700001 | The specified bundleName is not found. | 1624| 17700030 | The specified bundle does not support clearing of cache files. | 1625 1626**示例:** 1627 1628```ts 1629import bundleManager from '@ohos.bundle.bundleManager'; 1630import hilog from '@ohos.hilog'; 1631let bundleName = "com.ohos.myapplication"; 1632 1633try { 1634 bundleManager.cleanBundleCacheFiles(bundleName).then(() => { 1635 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1636 }).catch(err => { 1637 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1638 }); 1639} catch (err) { 1640 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1641} 1642``` 1643 1644### bundleManager.setApplicationEnabled 1645 1646setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void; 1647 1648设置指定应用的禁用或使能状态,使用callback形式返回结果。 1649 1650**系统接口:** 此接口为系统接口。 1651 1652**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1653 1654**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1655 1656**参数:** 1657 1658| 参数名 | 类型 | 必填 | 说明 | 1659| ---------- | ------- | ---- | ------------------------------------- | 1660| bundleName | string | 是 | 指定应用的bundleName。 | 1661| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 1662| callback | AsyncCallback\<void> | 是 | 回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。 | 1663 1664**错误码:** 1665 1666以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1667 1668| 错误码ID | 错误信息 | 1669| -------- | -------------------------------------- | 1670| 17700001 | The specified bundleName is not found. | 1671 1672**示例:** 1673 1674```ts 1675import bundleManager from '@ohos.bundle.bundleManager'; 1676import hilog from '@ohos.hilog'; 1677let bundleName = "com.ohos.myapplication"; 1678 1679try { 1680 bundleManager.setApplicationEnabled(bundleName, false, err => { 1681 if (err) { 1682 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 1683 } else { 1684 hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.'); 1685 } 1686 }); 1687} catch (err) { 1688 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 1689} 1690``` 1691 1692### bundleManager.setApplicationEnabled 1693 1694setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void>; 1695 1696设置指定应用的禁用或使能状态,使用Promise形式返回结果。 1697 1698**系统接口:** 此接口为系统接口。 1699 1700**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1701 1702**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1703 1704**参数:** 1705 1706| 参数名 | 类型 | 必填 | 说明 | 1707| ---------- | ------- | ---- | ------------------------------------- | 1708| bundleName | string | 是 | 表示应用程序的bundleName。 | 1709| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 1710 1711**返回值:** 1712 1713| 类型 | 说明 | 1714| -------------- | ------------------------------------ | 1715| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1716 1717**错误码:** 1718 1719以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1720 1721| 错误码ID | 错误信息 | 1722| -------- | -------------------------------------- | 1723| 17700001 | The specified bundleName is not found. | 1724 1725**示例:** 1726 1727```ts 1728import bundleManager from '@ohos.bundle.bundleManager'; 1729import hilog from '@ohos.hilog'; 1730let bundleName = "com.ohos.myapplication"; 1731 1732try { 1733 bundleManager.setApplicationEnabled(bundleName, false).then(() => { 1734 hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); 1735 }).catch(err => { 1736 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 1737 }); 1738} catch (err) { 1739 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 1740} 1741``` 1742 1743### bundleManager.setAbilityEnabled 1744 1745setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\<void>): void; 1746 1747设置指定组件的禁用或使能状态,使用callback形式返回结果。 1748 1749**系统接口:** 此接口为系统接口。 1750 1751**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1752 1753**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1754 1755**参数:** 1756 1757| 参数名 | 类型 | 必填 | 说明 | 1758| -------- | ----------- | ---- | ------------------------------------- | 1759| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 1760| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 1761| callback | AsyncCallback\<void> | 是 | 回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。 | 1762 1763**错误码:** 1764 1765以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1766 1767| 错误码ID | 错误信息 | 1768| -------- | ---------------------------------------| 1769| 17700001 | The specified bundleName is not found. | 1770| 17700003 | The specified abilityInfo is not found. | 1771 1772**示例:** 1773 1774```ts 1775import bundleManager from '@ohos.bundle.bundleManager'; 1776import hilog from '@ohos.hilog'; 1777let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1778let userId = 100; 1779let want = { 1780 bundleName : "com.example.myapplication", 1781 abilityName : "com.example.myapplication.MainAbility" 1782}; 1783let info; 1784 1785try { 1786 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 1787 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 1788 info = abilitiesInfo[0]; 1789 1790 bundleManager.setAbilityEnabled(info, false, err => { 1791 if (err) { 1792 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 1793 } else { 1794 hilog.info(0x0001, "testTag", "setAbilityEnabled successfully."); 1795 } 1796 }); 1797 }).catch(err => { 1798 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1799 }); 1800} catch (err) { 1801 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1802} 1803``` 1804 1805### bundleManager.setAbilityEnabled 1806 1807setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\<void>; 1808 1809设置指定组件的禁用或使能状态,使用Promise形式返回结果。 1810 1811**系统接口:** 此接口为系统接口。 1812 1813**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1814 1815**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1816 1817**参数:** 1818 1819| 参数名 | 类型 | 必填 | 说明 | 1820| -------- | ----------- | ---- | ------------------------------------- | 1821| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 1822| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 1823 1824**返回值:** 1825 1826| 类型 | 说明 | 1827| -------------- | --------------------------------- | 1828| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 1829 1830**错误码:** 1831 1832以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1833 1834| 错误码ID | 错误信息 | 1835| -------- | -------------------------------------- | 1836| 17700001 | The specified bundleName is not found. | 1837| 17700003 | The specified abilityInfo is not found. | 1838 1839**示例:** 1840 1841```ts 1842import bundleManager from '@ohos.bundle.bundleManager'; 1843import hilog from '@ohos.hilog'; 1844let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1845let userId = 100; 1846let want = { 1847 bundleName : "com.example.myapplication", 1848 abilityName : "com.example.myapplication.MainAbility" 1849}; 1850let info; 1851 1852try { 1853 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 1854 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 1855 info = abilitiesInfo[0]; 1856 1857 bundleManager.setAbilityEnabled(info, false).then(() => { 1858 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 1859 }).catch(err => { 1860 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 1861 }); 1862 }).catch(err => { 1863 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1864 }); 1865} catch (err) { 1866 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1867} 1868``` 1869 1870### bundleManager.isApplicationEnabled 1871 1872isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void; 1873 1874以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。 1875 1876**系统接口:** 此接口为系统接口。 1877 1878**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1879 1880**参数:** 1881 1882| 参数名 | 类型 | 必填 | 说明 | 1883| ---------- | ------ | ---- | -------------------------- | 1884| bundleName | string | 是 | 表示应用程序的bundleName。 | 1885| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 | 1886 1887**错误码:** 1888 1889以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1890 1891| 错误码ID | 错误信息 | 1892| -------- | -------------------------------------- | 1893| 17700001 | The specified bundleName is not found. | 1894 1895**示例:** 1896 1897```ts 1898import bundleManager from '@ohos.bundle.bundleManager'; 1899import hilog from '@ohos.hilog'; 1900let bundleName = 'com.example.myapplication'; 1901 1902try { 1903 bundleManager.isApplicationEnabled(bundleName, (err, data) => { 1904 if (err) { 1905 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message); 1906 } else { 1907 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data)); 1908 } 1909 }); 1910} catch (err) { 1911 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message); 1912} 1913``` 1914 1915### bundleManager.isApplicationEnabled 1916 1917isApplicationEnabled(bundleName: string): Promise\<boolean>; 1918 1919以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。 1920 1921**系统接口:** 此接口为系统接口。 1922 1923**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1924 1925**参数:** 1926 1927| 参数名 | 类型 | 必填 | 说明 | 1928| ---------- | ------ | ---- | -------------------------- | 1929| bundleName | string | 是 | 表示应用程序的bundleName。 | 1930 1931**返回值:** 1932 1933| 类型 | 说明 | 1934| ----------------- | ------------------------------------------------------------ | 1935| Promise\<boolean> | Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 1936 1937**错误码:** 1938 1939以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1940 1941| 错误码ID | 错误信息 | 1942| -------- | -------------------------------------- | 1943| 17700001 | The specified bundleName is not found. | 1944 1945**示例:** 1946 1947```ts 1948import bundleManager from '@ohos.bundle.bundleManager'; 1949import hilog from '@ohos.hilog'; 1950let bundleName = 'com.example.myapplication'; 1951 1952try { 1953 bundleManager.isApplicationEnabled(bundleName).then((data) => { 1954 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data)); 1955 }).catch(err => { 1956 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 1957 }); 1958} catch (err) { 1959 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 1960} 1961``` 1962 1963### bundleManager.isAbilityEnabled 1964 1965isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\<boolean>): void; 1966 1967以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。 1968 1969**系统接口:** 此接口为系统接口。 1970 1971**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1972 1973**参数:** 1974 1975| 参数名 | 类型 | 必填 | 说明 | 1976| ---- | ----------- | ---- | --------------------------- | 1977| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 1978| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用组件为使能状态,返回false表示应用组件为禁用状态。 | 1979 1980**错误码:** 1981 1982以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1983 1984| 错误码ID | 错误信息 | 1985| -------- | --------------------------------------- | 1986| 17700001 | The specified bundleName is not found. | 1987| 17700003 | The specified abilityName is not found. | 1988 1989**示例:** 1990 1991```ts 1992import bundleManager from '@ohos.bundle.bundleManager'; 1993import hilog from '@ohos.hilog'; 1994let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1995let userId = 100; 1996let want = { 1997 bundleName : "com.example.myapplication", 1998 abilityName : "com.example.myapplication.MainAbility" 1999}; 2000let info; 2001 2002try { 2003 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2004 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2005 info = abilitiesInfo[0]; 2006 2007 bundleManager.isAbilityEnabled(info, (err, data) => { 2008 if (err) { 2009 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message); 2010 } else { 2011 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data)); 2012 } 2013 }); 2014 }).catch(err => { 2015 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2016 }); 2017} catch (err) { 2018 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2019} 2020``` 2021 2022### bundleManager.isAbilityEnabled 2023 2024isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\<boolean>; 2025 2026以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。 2027 2028**系统接口:** 此接口为系统接口。 2029 2030**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2031 2032**参数:** 2033 2034| 参数名 | 类型 | 必填 | 说明 | 2035| ---- | ----------- | ---- | --------------------------- | 2036| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2037 2038**返回值:** 2039 2040| 类型 | 说明 | 2041| ----------------- | ------------------------------------------------------------ | 2042| Promise\<boolean> | Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 2043 2044**错误码:** 2045 2046以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2047 2048| 错误码ID | 错误信息 | 2049| -------- | --------------------------------------- | 2050| 17700001 | The specified bundleName is not found. | 2051| 17700003 | The specified abilityName is not found. | 2052 2053**示例:** 2054 2055```ts 2056import bundleManager from '@ohos.bundle.bundleManager'; 2057import hilog from '@ohos.hilog'; 2058let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2059let userId = 100; 2060let want = { 2061 bundleName : "com.example.myapplication", 2062 abilityName : "com.example.myapplication.MainAbility" 2063}; 2064let info; 2065 2066try { 2067 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2068 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2069 info = abilitiesInfo[0]; 2070 2071 bundleManager.isAbilityEnabled(info).then((data) => { 2072 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2073 }).catch(err => { 2074 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); 2075 }); 2076 }).catch(err => { 2077 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2078 }); 2079} catch (err) { 2080 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2081} 2082``` 2083 2084### bundleManager.getLaunchWantForBundle 2085 2086getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void; 2087 2088以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。 2089 2090**系统接口:** 此接口为系统接口。 2091 2092**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2093 2094**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2095 2096**参数:** 2097 2098| 参数名 | 类型 | 必填 | 说明 | 2099| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2100| bundleName | string | 是 | 表示应用程序的bundleName。 | 2101| userId | number | 是 | 表示用户ID。 | 2102| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 2103 2104**错误码:** 2105 2106以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2107 2108| 错误码ID | 错误信息 | 2109| -------- | --------------------------------------| 2110| 17700001 | The specified bundleName is not found. | 2111| 17700004 | The specified user ID is not found. | 2112| 17700026 | The specified bundle is disabled. | 2113 2114**示例:** 2115 2116```ts 2117import bundleManager from '@ohos.bundle.bundleManager'; 2118import hilog from '@ohos.hilog'; 2119let bundleName = 'com.example.myapplication'; 2120let userId = 100; 2121 2122try { 2123 bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => { 2124 if (err) { 2125 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2126 } else { 2127 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2128 } 2129 }); 2130} catch (err) { 2131 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2132} 2133``` 2134 2135### bundleManager.getLaunchWantForBundle 2136 2137getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void; 2138 2139以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。 2140 2141**系统接口:** 此接口为系统接口。 2142 2143**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2144 2145**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2146 2147**参数:** 2148 2149| 参数名 | 类型 | 必填 | 说明 | 2150| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2151| bundleName | string | 是 | 表示应用程序的bundleName。 | 2152| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 2153 2154**错误码:** 2155 2156以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2157 2158| 错误码ID | 错误信息 | 2159| -------- | --------------------------------------| 2160| 17700001 | The specified bundleName is not found. | 2161| 17700004 | The specified user ID is not found. | 2162| 17700026 | The specified bundle is disabled. | 2163 2164**示例:** 2165 2166```ts 2167import bundleManager from '@ohos.bundle.bundleManager'; 2168import hilog from '@ohos.hilog'; 2169let bundleName = 'com.example.myapplication'; 2170 2171try { 2172 bundleManager.getLaunchWantForBundle(bundleName, (err, data) => { 2173 if (err) { 2174 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2175 } else { 2176 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2177 } 2178 }); 2179} catch (err) { 2180 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2181} 2182``` 2183 2184### bundleManager.getLaunchWantForBundle 2185 2186getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want>; 2187 2188以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。 2189 2190**系统接口:** 此接口为系统接口。 2191 2192**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2193 2194**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2195 2196**参数:** 2197 2198| 参数名 | 类型 | 必填 | 说明 | 2199| ---------- | ------ | ---- | ------------------------- | 2200| bundleName | string | 是 | 表示应用程序的bundleName。 | 2201| userId | number | 否 | 表示用户ID。 | 2202 2203**返回值:** 2204 2205| 类型 | 说明 | 2206| -------------- | ------------------------- | 2207| Promise\<Want> | Promise对象,返回Want对象。 | 2208 2209**错误码:** 2210 2211以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2212 2213| 错误码ID | 错误信息 | 2214| -------- | --------------------------------------| 2215| 17700001 | The specified bundleName is not found. | 2216| 17700004 | The specified user ID is not found. | 2217| 17700026 | The specified bundle is disabled. | 2218 2219**示例:** 2220 2221```ts 2222import bundleManager from '@ohos.bundle.bundleManager'; 2223import hilog from '@ohos.hilog'; 2224let bundleName = 'com.example.myapplication'; 2225let userId = 100; 2226 2227try { 2228 bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => { 2229 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data)); 2230 }).catch(err => { 2231 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message); 2232 }); 2233} catch (err) { 2234 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message); 2235} 2236``` 2237 2238### bundleManager.getProfileByAbility 2239 2240getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void; 2241 2242以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。 2243 2244**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2245 2246**参数:** 2247 2248| 参数名 | 类型 | 必填 | 说明 | 2249| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 2250| moduleName | string | 是 | 表示应用程序的moduleName。 | 2251| abilityName | string | 是 | 表示应用程序的abilityName。 | 2252| metadataName | string | 是 | 表示应用程序的metadataName。 | 2253| callback | AsyncCallback<Array\<string>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 | 2254 2255**错误码:** 2256 2257以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2258 2259| 错误码ID | 错误信息 | 2260| -------- | ------------------------------------------------------------ | 2261| 17700002 | The specified moduleName is not existed. | 2262| 17700003 | The specified abilityName is not existed. | 2263| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2264| 17700026 | The specified bundle is disabled. | 2265| 17700029 | The specified ability is disabled. | 2266 2267**示例:** 2268 2269```ts 2270import bundleManager from '@ohos.bundle.bundleManager'; 2271import hilog from '@ohos.hilog'; 2272let moduleName = 'entry'; 2273let abilityName = 'MainAbility'; 2274let metadataName = 'com.example.myapplication.metadata'; 2275 2276try { 2277 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => { 2278 if (err) { 2279 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2280 } else { 2281 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data)); 2282 } 2283 }); 2284} catch (err) { 2285 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2286} 2287``` 2288 2289### bundleManager.getProfileByAbility 2290 2291getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\>; 2292 2293以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。 2294 2295**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2296 2297**参数:** 2298 2299| 参数名 | 类型 | 必填 | 说明 | 2300| ------------ | ------ | ---- | -------------------------- | 2301| moduleName | string | 是 | 表示应用程序的moduleName。 | 2302| abilityName | string | 是 | 表示应用程序的abilityName。 | 2303| metadataName | string | 否 | 表示应用程序的metadataName。 | 2304 2305**返回值:** 2306 2307| 类型 | 说明 | 2308| ----------------------- | ------------------------------- | 2309| Promise<Array\<string>> | Promise对象,返回Array\<string>。 | 2310 2311**错误码:** 2312 2313以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2314 2315| 错误码ID | 错误信息 | 2316| -------- | ------------------------------------------------------------ | 2317| 17700002 | The specified moduleName is not existed. | 2318| 17700003 | The specified abilityName is not existed. | 2319| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2320| 17700026 | The specified bundle is disabled. | 2321| 17700029 | The specified ability is disabled. | 2322 2323**示例:** 2324 2325```ts 2326import bundleManager from '@ohos.bundle.bundleManager'; 2327import hilog from '@ohos.hilog'; 2328let moduleName = 'entry'; 2329let abilityName = 'MainAbility'; 2330 2331try { 2332 bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => { 2333 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 2334 }).catch(err => { 2335 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2336 }); 2337} catch (err) { 2338 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2339} 2340``` 2341 2342```ts 2343import bundleManager from '@ohos.bundle.bundleManager'; 2344import hilog from '@ohos.hilog'; 2345let moduleName = 'entry'; 2346let abilityName = 'MainAbility'; 2347let metadataName = 'com.example.myapplication.metadata'; 2348try { 2349 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => { 2350 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 2351 }).catch(err => { 2352 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2353 }); 2354} catch (err) { 2355 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2356} 2357``` 2358 2359### bundleManager.getProfileByExtensionAbility 2360 2361getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void; 2362 2363以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。 2364 2365**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2366 2367**参数:** 2368 2369| 参数名 | 类型 | 必填 | 说明 | 2370| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ | 2371| moduleName | string | 是 | 表示应用程序的moduleName。 | 2372| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | 2373| metadataName | string | 是 | 表示应用程序的metadataName。 | 2374| callback | AsyncCallback<Array\<string>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 | 2375 2376**错误码:** 2377 2378以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2379 2380| 错误码ID | 错误信息 | 2381| -------- | ------------------------------------------------------------ | 2382| 17700002 | The specified moduleName is not existed. | 2383| 17700003 | The specified extensionAbilityName not existed. | 2384| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2385| 17700026 | The specified bundle is disabled. | 2386 2387**示例:** 2388 2389```ts 2390import bundleManager from '@ohos.bundle.bundleManager'; 2391import hilog from '@ohos.hilog'; 2392let moduleName = 'entry'; 2393let extensionAbilityName = 'com.example.myapplication.extension'; 2394let metadataName = 'com.example.myapplication.metadata'; 2395 2396try { 2397 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => { 2398 if (err) { 2399 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message); 2400 } else { 2401 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data)); 2402 } 2403 }); 2404} catch (err) { 2405 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message); 2406} 2407``` 2408 2409### bundleManager.getProfileByExtensionAbility 2410 2411getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\>; 2412 2413以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。 2414 2415**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2416 2417**参数:** 2418 2419| 参数名 | 类型 | 必填 | 说明 | 2420| -------------------- | ------ | ---- | ---------------------------------- | 2421| moduleName | string | 是 | 表示应用程序的moduleName。 | 2422| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | 2423| metadataName | string | 否 | 表示应用程序的metadataName。 | 2424 2425**返回值:** 2426 2427| 类型 | 说明 | 2428| ----------------------- | ----------------------------------- | 2429| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 | 2430 2431**错误码:** 2432 2433以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2434 2435| 错误码ID | 错误信息 | 2436| -------- | ------------------------------------------------------------ | 2437| 17700002 | The specified moduleName is not existed. | 2438| 17700003 | The specified extensionAbilityName not existed. | 2439| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2440| 17700026 | The specified bundle is disabled. | 2441 2442**示例:** 2443 2444```ts 2445import bundleManager from '@ohos.bundle.bundleManager'; 2446import hilog from '@ohos.hilog'; 2447let moduleName = 'entry'; 2448let extensionAbilityName = 'com.example.myapplication.extension'; 2449let metadataName = 'com.example.myapplication.metadata'; 2450 2451try { 2452 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => { 2453 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 2454 }).catch(err => { 2455 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 2456 }); 2457} catch (err) { 2458 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 2459} 2460 2461try { 2462 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => { 2463 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 2464 }).catch(err => { 2465 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 2466 }); 2467} catch (err) { 2468 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 2469} 2470``` 2471 2472### bundleManager.getPermissionDef 2473 2474getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void; 2475 2476以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。 2477 2478**系统接口:** 此接口为系统接口。 2479 2480**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2481 2482**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2483 2484**参数:** 2485 2486| 参数名 | 类型 | 必填 | 说明 | 2487| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2488| permissionName | string | 是 | 表示权限名称。 | 2489| callback | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<PermissionDef>;否则为错误对象。 | 2490 2491**错误码:** 2492 2493以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2494 2495| 错误码ID | 错误信息 | 2496| -------- | ------------------------------------- | 2497| 17700006 | The specified permission is not found. | 2498 2499**示例:** 2500 2501```ts 2502import bundleManager from '@ohos.bundle.bundleManager'; 2503import hilog from '@ohos.hilog'; 2504let permission = "ohos.permission.GET_BUNDLE_INFO"; 2505try { 2506 bundleManager.getPermissionDef(permission, (err, data) => { 2507 if (err) { 2508 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message); 2509 } else { 2510 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data)); 2511 } 2512 }); 2513} catch (err) { 2514 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message); 2515} 2516``` 2517 2518### bundleManager.getPermissionDef 2519 2520getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>; 2521 2522以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。 2523 2524**系统接口:** 此接口为系统接口。 2525 2526**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2527 2528**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2529 2530**参数:** 2531 2532| 参数名 | 类型 | 必填 | 说明 | 2533| -------------- | ------ | ---- | -------------- | 2534| permissionName | string | 是 | 表示权限参数名。 | 2535 2536**返回值:** 2537 2538| 类型 | 说明 | 2539| ------------------------------------------------------------ | ------------------------------------------ | 2540| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Promise对象,返回Array\<PermissionDef>对象。 | 2541 2542**错误码:** 2543 2544以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2545 2546| 错误码ID | 错误信息 | 2547| -------- | ------------------------------------- | 2548| 17700006 | The specified permission is not found. | 2549 2550**示例:** 2551 2552```ts 2553import bundleManager from '@ohos.bundle.bundleManager'; 2554import hilog from '@ohos.hilog'; 2555let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 2556try { 2557 bundleManager.getPermissionDef(permissionName).then((data) => { 2558 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data)); 2559 }).catch(err => { 2560 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message); 2561 }); 2562} catch (err) { 2563 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message); 2564} 2565``` 2566 2567### bundleManager.getAbilityLabel 2568 2569getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void; 2570 2571以异步的方法获取指定bundleName、moduleName和abilityName的label,使用callback形式返回结果。 2572 2573**系统接口:** 此接口为系统接口。 2574 2575**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2576 2577**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 2578 2579**参数:** 2580 2581| 参数名 | 类型 | 必填 | 说明 | 2582| ----------- | ---------------------- | ---- | ------------------------------------------------------------ | 2583| bundleName | string | 是 | 表示应用程序的bundleName。 | 2584| moduleName | string | 是 | 表示应用程序的moduleName。 | 2585| abilityName | string | 是 | 表示应用程序的abilityName。 | 2586| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 | 2587 2588**错误码:** 2589 2590以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2591 2592| 错误码ID | 错误信息 | 2593| -------- | -------------------------------------- | 2594| 17700001 | The specified bundleName is not found. | 2595| 17700002 | The specified moduleName is not found. | 2596| 17700003 | The specified abilityName is not found. | 2597| 17700026 | The specified bundle is disabled. | 2598| 17700029 | The specified ability is disabled. | 2599 2600**示例:** 2601 2602```ts 2603import bundleManager from '@ohos.bundle.bundleManager'; 2604import hilog from '@ohos.hilog'; 2605let bundleName = 'com.example.myapplication'; 2606let moduleName = 'entry'; 2607let abilityName = 'MainAbility'; 2608 2609try { 2610 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => { 2611 if (err) { 2612 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message); 2613 } else { 2614 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data)); 2615 } 2616 }); 2617} catch (err) { 2618 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message); 2619} 2620``` 2621 2622### bundleManager.getAbilityLabel 2623 2624getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string>; 2625 2626以异步的方法获取指定bundleName、moduleName和abilityName的label,使用Promise形式返回结果。 2627 2628**系统接口:** 此接口为系统接口。 2629 2630**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2631 2632**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 2633 2634**参数:** 2635 2636| 参数名 | 类型 | 必填 | 说明 | 2637| ----------- | ------ | ---- | ------------------------- | 2638| bundleName | string | 是 | 表示应用程序的bundleName。 | 2639| moduleName | string | 是 | 表示应用程序的moduleName。 | 2640| abilityName | string | 是 | 表示应用程序的abilityName。 | 2641 2642**返回值:** 2643 2644| 类型 | 说明 | 2645| ---------------- | ----------------------------------- | 2646| Promise\<string> | Promise对象,返回指定组件的Lablel值。 | 2647 2648**错误码:** 2649 2650以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2651 2652| 错误码ID | 错误信息 | 2653| -------- | --------------------------------------- | 2654| 17700001 | The specified bundleName is not found. | 2655| 17700002 | The specified moduleName is not found. | 2656| 17700003 | The specified abilityName is not found. | 2657| 17700026 | The specified bundle is disabled. | 2658| 17700029 | The specified ability is disabled. | 2659 2660**示例:** 2661 2662```ts 2663import bundleManager from '@ohos.bundle.bundleManager'; 2664import hilog from '@ohos.hilog'; 2665let bundleName = 'com.example.myapplication'; 2666let moduleName = 'entry'; 2667let abilityName = 'MainAbility'; 2668 2669try { 2670 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => { 2671 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data)); 2672 }).catch(err => { 2673 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message); 2674 }); 2675} catch (err) { 2676 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message); 2677} 2678``` 2679 2680### bundleManager.getApplicationInfoSync 2681 2682getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); 2683 2684以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。 2685 2686**系统接口:** 此接口为系统接口。 2687 2688**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2689 2690**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。 2691 2692**参数:** 2693 2694| 参数名 | 类型 | 必填 | 说明 | 2695| ----------- | ------ | ---- | ----------------------------------------------------------| 2696| bundleName | string | 是 | 表示应用程序的bundleName。 | 2697| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 2698| userId | number | 是 | 表示用户ID。 | 2699 2700**返回值:** 2701 2702| 类型 | 说明 | 2703| --------------- | ------------------------- | 2704| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 2705 2706**错误码:** 2707 2708以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2709 2710| 错误码ID | 错误信息 | 2711| -------- | -------------------------------------- | 2712| 17700001 | The specified bundleName is not found. | 2713| 17700004 | The specified user ID is not found. | 2714| 17700026 | The specified bundle is disabled. | 2715 2716**示例:** 2717 2718```ts 2719import bundleManager from '@ohos.bundle.bundleManager'; 2720import hilog from '@ohos.hilog'; 2721let bundleName = 'com.example.myapplication'; 2722let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 2723let userId = 100; 2724 2725try { 2726 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId); 2727 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 2728} catch (err) { 2729 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message); 2730} 2731``` 2732 2733### bundleManager.getApplicationInfoSync 2734 2735getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); 2736 2737以同步方法根据给定的bundleName、applicationFlags获取ApplicationInfo。 2738 2739**系统接口:** 此接口为系统接口。 2740 2741**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2742 2743**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2744 2745**参数:** 2746 2747| 参数名 | 类型 | 必填 | 说明 | 2748| ---------------- | -------------------------- | ---- | ----------------------------------------------------- | 2749| bundleName | string | 是 | 表示应用程序的bundleName。 | 2750| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 2751 2752**返回值:** 2753 2754| 类型 | 说明 | 2755| ----------------------------------------------------------- | ------------------------- | 2756| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 2757 2758**错误码:** 2759 2760以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2761 2762| 错误码ID | 错误信息 | 2763| -------- | -------------------------------------- | 2764| 17700001 | The specified bundleName is not found. | 2765| 17700026 | The specified bundle is disabled. | 2766 2767**示例:** 2768 2769```ts 2770import bundleManager from '@ohos.bundle.bundleManager'; 2771import hilog from '@ohos.hilog'; 2772let bundleName = 'com.example.myapplication'; 2773let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 2774 2775try { 2776 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags); 2777 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 2778} catch (err) { 2779 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message); 2780} 2781``` 2782 2783### bundleManager.getBundleInfoSync 2784 2785getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md); 2786 2787以同步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo。 2788 2789**系统接口:** 此接口为系统接口。 2790 2791**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2792 2793**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2794 2795**参数:** 2796 2797| 参数名 | 类型 | 必填 | 说明 | 2798| ----------- | ------ | ---- | -------------------------------------------------------- | 2799| bundleName | string | 是 | 表示应用程序的bundleName。 | 2800| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 2801| userId | number | 是 | 表示用户ID。 | 2802 2803**返回值:** 2804 2805| 类型 | 说明 | 2806| ---------- | -------------------- | 2807| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 2808 2809**错误码:** 2810 2811以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2812 2813| 错误码ID | 错误信息 | 2814| -------- | ------------------------------------- | 2815| 17700001 | The specified bundleName is not found. | 2816| 17700004 | The specified user ID is not found. | 2817| 17700026 | The specified bundle is disabled. | 2818 2819**示例:** 2820 2821```ts 2822import bundleManager from '@ohos.bundle.bundleManager'; 2823import hilog from '@ohos.hilog'; 2824let bundleName = 'com.example.myapplication'; 2825let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 2826let userId = 100; 2827 2828try { 2829 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId); 2830 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 2831} catch (err) { 2832 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message); 2833} 2834``` 2835 2836### bundleManager.getBundleInfoSync 2837 2838getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md); 2839 2840以同步方法根据给定的bundleName、bundleFlags获取BundleInfo。 2841 2842**系统接口:** 此接口为系统接口。 2843 2844**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 2845 2846**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2847 2848**参数:** 2849 2850| 参数名 | 类型 | 必填 | 说明 | 2851| ----------- | --------------------- | ---- | ------------------------------------------------------ | 2852| bundleName | string | 是 | 表示应用程序的bundleName。 | 2853| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 2854 2855**返回值:** 2856 2857| 类型 | 说明 | 2858| ------------------------------------------------- | -------------------- | 2859| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 2860 2861**错误码:** 2862 2863以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2864 2865| 错误码ID | 错误信息 | 2866| -------- | -------------------------------------- | 2867| 17700001 | The specified bundleName is not found. | 2868| 17700026 | The specified bundle is disabled. | 2869 2870**示例:** 2871 2872```ts 2873import bundleManager from '@ohos.bundle.bundleManager'; 2874import hilog from '@ohos.hilog'; 2875let bundleName = 'com.example.myapplication'; 2876let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 2877try { 2878 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags); 2879 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 2880} catch (err) { 2881 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message); 2882} 2883``` 2884