@ohos.bundle (Bundle) (System API)
The bundle module provides APIs for obtaining information about an application, including bundle information, application information, and ability information. It also provides APIs to obtain and set the application disabling state.
NOTE
The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The APIs of this module are deprecated since API version 9. You are advised to use @ohos.bundle.bundleManager instead.
This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.bundle.
Modules to Import
import bundle from '@ohos.bundle';
Required Permissions
Permission | APL | Description |
---|---|---|
ohos.permission.CHANGE_ABILITY_ENABLED_STATE | system_basic | Permission to enable or disable an application or ability. |
ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about a specified bundle. |
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles. |
ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles. |
ohos.permission.REMOVE_CACHE_FILES | system_basic | Permission to clear cache files of a bundle. |
For details, see Permission APL.
bundle.getBundleInstallerdeprecated
This API is deprecated since API version 9. You are advised to use installer.getBundleInstaller instead.
getBundleInstaller(): Promise<BundleInstaller>
Obtains the installation package. This API uses a promise to return the result.
Required permissions
ohos.permission.INSTALL_BUNDLE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Return value
Type | Description |
---|---|
Promise<BundleInstaller> | Promise used to return the installation package. |
Example
import bundle from '@ohos.bundle';
import { BusinessError } from '@ohos.base';
bundle.getBundleInstaller().then((data) => {
console.info('getBundleInstaller successfully.');
}).catch((error: BusinessError) => {
console.error('getBundleInstaller failed.');
});
bundle.getBundleInstallerdeprecated
This API is deprecated since API version 9. You are advised to use installer.getBundleInstaller instead.
getBundleInstaller(callback: AsyncCallback<BundleInstaller>): void
Obtains the installation package. This API uses an asynchronous callback to return the result.
Required permissions
ohos.permission.INSTALL_BUNDLE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<BundleInstaller> | Yes | Callback used to return the installation package. |
Example
import bundle from '@ohos.bundle';
bundle.getBundleInstaller((err, data) => {
if (err.code == 0) {
console.error('getBundleInstaller failed.');
} else {
console.info('getBundleInstaller successfully');
}
});
bundle.cleanBundleCacheFiles8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.cleanBundleCacheFiles instead.
cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback<void>): void
Clears the cache data of an application. This API uses an asynchronous callback to return the result.
Required permissions
ohos.permission.REMOVE_CACHE_FILES
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import bundle from '@ohos.bundle';
let bundleName: string = "com.example.myapplication";
bundle.cleanBundleCacheFiles(bundleName, err => {
if (err) {
console.error('cleanBundleCacheFiles failed.');
} else {
console.info('cleanBundleCacheFiles successfully.');
}
});
bundle.cleanBundleCacheFiles8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.cleanBundleCacheFiles instead.
cleanBundleCacheFiles(bundleName: string): Promise<void>
Clears the cache data of an application. This API uses a promise to return the result.
Required permissions
ohos.permission.REMOVE_CACHE_FILES
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Example
import bundle from '@ohos.bundle';
import { BusinessError } from '@ohos.base';
let bundleName: string = "com.example.myapplication";
bundle.cleanBundleCacheFiles(bundleName).then(()=> {
console.info('cleanBundleCacheFiles successfully.');
}).catch((error: BusinessError) => {
console.error('cleanBundleCacheFiles failed.');
});
bundle.setApplicationEnabled8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.setApplicationEnabled instead.
setApplicationEnabled(bundleName: string, isEnable: boolean, callback: AsyncCallback<void>): void
Sets whether to enable an application. This API uses an asynchronous callback to return the result.
Required permissions
ohos.permission.CHANGE_ABILITY_ENABLED_STATE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
isEnable | boolean | Yes | Whether to enable the application. The value true means to enable the application, and false means the opposite. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import bundle from '@ohos.bundle';
let bundleName: string = "com.example.myapplication";
bundle.setApplicationEnabled(bundleName, false, err => {
if (err) {
console.error('setApplicationEnabled failed.');
} else {
console.info('setApplicationEnabled successfully.');
}
});
bundle.setApplicationEnabled8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.setApplicationEnabled instead.
setApplicationEnabled(bundleName: string, isEnable: boolean): Promise<void>
Sets whether to enable an application. This API uses a promise to return the result.
Required permissions
ohos.permission.CHANGE_ABILITY_ENABLED_STATE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
isEnable | boolean | Yes | Whether to enable the application. The value true means to enable the application, and false means the opposite. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Example
import bundle from '@ohos.bundle';
import { BusinessError } from '@ohos.base';
let bundleName: string = "com.example.myapplication";
bundle.setApplicationEnabled(bundleName, false).then(()=> {
console.info('setApplicationEnabled successfully.');
}).catch((error: BusinessError) => {
console.error('setApplicationEnabled failed.');
});
bundle.setAbilityEnabled8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.setAbilityEnabled instead.
setAbilityEnabled(info: AbilityInfo, isEnable: boolean, callback: AsyncCallback<void>): void
Sets whether to enable an ability. This API uses an asynchronous callback to return the result.
Required permissions
ohos.permission.CHANGE_ABILITY_ENABLED_STATE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
info | AbilityInfo | Yes | Ability information. |
isEnable | boolean | Yes | Whether to enable the application. The value true means to enable the application, and false means the opposite. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
bundle.setAbilityEnabled8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.setAbilityEnabled instead.
setAbilityEnabled(info: AbilityInfo, isEnable: boolean): Promise<void>
Sets whether to enable an ability. This API uses a promise to return the result.
Required permissions
ohos.permission.CHANGE_ABILITY_ENABLED_STATE
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
info | AbilityInfo | Yes | Ability information. |
isEnable | boolean | Yes | Whether to enable the application. The value true means to enable the application, and false means the opposite. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Example
import bundle from '@ohos.bundle';
import { BusinessError } from '@ohos.base';
let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo) => {
console.info('getAbilityInfo successfully. Data: ' + JSON.stringify(abilityInfo));
bundle.setAbilityEnabled(abilityInfo, false).then(data => {
console.info('setAbilityEnabled successfully.');
}).catch((error: BusinessError) => {
console.error('setAbilityEnabled failed:' + JSON.stringify(error));
})
}).catch((error: BusinessError) => {
console.error('getAbilityInfo failed. Cause: ' + JSON.stringify(error));
});
bundle.getPermissionDef8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.getPermissionDef instead.
getPermissionDef(permissionName: string, callback: AsyncCallback<PermissionDef>): void
Obtains the permission details by permission name. This API uses an asynchronous callback to return the result.
Required permissions
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
permissionName | string | Yes | Name of the permission. |
callback | AsyncCallback<PermissionDef> | Yes | Callback used to return the permission details. |
Example
import bundle from '@ohos.bundle';
let permission: string = "ohos.permission.GET_BUNDLE_INFO";
bundle.getPermissionDef(permission, (err, data) => {
if (err) {
console.error('getPermissionDef failed:' + err.message);
} else {
console.info('getPermissionDef successfully:' + JSON.stringify(data));
}
});
bundle.getPermissionDef8+ deprecated
This API is deprecated since API version 9. You are advised to use bundleManager.getPermissionDef instead.
getPermissionDef(permissionName: string): Promise<PermissionDef>
Obtains the permission details by permission name. This API uses a promise to return the result.
Required permissions
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
System capability
SystemCapability.BundleManager.BundleFramework
System API
This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
permissionName | string | Yes | Name of the permission. |
Return value
Type | Description |
---|---|
Promise<PermissionDef> | Promise used to return the permission details. |
Example
import bundle from '@ohos.bundle';
import { BusinessError } from '@ohos.base';
let permissionName: string = "ohos.permission.GET_BUNDLE_INFO";
bundle.getPermissionDef(permissionName).then((data) => {
console.info('getPermissionDef successfully. Data: ' + JSON.stringify(data));
}).catch((error: BusinessError) => {
console.error('getPermissionDef failed. Cause: ' + error.message);
});