The module provides APIs for obtaining application information, including bundle information, application information, ability information (information about a UIAbility), and ExtensionAbility information.
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.
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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| GET_BUNDLE_INFO_WITH_METADATA | 0x00000020 | Used to obtain the metadata contained in the application, 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. - To obtain the metadata contained in the application information, it must be used together with GET_BUNDLE_INFO_WITH_APPLICATION. - To obtain the metadata contained in the module information, it must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE. - To obtain the metadata contained in the ability information, it must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE and GET_BUNDLE_INFO_WITH_ABILITY. - To obtain the metadata contained in the ExtensionAbility information, it must be used together with GET_BUNDLE_INFO_WITH_HAP_MODULE 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_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. Atomic service API: This API can be used in atomic services since API version 11. |
| 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. Atomic service API: This API can be used in atomic services since API version 11. |
| GET_BUNDLE_INFO_WITH_MENU11+ | 0x00000100 | Used 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+ | 0x00000200 | Used 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+ | 0x00000800 | Used 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. |
| GET_BUNDLE_INFO_WITH_ENTRY_MODULE23+ | 0x00010000 | Used to obtain the bundle information with the HAP module information. It is valid only for bundleInfo.hapModulesInfo corresponding to the entry module. If the entry module does not exist, the bundleInfo.hapModulesInfo list is empty. The obtained bundle 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 23. |
Enumerates the types of ExtensionAbility components.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| FORM | 0 | FormExtensionAbility: widget extension capability, providing widget development capabilities. Atomic service API: This API can be used in atomic services since API version 11. |
| WORK_SCHEDULER | 1 | WorkSchedulerExtensionAbility: deferred task extension capability, allowing apps to execute tasks with low real-time requirements when the system is idle. |
| INPUT_METHOD | 2 | InputMethodExtensionAbility: input method extension capability, used to develop input method apps. |
| ACCESSIBILITY | 4 | AccessibilityExtensionAbility: accessibility service extension capability, supporting access to and operation of foreground UIs. |
| BACKUP | 9 | BackupExtensionAbility: data backup extension capability, providing backup and restoration capabilities for app data. |
| ENTERPRISE_ADMIN | 11 | EnterpriseAdminExtensionAbility: enterprise device management extension capability, providing the capability to process management events during enterprise management. |
| SHARE10+ | 16 | ShareExtensionAbility: provides sharing service capabilities, providing developers with a sharing service template based on UIExtension. |
| DRIVER10+ | 18 | DriverExtensionAbility: driver extension capability, providing peripheral driver extension capabilities. After an app configures an ExtensionAbility of the driver type, it is regarded as a driver app. Driver apps are not distinguished by user during installation, uninstallation, and restoration, and existing driver apps on the device are also installed when a new user is created. For example, when a sub-user is created, the existing driver apps of the primary user are installed by default. When a driver app is uninstalled on a sub-user, the corresponding driver app on the primary user is also uninstalled. |
| ACTION10+ | 19 | ActionExtensionAbility: custom service extension capability, providing developers with a custom operation service template based on UIExtension. |
| EMBEDDED_UI12+ | 21 | EmbeddedUIExtensionAbility: embedded UI extension capability, providing the capability to embed UIs across processes. |
| INSIGHT_INTENT_UI12+ | 22 | InsightIntentUIExtensionAbility: provides developers with the extension capability to be invoked by system entries and present content in window form. |
| FENCE18+ | 24 | FenceExtensionAbility: provides developers with geofence-related capabilities, inherited from ExtensionAbility. |
| ASSET_ACCELERATION18+ | 26 | AssetAccelerationExtensionAbility: resource pre-download extension capability, providing the capability to pre-download resources in the background when the device is idle. |
| FORM_EDIT18+ | 27 | FormEditExtensionAbility: provides developers with the capability to edit widgets, inherited from UIExtensionAbility. |
| DISTRIBUTED20+ | 28 | DistributedExtensionAbility: provides distributed-related extension capabilities, providing lifecycle callbacks for distributed creation, destruction, and connection. |
| APP_SERVICE20+ | 29 | AppServiceExtensionAbility: provides background service capabilities for enterprise common apps. |
| LIVE_FORM20+ | 30 | LiveFormExtensionAbility: interactive widget-related extension capability, providing lifecycle callbacks for interactive widget creation and destruction. Atomic service API: This API can be used in atomic services since API version 20. |
| SELECTION24+ | 31 | SelectionExtensionAbility: ExtensionAbility that provides developers with the word-selection popup capability. Model restriction: This API can be used only in the stage model. |
| WEB_NATIVE_MESSAGING21+ | 32 | WebNativeMessagingExtensionAbility: ExtensionAbility that provides developers with Web message communication capabilities. |
| FAULT_LOG21+ | 33 | FaultLogExtensionAbility: provides the capability to delay fault notifications. |
| NOTIFICATION_SUBSCRIBER22+ | 34 | NotificationSubscriberExtensionAbility: provides notification subscription-related functions. |
| CRYPTO22+ | 35 | CryptoExtensionAbility: provides external key management extension-related functions. |
| PARTNER_AGENT23+ | 36 | PartnerAgentExtensionAbility: provides device discovery and device offline notification functions based on Bluetooth communication technology. Model restriction: This API can be used only in the stage model. |
| AGENT24+ | 37 | AgentExtensionAbility: provides agent extension capabilities, including lifecycle callback APIs for agent service creation, destruction, connection, and disconnection, as well as callback APIs for receiving data sent by clients and security authentication. Model restriction: This API can be used only in the stage model. |
| AGENT_UI24+ | 38 | AgentUIExtensionAbility: provides developers with the capability to access and display on-device Agent UIs. Model restriction: This API can be used only in the stage model. |
| MODULAR_OBJECT | 39 | modular_object_extension_ability: provides [modular object] extension capability, which can encapsulate an app's own functions into independent functional modules and open them to other apps. Model restriction: This API can be used only in the stage model. Since: 26.0.0 |
| UNSPECIFIED | 255 | No type specified can be queried. |
| CALLER_INFO_QUERY19+ | 25 | CallerInfoQueryExtensionAbility: provides the capability of querying incoming and outgoing call information. |
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
| Name | Value | Description |
|---|---|---|
| PERMISSION_DENIED | -1 | Permission denied. |
| PERMISSION_GRANTED | 0 | Permission granted. |
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
| 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. |
Enumerates the launch types of the UIAbility.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| SINGLETON | 0 | The UIAbility can have only one instance. |
| MULTITON | 1 | The UIAbility can have multiple instances. |
| SPECIFIED | 2 | The UIAbility can have one or multiple instances, depending on the internal service of the ability. |
Enumerates the types of ability components.
Model restriction: This API can be used only in the FA model.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| PAGE | 1 | Ability that has the UI. FA developed using the Page template to provide the capability of interacting with users. |
| SERVICE | 2 | Ability of the background service type, without a UI. It represents a ParticleAbility developed based on the Service template, used to provide the capability of running background tasks, such as background download or music playback. |
| DATA | 3 | It represents a ParticleAbility developed based on the Data template, used to provide a unified data access object to the outside. |
Enumerates the display orientations of the ability. It is applicable only to PageAbility in the FA model.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| UNSPECIFIED | 0 | Unspecified. The orientation is determined by the system. Atomic service API: This API can be used in atomic services since API version 11. |
| LANDSCAPE | 1 | Landscape. Atomic service API: This API can be used in atomic services since API version 11. |
| PORTRAIT | 2 | Portrait. Atomic service API: This API can be used in atomic services since API version 11. |
| FOLLOW_RECENT | 3 | The last display orientation is used. Atomic service API: This API can be used in atomic services since API version 11. |
| LANDSCAPE_INVERTED | 4 | Reverse landscape. Atomic service API: This API can be used in atomic services since API version 11. |
| PORTRAIT_INVERTED | 5 | Reverse portrait. Atomic service API: This API can be used in atomic services since API version 11. |
| AUTO_ROTATION | 6 | Automatically 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_LANDSCAPE | 7 | Automatically 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_PORTRAIT | 8 | Automatically 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_RESTRICTED | 9 | Switched-determined auto rotation. Atomic service API: This API can be used in atomic services since API version 11. |
| AUTO_ROTATION_LANDSCAPE_RESTRICTED | 10 | Indicates the automatic landscape rotation mode controlled by the switch. Atomic service API: This API can be used in atomic services since API version 11. |
| AUTO_ROTATION_PORTRAIT_RESTRICTED | 11 | Switched-determined auto rotation in the vertical direction. Atomic service API: This API can be used in atomic services since API version 11. |
| LOCKED | 12 | Locked. Atomic service API: This API can be used in atomic services since API version 11. |
| AUTO_ROTATION_UNSPECIFIED12+ | 13 | Auto 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+ | 14 | Following the orientation of the home screen. Atomic service API: This API can be used in atomic services since API version 12. |
Defines the version compatibility type of the dynamic shared library.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| BACKWARD_COMPATIBILITY | 1 | The shared library is backward compatible. |
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
| Name | Value | Description |
|---|---|---|
| ENTRY | 1 | Main module of and entry to the application, providing the basic application functionality. |
| FEATURE | 2 | Dynamic feature module of the application, extending the application functionality. This type of HAP can be installed based on user needs and device types. |
| SHARED | 3 | Dynamic shared library of the application. |
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
| Name | Value | Description |
|---|---|---|
| APP | 0 | The bundle is an application. |
| ATOMIC_SERVICE | 1 | The bundle is an atomic service. |
Enumerates the types of the multi-app mode.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| UNSPECIFIED | 0 | Unspecified. It is the default value of multiAppMode. |
| MULTI_INSTANCE | 1 | Multi-instance mode. A resident process does not support this value. |
| APP_CLONE | 2 | App clone mode |
Enumerates the ability flags, which indicate the type of ability information to obtain.
Atomic service API: This API can be used in atomic services since API version 20.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
|---|---|---|
| GET_ABILITY_INFO_DEFAULT | 0x00000000 | Used to obtain the default ability information, which does not contain permissions, metadata, or ability information of disabled abilities. |
| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the ability information containing permissions. |
| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | Used to obtain the ability information containing application information. |
| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | Used to obtain the ability information containing 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. |
| GET_ABILITY_INFO_WITH_APP_LINKING | 0x00000040 | Used to obtain the ability information that passes domain name verification. |
| GET_ABILITY_INFO_WITH_SKILL | 0x00000080 | Used to obtain the ability information containing skills. |
getBundleInfoForSelf(bundleFlags: number): Promise<BundleInfo>
Obtains the bundle information of the current application 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
| 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. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter 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);
} getBundleInfoForSelf(bundleFlags: number, callback: AsyncCallback<BundleInfo>): void
Obtains the bundle information of the current application 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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleFlags | number | Yes | Type of the bundle information to obtain. |
| callback | AsyncCallback<BundleInfo> | Yes | AsyncCallback used to return the result. If the operation is successful, err is undefined and data is the BundleInfo of the current app; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
Example
// Obtain the bundle information, which contains the ability 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);
} 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 under metadata in abilities of the module.json5 file). This API uses an asynchronous callback to return the result.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Name of the UIAbility component. |
| metadataName | string | Yes | Metadata name of the UIAbility component, that is, name of the metadata tag under abilities in the module.json5 file. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result. If the operation is successful, err is undefined and data is the obtained Array<string>; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
| 17700029 | The 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);
} 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 under metadata in abilities of the module.json5 file). This API uses a promise to return the result.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Name of the UIAbility component. |
| metadataName | string | No | Metadata 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
| Type | Description |
|---|---|
| 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.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
| 17700029 | The 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);
} 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.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Name of the UIAbility component. |
| metadataName | string | No | Metadata 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
| Type | Description |
|---|---|
| Array<string> | An array of JSON strings. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
| 17700029 | The 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);
} 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.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| extensionAbilityName | string | Yes | Name of the ExtensionAbility component. |
| metadataName | string | Yes | Metadata name of the ExtensionAbility component, that is, name of the metadata tag under extensionAbilities in the module.json5 file. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result. If the operation is successful, err is undefined and data is the obtained Array<string>; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
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);
} 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.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| extensionAbilityName | string | Yes | Name of the ExtensionAbility component. |
| metadataName | string | No | Metadata 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
| Type | Description |
|---|---|
| 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.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
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);
} 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.
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.
Atomic service API: This API can be used in atomic services since API version 11.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| moduleName | string | Yes | Module name. |
| extensionAbilityName | string | Yes | Name of the ExtensionAbility component. |
| metadataName | string | No | Metadata 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
| Type | Description |
|---|---|
| Array<string> | An array of JSON strings. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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. |
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);
} getBundleInfoForSelfSync(bundleFlags: number): BundleInfo
Obtains the bundle information of the current application 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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| 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 Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter 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);
} canOpenLink(link: string): boolean
Checks whether the target application can be accessed based on the provided link. The scheme specified in the 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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| link | string | Yes | Link to check. |
Return value
| Type | Description |
|---|---|
| boolean | Check result for whether the link can be opened. true if it can be opened, false otherwise. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700055 | The specified link is invalid. |
| 17700056 | The 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);
} getLaunchWant(): Want
Obtains the Want parameters of the entry UIAbility of the current application.
Atomic service API: This API can be used in atomic services since API version 13.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Return value
| Type | Description |
|---|---|
| Want | Want object that contains only the bundle name and ability name. |
Error codes
For details about the error codes, see Bundle Error Codes.
| ID | Error Message |
|---|---|
| 17700072 | The 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);
} getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback<BundleInfo>): void
Obtains the BundleInfo 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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, which can be obtained by getOsAccountLocalId. |
| callback | AsyncCallback<BundleInfo> | Yes | AsyncCallback used to return the result. If the operation is successful, err is undefined and data is the obtained BundleInfo; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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, 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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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 undefined and data is the obtained BundleInfo; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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 '@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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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, which can be obtained by getOsAccountLocalId. Default value: the user where the caller is located. Value range: 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 Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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 '@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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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, which can be obtained by getOsAccountLocalId. |
Return value
| Type | Description |
|---|---|
| BundleInfo | Bundle information obtained. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 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 '@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);
} getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo
Obtains the bundle information for the caller's user 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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 Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700001 | The specified bundleName is not found. |
| 17700026 | The 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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| uid | number | Yes | UID of the application. |
| callback | AsyncCallback<string> | Yes | AsyncCallback. If the operation is successful, err is undefined and data is the obtained bundle name; otherwise, err is an error object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700021 | The 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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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 Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700021 | The 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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
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 Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700021 | The 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);
} 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 or ohos.permission.GET_BUNDLE_INFO
When the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
When the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO permission is required.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| uid | number | Yes | UID of the application. |
Return value
| Type | Description |
|---|---|
| Promise<AppCloneIdentity> | Promise used to return the AppCloneIdentity information. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700021 | The 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);
} 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
| Name | Type | Mandatory | Description |
|---|---|---|---|
| uid | number | Yes | UID of the application. |
Return value
| Type | Description |
|---|---|
| SignatureInfo | SignatureInfo object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 17700021 | The 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);
} getAbilityInfo(uri: string, abilityFlags: number): Promise<Array<AbilityInfo>>
Obtains the ability information based on the given resource identifier and ability flag. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 20.
Required permissions: ohos.permission.GET_ABILITY_INFO
System capability: SystemCapability.BundleManager.BundleFramework.Core
Device behavior differences: This API can be properly called only on PCs/2-in-1 devices. If it is called on other device types, error code 201 is returned.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| uri | string | Yes | URI of the resource. The value is the same as that of the uris field under skills in the module.json5 file. |
| abilityFlags | number | Yes | Ability flag, indicating the ability information to be obtained. |
Return value
| Type | Description |
|---|---|
| Promise<Array<AbilityInfo>> | Promise used to return an array of ability information. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 17700003 | The ability is not found. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION;
let uri = "https://www.example.com";
try {
bundleManager.getAbilityInfo(uri, abilityFlags).then((data) => {
hilog.info(0x0000, 'testTag', 'getAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
}).catch((err: BusinessError) => {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'getAbilityInfo failed. Cause: %{public}s', message);
});
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'getAbilityInfo failed. Cause: %{public}s', message);
} cleanBundleCacheFilesForSelf(): Promise<void>
Clears the application cache. This API uses a promise to return the result.
Atomic service API: This API can be used in atomic services since API version 21.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
bundleManager.cleanBundleCacheFilesForSelf().then(() => {
hilog.info(0x0000, 'testTag', 'cleanBundleCacheFilesForSelf complete.');
}); getPluginBundlePathForSelf(pluginBundleName: string): string
Obtains the installation path of a specified plugin in the current application sandbox.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| pluginBundleName | string | Yes | Bundle name of the target plugin. |
Return value
| Type | Description |
|---|---|
| string | Installation path of the target plugin in the current application sandbox. |
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 '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
// Use the actual bundle name of the plugin.
let pluginBundleName = 'com.ohos.pluginDemo';
try {
let path = bundleManager.getPluginBundlePathForSelf(pluginBundleName);
hilog.info(0x0000, 'testTag', 'getPluginBundlePathForSelf successfully. path: %{public}s', path);
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'getPluginBundlePathForSelf failed. Cause: %{public}s', message);
} getLaunchWantForBundleSync(bundleName: string, userId?: number): Want
Obtains the Want parameters for starting an application based on the given bundle name and user ID.
Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or (ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS)
To obtain the Want parameters for starting an application under the current user, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required.
To obtain the Want parameters for starting an application under another user, if the caller is a system application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED permission is required; if the caller is a third-party application, the ohos.permission.GET_BUNDLE_INFO_PRIVILEGED and ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permissions are required.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleName | string | Yes | Bundle name of the app. |
| userId | number | No | User ID, which can be obtained through getOsAccountLocalId. Default value: the user where the caller is located. Value range: greater than or equal to 0. |
Return value
| Type | Description |
|---|---|
| Want | Want object. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
| 17700001 | The specified bundle is not found. |
| 17700004 | The specified user id is not found. |
| 17700026 | The specified bundle is disabled. |
Example
// The sample API contains the userId parameter and obtains the Want parameter required for starting the application of a specified user.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { Want } from '@kit.AbilityKit';
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);
} // The sample API does not contain the userId parameter and obtains the Want parameter required for starting the application of the current user.
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { Want } from '@kit.AbilityKit';
let bundleName = 'com.example.myapplication';
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);
} getApplicationLabel(bundleName: string, appIndex: number): Promise<string>
Obtains the app name based on the given bundle name and app index. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
System capability: SystemCapability.BundleManager.BundleFramework.Resource
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleName | string | Yes | Bundle name of the app. |
| appIndex | number | Yes | App index. The value ranges from 0 to 5, where 0 indicates the main app and 1 to 5 indicate the indexes of app clones. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the app name if the call succeeds, or an error object if the call fails. |
Error codes
For details about the error codes, see Universal Error Codes and Bundle Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 17700001 | The specified bundle is not found. |
| 17700061 | The specified app index is invalid. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
bundleManager.getApplicationLabel('com.hap.myapplication', 1).then((data: string) => {
hilog.info(0x0000, 'testTag', 'getApplicationLabel succeed: Data: %{public}s', data);
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'getApplicationLabel failed: %{public}d %{public}s', err.code, err.message);
});
} catch (err) {
hilog.error(0x0000, 'testTag', 'getApplicationLabel failed: error %{public}d %{public}s', err.code, err.message);
} getInstalledBundleList(bundleFlags: number): Promise<Array<BundleInfo>>
Obtains all BundleInfo objects in the system based on the given bundleFlags. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
Required permissions: ohos.permission.ENTERPRISE_GET_INSTALLED_BUNDLE_LIST
System capability: SystemCapability.BundleManager.BundleFramework.Core
Device behavior differences: This API is supported only on PC/2-in-1 devices. On other device types, it returns error code 201.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| bundleFlags | number | Yes | Information contained in the returned BundleInfo. For details, see BundleFlag. |
Return value
| Type | Description |
|---|---|
| Promise<Array<BundleInfo>> | Promise used to return the list of information about the currently installed apps. |
Error codes
For details about the error codes, see Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getInstalledBundleList(bundleFlags).then((data) => {
hilog.info(0x0000, 'testTag', 'getInstalledBundleList successfully. Data: %{public}s', JSON.stringify(data));
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'getInstalledBundleList failed. Cause: %{public}s', err.message);
});
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'getInstalledBundleList failed. Cause: %{public}s', message);
} setAlternateIcon(alternateIconName: string): Promise<void>;
Sets the alternate icon of the caller based on the given alternate icon name. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| alternateIconName | string | Yes | Name of the alternate icon to set. The alternate icon name must be in the name field of the alternateIcons tag in app.json5. If alternateIconName is empty, the alternate icon is canceled. |
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 |
|---|---|
| 17700308 | The alternateIconName must match the name field under alternateIcons in the app.json5 file. |
| 17700309 | No alternate icon is enabled. |
| 17700310 | Failed to set the alternate icon. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
// Replace alternateIconName with the name of the alternate icon to set.
let alternateIconName: string = 'com.ohos.demo';
try {
bundleManager.setAlternateIcon(alternateIconName).then((data) => {
hilog.info(0x0000, 'testTag', 'setAlternateIcon successfully');
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'setAlternateIcon failed. Cause: %{public}s', err.message);
});
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'setAlternateIcon failed. Cause: %{public}s', message);
} getAlternateIcons(): Promise<Array<AlternateIconInfo>>
Queries the alternate icon information configured in the alternateIcons tag in app.json5 of the current app. This API uses a promise to return the result.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.BundleManager.BundleFramework.Core
Return value
| Type | Description |
|---|---|
| Promise<Array<AlternateIconInfo>> | Promise used to return the list of alternate icon information of the current app. |
Error codes
For details about the error codes, see Bundle Error Codes.
| ID | Error Message |
|---|---|
| 17700311 | Failed to obtain the alternate icon. |
Example
import { bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
bundleManager.getAlternateIcons().then((data) => {
hilog.info(0x0000, 'testTag', 'getAlternateIcons successfully. Data: %{public}s', JSON.stringify(data));
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'getAlternateIcons failed. Cause: %{public}s', err.message);
});
} catch (err) {
let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'getAlternateIcons failed. Cause: %{public}s', message);
} 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
| Type | Description |
|---|---|
| _ApplicationInfo | Application information. |
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
| Type | Description |
|---|---|
| _ModuleMetadata | Metadata of the module. |
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
| Type | Description |
|---|---|
| _Metadata | Metadata. |
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
| Type | Description |
|---|---|
| _BundleInfo.BundleInfo | Bundle information. |
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
| Type | Description |
|---|---|
| _BundleInfo.UsedScene | Use scenario and timing for using the permission. |
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
| Type | Description |
|---|---|
| _BundleInfo.ReqPermissionDetail | Detailed information of the permissions to request from the system. |
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
| Type | Description |
|---|---|
| _BundleInfo.SignatureInfo | Signature information of the bundle. |
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
| Type | Description |
|---|---|
| _HapModuleInfo.HapModuleInfo | Module information. |
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
| Type | Description |
|---|---|
| _HapModuleInfo.PreloadItem | Preloaded module information in the atomic service. |
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
| Type | Description |
|---|---|
| _HapModuleInfo.Dependency | Information about the dynamic shared libraries on which the module depends. |
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
| Type | Description |
|---|---|
| _HapModuleInfo.RouterItem | Router table configuration of the module. |
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
| Type | Description |
|---|---|
| _HapModuleInfo.DataItem | User-defined data in the routing table configuration of the module. |
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
| Type | Description |
|---|---|
| _AbilityInfo.AbilityInfo | Ability information. |
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
| Type | Description |
|---|---|
| _AbilityInfo.WindowSize | Window size. |
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
| Type | Description |
|---|---|
| _ExtensionAbilityInfo.ExtensionAbilityInfo | ExtensionAbility information. |
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
| Type | Description |
|---|---|
| _ElementName | Element name. |
type Skill = _Skill.Skill
Skill information.
Atomic service API: This API can be used in atomic services since API version 12.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Type | Description |
|---|---|
| _Skill.Skill | Skill information. |
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
| Type | Description |
|---|---|
| _Skill.SkillUri | SkillUri information. |
type AppCloneIdentity = _BundleInfo.AppCloneIdentity
Describes the identity information of an application clone.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Type | Description |
|---|---|
| _BundleInfo.AppCloneIdentity | Identity information of an application clone. |
type AlternateIconInfo = _BundleInfo.AlternateIconInfo
Alternate icon information of the app.
Since: 26.0.0
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.BundleManager.BundleFramework.Core
| Type | Description |
|---|---|
| _BundleInfo.AlternateIconInfo | Alternate icon information of the app. |