harmony 鸿蒙@ohos.bundle.bundleManager (bundleManager)

  • 2022-12-05
  • 浏览 (852)

@ohos.bundle.bundleManager (bundleManager)

The bundleManager module provides APIs for querying information about bundles, applications, abilities, ExtensionAbilities, and more.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

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

Required Permissions

Permission Permission Level Description
ohos.permission.GET_BUNDLE_INFO normal Permission to obtain basic information about a bundle.
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED system_basic Permission to obtain basic information and other sensitive information about a bundle.
ohos.permission.REMOVE_CACHE_FILES system_basic Permission to clear cache files of a bundle.
ohos.permission.CHANGE_ABILITY_ENABLED_STATE system_basic Permission to enable or disable an application or ability.
ohos.permission.GET_INSTALLED_BUNDLE_LIST system_basic Permission to read installed application list.

For details, see Permission Levels.

Enums

BundleFlag

Enumerates the bundle flags, which indicate the type of bundle information to obtain.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
GET_BUNDLE_INFO_DEFAULT 0x00000000 Used to obtain the default bundle information. The obtained information does not contain information about the signature, application, HAP module, ability, ExtensionAbility, or permission.
GET_BUNDLE_INFO_WITH_APPLICATION 0x00000001 Used to obtain the bundle information with application information. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.
GET_BUNDLE_INFO_WITH_HAP_MODULE 0x00000002 Used to obtain the bundle information with HAP module information. The obtained information does not contain information about the signature, application, ability, ExtensionAbility, or permission.
GET_BUNDLE_INFO_WITH_ABILITY 0x00000004 Used to obtain the bundle information with ability information. The obtained information does not contain information about the signature, application, ExtensionAbility, or permission. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE.
GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY 0x00000008 Used to obtain the bundle information with ExtensionAbility information. The obtained information does not contain information about the signature, application, ability, or permission. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE.
GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION 0x00000010 Used to obtain the bundle information with permission information. The obtained information does not contain information about the signature, application, HAP module, ability, or ExtensionAbility.
GET_BUNDLE_INFO_WITH_METADATA 0x00000020 Used to obtain the metadata contained in the application, HAP module, ability, or ExtensionAbility information. It must be used together with GET_BUNDLE_INFO_WITH_APPLICATION, GET_BUNDLE_INFO_WITH_HAP_MODULE, GET_BUNDLE_INFO_WITH_ABILITY, and GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY.
GET_BUNDLE_INFO_WITH_DISABLE 0x00000040 Used to obtain the information about disabled bundles and abilities of a bundle. The obtained information does not contain information about the signature, application, HAP module, ability, ExtensionAbility, or permission.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO 0x00000080 Used to obtain the bundle information with signature information. The obtained information does not contain information about the application, HAP module, ability, ExtensionAbility, or permission.
GET_BUNDLE_INFO_WITH_MENU 0x00000100 Used to obtain the bundle information with the file context menu. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE. If this flag is passed in to GetBundleInfo or GetBundleInfoForSelf, the HAP module information returned contains only the module information for which the file context menu is configured. If this flag is passed in to GetAllBundleInfo, the bundle information returned contains only the bundle information of applications for which the file context menu is configured.

ApplicationFlag

Enumerates the application flags, which indicate the type of application information to obtain.

System capability: SystemCapability.BundleManager.BundleFramework.Core

System API: This is a system API.

Name Value Description
GET_APPLICATION_INFO_DEFAULT 0x00000000 Used to obtain the default application information. The obtained information does not contain the permission information or metadata.
GET_APPLICATION_INFO_WITH_PERMISSION 0x00000001 Used to obtain the application information with permission information.
GET_APPLICATION_INFO_WITH_METADATA 0x00000002 Used to obtain the application information with metadata.
GET_APPLICATION_INFO_WITH_DISABLE 0x00000004 Used to obtain the application information of disabled bundles.

AbilityFlag

Enumerates the ability flags, which indicate the type of ability information to obtain.

System capability: SystemCapability.BundleManager.BundleFramework.Core

System API: This is a system API.

Name Value Description
GET_ABILITY_INFO_DEFAULT 0x00000000 Used to obtain the default ability information. The obtained information does not contain the permission, metadata, or disabled ability information.
GET_ABILITY_INFO_WITH_PERMISSION 0x00000001 Used to obtain the ability information with permission information.
GET_ABILITY_INFO_WITH_APPLICATION 0x00000002 Used to obtain the ability information with application information.
GET_ABILITY_INFO_WITH_METADATA 0x00000004 Used to obtain the ability information with metadata.
GET_ABILITY_INFO_WITH_DISABLE 0x00000008 Used to obtain the ability information of disabled abilities.
GET_ABILITY_INFO_ONLY_SYSTEM_APP 0x00000010 Used to obtain the ability information of system applications.

ExtensionAbilityFlag

Enumerates the ExtensionAbility flags, which indicate the type of ExtensionAbility information to obtain.

System capability: SystemCapability.BundleManager.BundleFramework.Core

System API: This is a system API.

Name Value Description
GET_EXTENSION_ABILITY_INFO_DEFAULT 0x00000000 Used to obtain the default ExtensionAbility information. The obtained information does not contain the permission, metadata, or disabled ability information.
GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION 0x00000001 Used to obtain the ExtensionAbility information with permission information.
GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION 0x00000002 Used to obtain the ExtensionAbility information with application information.
GET_EXTENSION_ABILITY_INFO_WITH_METADATA 0x00000004 Used to obtain the ExtensionAbility information with metadata.

ExtensionAbilityType

Enumerates the types of ExtensionAbilities.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
FORM 0 FormExtensionAbility: provides APIs for widget development.
WORK_SCHEDULER 1 WorkSchedulerExtensionAbility: enables applications to execute non-real-time tasks when the system is idle.
INPUT_METHOD 2 InputMethodExtensionAbility: provides APIs for developing input method applications.
SERVICE 3 ServiceExtensionAbility: enables applications to run in the background and provide services.
ACCESSIBILITY 4 AccessibilityExtensionAbility: provides accessibility for access to and operations on the UI.
DATA_SHARE 5 DataShareExtensionAbility: enables applications to read and write data.
FILE_SHARE 6 FileShareExtensionAbility: enables file sharing between applications. This ability is reserved.
STATIC_SUBSCRIBER 7 StaticSubscriberExtensionAbility: provides APIs for processing static events, such as the startup event.
WALLPAPER 8 WallpaperExtensionAbility: provides APIs to implement the home screen wallpaper. This ability is reserved.
BACKUP 9 BackupExtensionAbility: provides APIs for backing up and restoring application data and public data. This ability is reserved.
WINDOW 10 WindowExtensionAbility: allows system applications to display UIs of other applications.
ENTERPRISE_ADMIN 11 EnterpriseAdminExtensionAbility: provides APIs for processing enterprise management events, such as application installation events on devices and events indicating too many incorrect screen-lock password attempts.
THUMBNAIL 13 ThumbnailExtensionAbility: provides thumbnails for files. This ability is reserved.
PREVIEW 14 PreviewExtensionAbility: provides APIs for file preview so that other applications can be embedded and displayed in the current application. This ability is reserved.
PRINT10+ 15 PrintExtensionAbility: provides APIs for printing images. Printing documents is not supported yet.
SHARE10+ 16 ShareExtensionAbility: provides sharing service templates based on UIExtensionAbilities.
PUSH10+ 17 PushExtensionAbility: provides APIs for pushing scenario-specific messages. This ability is reserved.
DRIVER10+ 18 DriverExtensionAbility: provides APIs for the peripheral driver. This type of ability is not supported yet.
ACTION10+ 19 ActionExtensionAbility: provides custom action service templates based on UIExtensionAbilities.
UNSPECIFIED 255 No type is specified. It is used together with queryExtensionAbilityInfo to query all types of ExtensionAbilities.

PermissionGrantState

Enumerates the permission grant states.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
PERMISSION_DENIED -1 Permission denied.
PERMISSION_GRANTED 0 Permission granted.

SupportWindowMode

Enumerates the window modes supported by the ability.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
FULL_SCREEN 0 A window in full-screen mode is supported.
SPLIT 1 A window in split-screen mode is supported.
FLOATING 2 A floating window is supported.

LaunchType

Enumerates the launch types of the ability.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
SINGLETON 0 The ability can have only one instance.
MULTITON 1 The ability can have multiple instances.
SPECIFIED 2 The ability can have one or multiple instances, depending on the internal service of the ability.

AbilityType

Enumerates the types of abilities.

Model restriction: This API can be used only in the FA model.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
PAGE 1 FA developed using the Page template to provide the capability of interacting with users.
SERVICE 2 PA developed using the Service template to provide the capability of running tasks in the background.
DATA 3 PA developed using the Data template to provide unified data access for external systems.

DisplayOrientation

Enumerates the display orientations of the ability. This attribute applies only to the ability using the Page template.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
UNSPECIFIED 0 Unspecified. The orientation is determined by the system.
LANDSCAPE 1 Landscape.
PORTRAIT 2 Portrait.
FOLLOW_RECENT 3 The last display orientation is used.
LANDSCAPE_INVERTED 4 Reverse landscape.
PORTRAIT_INVERTED 5 Reverse portrait.
AUTO_ROTATION 6 Auto rotation.
AUTO_ROTATION_LANDSCAPE 7 Auto rotation in the horizontal direction.
AUTO_ROTATION_PORTRAIT 8 Auto rotation in the vertical direction.
AUTO_ROTATION_RESTRICTED 9 Switched-determined auto rotation.
AUTO_ROTATION_LANDSCAPE_RESTRICTED 10 Switched-determined auto rotation in the horizontal direction.
AUTO_ROTATION_PORTRAIT_RESTRICTED 11 Switched-determined auto rotation in the vertical direction.
LOCKED 12 Locked.

CompatiblePolicy10+

Defines the version compatibility type of the shared library.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
BACKWARD_COMPATIBILITY 1 The shared library is backward compatible.

ModuleType

Enumerates the module types.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
ENTRY 1 Main module of the application.
FEATURE 2 Dynamic feature module of the application.
SHARED 3 Dynamic shared library module of the application.

BundleType

Enumerates the bundle types.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Name Value Description
APP 0 The bundle is a common application.
ATOMIC_SERVICE 1 The bundle is an atomic service.

ProfileType11+

Enumerates the types of profiles (also called application files).

System capability: SystemCapability.BundleManager.BundleFramework.Core

System API: This is a system API.

Name Value Description
INTENT_PROFILE 1 Profile of the intent framework.

APIs

bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: number): Promise<BundleInfo>;

Obtains the bundle information of this bundle based on the given bundle flags. This API uses a promise to return the result.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.

Return value

Type Description
Promise<BundleInfo> Promise used to return the bundle information.

Example

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;

Obtains the bundle information of this bundle based on the given bundle flags. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.
callback AsyncCallback<BundleInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the bundle information obtained. Otherwise, err is an error object.

Example

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;

Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses an asynchronous callback to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
bundleFlags number Yes Type of the bundle information to obtain.
userId number Yes User ID.
callback AsyncCallback<BundleInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the bundle information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

// Obtain the bundle information with the ability information.
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);
}
// Obtain the bundle information with the metadata in the application information.
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;

Obtains the bundle information based on the given bundle name and bundle flags. This API uses an asynchronous callback to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
bundleFlags number Yes Type of the bundle information to obtain.
callback AsyncCallback<BundleInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the bundle information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700026 The specified bundle is disabled.

Example

// Obtain the bundle information with the ExtensionAbility information.
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>;

Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses a promise to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
bundleFlags number Yes Type of the bundle information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise<BundleInfo> Promise used to return the bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

// Obtain the bundle information with the application and signature information.
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;

Obtains the application information based on the given bundle name, application flags, and user ID. This API uses an asynchronous callback to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
appFlags number Yes Type of the application information to obtain.
userId number Yes User ID.
callback AsyncCallback<ApplicationInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the application information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the application information based on the given bundle name and application flags. This API uses an asynchronous callback to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
appFlags number Yes Type of the application information to obtain.
callback AsyncCallback<ApplicationInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the application information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700026 The specified bundle is disabled.

Example

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>;

Obtains the application information based on the given bundle name, application flags, and user ID. This API uses a promise to return the result.

No permission is required for obtaining the caller’s own information.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
appFlags number Yes Type of the application information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise<ApplicationInfo> Promise used to return the application information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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>): void;

Obtains the information about all bundles based on the given bundle flags and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.
userId number Yes User ID.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of bundle information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>): void;

Obtains the information about all bundles based on the given bundle flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of bundle information obtained. Otherwise, err is an error object.

Example

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>;

Obtains the information about all bundles based on the given bundle flags and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise> Promise used to return the array of bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>): void;

Obtains the information about all applications based on the given application flags and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
appFlags number Yes Type of the application information to obtain.
userId number Yes User ID.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of application information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>): void;

Obtains the information about all applications based on the given application flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
appFlags number Yes Type of the application information to obtain.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of application information obtained. Otherwise, err is an error object.

Example

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>;

Obtains the information about all applications based on the given application flags and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
appFlags number Yes Type of the application information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise> Promise used to return the array of application information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700004 The specified user ID is not found.

Example

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>): void;

Obtains an array of ability information based on the given want, ability flags, and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
abilityFlags number Yes Type of the ability information to obtain.
userId number Yes User ID.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of ability information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified ability is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>): void;

Obtains an array of ability information based on the given want and ability flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
abilityFlags number Yes Type of the ability information to obtain.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of ability information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified ability is not found.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>;

Obtains the ability information based on the given want, ability flags, and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
abilityFlags number Yes Type of the ability information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise> Promise used to return the array of ability information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified ability is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>;

Obtains the ability information based on the given want, ability flags, and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
abilityFlags number Yes Type of the ability information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Array<AbilityInfo> An array of ability information.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified ability is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>): void;

Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
extensionAbilityType ExtensionAbilityType Yes Type of the ExtensionAbility.
extensionAbilityFlags number Yes Type of the ExtensionAbility information to obtain.
userId number Yes User ID.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of ExtensionAbility information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified extensionAbility is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.

Example

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>): void;

Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, and ExtensionAbility flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
extensionAbilityType ExtensionAbilityType Yes Type of the ExtensionAbility.
extensionAbilityFlags number Yes Type of the ExtensionAbility information to obtain.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of ExtensionAbility information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified extensionAbility is not found.
17700026 The specified bundle is disabled.

Example

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>;

Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
extensionAbilityType ExtensionAbilityType Yes Type of the ExtensionAbility.
extensionAbilityFlags number Yes Type of the ExtensionAbility information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise> Promise used to return the array of ExtensionAbility information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified extensionAbility is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.

Example

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>;

Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
extensionAbilityType ExtensionAbilityType Yes Type of the ExtensionAbility.
extensionAbilityFlags number Yes Type of the ExtensionAbility information to obtain.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Array<ExtensionAbilityInfo> An array of ExtensionAbility information.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified extensionAbility is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.

Example

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;

Obtains the bundle name based on the given UID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
uid number Yes UID of the application.
callback AsyncCallback<string> Yes Callback used to return the result. If the operation is successful, err is null and data is the bundle name obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700021 The uid is not found.

Example

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>;

Obtains the bundle name based on the given UID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
uid number Yes UID of the application.

Return value

Type Description
Promise<string> Promise used to return the bundle name obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700021 The uid is not found.

Example

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;

Obtains the bundle name based on the given UID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
uid number Yes UID of the application.

Return value

Type Description
string Bundle name obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700021 The uid is not found.

Example

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;

Obtains the bundle information based on the given HAP file path and bundle flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
hapFilePath string Yes Path where the HAP file is stored. The path must be the relative path of the current bundle’s data directory.
bundleFlags number Yes Type of the bundle information to obtain.
callback AsyncCallback<BundleInfo> Yes Callback used to return the result. If the operation is successful, err is null and data is the bundle information obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700022 The hapFilePath is invalid.

Example

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>;

Obtains the bundle information based on the given HAP file path and bundle flags. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
hapFilePath string Yes Path where the HAP file is stored. The path must be the relative path of the current bundle’s data directory.
bundleFlags number Yes Type of the bundle information to obtain.

Return value

Type Description
Promise<BundleInfo> Promise used to return the bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700022 The hapFilePath is invalid.

Example

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;

Obtains the bundle information based on the given HAP file path and bundle flags. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
hapFilePath string Yes Path where the HAP file is stored. The path must be the relative path of the current bundle’s data directory.
bundleFlags number Yes Type of the bundle information to obtain.

Return value

Type Description
BundleInfo Bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700022 The hapFilePath is invalid.

Example

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;

Clears the cache files based on the given bundle name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.REMOVE_CACHE_FILES

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
callback AsyncCallback<void> Yes Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700030 The specified bundle does not support clearing of cache files.

Example

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>;

Clears the cache files based on the given bundle name. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.REMOVE_CACHE_FILES

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
Promise<void> Promise that returns no value. If clearing the cache files fails, an error object is thrown.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700030 The specified bundle does not support clearing of cache files.

Example

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;

Enables or disables an application. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
isEnabled boolean Yes Whether to enable the application. The value true means to enable the application, and false means to disable the application.
callback AsyncCallback<void> Yes Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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>;

Enables or disables an application. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
isEnabled boolean Yes Whether to enable the application. The value true means to enable the application, and false means to disable the application.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Enables or disables an application. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
isEnabled boolean Yes Whether to enable the application. The value true means to enable the application, and false means to disable the application.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Enables or disables an ability. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.
isEnabled boolean Yes Whether to enable the ability. The value true means to enable the ability, and false means to disable the ability.
callback AsyncCallback<void> Yes Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityInfo is not found.

Example

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>;

Enables or disables an ability. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.
isEnabled boolean Yes Whether to enable the ability. The value true means to enable the ability, and false means to disable the ability.

Return value

Type Description
Promise<void> Promise that returns no value.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityInfo is not found.

Example

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;

Enables or disables an ability. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.CHANGE_ABILITY_ENABLED_STATE

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.
isEnabled boolean Yes Whether to enable the ability. The value true means to enable the ability, and false means to disable the ability.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityInfo is not found.

Example

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;

Checks whether an application is enabled. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the application is enabled, and false means the opposite.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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>;

Checks whether an application is enabled. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the application is enabled, and false means the opposite.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Checks whether an application is enabled. This API returns the result synchronously.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
boolean Returns true if the application is enabled; returns false otherwise.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Checks whether an ability is enabled. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.
callback AsyncCallback<boolean> Yes Callback used to return the result. The value true means that the ability is enabled, and false means the opposite.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityName is not found.

Example

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>;

Checks whether an ability is enabled. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.

Return value

Type Description
Promise<boolean> Promise used to return the result. The value true means that the ability is enabled, and false means the opposite.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityName is not found.

Example

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;

Checks whether an ability is enabled. This API returns the result synchronously.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
info AbilityInfo Yes Information about the target ability.

Return value

Type Description
boolean Returns true if the ability is enabled; returns false otherwise.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified abilityName is not found.

Example

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;

Obtains the Want used to launch the bundle based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number Yes User ID.
callback AsyncCallback<Want> Yes Callback used to return the result. If the operation is successful, err is null and data is the Want object obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the Want used to launch the bundle based on the given bundle name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
callback AsyncCallback<Want> Yes Callback used to return the result. If the operation is successful, err is null and data is the Want object obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700026 The specified bundle is disabled.

Example

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>;

Obtains the Want used to launch the bundle based on the given bundle name and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Promise<Want> Promise used to return the Want object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the Want used to launch the bundle based on the given bundle name and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Want Want object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API uses an asynchronous callback to return the result.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
abilityName string Yes Ability name.
metadataName string Yes Metadata name.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of JSON strings obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified abilityName is not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>>;

Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API uses a promise to return the result.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
abilityName string Yes Ability name.
metadataName string No Metadata name. By default, no value is passed.

Return value

Type Description
Promise> Promise used to return the array of JSON strings obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified abilityName is not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>;

Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API returns the result synchronously.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
abilityName string Yes Ability name.
metadataName string No Metadata name. By default, no value is passed.

Return value

Type Description
Array<string> An array of JSON strings.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified abilityName is not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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;

Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API uses an asynchronous callback to return the result.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
extensionAbilityName string Yes ExtensionAbility name.
metadataName string Yes Metadata name.
callback AsyncCallback> Yes Callback used to return the result. If the operation is successful, err is null and data is the array of JSON strings obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified extensionAbilityName not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.

Example

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>>;

Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API uses a promise to return the result.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
extensionAbilityName string Yes ExtensionAbility name.
metadataName string No Metadata name. By default, no value is passed.

Return value

Type Description
Promise> Promise used to return the array of JSON strings obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified extensionAbilityName not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.

Example

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>;

Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API returns the result synchronously.

NOTE

If the profile uses the resource reference format, the return value retains this format (for example, $string:res_id). You can obtain the referenced resources through related APIs of the resource management module.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
moduleName string Yes Module name.
extensionAbilityName string Yes ExtensionAbility name.
metadataName string No Metadata name. By default, no value is passed.

Return value

Type Description
Array<string> An array of JSON strings.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700002 The specified moduleName is not existed.
17700003 The specified extensionAbilityName not existed.
17700024 Failed to get the profile because there is no profile in the HAP.
17700026 The specified bundle is disabled.

Example

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;

Obtains the PermissionDef struct based on the given permission name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
permissionName string Yes Name of the permission.
callback AsyncCallback<PermissionDef> Yes Callback used to return the result. If the operation is successful, err is null and data is the PermissionDef object obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700006 The specified permission is not found.

Example

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>;

Obtains the PermissionDef struct based on the given permission name. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
permissionName string Yes Name of the permission.

Return value

Type Description
Promise<PermissionDef> Promise used to return the PermissionDef object obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700006 The specified permission is not found.

Example

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;

Obtains the PermissionDef struct based on the given permission name. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
permissionName string Yes Name of the permission.

Return value

Type Description
PermissionDef PermissionDef object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700006 The specified permission is not found.

Example

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;

Obtains the ability label based on the given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
moduleName string Yes Module name.
abilityName string Yes Ability name.
callback AsyncCallback<string> Yes Callback used to return the result. If the operation is successful, err is null and data is the label obtained. Otherwise, err is an error object.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.
17700003 The specified abilityName is not found.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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>;

Obtains the ability label based on the given bundle name, module name, and ability name. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
moduleName string Yes Module name.
abilityName string Yes Ability name.

Return value

Type Description
Promise<string> Promise used to return the label.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.
17700003 The specified abilityName is not found.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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;

Obtains the ability label based on the given bundle name, module name, and ability name. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
moduleName string Yes Module name.
abilityName string Yes Ability name.

Return value

Type Description
string Label of the ability.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.
17700003 The specified abilityName is not found.
17700026 The specified bundle is disabled.
17700029 The specified ability is disabled.

Example

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;

Obtains the application information based on the given bundle name, application flags, and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
applicationFlags number Yes Type of the application information to obtain.
userId number Yes User ID.

Return value

Type Description
ApplicationInfo Application information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the application information based on the given bundle name and application flags. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
applicationFlags number Yes Type of the application information to obtain.

Return value

Type Description
ApplicationInfo Application information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
bundleFlags number Yes Type of the bundle information to obtain.
userId number Yes User ID.

Return value

Type Description
BundleInfo Bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the bundle information based on the given bundle name and bundle flags. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
bundleFlags number Yes Type of the bundle information to obtain.

Return value

Type Description
BundleInfo Bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700026 The specified bundle is disabled.

Example

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;

Obtains the shared bundle information based on the given bundle name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
moduleName string Yes Module name.
callback AsyncCallback<Array<SharedBundleInfo>> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the shared bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.

Example

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>>;

Obtains the shared bundle information based on the given bundle name. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
moduleName string Yes Module name.

Return value

Type Description
Promise<Array<SharedBundleInfo>> Promise used to return the shared bundle information obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.

Example

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;

Obtains the information about all shared bundles. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
callback AsyncCallback<Array<SharedBundleInfo>> Yes Callback invoked to return the result. If the operation is successful, err is null and data is an array of the shared bundle information obtained.

Example

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>>;

Obtains the information about all shared bundles. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Return value

Type Description
Promise<Array<SharedBundleInfo>> Promise used to return an array of the shared bundle information obtained.

Example

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;

Obtains the provision profile based on the given bundle name. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
callback AsyncCallback<AppProvisionInfo> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the provision profile obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Obtains the provision profile based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number Yes User ID, which can be obtained by calling getOsAccountLocalId.
callback AsyncCallback<AppProvisionInfo> Yes Callback invoked to return the result. If the operation is successful, err is null and data is the provision profile obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.

Example

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>;

Obtains the provision profile based on the given bundle name and user ID. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. You can call getOsAccountLocalId to obtain the user ID on the current device.

Return value

Type Description
Promise<AppProvisionInfo> Promise used to return the provision profile obtained.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.

Example

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;

Obtains the provision profile based on the given bundle name and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. You can call getOsAccountLocalId to obtain the user ID on the current device.

Return value

Type Description
AppProvisionInfo Provision profile.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700004 The specified user ID is not found.

Example

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;

Obtains the distribution type of a bundle in synchronous mode. The return value is the specifiedDistributionType field value in InstallParam passed when install is called.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
string Distribution type of the bundle.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Obtains additional information about a bundle in synchronous mode. The return value is the additionalInfo field value in InstallParam passed when install is called.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name.

Return value

Type Description
string Additional information about the bundle.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.

Example

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;

Obtains the bundle information of this bundle based on the given bundle flags in synchronous mode.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
bundleFlags number Yes Type of the bundle information to obtain.

Return value

Type Description
BundleInfo Bundle information obtained.

Example

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);
}

bundleManager.queryExtensionAbilityInfoSync11+

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

Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
want Want Yes Want containing the bundle name to query.
extensionAbilityType string Yes Type of the custom ExtensionAbility.
extensionAbilityFlags number Yes Information flags to be contained in the returned ExtensionAbilityInfo object.
userId number No User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

Type Description
Array<ExtensionAbilityInfo> An array of ExtensionAbilityInfo objects.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700003 The specified extensionAbility is not found.
17700004 The specified userId is invalid.
17700026 The specified bundle is disabled.

Example

// Call the API with the userId parameter specified.
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';

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

try {
    var data = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId)
    hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed.');
}
// Call the API without passing in the userId parameter.
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';

let extensionAbilityType = "form";
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "EntryAbility"
};

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

bundleManager.getJsonProfile11+

getJsonProfile(profileType: ProfileType, bundleName: string, moduleName?: string): string;

Obtains the JSON strings of the profile based on the given profile type, bundle name, and module name. This API returns the result synchronously.

No permission is required for obtaining the caller’s own profile.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

Name Type Mandatory Description
profileType ProfileType Yes Type of the profile.
bundleName string Yes Bundle name of the application.
moduleName string No Module name of the application. If this parameter is not passed in, the entry module is used.

Return value

Type Description
string JSON string of the profile.

Error codes

For details about the error codes, see Bundle Error Codes.

ID Error Message
17700001 The specified bundleName is not found.
17700002 The specified moduleName is not found.
17700024 Failed to get the profile because the specified profile is not found in the HAP.
17700026 The specified bundle is disabled.

Example

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

let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let profileType = bundleManager.ProfileType.INTENT_PROFILE;

try {
    let data = bundleManager.getJsonProfile(profileType, bundleName, moduleName)
    hilog.info(0x0000, 'testTag', 'getJsonProfile successfully. Data: %{public}s', data);
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getJsonProfile failed.');
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞