@ohos.bundle.bundleResourceManager (bundleResourceManager Module) (System API)

The module provides APIs for obtaining resource information, including BundleResourceInfo and LauncherAbilityResourceInfo.

NOTE

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

Starting from API version 12, this module supports query of icons and names of disabled applications and applications installed by all users.

The APIs provided by this module are system APIs.

Modules to Import

import { bundleResourceManager } from '@kit.AbilityKit';

Enums

ResourceFlag

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

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Name Value Description
GET_RESOURCE_INFO_ALL 0x00000001 Both the application icon and label are obtained.
GET_RESOURCE_INFO_WITH_LABEL 0x00000002 Only the application label is obtained.
GET_RESOURCE_INFO_WITH_ICON 0x00000004 Only the application icon is obtained.
GET_RESOURCE_INFO_WITH_SORTED_BY_LABEL 0x00000008 The obtained information is sorted by label. It must be used together with GET_RESOURCE_INFO_ALL or GET_RESOURCE_INFO_WITH_LABEL.
GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR12+ 0x00000010 The drawableDescriptor object of the application icon is obtained.
GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY20+ 0x00000020 The resource information about abilities that show icons only on the home screen is obtained. It is valid only in the getLauncherAbilityResourceInfo and getAllLauncherAbilityResourceInfo APIs.

APIs

bundleResourceManager.getBundleResourceInfo

getBundleResourceInfo(bundleName: string, resourceFlags?: number): BundleResourceInfo

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

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

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

Return value

Type Description
BundleResourceInfo Resource information of the application obtained.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001 The specified bundleName is not found.

Example

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

let bundleName = "com.example.myapplication";
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, resourceFlag);
  hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s',
    JSON.stringify(resourceInfo.label));
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getLauncherAbilityResourceInfo

getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: number): Array<LauncherAbilityResourceInfo>

Obtains the bundle information of the entry ability of an application based on the given bundle name and resource flags. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
resourceFlags number No Type of the resource information to obtain. The default value is ResourceFlag.GET_RESOURCE_INFO_ALL.

Return value

Type Description
Array<LauncherAbilityResourceInfo> Resource information of the entry ability obtained.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001 The specified bundleName is not found.

Example

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

let bundleName = "com.example.myapplication";
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, resourceFlag);
  hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s',
    JSON.stringify(resourceInfo[0].label));
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getAllBundleResourceInfo

getAllBundleResourceInfo(resourceFlags: number, callback: AsyncCallback<Array<BundleResourceInfo>>): void

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

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
resourceFlags number Yes Type of the resource information to obtain.
callback AsyncCallback<Array<BundleResourceInfo>> Yes Callback used to return the result. If the information is successfully obtained, err is null and data is a BundleResourceInfo array. Otherwise, err is an error object.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

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

let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getAllBundleResourceInfo(resourceFlag, (err, data) => {
    if (err) {
      hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message);
      return;
    }
    hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  });
} catch (err) {
  let message = (err as BusinessError).message;
}

bundleResourceManager.getAllBundleResourceInfo

getAllBundleResourceInfo(resourceFlags: number): Promise<Array<BundleResourceInfo>>;

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

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
resourceFlags number Yes Type of the resource information to obtain.

Return value

Type Description
Promise<Array<BundleResourceInfo>> Promise used to return the BundleResourceInfo array.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

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

let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getAllBundleResourceInfo(resourceFlag).then(data => {
    hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message);
  })
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getAllLauncherAbilityResourceInfo

getAllLauncherAbilityResourceInfo(resourceFlags: number, callback: AsyncCallback<Array<LauncherAbilityResourceInfo>>): void

Obtains the resource information of the entry abilities of the current application based on the given resource flags. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
resourceFlags number Yes Type of the resource information to obtain.
callback AsyncCallback<Array<LauncherAbilityResourceInfo>> Yes Callback used to return the result. If the information is successfully obtained, err is null and data is a LauncherAbilityResourceInfo array. Otherwise, err is an error object.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

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

let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getAllLauncherAbilityResourceInfo(resourceFlag, (err, data) => {
    if (err) {
      hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message);
      return;
    }
    hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  });
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getAllLauncherAbilityResourceInfo

getAllLauncherAbilityResourceInfo(resourceFlags: number): Promise<Array<LauncherAbilityResourceInfo>>

Obtains the resource information of the entry abilities of the current application based on the given resource flags. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
resourceFlags number Yes Type of the resource information to obtain.

Return value

Type Description
Promise<Array<LauncherAbilityResourceInfo>> Promise used to return the LauncherAbilityResourceInfo array.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.

Example

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

let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getAllLauncherAbilityResourceInfo(resourceFlag).then(data => {
    hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message);
  })
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getBundleResourceInfo12+

getBundleResourceInfo(bundleName: string, resourceFlags?: number, appIndex?: number): BundleResourceInfo

Obtains the resource information of an application based on the given bundle name, resource flags, and app index. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
resourceFlags number No Type of the resource information to obtain.
appIndex number No Index of the application clone. The default value is 0.

Return value

Type Description
BundleResourceInfo Resource information of the application obtained.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001 The specified bundleName is not found.
17700061 AppIndex not in valid range or not found.

Example

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

let bundleName = "com.example.myapplication";
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
let appIndex = 1;
try {
  let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, resourceFlag, appIndex);
  hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s',
    JSON.stringify(resourceInfo.label));
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getLauncherAbilityResourceInfo12+

getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: number, appIndex?: number): Array<LauncherAbilityResourceInfo>

Obtains the launcher ability resource information of an application based on the given bundle name, resource flags, and app index. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
resourceFlags number No Type of the resource information to obtain. The default value is ResourceFlag.GET_RESOURCE_INFO_ALL.
appIndex number No Index of the application clone. The default value is 0.

Return value

Type Description
Array<LauncherAbilityResourceInfo> Resource information of the entry ability obtained.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
401 Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.
17700001 The specified bundleName is not found.
17700061 AppIndex not in valid range or not found.

Example

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

let bundleName = "com.example.myapplication";
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
let appIndex = 1;
try {
  let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, resourceFlag, appIndex);
  hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s',
    JSON.stringify(resourceInfo[0].label));
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getExtensionAbilityResourceInfo20+

getExtensionAbilityResourceInfo(bundleName: string, extensionAbilityType: bundleManager.ExtensionAbilityType, resourceFlags: number, appIndex?: number): Array<LauncherAbilityResourceInfo>

Obtains the ExtensionAbility resource information of an application based on the bundle name, ExtensionAbility type, resource flags, and clone ID. This API returns the result synchronously.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
bundleName string Yes Bundle name of the application.
extensionAbilityType bundleManager.ExtensionAbilityType Yes ExtensionAbility type. Only ExtensionAbilityType.INPUT_METHOD, ExtensionAbilityType.SHARE and ExtensionAbilityType.ACTION are supported.
resourceFlags number Yes Resource information flags, which indicate the type of resource information to obtain.
appIndex number No ID of the application clone. The default value is 0. The value ranges from 0 to 5. The value 0 indicates the main application.

Return value

Type Description
Array<LauncherAbilityResourceInfo> ExtensionAbility resource information of the application, including the icon and name.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.
17700001 The specified bundleName is not found.
17700061 AppIndex not in valid range or not found.

Example

import { bundleManager, bundleResourceManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

let bundleName = "com.example.myapplication";
let extensionAbilityType = bundleManager.ExtensionAbilityType.INPUT_METHOD;
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  let resourceInfo =
    bundleResourceManager.getExtensionAbilityResourceInfo(bundleName, extensionAbilityType, resourceFlag);
  console.info('getExtensionAbilityResourceInfo successfully. Data label: ' + JSON.stringify(resourceInfo[0].label));
} catch (err) {
  let message = (err as BusinessError).message;
  let code = (err as BusinessError).code;
  console.error(`getExtensionAbilityResourceInfo failed, err code:${code}, err msg: ${message}`);
}

bundleResourceManager.getAllUninstalledBundleResourceInfo21+

getAllUninstalledBundleResourceInfo(resourceFlags: number): Promise<Array<BundleResourceInfo>>

Obtains the bundle resource information of all uninstalled applications that have retained data based on the given resource flags. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
resourceFlags number Yes Type of the resource information to obtain. For details, see ResourceFlag.

Return value

Type Description
Promise<Array<BundleResourceInfo>> Promise used to return the BundleResourceInfo array.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied, non-system app called system api.

Example

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

let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getAllUninstalledBundleResourceInfo(resourceFlag).then(data => {
    hilog.info(0x0000, 'testTag', 'getAllUninstalledBundleResourceInfo successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', 'getAllUninstalledBundleResourceInfo failed. err: %{public}s', err.message);
  })
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getAllUninstalledBundleResourceInfo failed: %{public}s', message);
}

bundleResourceManager.getLauncherAbilityResourceInfoList23+

getLauncherAbilityResourceInfoList(optionsList: Array<BundleOptions>, resourceFlags: number): Promise<Array<LauncherAbilityResourceInfo>>

Obtains the launcher ability resource information of each application corresponding to the BundleOptions element in optionsList. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Parameters

Name Type Mandatory Description
optionsList Array<BundleOptions> Yes Parameters of the applications to query.
bundleName, moduleName, and abilityName are mandatory parameters.
Value range of appIndex: [0, 5]. The default value is 0 if not specified.
userId is an invalid parameter. It does not need to be passed, and will not take effect if passed.
resourceFlags number Yes Resource information flags, which indicate the type of resource information to obtain. The value is an enumerated value of ResourceFlag, excluding ResourceFlag.GET_RESOURCE_INFO_WITH_SORTED_BY_LABEL and ResourceFlag.GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY.

Return value

Type Description
Promise<Array<LauncherAbilityResourceInfo>> Promise used to return the launcher ability resource information of the specified application list.

Error codes

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

ID Error Message
201 Permission denied.
202 Permission denied. A non-system application is not allowed to call a system API.
801 Capability not supported.
17700001 The specified bundle is not found.
17700002 The specified module is not found.
17700003 The specified ability is not found.
17700061 The specified app index is invalid.

Example

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

// Replace the application information with the actual one.
let option: bundleManager.BundleOptions = {
  bundleName: 'com.example.demo',
  moduleName: 'entry',
  abilityName: 'EntryAbility',
  appIndex: 0
};

let optionsList: Array<bundleManager.BundleOptions> = [];
optionsList.push(option);
let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
try {
  bundleResourceManager.getLauncherAbilityResourceInfoList(optionsList, resourceFlag).then(data => {
    hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfoList successfully. Data length: %{public}s',
      JSON.stringify(data.length));
  }).catch((err: BusinessError) => {
    hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfoList failed. err: %{public}s', err.message);
  })
} catch (err) {
  let message = (err as BusinessError).message;
  hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfoList failed: %{public}s', message);
}

BundleResourceInfo

type BundleResourceInfo = _BundleResourceInfo

Defines the icon and name of an application.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Type Description
_BundleResourceInfo Icon and name of the application.

LauncherAbilityResourceInfo

type LauncherAbilityResourceInfo = _LauncherAbilityResourceInfo

Defines the entry icon and name of an application.

System API: This is a system API.

System capability: SystemCapability.BundleManager.BundleFramework.Resource

Type Description
_LauncherAbilityResourceInfo Defines the entry icon and name of an application.