openharmony 鸿蒙 js-apis-Bundle

2025-06-12 浏览 (1)

@ohos.bundle (Bundle)

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.

Modules to Import

import bundle from '@ohos.bundle';

Required Permissions

PermissionAPLDescription
ohos.permission.GET_BUNDLE_INFOnormalPermission to query information about a specified bundle.
ohos.permission.GET_BUNDLE_INFO_PRIVILEGEDsystem_basicPermission to query information about all bundles.

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

bundle.getApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getApplicationInfo instead.

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

Obtains the application information based on a given bundle name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
userIdnumberNoUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<ApplicationInfo>Promise used to return the application information.

Example

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

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 0;
let userId: number = 100;

bundle.getApplicationInfo(bundleName, bundleFlags, userId)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getApplicationInfo instead.

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

Obtains the application information of the specified user based on a given bundle name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
userIdnumberYesUser ID. The value must be greater than or equal to 0.
callbackAsyncCallback<ApplicationInfo>YesCallback used to return the application information.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 0;
let userId: number = 100;

bundle.getApplicationInfo(bundleName, bundleFlags, userId, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getApplicationInfo instead.

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

Obtains the application information based on a given bundle name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
callbackAsyncCallback<ApplicationInfo>YesCallback used to return the application information.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 0;

bundle.getApplicationInfo(bundleName, bundleFlags, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAllBundleInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllBundleInfo instead.

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

Obtains the information of all bundles of the specified user. This API uses a promise to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagBundleFlagYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
userIdnumberNoUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<Array<BundleInfo>>Promise used to return the information of all bundles.

Example

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

let bundleFlag: number = 0;
let userId: number = 100;

bundle.getAllBundleInfo(bundleFlag, userId)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getAllBundleInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllBundleInfo instead.

getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array<BundleInfo>>): void

Obtains the information of all bundles of the current user. This API uses an asynchronous callback to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagBundleFlagYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
callbackAsyncCallback<Array<BundleInfo>>YesCallback used to return the information of all bundles.

Example

import bundle from '@ohos.bundle';

let bundleFlag: number = 0;

bundle.getAllBundleInfo(bundleFlag, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAllBundleInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllBundleInfo instead.

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

Obtains the information of all bundles of the specified user. This API uses an asynchronous callback to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagBundleFlagYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
userIdnumberYesUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.
callbackAsyncCallback<Array<BundleInfo>>YesCallback used to return the information of all bundles.

Example

import bundle from '@ohos.bundle';

let bundleFlag: number = 0;
let userId: number = 100;

bundle.getAllBundleInfo(bundleFlag, userId, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getBundleInfodeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.getBundleInfo instead.

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

Obtains the bundle information based on a given bundle name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
optionsBundleOptionsNoOptions that contain the user ID.

Return value

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

Example

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

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 1;
let options: bundle.BundleOptions = {
  "userId": 100
};

bundle.getBundleInfo(bundleName, bundleFlags, options)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getBundleInfodeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.getBundleInfo instead.

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

Obtains the bundle information based on a given bundle name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
callbackAsyncCallback<BundleInfo>YesCallback used to return the bundle information.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 1;

bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getBundleInfodeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.getBundleInfo instead.

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

Obtains the bundle information based on a given bundle name and bundle options. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
optionsBundleOptionsYesIncludes userId.
callbackAsyncCallback<BundleInfo>YesCallback used to return the bundle information.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let bundleFlags: number = 1;
let options: bundle.BundleOptions = {
  "userId": 100
};

bundle.getBundleInfo(bundleName, bundleFlags, options, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAllApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllApplicationInfo instead.

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

Obtains the information about all applications of the specified user. This API uses a promise to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
userIdnumberNoUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<Array<ApplicationInfo>>Promise used to return the application information.

Example

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

let bundleFlags: number = 8;
let userId: number = 100;

bundle.getAllApplicationInfo(bundleFlags, userId)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getAllApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllApplicationInfo instead.

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

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

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
userIdnumberYesUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.
callbackAsyncCallback<Array<ApplicationInfo>>YesCallback used to return the application information.

Example

import bundle from '@ohos.bundle';

let bundleFlags: number = bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
let userId: number = 100;

bundle.getAllApplicationInfo(bundleFlags, userId, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAllApplicationInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAllApplicationInfo instead.

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

Obtains the information about all applications of the current user. This API uses an asynchronous callback to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleFlagsnumberYesType of information that will be returned. For details about the available enumerated values, see the application information flags in BundleFlag.
callbackAsyncCallback<Array<ApplicationInfo>>YesCallback used to return the application information.

Example

import bundle from '@ohos.bundle';

let bundleFlags: number = bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION;

bundle.getAllApplicationInfo(bundleFlags, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getBundleArchiveInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getBundleArchiveInfo instead.

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

Obtains information about the bundles contained in a HAP file. This API uses a promise to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
hapFilePathstringYesPath where the HAP file is stored. The absolute path of the application and the data directory sandbox path are supported.
bundleFlagsnumberYesFlags used to specify information contained in the BundleInfo object that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.

Return value

TypeDescription
Promise<BundleInfo>Promise used to return the information about the bundles.

Example

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

let hapFilePath: string = "/data/storage/el2/base/test.hap";
let bundleFlags: number = 0;

bundle.getBundleArchiveInfo(hapFilePath, bundleFlags)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getBundleArchiveInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getBundleArchiveInfo instead.

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

Obtains information about the bundles contained in a HAP file. This API uses an asynchronous callback to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
hapFilePathstringYesPath where the HAP file is stored. The absolute path of the application and the data directory sandbox path are supported.
bundleFlagsnumberYesFlags used to specify information contained in the BundleInfo object that will be returned. For details about the available enumerated values, see the bundle information flags in BundleFlag.
callbackAsyncCallback<BundleInfo>YesCallback used to return the information about the bundles.

Example

import bundle from '@ohos.bundle';

let hapFilePath: string = "/data/storage/el2/base/test.hap";
let bundleFlags: number = 0;

bundle.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAbilityInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.queryAbilityInfo instead.

getAbilityInfo(bundleName: string, abilityName: string): Promise<AbilityInfo>

Obtains the ability information based on a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.

Return value

TypeDescription
Promise<AbilityInfo>Promise used to return the ability information.

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((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getAbilityInfodeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.queryAbilityInfo instead.

getAbilityInfo(bundleName: string, abilityName: string, callback: AsyncCallback<AbilityInfo>): void

Obtains the ability information based on a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.
callbackAsyncCallback<AbilityInfo>YesCallback used to return the ability information.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityInfo(bundleName, abilityName, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAbilityLabel8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAbilityLabel instead.

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

Obtains the application name based on a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.

Return value

TypeDescription
Promise<string>Promise used to return the application name.

Example

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

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityLabel(bundleName, abilityName)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getAbilityLabel8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getAbilityLabel instead.

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

Obtains the application name based on a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.
callbackAsyncCallback<string>YesCallback used to return the application name.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityLabel(bundleName, abilityName, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.isAbilityEnabled8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.isAbilityEnabled instead.

isAbilityEnabled(info: AbilityInfo): Promise<boolean>

Checks whether the ability that matches a given AbilityInfo object is enabled. This API uses a promise to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
infoAbilityInfoYesAbility information.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. If the ability is enabled, true will be returned; otherwise, false will be returned.

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) => {
  bundle.isAbilityEnabled(abilityInfo).then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })
})

bundle.isAbilityEnabled8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.isAbilityEnabled instead.

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

Checks whether the ability that matches a given AbilityInfo object is enabled. This API uses an asynchronous callback to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
infoAbilityInfoYesAbility information.
callbackAsyncCallback<boolean>YesCallback used to return the result. If the ability is enabled, true will be returned; otherwise, false will be returned.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo) => {
  bundle.isAbilityEnabled(abilityInfo, (err, data) => {
    if (err) {
      console.error('Operation failed. Cause: ' + JSON.stringify(err));
      return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
  })
})

bundle.isApplicationEnabled8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.isApplicationEnabled instead.

isApplicationEnabled(bundleName: string): Promise<boolean>

Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.

Return value

TypeDescription
Promise<boolean>Promise used to return the result. If the application is enabled, true will be returned; otherwise, false will be returned.

Example

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

let bundleName: string = "com.example.myapplication";

bundle.isApplicationEnabled(bundleName)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.isApplicationEnabled8+ deprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to usebundleManager.isApplicationEnabled instead.

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

Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result.

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
callbackAsyncCallback<boolean>YesCallback used to return the result. If the application is enabled, true will be returned; otherwise, false will be returned.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";

bundle.isApplicationEnabled(bundleName, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.queryAbilityByWantdeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.queryAbilityInfo instead.

queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise<Array<AbilityInfo>>

Obtains the ability information based on given Want. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
wantWantYesWant containing the bundle name.
bundleFlagsnumberYesAbility information to be returned. For details about the available enumerated values, see the ability information flags in BundleFlag.
userIdnumberNoUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

Return value

TypeDescription
Promise<Array<AbilityInfo>>Promise used to return the ability information.

Example

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

let bundleFlags: number = 0;
let userId: number = 100;
let want: Want = {
  bundleName: "com.example.myapplication",
  abilityName: "EntryAbility"
};

bundle.queryAbilityByWant(want, bundleFlags, userId)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.queryAbilityByWantdeprecated

This API is deprecated since API version 9.

queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array<AbilityInfo>>): void

Obtains the ability information of the specified user based on given Want. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
wantWantYesWant containing the bundle name.
bundleFlagsnumberYesAbility information to be returned. For details about the available enumerated values, see the ability information flags in BundleFlag.
userIdnumberYesUser ID. The value must be greater than or equal to 0.
callbackAsyncCallback<Array<AbilityInfo>>YesCallback used to return the ability information.

Example

import bundle from '@ohos.bundle';
import Want from '@ohos.app.ability.Want';

let bundleFlags: number = 0;
let userId: number = 100;
let want: Want = {
  bundleName: "com.example.myapplication",
  abilityName: "EntryAbility"
};

bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.queryAbilityByWantdeprecated

This API is deprecated since API version 9.

queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Array<AbilityInfo>>): void

Obtains the ability information based on given Want. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
wantWantYesWant containing the bundle name.
bundleFlagsnumberYesAbility information to be returned. For details about the available enumerated values, see the ability information flags in BundleFlag.
callbackAsyncCallback<Array<AbilityInfo>>YesCallback used to return the ability information.

Example

import bundle from '@ohos.bundle';
import Want from '@ohos.app.ability.Want';

let bundleFlags: number = 0;
let want: Want = {
  bundleName: "com.example.myapplication",
  abilityName: "EntryAbility"
};

bundle.queryAbilityByWant(want, bundleFlags, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getLaunchWantForBundledeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getLaunchWantForBundle instead.

getLaunchWantForBundle(bundleName: string): Promise<Want>

Obtains the Want object that launches the specified application. This API uses a promise to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.

Return value

TypeDescription
Promise<Want>Promise used to return the Want object.

Example

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

let bundleName: string = "com.example.myapplication";

bundle.getLaunchWantForBundle(bundleName)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getLaunchWantForBundledeprecated

This API is deprecated since API version 9. The substitute API is open only to system applications. You are advised to use bundleManager.getLaunchWantForBundle instead.

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

Obtains the Want object that launches the specified application. This API uses an asynchronous callback to return the result.

Required permissions

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
callbackAsyncCallback<Want>YesCallback used to return the Want object.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";

bundle.getLaunchWantForBundle(bundleName, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getNameForUid8+ deprecated

This API is deprecated since API version 9. You are advised to use bundleManager.getBundleNameByUid instead.

getNameForUid(uid: number): Promise<string>

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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
uidnumberYesUID based on which the bundle name is to obtain.

Return value

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

Example

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

let uid: number = 20010005;

bundle.getNameForUid(uid)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getNameForUid8+ deprecated

This API is deprecated since API version 9. You are advised to use bundleManager.getBundleNameByUid instead.

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

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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
uidnumberYesUID based on which the bundle name is to obtain.
callbackAsyncCallback<string>YesCallback used to return the bundle name.

Example

import bundle from '@ohos.bundle';

let uid: number = 20010005;

bundle.getNameForUid(uid, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

bundle.getAbilityIcon8+ deprecated

This API is deprecated since API version 9. You are advised to use resourceManager.getMediaContent instead.

getAbilityIcon(bundleName: string, abilityName: string): Promise<image.PixelMap>

Obtains the PixelMap of the icon corresponding to a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.

Return value

TypeDescription
Promise<image.PixelMap>Promise used to return the pixel map.

Example

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

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityIcon(bundleName, abilityName)
  .then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
  }).catch((error: BusinessError) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
  })

bundle.getAbilityIcon8+ deprecated

This API is deprecated since API version 9. You are advised to use resourceManager.getMediaContent instead.

getAbilityIcon(bundleName: string, abilityName: string, callback: AsyncCallback<image.PixelMap>): void

Obtains the PixelMap of the icon corresponding to a given bundle name and ability name. 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

System capability

SystemCapability.BundleManager.BundleFramework

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name.
abilityNamestringYesAbility name.
callbackAsyncCallback<image.PixelMap>YesCallback used to return the pixel map.

Example

import bundle from '@ohos.bundle';

let bundleName: string = "com.example.myapplication";
let abilityName: string = "EntryAbility";

bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
  if (err) {
    console.error('Operation failed. Cause: ' + JSON.stringify(err));
    return;
  }
  console.info('Operation successful. Data:' + JSON.stringify(data));
})

InstallErrorCodedeprecated

This API is deprecated since API version 9. You are advised to use errorcode-bundle instead.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
SUCCESS0Installation succeeded.
STATUS_INSTALL_FAILURE1Installation failed. (The application to be installed is not found.)
STATUS_INSTALL_FAILURE_ABORTED2Installation aborted.
STATUS_INSTALL_FAILURE_INVALID3Invalid installation parameter.
STATUS_INSTALL_FAILURE_CONFLICT4Installation conflict. (The basic information of the application to update is inconsistent with that of the existing application.)
STATUS_INSTALL_FAILURE_STORAGE5Failed to store the bundle information.
STATUS_INSTALL_FAILURE_INCOMPATIBLE6Installation incompatibility. (A downgrade occurs or the signature information is incorrect.)
STATUS_UNINSTALL_FAILURE7Uninstallation failed. (The application to be uninstalled is not found.)
STATUS_UNINSTALL_FAILURE_BLOCKED8Uninstallation aborted. (This error code is not in use.)
STATUS_UNINSTALL_FAILURE_ABORTED9Uninstallation aborted. (Invalid parameters.)
STATUS_UNINSTALL_FAILURE_CONFLICT10Uninstallation conflict. (Failed to uninstall a system application or end the application process.)
STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT0x0BInstallation failed. (Download timed out.)
STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED0x0CInstallation failed. (Download failed.)
STATUS_RECOVER_FAILURE_INVALID8+0x0DFailed to restore the pre-installed application.
STATUS_ABILITY_NOT_FOUND0x40Ability not found.
STATUS_BMS_SERVICE_ERROR0x41BMS service error.
STATUS_FAILED_NO_SPACE_LEFT8+0x42Insufficient device space.
STATUS_GRANT_REQUEST_PERMISSIONS_FAILED8+0x43Application authorization failed.
STATUS_INSTALL_PERMISSION_DENIED8+0x44No installation permission.
STATUS_UNINSTALL_PERMISSION_DENIED8+0x45No uninstallation permission.

BundleFlagdeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.BundleFlag instead.

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

If an API does not match the flag, the flag is ignored. For example, using GET_ABILITY_INFO_WITH_PERMISSION to obtain the application information does not affect the result.

Flags can be used together. For example, you can use the combination of GET_APPLICATION_INFO_WITH_PERMISSION and GET_APPLICATION_INFO_WITH_DISABLE to obtain the result that contains both application permission information and disabled application information.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
GET_BUNDLE_DEFAULT0x00000000Obtains the default application information.
GET_BUNDLE_WITH_ABILITIES0x00000001Obtains the bundle information with the ability information.
GET_ABILITY_INFO_WITH_PERMISSION0x00000002Obtains the ability information with the permission information.
GET_ABILITY_INFO_WITH_APPLICATION0x00000004Obtains the ability information with the application information.
GET_APPLICATION_INFO_WITH_PERMISSION0x00000008Obtains the application information with the permission information.
GET_BUNDLE_WITH_REQUESTED_PERMISSION0x00000010Obtains the bundle information with the information about the required permissions.
GET_ABILITY_INFO_WITH_METADATA8+0x00000020Obtains the ability metadata information.
GET_APPLICATION_INFO_WITH_METADATA8+0x00000040Obtains the application metadata information.
GET_ABILITY_INFO_SYSTEMAPP_ONLY8+0x00000080Obtains the ability information of system applications.
GET_ABILITY_INFO_WITH_DISABLE8+0x00000100Obtains information about disabled abilities.
GET_APPLICATION_INFO_WITH_DISABLE8+0x00000200Obtains information about disabled applications.
GET_ALL_APPLICATION_INFO0xFFFF0000Obtains all application information.

BundleOptionsdeprecated

This API is deprecated since API version 9. You are not advised using it anymore.

Options that contain the user ID.

System capability: SystemCapability.BundleManager.BundleFramework

NameTypeRead-OnlyOptionalDescription
userIdnumberNoYesUser ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.

AbilityTypedeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.AbilityType instead.

Enumerates the ability types.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
UNKNOWNNoneUnknown ability type.
PAGENoneFA developed using the Page template to provide the capability of interacting with users.
SERVICENonePA developed using the Service template to provide the capability of running tasks in the background.
DATANonePA developed using the Data template to provide unified data access for external systems.

DisplayOrientationdeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.DisplayOrientation instead.

Enumerates display orientations.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
UNSPECIFIEDNoneUnspecified display orientation.
LANDSCAPENoneLandscape orientation.
PORTRAITNonePortrait orientation.
FOLLOW_RECENTNoneOrientation same as that of the nearest ability in the stack.

LaunchModedeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.LaunchType instead.

Enumerates the ability launch modes.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
SINGLETON0The ability has only one instance.
STANDARD1The ability can have multiple instances.

AbilitySubTypedeprecated

This API is deprecated since API version 9. You are not advised using it anymore.

Enumerates the ability subtypes.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
UNSPECIFIED0Undefined ability subtype.
CA1Ability that has a UI.

ColorModedeprecated

This API is deprecated since API version 9. You are not advised using it anymore.

Enumerates the color modes of applications and widgets.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
AUTO_MODE-1Auto mode.
DARK_MODE0Dark mode.
LIGHT_MODE1Light mode.

GrantStatusdeprecated

This API is deprecated since API version 9. You are advised to use bundleManager.PermissionGrantState instead.

Enumerates the permission grant states.

System capability: SystemCapability.BundleManager.BundleFramework

NameValueDescription
PERMISSION_DENIED-1Permission denied.
PERMISSION_GRANTED0Permission granted.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

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