1# @ohos.bundle.bundleResourceManager (bundleResourceManager) (System API) 2 3The **bundleResourceManager** module provides APIs for obtaining resource information, including [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) and [LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md). 4 5> **NOTE** 6> 7> 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. 8> 9> Since API version 12, this module supports query of icons and names of disabled applications and applications installed by all users. 10> 11> The APIs provided by this module are system APIs. 12 13## Modules to Import 14 15```ts 16import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 17``` 18 19## Required Permissions 20 21| Permission | APL | Description | 22| ------------------------------------------ | ------------ | ------------------| 23| ohos.permission.GET_BUNDLE_RESOURCES| system_basic | Allows an application to obtain resource information of another application.| 24| ohos.permission.GET_INSTALLED_BUNDLE_LIST | system_basic | Allows an application to read the list of installed applications.| 25 26For details about the APL, see [Basic Concepts in the Permission Mechanism](../../security/AccessToken/app-permission-mgmt-overview.md#basic-concepts-in-the-permission-mechanism). 27 28## Enums 29 30### ResourceFlag 31 32Enumerates the resource information flags, which indicate the type of resource information to obtain. 33 34**System API**: This is a system API. 35 36 **System capability**: SystemCapability.BundleManager.BundleFramework.Resource 37 38| Name | Value | Description | 39| ----------------------------------------- | ---------- | ------------------------------------------------------------ | 40| GET_RESOURCE_INFO_ALL | 0x00000001 | Both the application icon and label are obtained.| 41| GET_RESOURCE_INFO_WITH_LABEL | 0x00000002 | Only the application label is obtained.| 42| GET_RESOURCE_INFO_WITH_ICON | 0x00000004 | Only the application icon is obtained.| 43| 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**.| 44| GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR<sup>12+</sup>| 0x00000010 | The [drawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor-sys.md) object of the application icon is obtained.| 45 46 47## APIs 48 49### bundleResourceManager.getBundleResourceInfo 50 51getBundleResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) 52 53Obtains the resource information of an application based on the given bundle name and resource flags. This API returns the result synchronously. 54 55**System API**: This is a system API. 56 57**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 58 59**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 60 61**Parameters** 62 63| Name | Type | Mandatory| Description | 64| ----------- | ------ | ---- | --------------------- | 65| bundleName | string | Yes | Bundle name of the application.| 66| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 67 68**Return value** 69 70| Type | Description | 71| ----------------------------------------------------------- | ------------------------------------- | 72| [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) | Resource information of the application obtained.| 73 74 75**Error codes** 76 77For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 78 79| ID| Error Message | 80| -------- | ------------------------------------- | 81| 201 | Permission denied. | 82| 202 | Permission denied, non-system app called system api. | 83| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 84| 17700001 | The specified bundleName is not found. | 85 86 87**Example** 88 89```ts 90import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 91import { BusinessError } from '@ohos.base'; 92import hilog from '@ohos.hilog'; 93let bundleName = "com.example.myapplication"; 94let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 95try { 96 let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 97 hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 98} catch (err) { 99 let message = (err as BusinessError).message; 100 hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message); 101} 102``` 103 104### bundleResourceManager.getLauncherAbilityResourceInfo 105 106getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> 107 108Obtains 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. 109 110**System API**: This is a system API. 111 112**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 113 114**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 115 116**Parameters** 117 118| Name | Type | Mandatory| Description | 119| ----------- | ------ | ---- | --------------------- | 120| bundleName | string | Yes | Bundle name of the application.| 121| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 122 123**Return value** 124 125| Type | Description | 126| ----------------------------------------------------------- | ------------------------------------- | 127| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> | Resource information of the entry ability obtained.| 128 129**Error codes** 130 131For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 132 133| ID| Error Message | 134| -------- | ------------------------------------- | 135| 201 | Permission denied. | 136| 202 | Permission denied, non-system app called system api. | 137| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 138| 17700001 | The specified bundleName is not found. | 139 140 141**Example** 142 143```ts 144import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 145import { BusinessError } from '@ohos.base'; 146import hilog from '@ohos.hilog'; 147let bundleName = "com.example.myapplication"; 148let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 149try { 150 let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, bundleFlags); 151 hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo[0].label)); 152} catch (err) { 153 let message = (err as BusinessError).message; 154 hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message); 155} 156``` 157 158### bundleResourceManager.getAllBundleResourceInfo 159 160getAllBundleResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>>): void 161 162Obtains resource information of all applications based on the given resource flags. This API uses an asynchronous callback to return the result. 163 164**System API**: This is a system API. 165 166**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 167 168**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 169 170**Parameters** 171 172| Name | Type | Mandatory| Description | 173| ----------- | ------ | ---- | --------------------- | 174| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 175| callback | AsyncCallback\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the resource information of the application obtained. Otherwise, **err** is an error object.| 176 177**Error codes** 178 179For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 180 181| ID| Error Message | 182| -------- | ------------------------------------- | 183| 201 | Permission denied. | 184| 202 | Permission denied, non-system app called system api. | 185| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 186 187**Example** 188 189```ts 190import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 191import { BusinessError } from '@ohos.base'; 192import hilog from '@ohos.hilog'; 193let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 194try { 195 bundleResourceManager.getAllBundleResourceInfo(bundleFlags, (err, data) => { 196 if (err) { 197 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message); 198 return; 199 } 200 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 201 }); 202} catch (err) { 203 let message = (err as BusinessError).message; 204 hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message); 205} 206``` 207 208### bundleResourceManager.getAllBundleResourceInfo 209 210getAllBundleResourceInfo(resourceFlags: [number](#resourceflag)): Promise<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>>; 211 212Obtains resource information of all applications based on the given resource flags. This API uses a promise to return the result. 213 214**System API**: This is a system API. 215 216**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 217 218**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 219 220**Parameters** 221 222| Name | Type | Mandatory| Description | 223| ----------- | ------ | ---- | --------------------- | 224| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 225 226**Return value** 227 228| Type | Description | 229| ------------------------------------------------------------ | -------------------------------- | 230| Promise\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>> | Promise used to return the resource information of the application obtained.| 231 232**Error codes** 233 234For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 235 236| ID| Error Message | 237| -------- | ------------------------------------- | 238| 201 | Permission denied. | 239| 202 | Permission denied, non-system app called system api. | 240| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 241 242**Example** 243 244```ts 245import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 246import { BusinessError } from '@ohos.base'; 247import hilog from '@ohos.hilog'; 248let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 249try { 250 bundleResourceManager.getAllBundleResourceInfo(bundleFlags).then(data=> { 251 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 252 }).catch((err: BusinessError) => { 253 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message); 254 }) 255} catch (err) { 256 let message = (err as BusinessError).message; 257 hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message); 258} 259``` 260 261### bundleResourceManager.getAllLauncherAbilityResourceInfo 262 263getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>>): void 264 265Obtains resource information of the entry abilities of all applications based on the given resource flags. This API uses an asynchronous callback to return the result. 266 267**System API**: This is a system API. 268 269**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 270 271**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 272 273**Parameters** 274 275| Name | Type | Mandatory| Description | 276| ----------- | ------ | ---- | --------------------- | 277| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 278| callback | AsyncCallback\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the resource information of the entry abilities obtained. Otherwise, **err** is an error object.| 279 280**Error codes** 281 282For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 283 284| ID| Error Message | 285| -------- | ------------------------------------- | 286| 201 | Permission denied. | 287| 202 | Permission denied, non-system app called system api. | 288| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 289 290**Example** 291 292```ts 293import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 294import { BusinessError } from '@ohos.base'; 295import hilog from '@ohos.hilog'; 296let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 297try { 298 bundleResourceManager.getAllLauncherAbilityResourceInfo(bundleFlags, (err, data) => { 299 if (err) { 300 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message); 301 return; 302 } 303 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 304 }); 305} catch (err) { 306 let message = (err as BusinessError).message; 307 hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message); 308} 309``` 310 311### bundleResourceManager.getAllLauncherAbilityResourceInfo 312 313getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag)) : Promise<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>> 314 315Obtains resource information of the entry abilities of all applications based on the given resource flags. This API uses a promise to return the result. 316 317**System API**: This is a system API. 318 319**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 320 321**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 322 323**Parameters** 324 325| Name | Type | Mandatory| Description | 326| ----------- | ------ | ---- | --------------------- | 327| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 328 329**Return value** 330 331| Type | Description | 332| ------------------------------------------------------------ | -------------------------------- | 333| Promise\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>> | Promise used to return the resource information of the entry abilities obtained.| 334 335**Error codes** 336 337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 338 339| ID| Error Message | 340| -------- | ------------------------------------- | 341| 201 | Permission denied. | 342| 202 | Permission denied, non-system app called system api. | 343| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 344 345**Example** 346```ts 347import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 348import { BusinessError } from '@ohos.base'; 349import hilog from '@ohos.hilog'; 350let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 351try { 352 bundleResourceManager.getAllLauncherAbilityResourceInfo(bundleFlags).then(data=> { 353 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 354 }).catch((err: BusinessError) => { 355 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message); 356 }) 357} catch (err) { 358 let message = (err as BusinessError).message; 359 hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message); 360} 361``` 362 363### bundleResourceManager.getBundleResourceInfo<sup>12+</sup> 364 365getBundleResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag), appIndex?: number): [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) 366 367Obtains the resource information of an application based on the given bundle name, resource flags, and app index. This API returns the result synchronously. 368 369**System API**: This is a system API. 370 371**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 372 373**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 374 375**Parameters** 376 377| Name | Type | Mandatory| Description | 378| ----------- | ------ | ---- | --------------------- | 379| bundleName | string | Yes | Bundle name of the application.| 380| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 381| appIndex | number | No | Index of the application clone.| 382 383**Return value** 384 385| Type | Description | 386| ----------------------------------------------------------- | ------------------------------------- | 387| [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) | Resource information of the application obtained.| 388 389 390**Error codes** 391 392For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 393 394| ID| Error Message | 395| -------- | ------------------------------------- | 396| 201 | Permission denied. | 397| 202 | Permission denied, non-system app called system api. | 398| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 399| 17700001 | The specified bundleName is not found. | 400| 17700061 | AppIndex not in valid range or not found. | 401 402 403**Example** 404 405```ts 406import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 407import { BusinessError } from '@ohos.base'; 408import hilog from '@ohos.hilog'; 409let bundleName = "com.example.myapplication"; 410let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 411let appIndex = 1; 412try { 413 let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags, appIndex); 414 hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 415} catch (err) { 416 let message = (err as BusinessError).message; 417 hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message); 418} 419``` 420 421### bundleResourceManager.getLauncherAbilityResourceInfo<sup>12+</sup> 422 423getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag), appIndex?: number): Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> 424 425Obtains 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. 426 427**System API**: This is a system API. 428 429**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 430 431**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 432 433**Parameters** 434 435| Name | Type | Mandatory| Description | 436| ----------- | ------ | ---- | --------------------- | 437| bundleName | string | Yes | Bundle name of the application.| 438| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 439| appIndex | number | No | Index of the application clone.| 440 441**Return value** 442 443| Type | Description | 444| ----------------------------------------------------------- | ------------------------------------- | 445| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> | Resource information of the entry ability obtained.| 446 447**Error codes** 448 449For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 450 451| ID| Error Message | 452| -------- | ------------------------------------- | 453| 201 | Permission denied. | 454| 202 | Permission denied, non-system app called system api. | 455| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 456| 17700001 | The specified bundleName is not found. | 457| 17700061 | AppIndex not in valid range or not found. | 458 459**Example** 460 461```ts 462import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 463import { BusinessError } from '@ohos.base'; 464import hilog from '@ohos.hilog'; 465let bundleName = "com.example.myapplication"; 466let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 467let appIndex = 1; 468try { 469 let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, bundleFlags, appIndex); 470 hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo[0].label)); 471} catch (err) { 472 let message = (err as BusinessError).message; 473 hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message); 474} 475``` 476