1# @ohos.bundle.bundleResourceManager (bundleResourceManager) 2 3The **bundleResourceManager** module provides APIs for obtaining resource information, including [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md) and [LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.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## Modules to Import 10 11```ts 12import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 13``` 14 15## Required Permissions 16 17| Permission | APL | Description | 18| ------------------------------------------ | ------------ | ------------------| 19|ohos.permission.GET_BUNDLE_RESOURCES| system_basic | Allows an application to obtain resource information of another application.| 20| ohos.permission.GET_INSTALLED_BUNDLE_LIST | system_basic | Allows an application to read the list of installed applications.| 21 22For details, see [Permission APL](../../security/AccessToken/app-permission-mgmt-overview.md#permission-apl). 23 24## Enums 25 26### ResourceFlag 27 28Enumerates the resource information flags, which indicate the type of resource information to obtain. 29 30**System API**: This is a system API. 31 32 **System capability**: SystemCapability.BundleManager.BundleFramework.Resource 33 34| Name | Value | Description | 35| ----------------------------------------- | ---------- | ------------------------------------------------------------ | 36| GET_RESOURCE_INFO_ALL | 0x00000001 | Both the application icon and label are obtained.| 37| GET_RESOURCE_INFO_WITH_LABEL | 0x00000002 | Only the application label is obtained.| 38| GET_RESOURCE_INFO_WITH_ICON | 0x00000004 | Only the application icon is obtained.| 39| 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**.| 40 41 42## APIs 43 44### bundleResourceManager.getBundleResourceInfo 45 46getBundleResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md) 47 48Obtains the resource information of an application based on the given bundle name and resource flags. This API returns the result synchronously. 49 50**System API**: This is a system API. 51 52**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 53 54**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 55 56**Parameters** 57 58| Name | Type | Mandatory| Description | 59| ----------- | ------ | ---- | --------------------- | 60| bundleName | string | Yes | Bundle name of the application.| 61| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 62 63**Return value** 64 65| Type | Description | 66| ----------------------------------------------------------- | ------------------------------------- | 67| [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md) | Resource information of the application obtained.| 68 69 70**Error codes** 71 72For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 73 74| ID| Error Message | 75| -------- | ------------------------------------- | 76| 17700001 | The specified bundleName is not found. | 77 78 79**Example** 80 81```ts 82import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 83import { BusinessError } from '@ohos.base'; 84import hilog from '@ohos.hilog'; 85let bundleName = "com.example.myapplication"; 86let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 87try { 88 let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags); 89 hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label)); 90} catch (err) { 91 let message = (err as BusinessError).message; 92 hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message); 93} 94``` 95 96### bundleResourceManager.getLauncherAbilityResourceInfo 97 98getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.md)> 99 100Obtains 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. 101 102**System API**: This is a system API. 103 104**Required permissions**: ohos.permission.GET_BUNDLE_RESOURCES 105 106**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 107 108**Parameters** 109 110| Name | Type | Mandatory| Description | 111| ----------- | ------ | ---- | --------------------- | 112| bundleName | string | Yes | Bundle name of the application.| 113| resourceFlags | [number](#resourceflag) | No | Type of the resource information to obtain.| 114 115**Return value** 116 117| Type | Description | 118| ----------------------------------------------------------- | ------------------------------------- | 119| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.md)> | Resource information of the entry ability obtained.| 120 121**Error codes** 122 123For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 124 125| ID| Error Message | 126| -------- | ------------------------------------- | 127| 17700001 | The specified bundleName is not found. | 128 129 130**Example** 131 132```ts 133import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 134import { BusinessError } from '@ohos.base'; 135import hilog from '@ohos.hilog'; 136let bundleName = "com.example.myapplication"; 137let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 138try { 139 let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, bundleFlags); 140 hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo[0].label)); 141} catch (err) { 142 let message = (err as BusinessError).message; 143 hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message); 144} 145``` 146 147### bundleResourceManager.getAllBundleResourceInfo 148 149getAllBundleResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md)>>): void 150 151Obtains resource information of all applications based on the given resource flags. This API uses an asynchronous callback to return the result. 152 153**System API**: This is a system API. 154 155**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 156 157**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 158 159**Parameters** 160 161| Name | Type | Mandatory| Description | 162| ----------- | ------ | ---- | --------------------- | 163| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 164| callback | AsyncCallback\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.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.| 165 166**Example** 167 168```ts 169import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 170import { BusinessError } from '@ohos.base'; 171import hilog from '@ohos.hilog'; 172let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 173try { 174 bundleResourceManager.getAllBundleResourceInfo(bundleFlags, (err, data) => { 175 if (err) { 176 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message); 177 return; 178 } 179 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 180 }); 181} catch (err) { 182 let message = (err as BusinessError).message; 183 hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message); 184} 185``` 186 187### bundleResourceManager.getAllBundleResourceInfo 188 189getAllBundleResourceInfo(resourceFlags: [number](#resourceflag)): Promise<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md)>>; 190 191Obtains resource information of all applications based on the given resource flags. This API uses a promise to return the result. 192 193**System API**: This is a system API. 194 195**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 196 197**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 198 199**Parameters** 200 201| Name | Type | Mandatory| Description | 202| ----------- | ------ | ---- | --------------------- | 203| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 204 205**Return value** 206 207| Type | Description | 208| ------------------------------------------------------------ | -------------------------------- | 209| Promise\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo.md)>> | Promise used to return the resource information of the application obtained.| 210 211**Example** 212 213```ts 214import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 215import { BusinessError } from '@ohos.base'; 216import hilog from '@ohos.hilog'; 217let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 218try { 219 bundleResourceManager.getAllBundleResourceInfo(bundleFlags).then(data=> { 220 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 221 }).catch((err: BusinessError) => { 222 hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message); 223 }) 224} catch (err) { 225 let message = (err as BusinessError).message; 226 hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message); 227} 228``` 229 230### bundleResourceManager.getAllLauncherAbilityResourceInfo 231 232getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.md)>>): void 233 234Obtains 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. 235 236**System API**: This is a system API. 237 238**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 239 240**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 241 242**Parameters** 243 244| Name | Type | Mandatory| Description | 245| ----------- | ------ | ---- | --------------------- | 246| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 247| callback | AsyncCallback\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.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.| 248 249 250**Example** 251 252```ts 253import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 254import { BusinessError } from '@ohos.base'; 255import hilog from '@ohos.hilog'; 256let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 257try { 258 bundleResourceManager.getAllLauncherAbilityResourceInfo(bundleFlags, (err, data) => { 259 if (err) { 260 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message); 261 return; 262 } 263 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 264 }); 265} catch (err) { 266 let message = (err as BusinessError).message; 267 hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message); 268} 269``` 270 271### bundleResourceManager.getAllLauncherAbilityResourceInfo 272 273getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag)) : Promise<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.md)>> 274 275Obtains resource information of the entry abilities of all applications based on the given resource flags. This API uses a promise to return the result. 276 277**System API**: This is a system API. 278 279**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST and ohos.permission.GET_BUNDLE_RESOURCES 280 281**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 282 283**Parameters** 284 285| Name | Type | Mandatory| Description | 286| ----------- | ------ | ---- | --------------------- | 287| resourceFlags | [number](#resourceflag) | Yes | Type of the resource information to obtain.| 288 289**Return value** 290 291| Type | Description | 292| ------------------------------------------------------------ | -------------------------------- | 293| Promise\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo.md)>> | Promise used to return the resource information of the entry abilities obtained.| 294 295**Example** 296```ts 297import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; 298import { BusinessError } from '@ohos.base'; 299import hilog from '@ohos.hilog'; 300let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL; 301try { 302 bundleResourceManager.getAllLauncherAbilityResourceInfo(bundleFlags).then(data=> { 303 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length)); 304 }).catch((err: BusinessError) => { 305 hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message); 306 }) 307} catch (err) { 308 let message = (err as BusinessError).message; 309 hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message); 310} 311``` 312