• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.bundleResourceManager (bundleResourceManager模块)(系统接口)
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9本模块提供应用资源数据查询能力,支持[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)和[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)等信息的查询。
10
11> **说明:**
12>
13> 本模块首批接口从API version 11 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14>
15> 本模块从API version 12 开始支持查询被禁用应用和设备上已安装应用(不区用户)的图标和名称资源。
16>
17> 本模块为系统接口。
18
19## 导入模块
20
21```ts
22import { bundleResourceManager } from '@kit.AbilityKit';
23```
24
25## 枚举
26
27### ResourceFlag
28
29资源信息标志,指示需要获取的资源信息的内容。
30
31**系统接口:** 此接口为系统接口。
32
33**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource34
35| 名称                                                     | 值         | 说明                                                         |
36| -------------------------------------------------------- | ---------- | ------------------------------------------------------------ |
37| GET_RESOURCE_INFO_ALL                                    | 0x00000001 | 用于同时获取icon和label信息。                                |
38| GET_RESOURCE_INFO_WITH_LABEL                             | 0x00000002 | 用于获取仅包含label信息,icon信息为空。                      |
39| GET_RESOURCE_INFO_WITH_ICON                              | 0x00000004 | 用于获取仅包含icon信息,label信息为空。                      |
40| GET_RESOURCE_INFO_WITH_SORTED_BY_LABEL                   | 0x00000008 | 用于获取根据label排序后的信息。它不能单独使用需要与GET_RESOURCE_INFO_ALL 或 GET_RESOURCE_INFO_WITH_LABEL一起使用。 |
41| GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR<sup>12+</sup> | 0x00000010 | 用于获取应用图标的[drawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor-sys.md)对象。 |
42| GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY<sup>20+</sup>   | 0x00000020 | 用于获取仅在桌面上展示图标的Ability资源,它仅在[getLauncherAbilityResourceInfo](#bundleresourcemanagergetlauncherabilityresourceinfo)和[getAllLauncherAbilityResourceInfo](#bundleresourcemanagergetalllauncherabilityresourceinfo)接口中生效。 |
43
44
45## 接口
46
47### bundleResourceManager.getBundleResourceInfo
48
49getBundleResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)
50
51以同步方法根据给定的bundleName和resourceFlags获取当前应用的BundleResourceInfo。
52
53**系统接口:** 此接口为系统接口。
54
55**需要权限:** ohos.permission.GET_BUNDLE_RESOURCES
56
57**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
58
59**参数:**
60
61| 参数名     | 类型   | 必填 | 说明                |
62| ----------- | ------ | ---- | --------------------- |
63| bundleName | string | 是   | 指定查询应用的包名。 |
64| resourceFlags | [number](#resourceflag) | 否   | 指定返回的BundleResourceInfo所包含的信息。 |
65
66**返回值:**
67
68| 类型                                                        | 说明                                  |
69| ----------------------------------------------------------- | ------------------------------------- |
70| [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) | 返回指定应用的BundleResourceInfo。|
71
72
73**错误码:**
74
75以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
76
77| 错误码ID | 错误信息                              |
78| -------- | ------------------------------------- |
79| 201 | Permission denied. |
80| 202 | Permission denied, non-system app called system api. |
81| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
82| 17700001 | The specified bundleName is not found. |
83
84
85**示例:**
86
87```ts
88import { bundleResourceManager } from '@kit.AbilityKit';
89import { BusinessError } from '@ohos.base';
90import hilog from '@ohos.hilog';
91let bundleName = "com.example.myapplication";
92let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
93try {
94    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, resourceFlag);
95    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
96} catch (err) {
97    let message = (err as BusinessError).message;
98    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
99}
100```
101
102### bundleResourceManager.getLauncherAbilityResourceInfo
103
104getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag)): Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>
105
106以同步方法根据给定的bundleName和resourceFlags获取当前应用的LauncherAbilityResourceInfo。
107
108**系统接口:** 此接口为系统接口。
109
110**需要权限:** ohos.permission.GET_BUNDLE_RESOURCES
111
112**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
113
114**参数:**
115
116| 参数名     | 类型   | 必填 | 说明                |
117| ----------- | ------ | ---- | --------------------- |
118| bundleName | string | 是   | 指定查询应用的包名。 |
119| resourceFlags | [number](#resourceflag) | 否   | 指定返回的LauncherAbilityResourceInfo所包含的信息,默认值为[ResourceFlag](#resourceflag).GET_RESOURCE_INFO_ALL。 |
120
121**返回值:**
122
123| 类型                                                        | 说明                                  |
124| ----------------------------------------------------------- | ------------------------------------- |
125| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> | 返回指定应用的LauncherAbilityResourceInfo。|
126
127**错误码:**
128
129以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
130
131| 错误码ID | 错误信息                              |
132| -------- | ------------------------------------- |
133| 201 | Permission denied. |
134| 202 | Permission denied, non-system app called system api. |
135| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
136| 17700001 | The specified bundleName is not found. |
137
138
139**示例:**
140
141```ts
142import { bundleResourceManager } from '@kit.AbilityKit';
143import { BusinessError } from '@ohos.base';
144import hilog from '@ohos.hilog';
145let bundleName = "com.example.myapplication";
146let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
147try {
148    let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, resourceFlag);
149    hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo[0].label));
150} catch (err) {
151    let message = (err as BusinessError).message;
152    hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message);
153}
154```
155
156### bundleResourceManager.getAllBundleResourceInfo
157
158getAllBundleResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>>): void
159
160根据给定的resourceFlags获取所有应用的BundleResourceInfo。使用callback异步回调。
161
162**系统接口:** 此接口为系统接口。
163
164**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LISTohos.permission.GET_BUNDLE_RESOURCES
165
166**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
167
168**参数:**
169
170| 参数名     | 类型   | 必填 | 说明                |
171| ----------- | ------ | ---- | --------------------- |
172| resourceFlags | [number](#resourceflag) | 是   | 指定返回的BundleResourceInfo所包含的信息。 |
173| callback | AsyncCallback\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),当获取成功时,err为null,data为获取到的BundleResourceInfo数值;否则为错误对象。 |
174
175**错误码:**
176
177以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
178
179| 错误码ID | 错误信息                              |
180| -------- | ------------------------------------- |
181| 201 | Permission denied. |
182| 202 | Permission denied, non-system app called system api. |
183| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
184
185**示例:**
186
187```ts
188import { bundleResourceManager } from '@kit.AbilityKit';
189import { BusinessError } from '@ohos.base';
190import hilog from '@ohos.hilog';
191let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
192try {
193    bundleResourceManager.getAllBundleResourceInfo(resourceFlag, (err, data) => {
194        if (err) {
195            hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message);
196            return;
197        }
198        hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length));
199    });
200} catch (err) {
201    let message = (err as BusinessError).message;
202    hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message);
203}
204```
205
206### bundleResourceManager.getAllBundleResourceInfo
207
208getAllBundleResourceInfo(resourceFlags: [number](#resourceflag)): Promise<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>>;
209
210根据给定的resourceFlags获取所有应用的BundleResourceInfo。使用Promise异步回调。
211
212**系统接口:** 此接口为系统接口。
213
214**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LISTohos.permission.GET_BUNDLE_RESOURCES
215
216**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
217
218**参数:**
219
220| 参数名     | 类型   | 必填 | 说明                |
221| ----------- | ------ | ---- | --------------------- |
222| resourceFlags | [number](#resourceflag) | 是   | 指定返回的BundleResourceInfo所包含的信息。 |
223
224**返回值:**
225
226| 类型                                                         | 说明                             |
227| ------------------------------------------------------------ | -------------------------------- |
228| Promise\<Array<[BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)>> | Promise对象,返回BundleResourceInfo数值。 |
229
230**错误码:**
231
232以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
233
234| 错误码ID | 错误信息                              |
235| -------- | ------------------------------------- |
236| 201 | Permission denied. |
237| 202 | Permission denied, non-system app called system api. |
238| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
239
240**示例:**
241
242```ts
243import { bundleResourceManager } from '@kit.AbilityKit';
244import { BusinessError } from '@ohos.base';
245import hilog from '@ohos.hilog';
246let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
247try {
248    bundleResourceManager.getAllBundleResourceInfo(resourceFlag).then(data=> {
249        hilog.info(0x0000, 'testTag', 'getAllBundleResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length));
250    }).catch((err: BusinessError) => {
251        hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed. err: %{public}s', err.message);
252    })
253} catch (err) {
254    let message = (err as BusinessError).message;
255    hilog.error(0x0000, 'testTag', 'getAllBundleResourceInfo failed: %{public}s', message);
256}
257```
258
259### bundleResourceManager.getAllLauncherAbilityResourceInfo
260
261getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag), callback: AsyncCallback<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>>): void
262
263根据给定的resourceFlags获取当前所有应用的LauncherAbilityResourceInfo。使用callback异步回调。
264
265**系统接口:** 此接口为系统接口。
266
267**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LISTohos.permission.GET_BUNDLE_RESOURCES
268
269**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
270
271**参数:**
272
273| 参数名     | 类型   | 必填 | 说明                |
274| ----------- | ------ | ---- | --------------------- |
275| resourceFlags | [number](#resourceflag) | 是   | 指定返回的LauncherAbilityResourceInfo所包含的信息。 |
276| callback | AsyncCallback\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),当获取成功时,err为null,data为获取到的LauncherAbilityResourceInfo数值;否则为错误对象。 |
277
278**错误码:**
279
280以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
281
282| 错误码ID | 错误信息                              |
283| -------- | ------------------------------------- |
284| 201 | Permission denied. |
285| 202 | Permission denied, non-system app called system api. |
286| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
287
288**示例:**
289
290```ts
291import { bundleResourceManager } from '@kit.AbilityKit';
292import { BusinessError } from '@ohos.base';
293import hilog from '@ohos.hilog';
294let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
295try {
296    bundleResourceManager.getAllLauncherAbilityResourceInfo(resourceFlag, (err, data) => {
297        if (err) {
298            hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message);
299            return;
300        }
301        hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length));
302    });
303} catch (err) {
304    let message = (err as BusinessError).message;
305    hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message);
306}
307```
308
309### bundleResourceManager.getAllLauncherAbilityResourceInfo
310
311getAllLauncherAbilityResourceInfo(resourceFlags: [number](#resourceflag)): Promise<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>>
312
313根据给定的resourceFlags获取当前所有应用的LauncherAbilityResourceInfo。使用Promise异步回调。
314
315**系统接口:** 此接口为系统接口。
316
317**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LISTohos.permission.GET_BUNDLE_RESOURCES
318
319**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
320
321**参数:**
322
323| 参数名     | 类型   | 必填 | 说明                |
324| ----------- | ------ | ---- | --------------------- |
325| resourceFlags | [number](#resourceflag) | 是   | 指定返回的LauncherAbilityResourceInfo所包含的信息。 |
326
327**返回值:**
328
329| 类型                                                         | 说明                             |
330| ------------------------------------------------------------ | -------------------------------- |
331| Promise\<Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>> | Promise对象,返回LauncherAbilityResourceInfo数值。 |
332
333**错误码:**
334
335以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
336
337| 错误码ID | 错误信息                              |
338| -------- | ------------------------------------- |
339| 201 | Permission denied. |
340| 202 | Permission denied, non-system app called system api. |
341| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
342
343**示例:**
344```ts
345import { bundleResourceManager } from '@kit.AbilityKit';
346import { BusinessError } from '@ohos.base';
347import hilog from '@ohos.hilog';
348let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
349try {
350    bundleResourceManager.getAllLauncherAbilityResourceInfo(resourceFlag).then(data=> {
351        hilog.info(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo successfully. Data length: %{public}s', JSON.stringify(data.length));
352    }).catch((err: BusinessError) => {
353        hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed. err: %{public}s', err.message);
354    })
355} catch (err) {
356    let message = (err as BusinessError).message;
357    hilog.error(0x0000, 'testTag', 'getAllLauncherAbilityResourceInfo failed: %{public}s', message);
358}
359```
360
361### bundleResourceManager.getBundleResourceInfo<sup>12+</sup>
362
363getBundleResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag), appIndex?: number): [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md)
364
365以同步方法根据给定的bundleName、resourceFlags和appIndex获取当前应用的BundleResourceInfo。
366
367**系统接口:** 此接口为系统接口。
368
369**需要权限:** ohos.permission.GET_BUNDLE_RESOURCES
370
371**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
372
373**参数:**
374
375| 参数名     | 类型   | 必填 | 说明                |
376| ----------- | ------ | ---- | --------------------- |
377| bundleName | string | 是   | 指定查询应用的包名。 |
378| resourceFlags | [number](#resourceflag) | 否   | 指定返回的BundleResourceInfo所包含的信息。 |
379| appIndex | number | 否   | 指定查询应用分身的ID,默认值为0。 |
380
381**返回值:**
382
383| 类型                                                        | 说明                                  |
384| ----------------------------------------------------------- | ------------------------------------- |
385| [BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md) | 返回指定应用的BundleResourceInfo。|
386
387
388**错误码:**
389
390以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
391
392| 错误码ID | 错误信息                              |
393| -------- | ------------------------------------- |
394| 201 | Permission denied. |
395| 202 | Permission denied, non-system app called system api. |
396| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
397| 17700001 | The specified bundleName is not found. |
398| 17700061 | AppIndex not in valid range or not found. |
399
400
401**示例:**
402
403```ts
404import { bundleResourceManager } from '@kit.AbilityKit';
405import { BusinessError } from '@ohos.base';
406import hilog from '@ohos.hilog';
407let bundleName = "com.example.myapplication";
408let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
409let appIndex = 1;
410try {
411    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, resourceFlag, appIndex);
412    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
413} catch (err) {
414    let message = (err as BusinessError).message;
415    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
416}
417```
418
419### bundleResourceManager.getLauncherAbilityResourceInfo<sup>12+</sup>
420
421getLauncherAbilityResourceInfo(bundleName: string, resourceFlags?: [number](#resourceflag), appIndex?: number): Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)>
422
423以同步方法根据给定的bundleName、resourceFlags和appIndex获取当前应用的LauncherAbilityResourceInfo。
424
425**系统接口:** 此接口为系统接口。
426
427**需要权限:** ohos.permission.GET_BUNDLE_RESOURCES
428
429**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
430
431**参数:**
432
433| 参数名     | 类型   | 必填 | 说明                |
434| ----------- | ------ | ---- | --------------------- |
435| bundleName | string | 是   | 指定查询应用的包名。 |
436| resourceFlags | [number](#resourceflag) | 否   | 指定返回的LauncherAbilityResourceInfo所包含的信息,默认值为[ResourceFlag](#resourceflag).GET_RESOURCE_INFO_ALL。 |
437| appIndex | number | 否   | 指定查询应用分身的ID,默认值为0。 |
438
439**返回值:**
440
441| 类型                                                        | 说明                                  |
442| ----------------------------------------------------------- | ------------------------------------- |
443| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> | 返回指定应用的LauncherAbilityResourceInfo。|
444
445**错误码:**
446
447以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
448
449| 错误码ID | 错误信息                              |
450| -------- | ------------------------------------- |
451| 201 | Permission denied. |
452| 202 | Permission denied, non-system app called system api. |
453| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
454| 17700001 | The specified bundleName is not found. |
455| 17700061 | AppIndex not in valid range or not found. |
456
457**示例:**
458
459```ts
460import { bundleResourceManager } from '@kit.AbilityKit';
461import { BusinessError } from '@ohos.base';
462import hilog from '@ohos.hilog';
463let bundleName = "com.example.myapplication";
464let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
465let appIndex = 1;
466try {
467    let resourceInfo = bundleResourceManager.getLauncherAbilityResourceInfo(bundleName, resourceFlag, appIndex);
468    hilog.info(0x0000, 'testTag', 'getLauncherAbilityResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo[0].label));
469} catch (err) {
470    let message = (err as BusinessError).message;
471    hilog.error(0x0000, 'testTag', 'getLauncherAbilityResourceInfo failed: %{public}s', message);
472}
473```
474
475### bundleResourceManager.getExtensionAbilityResourceInfo<sup>20+</sup>
476
477getExtensionAbilityResourceInfo(bundleName: string, extensionAbilityType: bundleManager.ExtensionAbilityType, resourceFlags: number, appIndex?: number): Array\<LauncherAbilityResourceInfo>
478
479根据应用包名、扩展组件类型、资源信息标志、应用分身ID获取应用的扩展组件资源。使用同步方式返回。
480
481**系统接口:** 此接口为系统接口。
482
483**需要权限:** ohos.permission.GET_BUNDLE_RESOURCES
484
485**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
486
487**参数:**
488
489| 参数名     | 类型   | 必填 | 说明                |
490| ----------- | ------ | ---- | --------------------- |
491| bundleName | string | 是   | 应用包名。 |
492| extensionAbilityType | [bundleManager.ExtensionAbilityType](js-apis-bundleManager.md#extensionabilitytype) | 是   | 应用的扩展组件类型,仅支持ExtensionAbilityType.INPUT_METHODExtensionAbilityType.SHAREExtensionAbilityType.ACTION。 |
493| [resourceFlags](#resourceflag) | number | 是   | 资源信息标志,指示需要获取的资源信息的内容。 |
494| appIndex | number | 否   | 应用分身的ID,默认值是0。取值范围0~5,取值为0表示主应用。 |
495
496**返回值:**
497
498| 类型                                                        | 说明                                  |
499| ----------------------------------------------------------- | ------------------------------------- |
500| Array<[LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md)> | 返回指定应用的扩展组件资源,包含图标和名称等信息。|
501
502**错误码:**
503
504以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[包管理子系统通用错误码](errorcode-bundle.md)。
505
506| 错误码ID | 错误信息                              |
507| -------- | ------------------------------------- |
508| 201 | Permission denied. |
509| 202 | Permission denied,non-system app called system api. |
510| 17700001 | The specified bundleName is not found. |
511| 17700061 | AppIndex not in valid range or not found. |
512
513**示例:**
514
515```ts
516import { bundleManager, bundleResourceManager } from '@kit.AbilityKit';
517import { BusinessError } from '@kit.BasicServicesKit';
518
519let bundleName = "com.example.myapplication";
520let extensionAbilityType = bundleManager.ExtensionAbilityType.INPUT_METHOD;
521let resourceFlag = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
522try {
523    let resourceInfo = bundleResourceManager.getExtensionAbilityResourceInfo(bundleName, extensionAbilityType, resourceFlag);
524    console.info('getExtensionAbilityResourceInfo successfully. Data label: ' + JSON.stringify(resourceInfo[0].label));
525} catch (err) {
526    let message = (err as BusinessError).message;
527    let code = (err as BusinessError).code;
528    console.error(`getExtensionAbilityResourceInfo failed, err code:${code}, err msg: ${message}`);
529}
530```
531
532## BundleResourceInfo
533
534type BundleResourceInfo = _BundleResourceInfo
535
536应用配置的图标和名称信息。
537
538**系统接口:** 此接口为系统接口。
539
540**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
541
542| 类型                                                         | 说明           |
543| ------------------------------------------------------------ | -------------- |
544| [_BundleResourceInfo](js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo) |应用配置的图标和名称信息。 |
545
546## LauncherAbilityResourceInfo
547
548type LauncherAbilityResourceInfo = _LauncherAbilityResourceInfo
549
550应用配置的入口图标和名称信息。
551
552**系统接口:** 此接口为系统接口。
553
554**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource
555
556| 类型                                                         | 说明           |
557| ------------------------------------------------------------ | -------------- |
558| [_LauncherAbilityResourceInfo](js-apis-bundleManager-LauncherAbilityResourceInfo-sys.md#launcherabilityresourceinfo) |应用配置的入口图标和名称信息。 |