openharmony 鸿蒙 js-apis-bundleManager

2025-06-12 浏览 (1)

@ohos.bundle.bundleManager (bundleManager)

The bundleManager module provides APIs for obtaining application information, including bundle information, application information, ability information, and ExtensionAbility information.

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 '@kit.AbilityKit';

Required Permissions

PermissionAPLDescription
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basicPermission to obtain basic information and other sensitive information about a bundle.
ohos.permission.GET_SIGNATURE_INFOsystem_basicAllows an application to obtain the application package signature information.

For details about the APL, see Basic Concepts in the Permission Mechanism.

BundleFlag

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

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
GET_BUNDLE_INFO_DEFAULT0x00000000Used to obtain the default bundle information. The obtained information does not contain information about the signature, application, HAP module, ability, ExtensionAbility, or permission.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_APPLICATION0x00000001Used to obtain the bundle information with application information. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_HAP_MODULE0x00000002Used to obtain the bundle information with HAP module information. The obtained information does not contain information about the signature, application, ability, ExtensionAbility, or permission.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_ABILITY0x00000004Used 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.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY0x00000008Used 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.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION0x00000010Used to obtain the bundle information with permission information. The obtained information does not contain information about the signature, application, HAP module, ability, or ExtensionAbility.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_METADATA0x00000020Used 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.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_DISABLE0x00000040Used 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.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_SIGNATURE_INFO0x00000080Used to obtain the bundle information with signature information. The obtained information does not contain information about the application, HAP module, ability, ExtensionAbility, or permission.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_MENU11+0x00000100Used to obtain the bundle information with the file context menu configuration. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE.
Atomic service API: This API can be used in atomic services since API version 11.
GET_BUNDLE_INFO_WITH_ROUTER_MAP12+0x00000200Used to obtain the bundle information with the router map. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE.
Atomic service API: This API can be used in atomic services since API version 12.
GET_BUNDLE_INFO_WITH_SKILL12+0x00000800Used to obtain the bundle information with the skills. It must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE, GET_BUNDLE_INFO_WITH_ABILITY, and GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY.
Atomic service API: This API can be used in atomic services since API version 12.

ExtensionAbilityType

Enumerates the types of ExtensionAbilities.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
FORM0FormExtensionAbility: provides APIs for widget development.
Atomic service API: This API can be used in atomic services since API version 11.
WORK_SCHEDULER1WorkSchedulerExtensionAbility: enables applications to execute non-real-time tasks when the system is idle.
INPUT_METHOD2InputMethodExtensionAbility: provides APIs for developing input method applications.
SERVICE3ServiceExtensionAbility: enables applications to run in the background and provide services.
ACCESSIBILITY4AccessibilityExtensionAbility: provides accessibility for access to and operations on the UI.
DATA_SHARE5DataShareExtensionAbility: enables applications to read and write data.
FILE_SHARE6FileShareExtensionAbility: enables file sharing between applications. This ability is reserved and supported only by system applications.
STATIC_SUBSCRIBER7StaticSubscriberExtensionAbility: provides APIs for processing static events, such as the startup event.
WALLPAPER8WallpaperExtensionAbility: provides APIs to implement the home screen wallpaper. This ability is reserved and supported only by system applications.
BACKUP9BackupExtensionAbility: provides APIs to implement application data backup and restore.
WINDOW10WindowExtensionAbility: allows system applications to display UIs of other applications.
ENTERPRISE_ADMIN11EnterpriseAdminExtensionAbility: provides APIs for processing enterprise management events, such as application installation events on devices and events indicating too many incorrect screen-lock password attempts.
THUMBNAIL13ThumbnailExtensionAbility: provides thumbnails for files. This ability is reserved and supported only by system applications.
PREVIEW14PreviewExtensionAbility: provides APIs for file preview so that other applications can be embedded and displayed in the current application. This ability is reserved and supported only by system applications.
PRINT10+15PrintExtensionAbility: provides APIs for printing images. This ability is supported only by system applications.
SHARE10+16ShareExtensionAbility: provides sharing service templates based on UIExtensionAbilities.
PUSH10+17PushExtensionAbility: provides APIs for pushing scenario-specific messages. This ability is reserved and supported only by system applications.
DRIVER10+18DriverExtensionAbility: provides APIs for the peripheral driver. This ability is supported only by system applications.
ACTION10+19ActionExtensionAbility: provides custom action service templates based on UIExtensionAbilities.
ADS_SERVICE11+20AdsServiceExtensionAbility: provides background customized ad services for external systems. This ability is supported only by system applications.
EMBEDDED_UI12+21EmbeddedUIExtensionAbility: provides ExtensionAbilities for the embeddable UI across process.
INSIGHT_INTENT_UI12+22InsightIntentUIExtensionAbility: provides APIs that enable applications to be called by Celia intents so as to be displayed in windows.
FENCE18+24FenceExtensionAbility: provides geofence-related capabilities. It inherits from ExtensionAbility.
ASSET_ACCELERATION18+26AssetAccelerationExtensionAbility: provides the capability of pre-downloading background resources when the device is idle.
DISTRIBUTED18+28DistributedExtensionAbility: provides DistributedExtensionAbility capabilities and lifecycle callbacks for creation, destruction, and connection of DistributedExtensionAbilities.
UNSPECIFIED255The ability type is not specified. It can be used in queryExtensionAbilityInfo to obtain ExtensionAbilities of all types.

PermissionGrantState

Enumerates the permission grant states.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
PERMISSION_DENIED-1Permission denied.
PERMISSION_GRANTED0Permission granted.

SupportWindowMode

Enumerates the window modes supported by the ability.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
FULL_SCREEN0A window in full-screen mode is supported.
SPLIT1A window in split-screen mode is supported.
FLOATING2A floating window is supported.

LaunchType

Enumerates the launch types of the ability.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
SINGLETON0The ability can have only one instance.
MULTITON1The ability can have multiple instances.
SPECIFIED2The 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

NameValueDescription
PAGE1Ability that has the UI. FA developed using the Page template to provide the capability of interacting with users.
SERVICE2Ability of the background service type, without the UI. PA developed using the Service template to provide the capability of running tasks in the background.
DATA3PA developed using the Data template to provide unified data access for external systems.

DisplayOrientation

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

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
UNSPECIFIED0Unspecified. The orientation is determined by the system.
Atomic service API: This API can be used in atomic services since API version 11.
LANDSCAPE1Landscape.
Atomic service API: This API can be used in atomic services since API version 11.
PORTRAIT2Portrait.
Atomic service API: This API can be used in atomic services since API version 11.
FOLLOW_RECENT3The last display orientation is used.
Atomic service API: This API can be used in atomic services since API version 11.
LANDSCAPE_INVERTED4Reverse landscape.
Atomic service API: This API can be used in atomic services since API version 11.
PORTRAIT_INVERTED5Reverse portrait.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION6Automatically rotates when the sensor changes to landscape or portrait mode.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_LANDSCAPE7Automatically rotates when the sensor changes to landscape mode.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_PORTRAIT8Automatically rotates when the sensor changes to portrait mode.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_RESTRICTED9Switched-determined auto rotation.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_LANDSCAPE_RESTRICTED10Switched-determined auto rotation in the horizontal direction.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_PORTRAIT_RESTRICTED11Switched-determined auto rotation in the vertical direction.
Atomic service API: This API can be used in atomic services since API version 11.
LOCKED12Locked.
Atomic service API: This API can be used in atomic services since API version 11.
AUTO_ROTATION_UNSPECIFIED12+13Auto rotation controlled by the switch and determined by the system.
Atomic service API: This API can be used in atomic services since API version 12.
FOLLOW_DESKTOP12+14Following the orientation of the home screen.
Atomic service API: This API can be used in atomic services since API version 12.

CompatiblePolicy10+

Defines the version compatibility type of the shared library.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
BACKWARD_COMPATIBILITY1The shared library is backward compatible.

ModuleType

Enumerates the module types.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
ENTRY1Main module of and entry to the application, providing the basic application functionality.
FEATURE2Dynamic feature module of the application, extending the application functionality. This type of HAP can be installed based on user needs and device types.
SHARED3Dynamic shared library of the application.

BundleType

Enumerates the bundle types.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
APP0The bundle is an application.
ATOMIC_SERVICE1The bundle is an atomic service.

MultiAppModeType12+

Enumerates the types of the multi-app mode.

System capability: SystemCapability.BundleManager.BundleFramework.Core

NameValueDescription
UNSPECIFIED0Unspecified. It is the default value of multiAppMode.
MULTI_INSTANCE1Multi-instance mode. A resident process does not support this value.
APP_CLONE2App clone mode

bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: number): Promise<BundleInfo>

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

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of the bundle information to obtain.

Return value

TypeDescription
Promise<BundleInfo>Promise used to return the bundle information.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

// Obtain the bundle information, which contains the application information including a metadata array.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION|bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;

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 based on the given bundle flags. This API uses an asynchronous callback to return the result.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of the bundle information to obtain.
callbackAsyncCallback<BundleInfo>YesCallback used to return the result. If the information is successfully obtained, err is null and data is the bundle information of the current application. Otherwise, err is an error object.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

// Obtain the bundle information, which contains the application information including permissions.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE|bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY|bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;

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.getProfileByAbility

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

Obtains the JSON string array of the current application's configuration file based on the given module name, ability name, and metadata name (name configured in metadata of the module.json5 file). 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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
abilityNamestringYesName of the UIAbility component.
metadataNamestringYesMetadata name of the UIAbility component, that is, name of the metadata tag under abilities in the module.json5 file.
callbackAsyncCallback<Array<string>>YesCallback used to return the result. If the information is successfully obtained, err is null and data is Array<string>. Otherwise, err is an error object.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let abilityName = 'EntryAbility';
let metadataName = 'ability_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 string array of the current application's configuration file based on the given module name, ability name, and metadata name (name configured in metadata of the module.json5 file). 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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
abilityNamestringYesName of the UIAbility component.
metadataNamestringNoMetadata name of the UIAbility component, that is, name of the metadata tag under abilities in the module.json5 file. The default value is null.

Return value

TypeDescription
Promise<Array<string>>Promise used to return the array of JSON strings obtained.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
  // Obtain the JSON string array of the configuration file based on the module name and ability name.
  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 '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let abilityName = 'EntryAbility';
let metadataName = 'ability_metadata';

try {
  // Obtain the JSON string array of the current application's configuration file based on the module name, ability name, and metadata name.
  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 string array of the current application's configuration file based on the given module name, ability name, and metadata name (name configured in metadata of the module.json5 file). This API returns the result synchronously. The result value is a string array.

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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
abilityNamestringYesName of the UIAbility component.
metadataNamestringNoMetadata name of the UIAbility component, that is, name of the metadata tag under abilities in the module.json5 file. The default value is null.

Return value

TypeDescription
Array<string>An array of JSON strings.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified abilityName is not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.
17700029The specified ability is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let abilityName = 'EntryAbility';

try {
  // Obtain the JSON string array of the configuration file based on the module name and ability name.
  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 '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName: string = 'entry';
let abilityName: string = 'EntryAbility';
let metadataName: string = 'ability_metadata';

try {
  // Obtain the JSON string array of the configuration file based on the module name, ability name, and metadata name.
  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 string array of the current application's configuration file based on the given module name, ExtensionAbility name, and metadata name (name configured in metadata of the module.json5 file). 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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
extensionAbilityNamestringYesName of the ExtensionAbility component.
metadataNamestringYesMetadata name of the ExtensionAbility component, that is, name of the metadata tag under extensionAbilities in the module.json5 file.
callbackAsyncCallback<Array<string>>YesCallback used to return the result. If the information is successfully obtained, err is null and data is Array<string>. Otherwise, err is an error object.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'ability_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 string array of the current application's configuration file based on the given module name, ExtensionAbility name, and metadata name (name configured in metadata of the module.json5 file). 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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
extensionAbilityNamestringYesName of the ExtensionAbility component.
metadataNamestringNoMetadata name of the ExtensionAbility component, that is, name of the metadata tag under abilities in the module.json5 file. The default value is null.

Return value

TypeDescription
Promise<Array<string>>Promise used to return the array of JSON strings obtained.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'ability_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 string array of the current application's configuration file based on the given module name, ExtensionAbility name, and metadata name (name configured in metadata of the module.json5 file). This API returns the result synchronously. The result value is a string array.

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 manager module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
moduleNamestringYesModule name.
extensionAbilityNamestringYesName of the ExtensionAbility component.
metadataNamestringNoMetadata name of the ExtensionAbility component, that is, name of the metadata tag under extensionAbilities in the module.json5 file. The default value is null.

Return value

TypeDescription
Array<string>An array of JSON strings.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700002The specified moduleName is not existed.
17700003The specified extensionAbilityName not existed.
17700024Failed to get the profile because there is no profile in the HAP.
17700026The specified bundle is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'ability_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.getBundleInfoForSelfSync10+

getBundleInfoForSelfSync(bundleFlags: number): BundleInfo

Obtains the bundle information of this bundle based on the given bundle flags. This API returns the result synchronously.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of the bundle information to obtain.

Return value

TypeDescription
BundleInfoBundle information obtained.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.canOpenLink12+

canOpenLink(link: string): boolean

Checks whether a link can be opened. The scheme of the specified link must be configured in the querySchemes field of the module.json5 file.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
linkstringYesLink to check.

Return value

TypeDescription
booleantrue: The link can be opened.
false: The link cannot be opened.

Error codes

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

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700055The specified link is invalid.
17700056The scheme of the specified link is not in the querySchemes.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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

bundleManager.getLaunchWant13+

getLaunchWant(): Want

Obtains the Want parameter used to start this application.

Atomic service API: This API can be used in atomic services since API version 13.

System capability: SystemCapability.BundleManager.BundleFramework.Core

Return value

TypeDescription
WantWant object that contains the bundle name and ability name.

Error codes

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

IDError Message
17700072The launch want is not found.

Example

import { BusinessError } from '@kit.BasicServicesKit';
import { bundleManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

try {
  let want = bundleManager.getLaunchWant();
  hilog.info(0x0000, 'testTag', 'getLaunchWant ability name: %{public}s', want.abilityName);
  hilog.info(0x0000, 'testTag', 'getLaunchWant bundle name: %{public}s', want.bundleName);
} catch (error) {
  let message = (error as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getLaunchWant failed: %{public}s', message);
}

bundleManager.getBundleInfo14+

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.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of the bundle information to obtain.
userIdnumberYesUser ID, which can be obtained by calling getOsAccountLocalId.
callbackAsyncCallback<BundleInfo>YesCallback used to return the result. If the information is successfully obtained, err is null and data is the bundle information. Otherwise, err is an error object.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

Example

// Obtain the bundle information, which contains the ability information.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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, which contains the application information including metadata.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleInfo14+

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.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of the bundle information to obtain.
callbackAsyncCallback<BundleInfo>YesCallback used to return the result. If the information is successfully obtained, err is null and data is the bundle information. Otherwise, err is an error object.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

Example

// Obtain the bundle information with the ExtensionAbility information.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleInfo14+

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.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of the bundle information to obtain.
userIdnumberNoUser ID, which can be obtained by calling getOsAccountLocalId. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

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

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

Example

// Obtain the bundle information with the application and signature information.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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 '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleInfoSync14+

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.

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

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of the bundle information to obtain.
userIdnumberYesUser ID, which can be obtained by calling getOsAccountLocalId.

Return value

TypeDescription
BundleInfoBundle information obtained.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001The specified bundleName is not found.
17700004The specified user ID is not found.
17700026The specified bundle is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleInfoSync14+

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.

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

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of the bundle information to obtain.

Return value

TypeDescription
BundleInfoBundle information obtained.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001The specified bundleName is not found.
17700026The specified bundle is disabled.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleNameByUid14+

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.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
uidnumberYesUID of the application.
callbackAsyncCallback<string>YesCallback used to return the result. If the information is successfully obtained, err is null and data is the bundle name. Otherwise, err is an error object.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700021The uid is not found.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleNameByUid14+

getBundleNameByUid(uid: number): Promise<string>

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

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
uidnumberYesUID of the application.

Return value

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

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700021The uid is not found.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getBundleNameByUidSync14+

getBundleNameByUidSync(uid: number): string

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

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
uidnumberYesUID of the application.

Return value

TypeDescription
stringBundle name obtained.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700021The uid is not found.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

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.getAppCloneIdentity14+

getAppCloneIdentity(uid: number): Promise<AppCloneIdentity>;

Obtains the bundle name and clone index of a cloned application based on the given UID. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
uidnumberYesUID of the application.

Return value

TypeDescription
Promise<AppCloneIdentity>Promise used to return <AppCloneIdentity>.

Error codes

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

IDError Message
201Permission denied.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700021The uid is not found.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let uid = 20010005;

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

bundleManager.getSignatureInfo18+

getSignatureInfo(uid: number): SignatureInfo

Obtains the signature information of an application based on the given UID.

Required permissions: ohos.permission.GET_SIGNATURE_INFO

System capability: SystemCapability.BundleManager.BundleFramework.Core

Parameters

NameTypeMandatoryDescription
uidnumberYesUID of the application.

Return value

TypeDescription
SignatureInfoSignatureInfo object.

Error codes

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

IDError Message
201Permission denied.
17700021The uid is not found.

Example

import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

let uid = 20010005; // Replace uid with the UID of the corresponding application.
try {
    let data = bundleManager.getSignatureInfo(uid);
    hilog.info(0x0000, 'testTag', 'getSignatureInfo successfully. Data: %{public}s', JSON.stringify(data));
} catch (err) {
    let message = (err as BusinessError).message;
    hilog.error(0x0000, 'testTag', 'getSignatureInfo failed. Cause: %{public}s', message);
}

ApplicationInfo

type ApplicationInfo = _ApplicationInfo

Defines the application information.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_ApplicationInfoApplication information.

ModuleMetadata10+

type ModuleMetadata = _ModuleMetadata

Defines the metadata of a module.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_ModuleMetadataMetadata of the module.

Metadata

type Metadata = _Metadata

Defines the metadata.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_MetadataMetadata.

BundleInfo

type BundleInfo = _BundleInfo.BundleInfo

Defines the bundle information.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_BundleInfo.BundleInfoBundle information.

UsedScene

type UsedScene = _BundleInfo.UsedScene

Defines the use scenario and timing for using the permission.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_BundleInfo.UsedSceneUse scenario and timing for using the permission.

ReqPermissionDetail

type ReqPermissionDetail = _BundleInfo.ReqPermissionDetail

Defines the detailed information of the permissions to request from the system.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_BundleInfo.ReqPermissionDetailDetailed information of the permissions to request from the system.

SignatureInfo

type SignatureInfo = _BundleInfo.SignatureInfo

Defines the signature information of the bundle.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_BundleInfo.SignatureInfoSignature information of the bundle.

HapModuleInfo

type HapModuleInfo = _HapModuleInfo.HapModuleInfo

Defines the module information.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_HapModuleInfo.HapModuleInfoModule information.

PreloadItem

type PreloadItem = _HapModuleInfo.PreloadItem

Defines the preloaded module information in the atomic service.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_HapModuleInfo.PreloadItemPreloaded module information in the atomic service.

Dependency

type Dependency = _HapModuleInfo.Dependency

Defines the information about the dynamic shared libraries on which the module depends.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_HapModuleInfo.DependencyInformation about the dynamic shared libraries on which the module depends.

RouterItem12+

type RouterItem = _HapModuleInfo.RouterItem

Defines the router table configuration of the module.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_HapModuleInfo.RouterItemRouter table configuration of the module.

DataItem12+

type DataItem = _HapModuleInfo.DataItem

Defines the user-defined data in the routing table configuration of the module.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_HapModuleInfo.DataItemUser-defined data in the routing table configuration of the module.

AbilityInfo

type AbilityInfo = _AbilityInfo.AbilityInfo

Defines the ability information.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_AbilityInfo.AbilityInfoAbility information.

WindowSize

type WindowSize = _AbilityInfo.WindowSize

Defines the window size.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_AbilityInfo.WindowSizeWindow size.

ExtensionAbilityInfo

type ExtensionAbilityInfo = _ExtensionAbilityInfo.ExtensionAbilityInfo

Defines the ExtensionAbility information.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_ExtensionAbilityInfo.ExtensionAbilityInfoExtensionAbility information.

ElementName

type ElementName = _ElementName

Defines the element name.

Atomic service API: This API can be used in atomic services since API version 11.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_ElementNameElement name.

Skill12+

type Skill = _Skill.Skill

Defines the skill information.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_Skill.SkillSkill information.

SkillUrl12+

type SkillUrl = _Skill.SkillUri

Defines the SkillUri information.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_Skill.SkillUriSkillUri information.

AppCloneIdentity15+

type AppCloneIdentity = _BundleInfo.AppCloneIdentity

Describes the identity information of an application clone.

System capability: SystemCapability.BundleManager.BundleFramework.Core

TypeDescription
_BundleInfo.AppCloneIdentityIdentity information of an application clone.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/VWkmzX