HarmonyOS实战开发:@ohos.bundle.bundleManager (bundleManager模块)

本模块提供应用信息查询能力,支持BundleInfo、ApplicationInfo、Ability、ExtensionAbility等信息的查询。

说明: 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import bundleManager from '@ohos.bundle.bundleManager';

权限列表

权限权限等级描述
ohos.permission.GET_BUNDLE_INFOnormal允许查询应用的基本信息。
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basic允许查询应用的基本信息和其他敏感信息。
ohos.permission.REMOVE_CACHE_FILESsystem_basic清理应用缓存。
ohos.permission.CHANGE_ABILITY_ENABLED_STATEsystem_basic设置禁用使能所需的权限。
ohos.permission.GET_INSTALLED_BUNDLE_LISTsystem_basic读取已安装应用列表。

权限等级参考权限等级说明

枚举

BundleFlag

包信息标志,指示需要获取的包信息的内容。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
GET_BUNDLE_INFO_DEFAULT0x00000000用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。
GET_BUNDLE_INFO_WITH_APPLICATION0x00000001用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。
GET_BUNDLE_INFO_WITH_HAP_MODULE0x00000002用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。
GET_BUNDLE_INFO_WITH_ABILITY0x00000004用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。
GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY0x00000008用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。
GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION0x00000010用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。
GET_BUNDLE_INFO_WITH_METADATA0x00000020用于获取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一起使用。
GET_BUNDLE_INFO_WITH_DISABLE0x00000040用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO0x00000080用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。

ApplicationFlag

应用信息标志,指示需要获取的应用信息的内容。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

系统接口: 此接口为系统接口。

名称说明
GET_APPLICATION_INFO_DEFAULT0x00000000用于获取默认的applicationInfo,获取的applicationInfo不包含permission和metadata信息。
GET_APPLICATION_INFO_WITH_PERMISSION0x00000001用于获取包含permission的applicationInfo。
GET_APPLICATION_INFO_WITH_METADATA0x00000002用于获取包含metadata的applicationInfo。
GET_APPLICATION_INFO_WITH_DISABLE0x00000004用于获取包含禁用应用程序的applicationInfo。

AbilityFlag

Ability组件信息标志,指示需要获取的Ability组件信息的内容。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

系统接口: 此接口为系统接口。

名称说明
GET_ABILITY_INFO_DEFAULT0x00000000用于获取默认abilityInfo,获取的abilityInfo不包含permission、metadata和禁用的abilityInfo。
GET_ABILITY_INFO_WITH_PERMISSION0x00000001用于获取包含permission的abilityInfo。
GET_ABILITY_INFO_WITH_APPLICATION0x00000002用于获取包含applicationInfo的abilityInfo。
GET_ABILITY_INFO_WITH_METADATA0x00000004用于获取包含metadata的abilityInfo。
GET_ABILITY_INFO_WITH_DISABLE0x00000008用于获取包含禁用的abilityInfo的abilityInfo。
GET_ABILITY_INFO_ONLY_SYSTEM_APP0x00000010用于仅为系统应用程序获取abilityInfo。

ExtensionAbilityFlag

扩展组件信息标志,指示需要获取的扩展组件信息的内容。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

系统接口: 此接口为系统接口。

名称说明
GET_EXTENSION_ABILITY_INFO_DEFAULT0x00000000用于获取默认extensionAbilityInfo。获取的extensionAbilityInfo不包含permission、metadata 和禁用的abilityInfo。
GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION0x00000001用于获取包含permission的extensionAbilityInfo。
GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION0x00000002用于获取包含applicationInfo的extensionAbilityInfo。
GET_EXTENSION_ABILITY_INFO_WITH_METADATA0x00000004用于获取包含metadata的extensionAbilityInfo。

ExtensionAbilityType

指示扩展组件的类型。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
FORM0FormExtensionAbility:卡片扩展能力,提供卡片开发能力。
WORK_SCHEDULER1WorkSchedulerExtensionAbility:延时任务扩展能力,允许应用在系统闲时执行实时性不高的任务。
INPUT_METHOD2InputMethodExtensionAbility:输入法扩展能力,用于开发输入法应用。
SERVICE3ServiceExtensionAbility:后台服务扩展能力,提供后台运行并对外提供相应能力。
ACCESSIBILITY4AccessibilityExtensionAbility:无障碍服务扩展能力,支持访问与操作前台界面。
DATA_SHARE5DataShareExtensionAbility:数据共享扩展能力,用于对外提供数据读写服务。
FILE_SHARE6FileShareExtensionAbility:文件共享扩展能力,用于应用间的文件分享。预留能力,当前暂未支持。
STATIC_SUBSCRIBER7StaticSubscriberExtensionAbility:静态广播扩展能力,用于处理静态事件,比如开机事件。
WALLPAPER8WallpaperExtensionAbility:壁纸扩展能力,用于实现桌面壁纸。预留能力,当前暂未支持。
BACKUP9BackupExtensionAbility:数据备份扩展能力,提供应用数据和公共数据备份回复能力。预留能力,当前暂未支持。
WINDOW10WindowExtensionAbility:界面组合扩展能力,允许系统应用进行跨应用的界面拉起和嵌入。
ENTERPRISE_ADMIN11EnterpriseAdminExtensionAbility:企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。
THUMBNAIL13ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,当前暂未支持。
PREVIEW14PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,当前暂未支持。
PRINT10+15PrintExtensionAbility:文件打印扩展能力,提供应用打印照片、文档等办公场景。当前支持图片打印,文档类型暂未支持。
SHARE10+16ShareExtensionAbility:提供分享业务能力,为开发者提供基于UIExtension的分享业务模板。
PUSH10+17PushExtensionAbility:推送扩展能力,提供推送场景化消息能力。预留能力,当前暂未支持。
DRIVER10+18DriverExtensionAbility:驱动扩展能力,提供外设驱动扩展能力,当前暂未支持。
ACTION10+19ActionExtensionAbility:自定义服务扩展能力,为开发者提供基于UIExtension的自定义操作业务模板。
UNSPECIFIED255不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。

PermissionGrantState

指示权限授予状态。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
PERMISSION_DENIED-1拒绝授予权限。
PERMISSION_GRANTED0授予权限。

SupportWindowMode

标识该组件所支持的窗口模式。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
FULL_SCREEN0窗口支持全屏显示。
SPLIT1窗口支持分屏显示。
FLOATING2支持窗口化显示。

LaunchType

指示组件的启动方式。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
SINGLETON0ability的启动模式,表示单实例。
MULTITON1ability的启动模式,表示普通多实例。
SPECIFIED2ability的启动模式,表示该ability内部根据业务自己置顶多实例。

AbilityType

指示Ability组件的类型。

模型约束: 仅可在FA模型下使用

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
PAGE1表示基于Page模板开发的FA,用于提供与用户交互的能力。
SERVICE2表示基于Service模板开发的PA,用于提供后台运行任务的能力。
DATA3表示基于Data模板开发的PA,用于对外部提供统一的数据访问对象。

DisplayOrientation

标识该Ability的显示模式。该标签仅适用于page类型的Ability。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。

名称说明
UNSPECIFIED0表示未定义方向模式,由系统判定。
LANDSCAPE1表示横屏显示模式。
PORTRAIT2表示竖屏显示模式。
FOLLOW_RECENT3表示跟随上一个显示模式。
LANDSCAPE_INVERTED4表示反向横屏显示模式。
PORTRAIT_INVERTED5表示反向竖屏显示模式。
AUTO_ROTATION6表示传感器自动旋转模式。
AUTO_ROTATION_LANDSCAPE7表示传感器自动横向旋转模式。
AUTO_ROTATION_PORTRAIT8表示传感器自动竖向旋转模式。
AUTO_ROTATION_RESTRICTED9表示受开关控制的自动旋转模式。
AUTO_ROTATION_LANDSCAPE_RESTRICTED10表述受开关控制的自动横向旋转模式。
AUTO_ROTATION_PORTRAIT_RESTRICTED11表示受开关控制的自动竖向旋转模式。
LOCKED12表示锁定模式。

CompatiblePolicy10+

标识共享库的版本兼容类型。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

名称说明
BACKWARD_COMPATIBILITY1该字段表明共享库是向后兼容类型。

ModuleType

标识模块类型。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

名称说明
ENTRY1应用的主模块。
FEATURE2应用的动态特性模块。
SHARED3应用的动态共享库模块。

BundleType

标识应用的类型。

系统能力: 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

名称说明
APP0该Bundle是普通应用程序。
ATOMIC_SERVICE1该Bundle是原子化服务。

接口

bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: number): Promise<BundleInfo>

以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用Promise形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。

返回值:

类型说明
Promise<BundleInfo>Promise对象,返回当前应用的BundleInfo。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
    bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
}

bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: number, callback: AsyncCallback<BundleInfo>): void

以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用callback形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
callbackAsyncCallback<BundleInfo>回调函数,当获取成功时,err为null,data为获取到的当前应用的BundleInfo;否则为错误对象。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
}

bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback<BundleInfo>): void

以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用callback形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
userIdnumber表示用户ID。
callbackAsyncCallback<BundleInfo>回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

// 额外获取AbilityInfo
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY;
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
}
// 额外获取ApplicationInfo中的metadata
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
}

bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>): void

以异步方法根据给定的bundleName和bundleFlags获取BundleInfo,使用callback形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
callbackAsyncCallback<BundleInfo>回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

示例:

// 额外获取extensionAbility
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
}

bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: number, userId?: number): Promise<BundleInfo>

以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用Promise形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<BundleInfo>Promise对象,返回BundleInfo。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

// 额外获取ApplicationInfo和SignatureInfo
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message);
}

bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: number, userId: number, callback: AsyncCallback<ApplicationInfo>): void

以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用callback形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
userIdnumber表示用户ID。
callbackAsyncCallback<ApplicationInfo>回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message);
}

bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: number, callback: AsyncCallback<ApplicationInfo>): void

以异步方法根据给定的bundleName和appFlags获取ApplicationInfo,使用callback形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
callbackAsyncCallback<ApplicationInfo>回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message);
}

bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: number, userId?: number): Promise<ApplicationInfo>

以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用Promise形式返回结果。

获取调用方自己的信息时不需要权限。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要查询的应用Bundle名称。
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<ApplicationInfo>Promise对象,返回ApplicationInfo。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
let userId = 100;

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', message);
}

bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array<BundleInfo>>): void

以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
userIdnumber表示用户ID。
callbackAsyncCallback<Array<BundleInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<BundleInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message);
}

bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: number, callback: AsyncCallback<Array<BundleInfo>>): void

以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
callbackAsyncCallback<Array<BundleInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<BundleInfo>;否则为错误对象。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message);
}

bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: number, userId?: number): Promise<Array<BundleInfo>>

以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<Array<BundleInfo>>Promise对象,返回Array<BundleInfo>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', message);
}

bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: number, userId: number, callback: AsyncCallback<Array<ApplicationInfo>>): void

以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
userIdnumber表示用户ID。
callbackAsyncCallback<Array<ApplicationInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<ApplicationInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message);
}

bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: number, callback: AsyncCallback<Array<ApplicationInfo>>): void

以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
callbackAsyncCallback<Array<ApplicationInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<ApplicationInfo>;否则为错误对象。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message);
}

bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: number, userId?: number): Promise<Array<ApplicationInfo>>

以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_INSTALLED_BUNDLE_LIST

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
appFlagsnumber指定返回的ApplicationInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<Array<ApplicationInfo>>Promise对象,返回Array<ApplicationInfo>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', message);
}

bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: number, userId: number, callback: AsyncCallback<Array<AbilityInfo>>): void

以异步方法根据给定的want、abilityFlags和userId获取多个AbilityInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
abilityFlagsnumber指定返回的AbilityInfo所包含的信息。
userIdnumber表示用户ID。
callbackAsyncCallback<Array<AbilityInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<AbilityInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified ability is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message);
}

bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: number, callback: AsyncCallback<Array<AbilityInfo>>): void

以异步方法根据给定的want和abilityFlags获取一个或多个AbilityInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
abilityFlagsnumber指定返回的AbilityInfo所包含的信息。
callbackAsyncCallback<Array<AbilityInfo>>回调函数,当获取成功时,err为null,data为获取到的Array<AbilityInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified ability is not found.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message);
}

bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: number, userId?: number): Promise<Array<AbilityInfo>>

以异步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
abilityFlagsnumber表示指定返回的AbilityInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<Array<AbilityInfo>>Promise对象,返回Array<AbilityInfo>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified ability is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    })
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.queryAbilityInfoSync10+

queryAbilityInfoSync(want: Want, abilityFlags: number, userId?: number): Array<AbilityInfo>

以同步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
abilityFlagsnumber表示指定返回的AbilityInfo所包含的信息。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Array<AbilityInfo>Array<AbilityInfo>信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified ability is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    
    let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags, userId);
    hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags);
    hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message);
}

bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId: number, callback: AsyncCallback<Array<ExtensionAbilityInfo>>): void

以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
extensionAbilityTypeExtensionAbilityType标识extensionAbility的类型。
extensionAbilityFlagsnumber表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。
userIdnumber表示用户ID。
callbackAsyncCallback<Array<ExtensionAbilityInfo>>回调函数,当获取成功时,err为null,data为获取到Array<ExtensionAbilityInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified extensionAbility is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message);
}

bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, callback: AsyncCallback<Array<ExtensionAbilityInfo>>): void

以异步方法根据给定的want、extensionAbilityType和extensionAbilityFlags获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
extensionAbilityTypeExtensionAbilityType标识extensionAbility的类型。
extensionAbilityFlagsnumber表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。
callbackAsyncCallback<Array<ExtensionAbilityInfo>>回调函数,当获取成功时,err为null,data为获取到Array<ExtensionAbilityInfo>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified extensionAbility is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message);
}

bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId?: number): Promise<Array<ExtensionAbilityInfo>>

以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
extensionAbilityTypeExtensionAbilityType标识extensionAbility的类型。
extensionAbilityFlagsnumber表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<Array<ExtensionAbilityInfo>>Promise对象,返回Array<ExtensionAbilityInfo>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified extensionAbility is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';

let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
    })
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.queryExtensionAbilityInfoSync10+

queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId?: number): Array<ExtensionAbilityInfo>

以同步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
wantWant表示包含要查询的应用Bundle名称的Want。
extensionAbilityTypeExtensionAbilityType标识extensionAbility的类型。
extensionAbilityFlagsnumber表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Array<ExtensionAbilityInfo>Array<ExtensionAbilityInfo>信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified extensionAbility is not found.
17700004The specified userId is invalid.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';

let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId);
    hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags);
    hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message);
}

bundleManager.getBundleNameByUid

getBundleNameByUid(uid: number, callback: AsyncCallback<string>): void

以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
uidnumber表示应用程序的UID。
callbackAsyncCallback<string>回调函数,当获取成功时,err为null,data为获取到的BundleName;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700021The uid is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', message);
}

bundleManager.getBundleNameByUid

getBundleNameByUid(uid: number): Promise<string>

以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
uidnumber表示应用程序的UID。

返回值:

类型说明
Promise<string>Promise对象,返回bundleName。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700021The uid is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid).then((data) => {
        hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', message);
}

bundleManager.getBundleNameByUidSync10+

getBundleNameByUidSync(uid: number): string

以同步方法根据给定的uid获取对应的bundleName。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
uidnumber表示应用程序的UID。

返回值:

类型说明
string返回获取到的bundleName。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700021The uid is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let uid = 20010005;
try {
    let data = bundleManager.getBundleNameByUidSync(uid);
    hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', message);
}

bundleManager.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>): void

以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
hapFilePathstring表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。
bundleFlagsnumber表示用于指定要返回的BundleInfo对象中包含的信息的标志。
callbackAsyncCallback<BundleInfo>回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700022The hapFilePath is invalid.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message);
}

bundleManager.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string, bundleFlags: number): Promise<BundleInfo>

以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
hapFilePathstring表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。
bundleFlagsnumber表示用于指定要返回的BundleInfo对象中包含的信息的标志。

返回值:

类型说明
Promise<BundleInfo>Promise对象,返回BundleInfo。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700022The hapFilePath is invalid.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => {
        hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message);
}

bundleManager.getBundleArchiveInfoSync10+

getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: number): BundleInfo

以同步方法根据给定的hapFilePath和bundleFlags获取BundleInfo对象。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
hapFilePathstring表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。
bundleFlagsnumber表示用于指定要返回的BundleInfo对象中包含的信息的标志。

返回值:

类型说明
BundleInfo返回BundleInfo对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700022The hapFilePath is invalid.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    let data = bundleManager.getBundleArchiveInfoSync(hapFilePath, bundleFlags)
    hilog.info(0x0000, 'testTag', 'getBundleArchiveInfoSync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfoSync failed. Cause: %{public}s', message);
}

bundleManager.cleanBundleCacheFiles

cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback<void>): void

以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.REMOVE_CACHE_FILES

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要清理其缓存数据的应用程序的bundleName。
callbackAsyncCallback<void>回调函数,当清理应用缓存目录数据成功,err为null,否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700030The specified bundle does not support clearing of cache files.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.cleanBundleCacheFiles(bundleName, err => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message);
}

bundleManager.cleanBundleCacheFiles

cleanBundleCacheFiles(bundleName: string): Promise<void>

以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.REMOVE_CACHE_FILES

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示要清理其缓存数据的应用程序的bundleName。

返回值:

类型说明
Promise<void>无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700030The specified bundle does not support clearing of cache files.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.cleanBundleCacheFiles(bundleName).then(() => {
        hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message);
}

bundleManager.setApplicationEnabled

setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback<void>): void

设置指定应用的禁用或使能状态,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定应用的bundleName。
isEnabledboolean值为true表示使能,值为false表示禁用。
callbackAsyncCallback<void>回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.setApplicationEnabled(bundleName, false, err => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.');
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message);
}

bundleManager.setApplicationEnabled

setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise<void>

设置指定应用的禁用或使能状态,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
isEnabledboolean值为true表示使能,值为false表示禁用。

返回值:

类型说明
Promise<void>Promise对象。无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.setApplicationEnabled(bundleName, false).then(() => {
        hilog.info(0x0000, "testTag", "setApplicationEnabled successfully.");
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message);
}

bundleManager.setApplicationEnabledSync10+

setApplicationEnabledSync(bundleName: string, isEnabled: boolean): void

以同步方法设置指定应用的禁用或使能状态。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定应用的bundleName。
isEnabledboolean值为true表示使能,值为false表示禁用。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.setApplicationEnabledSync(bundleName, false);
    hilog.info(0x0000, 'testTag', 'setApplicationEnabledSync successfully.');
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'setApplicationEnabledSync failed: %{public}s', message);
}

bundleManager.setAbilityEnabled

setAbilityEnabled(info: AbilityInfo, isEnabled: boolean, callback: AsyncCallback<void>): void

设置指定组件的禁用或使能状态,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo需要被设置的组件。
isEnabledboolean值为true表示使能,值为false表示禁用。
callbackAsyncCallback<void>回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityInfo is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        bundleManager.setAbilityEnabled(info, false, err => {
            if (err) {
                hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
            } else {
                hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
            }
        });
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.setAbilityEnabled

setAbilityEnabled(info: AbilityInfo, isEnabled: boolean): Promise<void>

设置指定组件的禁用或使能状态,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo需要被设置的组件。
isEnabledboolean值为true表示使能,值为false表示禁用。

返回值:

类型说明
Promise<void>Promise对象。无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityInfo is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        bundleManager.setAbilityEnabled(info, false).then(() => {
            hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
        }).catch((err: BusinessError) => {
            hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
        });
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.setAbilityEnabledSync10+

setAbilityEnabledSync(info: AbilityInfo, isEnabled: boolean): void

以同步方法设置指定组件的禁用或使能状态。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo需要被设置的组件。
isEnabledboolean值为true表示使能,值为false表示禁用。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityInfo is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        try {
            bundleManager.setAbilityEnabledSync(info, false);
            hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully.");
        } catch (err) {
            let message = (err as BusinessError).message;
            hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message);
        }
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.isApplicationEnabled

isApplicationEnabled(bundleName: string, callback: AsyncCallback<boolean>): void

以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
callbackAsyncCallback<boolean>回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', message);
}

bundleManager.isApplicationEnabled

isApplicationEnabled(bundleName: string): Promise<boolean>

以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。

返回值:

类型说明
Promise<boolean>Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName).then((data) => {
        hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', message);
}

bundleManager.isApplicationEnabledSync10+

isApplicationEnabledSync(bundleName: string): boolean

以同步方法获取指定应用的禁用或使能状态。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。

返回值:

类型说明
boolean返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';

try {
    let data = bundleManager.isApplicationEnabledSync(bundleName);
    hilog.info(0x0000, 'testTag', 'isApplicationEnabledSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'isApplicationEnabledSync failed: %{public}s', message);
}

bundleManager.isAbilityEnabled

isAbilityEnabled(info: AbilityInfo, callback: AsyncCallback<boolean>): void

以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo表示关于检查ability的信息。
callbackAsyncCallback<boolean>回调函数,返回true表示当前应用组件为使能状态,返回false表示应用组件为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info, (err, data) => {
            if (err) {
                hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message);
            } else {
                hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data));
            }
        });
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.isAbilityEnabled

isAbilityEnabled(info: AbilityInfo): Promise<boolean>

以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo表示关于检查ability的信息。

返回值:

类型说明
Promise<boolean>Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info).then((data) => {
            hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data));
        }).catch((err: BusinessError) => {
            hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message);
        });
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.isAbilityEnabledSync10+

isAbilityEnabledSync(info: AbilityInfo): boolean

以同步方法获取指定组件的禁用或使能状态。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
infoAbilityInfo表示关于检查ability的信息。

返回值:

类型说明
boolean返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700003The specified abilityName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want: Want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
        let info = abilitiesInfo[0];

        try {
            let data = bundleManager.isAbilityEnabledSync(info);
            hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data));
        } catch (err) {
            let message = (err as BusinessError).message;
            hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message);
        }
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message);
}

bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback<Want>): void

以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
userIdnumber表示用户ID。
callbackAsyncCallback<Want>回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message);
}

bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, callback: AsyncCallback<Want>): void

以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
callbackAsyncCallback<Want>回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';

try {
    bundleManager.getLaunchWantForBundle(bundleName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message);
}

bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, userId?: number): Promise<Want>

以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
Promise<Want>Promise对象,返回Want对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', message);
}

bundleManager.getLaunchWantForBundleSync10+

getLaunchWantForBundleSync(bundleName: string, userId?: number): Want

以同步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。

返回值:

类型说明
WantWant对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId);
    hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName);
    hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message);
}

bundleManager.getProfileByAbility

getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback<Array<string>>): void

以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。
metadataNamestring表示应用程序的metadataName。
callbackAsyncCallback<Array<string>>回调函数,当获取成功时,err为null,data为获取到的Array<string>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let abilityName = 'EntryAbility';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
}

bundleManager.getProfileByAbility

getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise<Array<string>>

以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。
metadataNamestring表示应用程序的metadataName,默认值为空。

返回值:

类型说明
Promise<Array<string>>Promise对象,返回Array<string>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let abilityName = 'EntryAbility';
let metadataName = 'com.example.myapplication.metadata';
try {
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
}

bundleManager.getProfileByAbilitySync10+

getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array<string>

以同步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。
metadataNamestring表示应用程序的metadataName,默认值为空。

返回值:

类型说明
Array<string>数组对象,返回Array<string>。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
    let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName);
    hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
}
import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName: string = 'entry';
let abilityName: string = 'EntryAbility';
let metadataName: string = 'com.example.myapplication.metadata';
try {
    let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName);
    hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
}

bundleManager.getProfileByExtensionAbility

getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback<Array<string>>): void

以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
extensionAbilityNamestring表示应用程序的extensionAbilityName。
metadataNamestring表示应用程序的metadataName。
callbackAsyncCallback<Array<string>>回调函数,当获取成功时,err为null,data为获取到的Array<string>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', message);
}

bundleManager.getProfileByExtensionAbility

getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise<Array<string>>

以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
extensionAbilityNamestring表示应用程序的extensionAbilityName。
metadataNamestring表示应用程序的metadataName,默认值为空。

返回值:

类型说明
Promise<Array<string>>Promise对象,返回Array<string>对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message);
}

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message);
}

bundleManager.getProfileByExtensionAbilitySync10+

getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array<string>

以同步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
moduleNamestring表示应用程序的moduleName。
extensionAbilityNamestring表示应用程序的extensionAbilityName。
metadataNamestring表示应用程序的metadataName,默认值为空。

返回值:

类型说明
Array<string>返回Array<string>对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName);
    hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
}

try {
    let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName);
    hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
}

bundleManager.getPermissionDef

getPermissionDef(permissionName: string, callback: AsyncCallback<PermissionDef>): void

以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
permissionNamestring表示权限名称。
callbackAsyncCallback<PermissionDef>回调函数,当获取成功时,err为null,data为获取到的Array<PermissionDef>;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700006The specified permission is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let permission = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permission, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', message);
}

bundleManager.getPermissionDef

getPermissionDef(permissionName: string): Promise<PermissionDef>

以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
permissionNamestring表示权限参数名。

返回值:

类型说明
Promise<PermissionDef>Promise对象,返回Array<PermissionDef>对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700006The specified permission is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permissionName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', message);
}

bundleManager.getPermissionDefSync10+

getPermissionDefSync(permissionName: string): PermissionDef;

以同步方法根据给定的permissionName获取权限定义结构体PermissionDef信息。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
permissionNamestring表示权限参数名。

返回值:

类型说明
PermissionDefPermissionDef对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700006The specified permission is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
    let PermissionDef = bundleManager.getPermissionDefSync(permissionName);
    hilog.info(0x0000, 'testTag', 'getPermissionDefSync successfully. Data: %{public}s', JSON.stringify(PermissionDef));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getPermissionDefSync failed. Cause: %{public}s', message);
}

bundleManager.getAbilityLabel

getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback<string>): void

以异步的方法获取指定bundleName、moduleName和abilityName的label,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Resource

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。
callbackAsyncCallback<string>回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700002The specified moduleName is not found.
17700003The specified abilityName is not found.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', message);
}

bundleManager.getAbilityLabel

getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise<string>

以异步的方法获取指定bundleName、moduleName和abilityName的label,使用Promise形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Resource

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。

返回值:

类型说明
Promise<string>Promise对象,返回指定组件的Lablel值。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700002The specified moduleName is not found.
17700003The specified abilityName is not found.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', message);
}

bundleManager.getAbilityLabelSync10+

getAbilityLabelSync(bundleName: string, moduleName: string, abilityName: string): string

以同步的方法获取指定bundleName、moduleName和abilityName的label。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Resource

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
moduleNamestring表示应用程序的moduleName。
abilityNamestring表示应用程序的abilityName。

返回值:

类型说明
string指定组件的Lablel值。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700002The specified moduleName is not found.
17700003The specified abilityName is not found.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
    let abilityLabel = bundleManager.getAbilityLabelSync(bundleName, moduleName, abilityName);
    hilog.info(0x0000, 'testTag', 'getAbilityLabelSync successfully. Data: %{public}s', abilityLabel);
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAbilityLabelSync failed. Cause: %{public}s', message);
}

bundleManager.getApplicationInfoSync

getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : ApplicationInfo

以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core。

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
applicationFlagsnumber表示用于指定将返回的ApplicationInfo对象中包含的信息。
userIdnumber表示用户ID。

返回值:

类型说明
ApplicationInfo返回ApplicationInfo对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId);
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message);
}

bundleManager.getApplicationInfoSync

getApplicationInfoSync(bundleName: string, applicationFlags: number) : ApplicationInfo

以同步方法根据给定的bundleName、applicationFlags获取ApplicationInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
applicationFlagsnumber表示用于指定将返回的ApplicationInfo对象中包含的信息。

返回值:

类型说明
ApplicationInfo返回ApplicationInfo对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags);
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message);
}

bundleManager.getBundleInfoSync

getBundleInfoSync(bundleName: string, bundleFlags: number, userId: number): BundleInfo

以同步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
bundleFlagsnumber表示用于指定将返回的BundleInfo对象中包含的信息的标志。
userIdnumber表示用户ID。

返回值:

类型说明
BundleInfo返回BundleInfo对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message);
}

bundleManager.getBundleInfoSync

getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo

以同步方法根据给定的bundleName、bundleFlags获取BundleInfo。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
bundleFlagsnumber表示用于指定将返回的BundleInfo对象中包含的信息的标志。

返回值:

类型说明
BundleInfo返回BundleInfo对象。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
try {
    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags);
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message);
}

bundleManager.getSharedBundleInfo10+

getSharedBundleInfo(bundleName: string, moduleName: string, callback: AsyncCallback<Array<SharedBundleInfo>>): void

以异步的方法获取指定的共享包信息,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
moduleNamestring表示被查询的module的name。
callbackAsyncCallback<Array<SharedBundleInfo>>回调函数,当获取成功时,err为null,data为获取的指定共享包信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700002The specified moduleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'library';

try {
    bundleManager.getSharedBundleInfo(bundleName, moduleName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', message);
}

bundleManager.getSharedBundleInfo10+

getSharedBundleInfo(bundleName: string, moduleName: string): Promise<Array<SharedBundleInfo>>

以异步的方法获取指定的共享包信息,使用Promise形式返回结果。

系统接口: 此接口为系统接口

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring表示应用程序的bundleName。
moduleNamestring表示被查询的module的name。

返回值:

类型说明
Promise<Array<SharedBundleInfo>>Promise对象,返回指定的共享包信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700002The specified moduleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'library';

try {
    bundleManager.getSharedBundleInfo(bundleName, moduleName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', message);
}

bundleManager.getAllSharedBundleInfo10+

getAllSharedBundleInfo(callback: AsyncCallback<Array<SharedBundleInfo>>): void

以异步的方法获取所有的共享包信息,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
callbackAsyncCallback<Array<SharedBundleInfo>>回调函数,当获取成功时,err为null,data为获所有的共享包信息。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';

try {
    bundleManager.getAllSharedBundleInfo((err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', message);
}

bundleManager.getAllSharedBundleInfo10+

getAllSharedBundleInfo(): Promise<Array<SharedBundleInfo>>

以异步的方法获取所有的共享包信息,使用Promise形式返回结果。

系统接口: 此接口为系统接口

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

返回值:

类型说明
Promise<Array<SharedBundleInfo>>Promise对象,返回所有的共享包信息。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';

try {
    bundleManager.getAllSharedBundleInfo().then((data) => {
        hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', message);
}

bundleManager.getAppProvisionInfo10+

getAppProvisionInfo(bundleName: string, callback: AsyncCallback<AppProvisionInfo>): void

以异步的方法获取指定bundleName的provision配置文件信息,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定应用的bundleName。
callbackAsyncCallback<AppProvisionInfo>回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.getAppProvisionInfo(bundleName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message);
}

bundleManager.getAppProvisionInfo10+

getAppProvisionInfo(bundleName: string, userId: number, callback: AsyncCallback<AppProvisionInfo>): void

以异步的方法获取指定bundleName和userId的provision配置文件信息,使用callback形式返回结果。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定应用的bundleName。
userIdnumber指定用户ID, 可以通过接口getOsAccountLocalId获取当前设备上的用户ID。
callbackAsyncCallback<AppProvisionInfo>回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";
let userId = 100;

try {
    bundleManager.getAppProvisionInfo(bundleName, userId, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message);
}

bundleManager.getAppProvisionInfo10+

getAppProvisionInfo(bundleName: string, userId?: number): Promise<AppProvisionInfo>

以异步的方法根据bundleName和userId获取应用的provision配置文件信息,使用Promise形式返回结果。

系统接口: 此接口为系统接口

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定的bundleName。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口getOsAccountLocalId获取当前设备上的用户ID。

返回值:

类型说明
Promise<AppProvisionInfo>Promise对象,返回应用的provision配置文件信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";
let userId = 100;

try {
    bundleManager.getAppProvisionInfo(bundleName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message);
}

try {
    bundleManager.getAppProvisionInfo(bundleName, userId).then((data) => {
        hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch((err: BusinessError) => {
        hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message);
}

bundleManager.getAppProvisionInfoSync10+

getAppProvisionInfoSync(bundleName: string, userId?: number): AppProvisionInfo

以同步方法根据bundleName和userId获取应用的provision配置文件信息并返回结果。

系统接口: 此接口为系统接口

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定的bundleName。
userIdnumber表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口getOsAccountLocalId获取当前设备上的用户ID。

返回值:

类型说明
AppProvisionInfoAppProvisionInfo对象,返回应用的provision配置文件信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.
17700004The specified user ID is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleName = "com.ohos.myapplication";
let userId = 100;

try {
    let data = bundleManager.getAppProvisionInfoSync(bundleName);
    hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message);
}

try {
    let data = bundleManager.getAppProvisionInfoSync(bundleName, userId);
    hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message);
}

bundleManager.getSpecifiedDistributionType10+

getSpecifiedDistributionType(bundleName: string): string

以同步的方法查询指定bundleName的分发类型,该返回值是在调用install接口时传入的InstallParam中的specifiedDistributionType字段。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定的bundleName。

返回值:

类型说明
string返回指定bundleName的分发类型。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
let bundleName = "com.example.myapplication";

try {
    let type = bundleManager.getSpecifiedDistributionType(bundleName);
    console.info('getSpecifiedDistributionType successfully, type:' + type);
} catch (error) {
    let message = (error as BusinessError).message;
    console.error('getSpecifiedDistributionType failed. Cause: ' + message);
}

bundleManager.getAdditionalInfo10+

getAdditionalInfo(bundleName: string): string

以同步接口查询指定bundleName的额外信息。该返回值是在调用install接口时传入的InstallParam中的additionalInfo字段。

系统接口: 此接口为系统接口。

需要权限: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleNamestring指定的bundleName。

返回值:

类型说明
string返回指定bundleName的额外信息。

错误码:

以下错误码的详细介绍请参见ohos.bundle错误码

错误码ID错误信息
17700001The specified bundleName is not found.

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
let bundleName = "com.example.myapplication";

try {
    let info = bundleManager.getAdditionalInfo(bundleName);
    console.info('getAdditionalInfo successfully, additionInfo:' + info);
} catch (error) {
    let message = (error as BusinessError).message;
    console.error('getAdditionalInfo failed. Cause: ' + message);
}

bundleManager.getBundleInfoForSelfSync10+

getBundleInfoForSelfSync(bundleFlags: number): BundleInfo

以同步方法根据给定的bundleFlags获取当前应用的BundleInfo。

系统能力: SystemCapability.BundleManager.BundleFramework.Core

参数:

参数名类型必填说明
bundleFlagsnumber指定返回的BundleInfo所包含的信息。

返回值:

类型说明
BundleInfo返回BundleInfo对象。

示例:

import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
try {
    let data = bundleManager.getBundleInfoForSelfSync(bundleFlags);
    hilog.info(0x0000, 'testTag', 'getBundleInfoForSelfSync successfully: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelfSync failed: %{public}s', message);
}

最后

有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。 

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。

希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!

获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料

鸿蒙(HarmonyOS NEXT)最新学习路线

  •  HarmonOS基础技能

  • HarmonOS就业必备技能 
  •  HarmonOS多媒体技术

  • 鸿蒙NaPi组件进阶

  • HarmonOS高级技能

  • 初识HarmonOS内核 
  • 实战就业级设备开发

有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。

获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料

《鸿蒙 (OpenHarmony)开发入门教学视频》

《鸿蒙生态应用开发V2.0白皮书》

图片

《鸿蒙 (OpenHarmony)开发基础到实战手册》

OpenHarmony北向、南向开发环境搭建

图片

 《鸿蒙开发基础》

  • ArkTS语言
  • 安装DevEco Studio
  • 运用你的第一个ArkTS应用
  • ArkUI声明式UI开发
  • .……

图片

 《鸿蒙开发进阶》

  • Stage模型入门
  • 网络管理
  • 数据管理
  • 电话服务
  • 分布式应用开发
  • 通知与窗口管理
  • 多媒体技术
  • 安全技能
  • 任务管理
  • WebGL
  • 国际化开发
  • 应用测试
  • DFX面向未来设计
  • 鸿蒙系统移植和裁剪定制
  • ……

图片

《鸿蒙进阶实战》

  • ArkTS实践
  • UIAbility应用
  • 网络案例
  • ……

图片

 获取以上完整鸿蒙HarmonyOS学习资料,请点击→纯血版全套鸿蒙HarmonyOS学习资料

总结

总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑战,也是一个机会。只有积极应对变化,不断学习和提升自己,他们才能在这个变革的时代中立于不败之地。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值