• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.resourceManager (资源管理)
2
3资源管理模块,根据当前configuration:语言、区域、横竖屏、Mcc(移动国家码)和Mnc(移动网络码)、Device capability(设备类型)、Density(分辨率)提供获取应用资源信息读取接口。
4
5> **说明:**
6>
7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
11
12```js
13import resourceManager from '@ohos.resourceManager';
14```
15
16## 使用说明
17
18从API Version9开始,Stage模型通过context获取resourceManager对象的方式后,可直接调用其内部获取资源的接口,无需再导入包。此方式FA模型不适用,FA模型还需要先导入包,再调用[getResourceManager](#resourcemanagergetresourcemanager)接口获取资源对象。
19Stage模型下Context的引用方法请参考[Stage模型的Context详细介绍](../../application-models/application-context-stage.md)。
20
21```ts
22import UIAbility from '@ohos.app.ability.UIAbility';
23import window from '@ohos.window';
24
25export default class EntryAbility extends UIAbility {
26  onWindowStageCreate(windowStage: window.WindowStage) {
27    let context = this.context;
28    let resourceManager = context.resourceManager;
29  }
30}
31```
32
33## resourceManager.getResourceManager
34
35getResourceManager(callback: AsyncCallback<ResourceManager>): void
36
37获取当前应用的资源管理对象,使用callback形式返回ResourceManager对象。
38
39**系统能力**:SystemCapability.Global.ResourceManager
40
41**模型约束**:此接口仅可在FA模型下使用。
42
43**参数:**
44
45| 参数名      | 类型                                       | 必填   | 说明                            |
46| -------- | ---------------------------------------- | ---- | ----------------------------- |
47| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | 是    | callback方式返回ResourceManager对象 |
48
49**示例:**
50  ```js
51  resourceManager.getResourceManager((error, mgr) => {
52    if (error != null) {
53      console.log("error is " + error);
54      return;
55    }
56    mgr.getStringValue(0x1000000, (error, value) => {
57      if (error != null) {
58        console.log("error is " + error);
59      } else {
60        let str = value;
61      }
62    });
63  });
64  ```
65注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
66
67
68## resourceManager.getResourceManager
69
70getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void
71
72获取指定应用的资源管理对象,使用callback形式返回ResourceManager对象。
73
74**系统能力**:SystemCapability.Global.ResourceManager
75
76**模型约束**:此接口仅可在FA模型下使用。
77
78**参数:**
79
80| 参数名        | 类型                                       | 必填   | 说明                            |
81| ---------- | ---------------------------------------- | ---- | ----------------------------- |
82| bundleName | string                                   | 是    | 指定应用的Bundle名称                 |
83| callback   | AsyncCallback<[ResourceManager](#resourcemanager)> | 是    | callback方式返回ResourceManager对象 |
84
85**示例:**
86  ```js
87  resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
88  });
89  ```
90
91
92## resourceManager.getResourceManager
93
94getResourceManager(): Promise<ResourceManager>
95
96获取当前应用的资源管理对象,使用Promise形式返回ResourceManager对象。
97
98**系统能力**:SystemCapability.Global.ResourceManager
99
100**模型约束**:此接口仅可在FA模型下使用。
101
102**返回值:**
103
104| 类型                                       | 说明                |
105| ---------------------------------------- | ----------------- |
106| Promise<[ResourceManager](#resourcemanager)> | Promise方式返回资源管理对象 |
107
108**示例:**
109  ```js
110  import resourceManager from '@ohos.resourceManager';
111  import { BusinessError } from '@ohos.base';
112
113  resourceManager.getResourceManager().then((mgr: resourceManager.ResourceManager) => {
114    mgr.getStringValue(0x1000000, (error, value) => {
115      if (error != null) {
116        console.log("error is " + error);
117      } else {
118        let str = value;
119      }
120    });
121  }).catch((error: BusinessError) => {
122    console.log("error is " + error);
123  });
124  ```
125注:示例代码中的0x1000000表示资源对应的id, 其可在编译后的文件ResourceTable.txt中找到。
126
127
128## resourceManager.getResourceManager
129
130getResourceManager(bundleName: string): Promise<ResourceManager>
131
132获取指定应用的资源管理对象,使用Promise形式返回ResourceManager对象。
133
134**系统能力**:SystemCapability.Global.ResourceManager
135
136**模型约束**:此接口仅可在FA模型下使用。
137
138**参数:**
139
140| 参数名        | 类型     | 必填   | 说明            |
141| ---------- | ------ | ---- | ------------- |
142| bundleName | string | 是    | 指定应用的Bundle名称 |
143
144**返回值:**
145
146| 类型                                       | 说明                 |
147| ---------------------------------------- | ------------------ |
148| Promise<[ResourceManager](#resourcemanager)> | Promise方式返回的资源管理对象 |
149
150**示例:**
151  ```js
152  import resourceManager from '@ohos.resourceManager';
153  import { BusinessError } from '@ohos.base';
154
155  resourceManager.getResourceManager("com.example.myapplication").then((mgr: resourceManager.ResourceManager) => {
156  }).catch((error: BusinessError) => {
157  });
158  ```
159
160## resourceManager.getSystemResourceManager<sup>10+</sup>
161
162getSystemResourceManager(): ResourceManager
163
164获取系统资源管理对象,返回系统资源的ResourceManager对象。
165
166**系统能力**:SystemCapability.Global.ResourceManager
167
168**返回值:**
169
170| 类型                                       | 说明                 |
171| ---------------------------------------- | ------------------ |
172| [Resourcemanager](#resourcemanager) | 返回系统资源的管理对象 |
173
174**错误码:**
175
176以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
177
178| 错误码ID | 错误信息 |
179| -------- | ---------------------------------------- |
180| 9001009  | If application can't access system resource.                       |
181
182**示例:**
183  ```js
184import resourceManager from '@ohos.resourceManager';
185import { BusinessError } from '@ohos.base';
186
187  try {
188    let systemResourceManager = resourceManager.getSystemResourceManager();
189    systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then((value: string) => {
190      let str = value;
191    }).catch((error: BusinessError) => {
192      console.log("systemResourceManager getStringValue promise error is " + error);
193    });
194  } catch (error) {
195    let code = (error as BusinessError).code;
196    let message = (error as BusinessError).message;
197    console.error(`systemResourceManager getStringValue failed, error code: ${code}, message: ${message}.`);
198  }
199  ```
200
201
202## Direction
203
204用于表示设备屏幕方向。
205
206**系统能力**:SystemCapability.Global.ResourceManager
207
208| 名称                   | 值  | 说明   |
209| -------------------- | ---- | ---- |
210| DIRECTION_VERTICAL   | 0    | 竖屏   |
211| DIRECTION_HORIZONTAL | 1    | 横屏   |
212
213
214## DeviceType
215
216用于表示当前设备类型。
217
218**系统能力**:SystemCapability.Global.ResourceManager
219
220| 名称                   | 值  | 说明   |
221| -------------------- | ---- | ---- |
222| DEVICE_TYPE_TABLET   | 0x01 | 平板   |
223| DEVICE_TYPE_CAR      | 0x02 | 汽车   |
224| DEVICE_TYPE_TV       | 0x04 | 电视   |
225| DEVICE_TYPE_WEARABLE | 0x06 | 穿戴   |
226
227
228## ScreenDensity
229
230用于表示当前设备屏幕密度。
231
232**系统能力**:SystemCapability.Global.ResourceManager
233
234| 名称             | 值  | 说明         |
235| -------------- | ---- | ---------- |
236| SCREEN_SDPI    | 120  | 小规模的屏幕密度   |
237| SCREEN_MDPI    | 160  | 中规模的屏幕密度   |
238| SCREEN_LDPI    | 240  | 大规模的屏幕密度   |
239| SCREEN_XLDPI   | 320  | 特大规模的屏幕密度  |
240| SCREEN_XXLDPI  | 480  | 超大规模的屏幕密度  |
241| SCREEN_XXXLDPI | 640  | 超特大规模的屏幕密度 |
242
243
244## Configuration
245
246表示当前设备的状态。
247
248**系统能力**:SystemCapability.Global.ResourceManager
249
250**参数:**
251
252| 名称        | 类型                    | 可读   | 可写   | 说明       |
253| --------- | ----------------------- | ---- | ---- | -------- |
254| direction | [Direction](#direction) | 是    | 否    | 当前设备屏幕方向 |
255| locale    | string                  | 是    | 否    | 当前系统语言   |
256
257
258## DeviceCapability
259
260表示设备支持的能力。
261
262**系统能力**:SystemCapability.Global.ResourceManager
263
264**参数:**
265
266| 名称            | 类型                            | 可读   | 可写   | 说明       |
267| ------------- | ------------------------------- | ---- | ---- | -------- |
268| screenDensity | [ScreenDensity](#screendensity) | 是    | 否    | 当前设备屏幕密度 |
269| deviceType    | [DeviceType](#devicetype)       | 是    | 否    | 当前设备类型   |
270
271
272## RawFileDescriptor<sup>8+</sup>
273
274表示rawfile的descriptor信息。
275
276**系统能力:** SystemCapability.Global.ResourceManager
277
278**参数:**
279
280| 名称     | 类型    | 可读   | 可写  | 说明           |
281| ------ | ------  | ---- | ---- | ------------------ |
282| fd     | number  | 是    | 否 | rawfile所在hap的文件描述符 |
283| offset | number  | 是    | 否 | rawfile的起始偏移量      |
284| length | number  | 是    | 否 | rawfile的文件长度       |
285
286## Resource<sup>9+</sup>
287
288表示的资源信息。
289
290**系统能力:** 以下各项对应的系统能力均为SystemCapability.Global.ResourceManager
291
292**参数:**
293
294| 名称         | 类型     | 可读   | 可写  |说明          |
295| ---------- | ------ | ----- | ----  | ---------------|
296| bundleName | string | 是    | 否 | 应用的bundle名称 |
297| moduleName | string | 是    | 否 | 应用的module名称 |
298| id         | number | 是    | 否 | 资源的id值      |
299| params     | any[] | 是    | 否 | 其他资源参数(可选)      |
300| type       | number | 是    | 否 | 资源的类型(可选)      |
301
302
303## ResourceManager
304
305提供访问应用资源的能力。
306
307> **说明:**
308>
309> - ResourceManager涉及到的方法,仅限基于TS扩展的声明式开发范式使用。
310>
311> - 资源文件在工程的resources目录中定义,id可通过$r(资源地址).id的方式获取,例如$r('app.string.test').id。
312
313### getStringSync<sup>9+</sup>
314
315getStringSync(resId: number): string
316
317用户获取指定资源ID对应的字符串,使用同步方式返回字符串。
318
319**系统能力**:SystemCapability.Global.ResourceManager
320
321**参数:**
322
323| 参数名   | 类型     | 必填   | 说明    |
324| ----- | ------ | ---- | ----- |
325| resId | number | 是    | 资源ID值 |
326
327**返回值:**
328
329| 类型     | 说明          |
330| ------ | ----------- |
331| string | 资源ID值对应的字符串 |
332
333**错误码:**
334
335以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
336
337| 错误码ID | 错误信息 |
338| -------- | ---------------------------------------- |
339| 9001001  | If the resId invalid.                       |
340| 9001002  | If the resource not found by resId.         |
341| 9001006  | If the resource re-ref too much.            |
342
343**示例:**
344  ```ts
345  import { BusinessError } from '@ohos.base';
346
347  try {
348    this.context.resourceManager.getStringSync($r('app.string.test').id);
349  } catch (error) {
350    let code = (error as BusinessError).code;
351    let message = (error as BusinessError).message;
352    console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
353  }
354  ```
355
356### getStringSync<sup>10+</sup>
357
358getStringSync(resId: number, ...args: Array<string | number>): string
359
360用户获取指定资源ID对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
361
362**系统能力**:SystemCapability.Global.ResourceManager
363
364**参数:**
365
366| 参数名   | 类型     | 必填   | 说明    |
367| ----- | ------ | ---- | ----- |
368| resId | number | 是    | 资源ID值 |
369| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
370
371**返回值:**
372
373| 类型     | 说明          |
374| ------ | ---------------------------- |
375| string | 资源ID值对应的格式化字符串|
376
377**错误码:**
378
379以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
380
381| 错误码ID | 错误信息 |
382| -------- | ----------------------------------------------- |
383| 9001001  | If the resId invalid.                               |
384| 9001002  | If the resource not found by resId.                 |
385| 9001006  | If the resource re-ref too much.                    |
386| 9001007  | If the resource obtained by resId formatting error. |
387
388**示例:**
389  ```ts
390  import { BusinessError } from '@ohos.base';
391
392  try {
393    this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
394  } catch (error) {
395    let code = (error as BusinessError).code;
396    let message = (error as BusinessError).message;
397    console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
398  }
399  ```
400
401### getStringSync<sup>9+</sup>
402
403getStringSync(resource: Resource): string
404
405用户获取指定resource对象对应的字符串,使用同步方式返回字符串。
406
407**系统能力**:SystemCapability.Global.ResourceManager
408
409**模型约束**:此接口仅可在Stage模型下使用。
410
411**参数:**
412
413| 参数名      | 类型                     | 必填   | 说明   |
414| -------- | ---------------------- | ---- | ---- |
415| resource | [Resource](#resource9) | 是    | 资源信息 |
416
417**返回值:**
418
419| 类型     | 说明               |
420| ------ | ---------------- |
421| string | resource对象对应的字符串 |
422
423**错误码:**
424
425以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
426
427| 错误码ID | 错误信息 |
428| -------- | ---------------------------------------- |
429| 9001001  | If the resId invalid.                       |
430| 9001002  | If the resource not found by resId.         |
431| 9001006  | If the resource re-ref too much.            |
432
433**示例:**
434  ```ts
435  import resourceManager from '@ohos.resourceManager';
436  import { BusinessError } from '@ohos.base';
437
438  let resource: resourceManager.Resource = {
439    bundleName: "com.example.myapplication",
440    moduleName: "entry",
441    id: $r('app.string.test').id
442  };
443  try {
444    this.context.resourceManager.getStringSync(resource);
445  } catch (error) {
446    let code = (error as BusinessError).code;
447    let message = (error as BusinessError).message;
448    console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
449  }
450  ```
451
452### getStringSync<sup>10+</sup>
453
454getStringSync(resource: Resource, ...args: Array<string | number>): string
455
456用户获取指定resource对象对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
457
458**系统能力**:SystemCapability.Global.ResourceManager
459
460**模型约束**:此接口仅可在Stage模型下使用。
461
462**参数:**
463
464| 参数名      | 类型                     | 必填   | 说明   |
465| -------- | ---------------------- | ---- | ---- |
466| resource | [Resource](#resource9) | 是    | 资源信息 |
467| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
468
469**返回值:**
470
471| 类型     | 说明          |
472| ------ | ---------------------------- |
473| string | resource对象对应的格式化字符串|
474
475**错误码:**
476
477以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
478
479| 错误码ID | 错误信息 |
480| -------- | ---------------------------------------- |
481| 9001001  | If the resId invalid.                       |
482| 9001002  | If the resource not found by resId.         |
483| 9001006  | If the resource re-ref too much.            |
484| 9001007  | If the resource obtained by resId formatting error. |
485
486**示例:**
487  ```ts
488  import resourceManager from '@ohos.resourceManager';
489  import { BusinessError } from '@ohos.base';
490
491  let resource: resourceManager.Resource = {
492    bundleName: "com.example.myapplication",
493    moduleName: "entry",
494    id: $r('app.string.test').id
495  };
496  try {
497    this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
498  } catch (error) {
499    let code = (error as BusinessError).code;
500    let message = (error as BusinessError).message;
501    console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
502  }
503 ```
504
505### getStringByNameSync<sup>9+</sup>
506
507getStringByNameSync(resName: string): string
508
509用户获取指定资源名称对应的字符串,使用同步方式返回字符串。
510
511**系统能力**:SystemCapability.Global.ResourceManager
512
513**参数:**
514
515| 参数名     | 类型     | 必填   | 说明   |
516| ------- | ------ | ---- | ---- |
517| resName | string | 是    | 资源名称 |
518
519**返回值:**
520
521| 类型     | 说明         |
522| ------ | ---------- |
523| string | 资源名称对应的字符串 |
524
525**错误码:**
526
527以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
528
529| 错误码ID | 错误信息 |
530| -------- | ---------------------------------------- |
531| 9001003  | If the resName invalid.                     |
532| 9001004  | If the resource not found by resName.       |
533| 9001006  | If the resource re-ref too much.            |
534
535**示例:**
536  ```ts
537  import { BusinessError } from '@ohos.base';
538
539  try {
540    this.context.resourceManager.getStringByNameSync("test");
541  } catch (error) {
542    let code = (error as BusinessError).code;
543    let message = (error as BusinessError).message;
544    console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`);
545  }
546  ```
547
548### getStringByNameSync<sup>10+</sup>
549
550getStringByNameSync(resName: string, ...args: Array<string | number>): string
551
552用户获取指定资源名称对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
553
554**系统能力**:SystemCapability.Global.ResourceManager
555
556**参数:**
557
558| 参数名     | 类型     | 必填   | 说明   |
559| ------- | ------ | ---- | ---- |
560| resName | string | 是    | 资源名称 |
561| args | Array<string \| number> | 否    | 格式化字符串资源参数 <br> 支持参数类型:<br /> %d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
562
563**返回值:**
564
565| 类型     | 说明          |
566| ------ | ---------------------------- |
567| string | 资源名称对应的格式化字符串|
568
569**错误码:**
570
571以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
572
573| 错误码ID | 错误信息 |
574| -------- | ---------------------------------------- |
575| 9001003  | If the resName invalid.                     |
576| 9001004  | If the resource not found by resName.       |
577| 9001006  | If the resource re-ref too much.            |
578| 9001008  | If the resource obtained by resName formatting error. |
579
580**示例:**
581  ```ts
582  import { BusinessError } from '@ohos.base';
583
584  try {
585    this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
586  } catch (error) {
587    let code = (error as BusinessError).code;
588    let message = (error as BusinessError).message;
589    console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`);
590  }
591 ```
592
593### getStringValue<sup>9+</sup>
594
595getStringValue(resId: number, callback: AsyncCallback&lt;string&gt;): void
596
597用户获取指定资源ID对应的字符串,使用callback形式返回字符串。
598
599**系统能力**:SystemCapability.Global.ResourceManager
600
601**参数:**
602
603| 参数名      | 类型                          | 必填   | 说明              |
604| -------- | --------------------------- | ---- | --------------- |
605| resId    | number                      | 是    | 资源ID值           |
606| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
607
608**错误码:**
609
610以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
611
612| 错误码ID | 错误信息 |
613| -------- | ---------------------------------------- |
614| 9001001  | If the module resId invalid.             |
615| 9001002  | If the resource not found by resId.      |
616| 9001006  | If the resource re-ref too much.         |
617
618**示例Stage:**
619  ```ts
620  import { BusinessError } from '@ohos.base';
621
622  try {
623    this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => {
624      if (error != null) {
625        console.log("error is " + error);
626      } else {
627        let str = value;
628      }
629    });
630  } catch (error) {
631    let code = (error as BusinessError).code;
632    let message = (error as BusinessError).message;
633    console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`);
634  }
635  ```
636
637### getStringValue<sup>9+</sup>
638
639getStringValue(resId: number): Promise&lt;string&gt;
640
641用户获取指定资源ID对应的字符串,使用Promise形式返回字符串。
642
643**系统能力**:SystemCapability.Global.ResourceManager
644
645**参数:**
646
647| 参数名   | 类型     | 必填   | 说明    |
648| ----- | ------ | ---- | ----- |
649| resId | number | 是    | 资源ID值 |
650
651**返回值:**
652
653| 类型                    | 说明          |
654| --------------------- | ----------- |
655| Promise&lt;string&gt; | 资源ID值对应的字符串 |
656
657**错误码:**
658
659以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
660
661| 错误码ID | 错误信息 |
662| -------- | ---------------------------------------- |
663| 9001001  | If the resId invalid.                       |
664| 9001002  | If the resource not found by resId.         |
665| 9001006  | If the resource re-ref too much.            |
666
667**示例:**
668  ```ts
669  import { BusinessError } from '@ohos.base';
670
671  try {
672    this.context.resourceManager.getStringValue($r('app.string.test').id).then((value: string) => {
673      let str = value;
674    }).catch((error: BusinessError) => {
675      console.log("getStringValue promise error is " + error);
676    });
677  } catch (error) {
678    let code = (error as BusinessError).code;
679    let message = (error as BusinessError).message;
680    console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`);
681  }
682  ```
683
684### getStringValue<sup>9+</sup>
685
686getStringValue(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
687
688用户获取指定resource对象对应的字符串,使用callback形式返回字符串。
689
690**系统能力**:SystemCapability.Global.ResourceManager
691
692**模型约束**:此接口仅可在Stage模型下使用。
693
694**参数:**
695
696| 参数名      | 类型                          | 必填   | 说明              |
697| -------- | --------------------------- | ---- | --------------- |
698| resource | [Resource](#resource9)      | 是    | 资源信息            |
699| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
700
701**错误码:**
702
703以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
704
705| 错误码ID | 错误信息 |
706| -------- | ---------------------------------------- |
707| 9001001  | If the resId invalid.                       |
708| 9001002  | If the resource not found by resId.         |
709| 9001006  | If the resource re-ref too much.            |
710
711**示例:**
712  ```ts
713  import resourceManager from '@ohos.resourceManager';
714  import { BusinessError } from '@ohos.base';
715
716  let resource: resourceManager.Resource = {
717    bundleName: "com.example.myapplication",
718    moduleName: "entry",
719    id: $r('app.string.test').id
720  };
721  try {
722    this.context.resourceManager.getStringValue(resource, (error, value) => {
723      if (error != null) {
724        console.log("error is " + error);
725      } else {
726        let str = value;
727      }
728    });
729  } catch (error) {
730    let code = (error as BusinessError).code;
731    let message = (error as BusinessError).message;
732    console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`);
733  }
734  ```
735
736### getStringValue<sup>9+</sup>
737
738getStringValue(resource: Resource): Promise&lt;string&gt;
739
740用户获取指定resource对象对应的字符串,使用Promise形式返回字符串。
741
742**系统能力**:SystemCapability.Global.ResourceManager
743
744**模型约束**:此接口仅可在Stage模型下使用。
745
746**参数:**
747
748| 参数名      | 类型                     | 必填   | 说明   |
749| -------- | ---------------------- | ---- | ---- |
750| resource | [Resource](#resource9) | 是    | 资源信息 |
751
752**返回值:**
753
754| 类型                    | 说明               |
755| --------------------- | ---------------- |
756| Promise&lt;string&gt; | resource对象对应的字符串 |
757
758**错误码:**
759
760以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
761
762| 错误码ID | 错误信息 |
763| -------- | ---------------------------------------- |
764| 9001001  | If the resId invalid.                       |
765| 9001002  | If the resource not found by resId.         |
766| 9001006  | If the resource re-ref too much.            |
767
768**示例:**
769  ```ts
770  import resourceManager from '@ohos.resourceManager';
771  import { BusinessError } from '@ohos.base';
772
773  let resource: resourceManager.Resource = {
774    bundleName: "com.example.myapplication",
775    moduleName: "entry",
776    id: $r('app.string.test').id
777  };
778  try {
779    this.context.resourceManager.getStringValue(resource).then((value: string) => {
780      let str = value;
781    }).catch((error: BusinessError) => {
782      console.log("getStringValue promise error is " + error);
783    });
784  } catch (error) {
785    let code = (error as BusinessError).code;
786    let message = (error as BusinessError).message;
787    console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`);
788  }
789  ```
790
791### getStringByName<sup>9+</sup>
792
793getStringByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
794
795用户获取指定资源名称对应的字符串,使用callback形式返回字符串。
796
797**系统能力**:SystemCapability.Global.ResourceManager
798
799**参数:**
800
801| 参数名      | 类型                          | 必填   | 说明              |
802| -------- | --------------------------- | ---- | --------------- |
803| resName  | string                      | 是    | 资源名称            |
804| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
805
806**错误码:**
807
808以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
809
810| 错误码ID | 错误信息 |
811| -------- | ---------------------------------------- |
812| 9001003  | If the resName invalid.                     |
813| 9001004  | If the resource not found by resName.       |
814| 9001006  | If the resource re-ref too much.            |
815
816**示例:**
817  ```ts
818  import { BusinessError } from '@ohos.base';
819
820  try {
821    this.context.resourceManager.getStringByName("test", (error, value) => {
822      if (error != null) {
823        console.log("error is " + error);
824      } else {
825        let str = value;
826      }
827    });
828  } catch (error) {
829    let code = (error as BusinessError).code;
830    let message = (error as BusinessError).message;
831    console.error(`callback getStringByName failed, error code: ${code}, message: ${message}.`);
832  }
833  ```
834
835### getStringByName<sup>9+</sup>
836
837getStringByName(resName: string): Promise&lt;string&gt;
838
839用户获取指定资源名称对应的字符串,使用Promise形式返回字符串。
840
841**系统能力**:SystemCapability.Global.ResourceManager
842
843**参数:**
844
845| 参数名     | 类型     | 必填   | 说明   |
846| ------- | ------ | ---- | ---- |
847| resName | string | 是    | 资源名称 |
848
849**返回值:**
850
851| 类型                    | 说明         |
852| --------------------- | ---------- |
853| Promise&lt;string&gt; | 资源名称对应的字符串 |
854
855**错误码:**
856
857以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
858
859| 错误码ID | 错误信息 |
860| -------- | ---------------------------------------- |
861| 9001003  | If the resName invalid.                     |
862| 9001004  | If the resource not found by resName.       |
863| 9001006  | If the resource re-ref too much.            |
864
865**示例:**
866  ```ts
867  import { BusinessError } from '@ohos.base';
868
869  try {
870    this.context.resourceManager.getStringByName("test").then((value: string) => {
871      let str = value;
872    }).catch((error: BusinessError) => {
873      console.log("getStringByName promise error is " + error);
874    });
875  } catch (error) {
876    let code = (error as BusinessError).code;
877    let message = (error as BusinessError).message;
878    console.error(`promise getStringByName failed, error code: ${code}, message: ${message}.`);
879  }
880  ```
881
882### getStringArrayValueSync<sup>10+</sup>
883
884getStringArrayValueSync(resId: number): Array&lt;string&gt;
885
886用户获取指定资源ID对应的字符串数组,使用同步方式返回字符串数组。
887
888**系统能力**:SystemCapability.Global.ResourceManager
889
890**参数:**
891
892| 参数名   | 类型     | 必填   | 说明    |
893| ----- | ------ | ---- | ----- |
894| resId | number | 是    | 资源ID值 |
895
896**返回值:**
897
898| 类型                    | 说明          |
899| --------------------- | ----------- |
900| Array&lt;string&gt; | 资源ID值对应的字符串数组 |
901
902**错误码:**
903
904以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
905
906| 错误码ID | 错误信息 |
907| -------- | ---------------------------------------- |
908| 9001001  | If the resId invalid.                       |
909| 9001002  | If the resource not found by resId.         |
910| 9001006  | If the resource re-ref too much.            |
911
912**示例:**
913  ```ts
914  import { BusinessError } from '@ohos.base';
915
916  try {
917    this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id);
918  } catch (error) {
919    let code = (error as BusinessError).code;
920    let message = (error as BusinessError).message;
921    console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
922  }
923  ```
924
925### getStringArrayValueSync<sup>10+</sup>
926
927getStringArrayValueSync(resource: Resource): Array&lt;string&gt;
928
929用户获取指定resource对象对应的字符串数组,使用同步方式返回字符串数组。
930
931**系统能力**:SystemCapability.Global.ResourceManager
932
933**模型约束**:此接口仅可在Stage模型下使用。
934
935**参数:**
936
937| 参数名   | 类型     | 必填   | 说明    |
938| ----- | ------ | ---- | ----- |
939| resource | [Resource](#resource9) | 是    | 资源信息 |
940
941**返回值:**
942
943| 类型                    | 说明          |
944| --------------------- | ----------- |
945| Array&lt;string&gt; | resource对象对应的字符串数组 |
946
947**错误码:**
948
949以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
950
951| 错误码ID | 错误信息 |
952| -------- | ---------------------------------------- |
953| 9001001  | If the resId invalid.                       |
954| 9001002  | If the resource not found by resId.         |
955| 9001006  | If the resource re-ref too much.            |
956
957**示例:**
958  ```ts
959  import resourceManager from '@ohos.resourceManager';
960  import { BusinessError } from '@ohos.base';
961
962  let resource: resourceManager.Resource = {
963    bundleName: "com.example.myapplication",
964    moduleName: "entry",
965    id: $r('app.strarray.test').id
966  };
967  try {
968    this.context.resourceManager.getStringArrayValueSync(resource);
969  } catch (error) {
970    let code = (error as BusinessError).code;
971    let message = (error as BusinessError).message;
972    console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
973  }
974  ```
975
976### getStringArrayByNameSync<sup>10+</sup>
977
978getStringArrayByNameSync(resName: string): Array&lt;string&gt;
979
980用户获取指定资源名称对应的字符串数组,使用同步方式返回字符串数组。
981
982**系统能力**:SystemCapability.Global.ResourceManager
983
984**参数:**
985
986| 参数名   | 类型     | 必填   | 说明    |
987| ----- | ------ | ---- | ----- |
988| resName | string | 是    | 资源名称 |
989
990**返回值:**
991
992| 类型                    | 说明          |
993| --------------------- | ----------- |
994| Array&lt;string&gt; | 对应资源名称的字符串数组 |
995
996**错误码:**
997
998以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
999
1000| 错误码ID | 错误信息 |
1001| -------- | ---------------------------------------- |
1002| 9001003  | If the resName invalid.                       |
1003| 9001004  | If the resource not found by resName.         |
1004| 9001006  | If the resource re-ref too much.            |
1005
1006**示例:**
1007  ```ts
1008  try {
1009    this.context.resourceManager.getStringArrayByNameSync("test");
1010  } catch (error) {
1011    let code = (error as BusinessError).code;
1012    let message = (error as BusinessError).message;
1013    console.error(`getStringArrayByNameSync failed, error code: ${code}, message: ${message}.`);
1014  }
1015  ```
1016
1017### getStringArrayValue<sup>9+</sup>
1018
1019getStringArrayValue(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1020
1021用户获取指定资源ID对应的字符串数组,使用callback形式返回字符串数组。
1022
1023**系统能力**:SystemCapability.Global.ResourceManager
1024
1025**参数:**
1026
1027| 参数名      | 类型                                       | 必填   | 说明                |
1028| -------- | ---------------------------------------- | ---- | ----------------- |
1029| resId    | number                                   | 是    | 资源ID值             |
1030| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
1031
1032**错误码:**
1033
1034以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1035
1036| 错误码ID | 错误信息 |
1037| -------- | ---------------------------------------- |
1038| 9001001  | If the resId invalid.                       |
1039| 9001002  | If the resource not found by resId.         |
1040| 9001006  | If the resource re-ref too much.            |
1041
1042**示例:**
1043  ```ts
1044  import { BusinessError } from '@ohos.base';
1045
1046  try {
1047    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => {
1048      if (error != null) {
1049        console.log("error is " + error);
1050      } else {
1051        let strArray = value;
1052      }
1053    });
1054  } catch (error) {
1055    let code = (error as BusinessError).code;
1056    let message = (error as BusinessError).message;
1057    console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`);
1058  }
1059  ```
1060
1061### getStringArrayValue<sup>9+</sup>
1062
1063getStringArrayValue(resId: number): Promise&lt;Array&lt;string&gt;&gt;
1064
1065用户获取指定资源ID对应的字符串数组,使用Promise形式返回字符串数组。
1066
1067**系统能力**:SystemCapability.Global.ResourceManager
1068
1069**参数:**
1070
1071| 参数名   | 类型     | 必填   | 说明    |
1072| ----- | ------ | ---- | ----- |
1073| resId | number | 是    | 资源ID值 |
1074
1075**返回值:**
1076
1077| 类型                                 | 说明            |
1078| ---------------------------------- | ------------- |
1079| Promise&lt;Array&lt;string&gt;&gt; | 资源ID值对应的字符串数组 |
1080
1081**错误码:**
1082
1083以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1084
1085| 错误码ID | 错误信息 |
1086| -------- | ---------------------------------------- |
1087| 9001001  | If the resId invalid.                       |
1088| 9001002  | If the resource not found by resId.         |
1089| 9001006  | If the resource re-ref too much.            |
1090
1091**示例:**
1092  ```ts
1093  import { BusinessError } from '@ohos.base';
1094
1095  try {
1096    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then((value: Array<string>) => {
1097      let strArray = value;
1098    }).catch((error: BusinessError) => {
1099      console.log("getStringArrayValue promise error is " + error);
1100    });
1101  } catch (error) {
1102    let code = (error as BusinessError).code;
1103    let message = (error as BusinessError).message;
1104    console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`);
1105  }
1106  ```
1107
1108### getStringArrayValue<sup>9+</sup>
1109
1110getStringArrayValue(resource: Resource, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1111
1112用户获取指定resource对象对应的字符串数组,使用callback形式返回回字符串数组。
1113
1114**系统能力**:SystemCapability.Global.ResourceManager
1115
1116**模型约束**:此接口仅可在Stage模型下使用。
1117
1118**参数:**
1119
1120| 参数名      | 类型                                       | 必填   | 说明                |
1121| -------- | ---------------------------------------- | ---- | ----------------- |
1122| resource | [Resource](#resource9)                   | 是    | 资源信息              |
1123| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
1124
1125**错误码:**
1126
1127以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1128
1129| 错误码ID | 错误信息 |
1130| -------- | ---------------------------------------- |
1131| 9001001  | If the resId invalid.                       |
1132| 9001002  | If the resource not found by resId.         |
1133| 9001006  | If the resource re-ref too much.            |
1134
1135**示例:**
1136  ```ts
1137  import resourceManager from '@ohos.resourceManager';
1138  import { BusinessError } from '@ohos.base';
1139
1140  let resource: resourceManager.Resource = {
1141    bundleName: "com.example.myapplication",
1142    moduleName: "entry",
1143    id: $r('app.strarray.test').id
1144  };
1145  try {
1146    this.context.resourceManager.getStringArrayValue(resource, (error, value) => {
1147      if (error != null) {
1148        console.log("error is " + error);
1149      } else {
1150        let strArray = value;
1151      }
1152    });
1153  } catch (error) {
1154    let code = (error as BusinessError).code;
1155    let message = (error as BusinessError).message;
1156    console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`);
1157  }
1158  ```
1159
1160### getStringArrayValue<sup>9+</sup>
1161
1162getStringArrayValue(resource: Resource): Promise&lt;Array&lt;string&gt;&gt;
1163
1164用户获取指定resource对象对应的字符串数组,使用Promise形式返回字符串数组。
1165
1166**系统能力**:SystemCapability.Global.ResourceManager
1167
1168**模型约束**:此接口仅可在Stage模型下使用。
1169
1170**参数:**
1171
1172| 参数名      | 类型                     | 必填   | 说明   |
1173| -------- | ---------------------- | ---- | ---- |
1174| resource | [Resource](#resource9) | 是    | 资源信息 |
1175
1176**返回值:**
1177
1178| 类型                                 | 说明                 |
1179| ---------------------------------- | ------------------ |
1180| Promise&lt;Array&lt;string&gt;&gt; | resource对象对应的字符串数组 |
1181
1182**错误码:**
1183
1184以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1185
1186| 错误码ID | 错误信息 |
1187| -------- | ---------------------------------------- |
1188| 9001001  | If the resId invalid.                       |
1189| 9001002  | If the resource not found by resId.         |
1190| 9001006  | If the resource re-ref too much.            |
1191
1192**示例:**
1193  ```ts
1194  import resourceManager from '@ohos.resourceManager';
1195  import { BusinessError } from '@ohos.base';
1196
1197  let resource: resourceManager.Resource = {
1198    bundleName: "com.example.myapplication",
1199    moduleName: "entry",
1200    id: $r('app.strarray.test').id
1201  };
1202  try {
1203    this.context.resourceManager.getStringArrayValue(resource).then((value: Array<string>) => {
1204      let strArray = value;
1205    }).catch((error: BusinessError) => {
1206      console.log("getStringArray promise error is " + error);
1207    });
1208  } catch (error) {
1209    let code = (error as BusinessError).code;
1210    let message = (error as BusinessError).message;
1211    console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`);
1212  }
1213  ```
1214
1215### getStringArrayByName<sup>9+</sup>
1216
1217getStringArrayByName(resName: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1218
1219用户获取指定资源名称对应的字符串数组,使用callback形式返回字符串数组。
1220
1221**系统能力**:SystemCapability.Global.ResourceManager
1222
1223**参数:**
1224
1225| 参数名      | 类型                                       | 必填   | 说明                |
1226| -------- | ---------------------------------------- | ---- | ----------------- |
1227| resName  | string                                   | 是    | 资源名称              |
1228| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
1229
1230**错误码:**
1231
1232以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1233
1234| 错误码ID | 错误信息 |
1235| -------- | ---------------------------------------- |
1236| 9001003  | If the resName invalid.                     |
1237| 9001004  | If the resource not found by resName.       |
1238| 9001006  | If the resource re-ref too much.            |
1239
1240**示例:**
1241  ```ts
1242  import { BusinessError } from '@ohos.base';
1243
1244  try {
1245    this.context.resourceManager.getStringArrayByName("test", (error, value) => {
1246      if (error != null) {
1247        console.log("error is " + error);
1248      } else {
1249        let strArray = value;
1250      }
1251    });
1252  } catch (error) {
1253    let code = (error as BusinessError).code;
1254    let message = (error as BusinessError).message;
1255    console.error(`callback getStringArrayByName failed, error code: ${code}, message: ${message}.`);
1256  }
1257  ```
1258
1259### getStringArrayByName<sup>9+</sup>
1260
1261getStringArrayByName(resName: string): Promise&lt;Array&lt;string&gt;&gt;
1262
1263用户获取指定资源名称对应的字符串数组,使用Promise形式返回字符串数组。
1264
1265**系统能力**:SystemCapability.Global.ResourceManager
1266
1267**参数:**
1268
1269| 参数名     | 类型     | 必填   | 说明   |
1270| ------- | ------ | ---- | ---- |
1271| resName | string | 是    | 资源名称 |
1272
1273**返回值:**
1274
1275| 类型                                 | 说明           |
1276| ---------------------------------- | ------------ |
1277| Promise&lt;Array&lt;string&gt;&gt; | 资源名称对应的字符串数组 |
1278
1279**错误码:**
1280
1281以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1282
1283| 错误码ID | 错误信息 |
1284| -------- | ---------------------------------------- |
1285| 9001003  | If the resName invalid.                     |
1286| 9001004  | If the resource not found by resName.       |
1287| 9001006  | If the resource re-ref too much.            |
1288
1289**示例:**
1290  ```ts
1291  import { BusinessError } from '@ohos.base';
1292
1293  try {
1294    this.context.resourceManager.getStringArrayByName("test").then((value: Array<string>) => {
1295      let strArray = value;
1296    }).catch((error: BusinessError) => {
1297      console.log("getStringArrayByName promise error is " + error);
1298    });
1299  } catch (error) {
1300    let code = (error as BusinessError).code;
1301    let message = (error as BusinessError).message;
1302    console.error(`promise getStringArrayByName failed, error code: ${code}, message: ${message}.`);
1303  }
1304  ```
1305
1306### getPluralStringValueSync<sup>10+</sup>
1307
1308getPluralStringValueSync(resId: number, num: number): string
1309
1310根据指定数量获取指定ID字符串表示的单复数字符串,使用同步方式返回字符串。
1311
1312**系统能力**:SystemCapability.Global.ResourceManager
1313
1314**参数:**
1315
1316| 参数名   | 类型     | 必填   | 说明    |
1317| ----- | ------ | ---- | ----- |
1318| resId | number | 是    | 资源ID值 |
1319| num   | number | 是    | 数量值   |
1320
1321**返回值:**
1322
1323| 类型                    | 说明          |
1324| -------- | ----------- |
1325| string   | 根据指定数量获取指定ID字符串表示的单复数字符串 |
1326
1327**错误码:**
1328
1329以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1330
1331| 错误码ID | 错误信息 |
1332| -------- | ---------------------------------------- |
1333| 9001001  | If the resId invalid.                       |
1334| 9001002  | If the resource not found by resId.         |
1335| 9001006  | If the resource re-ref too much.            |
1336
1337**示例:**
1338  ```ts
1339  import { BusinessError } from '@ohos.base';
1340
1341  try {
1342    this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1);
1343  } catch (error) {
1344    let code = (error as BusinessError).code;
1345    let message = (error as BusinessError).message;
1346    console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
1347  }
1348  ```
1349
1350### getPluralStringValueSync<sup>10+</sup>
1351
1352getPluralStringValueSync(resource: Resource, num: number): string
1353
1354根据指定数量获取指定resource对象表示的单复数字符串,使用同步方式返回字符串。
1355
1356**系统能力**:SystemCapability.Global.ResourceManager
1357
1358**模型约束**:此接口仅可在Stage模型下使用。
1359
1360**参数:**
1361
1362| 参数名   | 类型     | 必填   | 说明    |
1363| ----- | ------ | ---- | ----- |
1364| resource | [Resource](#resource9) | 是    | 资源信息 |
1365| num      | number                 | 是    | 数量值   |
1366
1367**返回值:**
1368
1369| 类型                    | 说明          |
1370| --------------------- | ----------- |
1371| string | 根据指定数量获取指定resource对象表示的单复数字符串 |
1372
1373**错误码:**
1374
1375以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1376
1377| 错误码ID | 错误信息 |
1378| -------- | ---------------------------------------- |
1379| 9001001  | If the resId invalid.                       |
1380| 9001002  | If the resource not found by resId.         |
1381| 9001006  | If the resource re-ref too much.            |
1382
1383**示例:**
1384  ```ts
1385  import resourceManager from '@ohos.resourceManager';
1386  import { BusinessError } from '@ohos.base';
1387
1388  let resource: resourceManager.Resource = {
1389    bundleName: "com.example.myapplication",
1390    moduleName: "entry",
1391    id: $r('app.plural.test').id
1392  };
1393  try {
1394    this.context.resourceManager.getPluralStringValueSync(resource, 1);
1395  } catch (error) {
1396    let code = (error as BusinessError).code;
1397    let message = (error as BusinessError).message;
1398    console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
1399  }
1400  ```
1401
1402### getPluralStringByNameSync<sup>10+</sup>
1403
1404getPluralStringByNameSync(resName: string, num: number): string
1405
1406根据指定数量获取指定资源名称表示的单复数字符串,使用同步方式返回字符串。
1407
1408**系统能力**:SystemCapability.Global.ResourceManager
1409
1410**参数:**
1411
1412| 参数名   | 类型     | 必填   | 说明    |
1413| ----- | ------ | ---- | ----- |
1414| resName | string | 是    | 资源名称 |
1415| num      | number                 | 是    | 数量值   |
1416
1417**返回值:**
1418
1419| 类型                    | 说明          |
1420| --------------------- | ----------- |
1421| string | 根据指定数量获取指定资源名称表示的单复数字符串 |
1422
1423**错误码:**
1424
1425以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1426
1427| 错误码ID | 错误信息 |
1428| -------- | ---------------------------------------- |
1429| 9001003  | If the resName invalid.                       |
1430| 9001004  | If the resource not found by resName.         |
1431| 9001006  | If the resource re-ref too much.            |
1432
1433**示例:**
1434  ```ts
1435  import { BusinessError } from '@ohos.base';
1436
1437  try {
1438    this.context.resourceManager.getPluralStringByNameSync("test", 1);
1439  } catch (error) {
1440    let code = (error as BusinessError).code;
1441    let message = (error as BusinessError).message;
1442    console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`);
1443  }
1444  ```
1445
1446### getPluralStringValue<sup>9+</sup>
1447
1448getPluralStringValue(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
1449
1450根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。
1451
1452**系统能力**:SystemCapability.Global.ResourceManager
1453
1454**参数:**
1455
1456| 参数名      | 类型                          | 必填   | 说明                              |
1457| -------- | --------------------------- | ---- | ------------------------------- |
1458| resId    | number                      | 是    | 资源ID值                           |
1459| num      | number                      | 是    | 数量值                             |
1460| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 |
1461
1462**错误码:**
1463
1464以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1465
1466| 错误码ID | 错误信息 |
1467| -------- | ---------------------------------------- |
1468| 9001001  | If the resId invalid.                       |
1469| 9001002  | If the resource not found by resId.         |
1470| 9001006  | If the resource re-ref too much.            |
1471
1472**示例:**
1473  ```ts
1474  import { BusinessError } from '@ohos.base';
1475
1476  try {
1477    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => {
1478      if (error != null) {
1479        console.log("error is " + error);
1480      } else {
1481        let str = value;
1482      }
1483    });
1484  } catch (error) {
1485    let code = (error as BusinessError).code;
1486    let message = (error as BusinessError).message;
1487    console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`);
1488  }
1489  ```
1490
1491### getPluralStringValue<sup>9+</sup>
1492
1493getPluralStringValue(resId: number, num: number): Promise&lt;string&gt;
1494
1495根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。
1496
1497**系统能力**:SystemCapability.Global.ResourceManager
1498
1499**参数:**
1500
1501| 参数名   | 类型     | 必填   | 说明    |
1502| ----- | ------ | ---- | ----- |
1503| resId | number | 是    | 资源ID值 |
1504| num   | number | 是    | 数量值   |
1505
1506**返回值:**
1507
1508| 类型                    | 说明                        |
1509| --------------------- | ------------------------- |
1510| Promise&lt;string&gt; | 根据提供的数量获取对应ID字符串表示的单复数字符串 |
1511
1512**错误码:**
1513
1514以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1515
1516| 错误码ID | 错误信息 |
1517| -------- | ---------------------------------------- |
1518| 9001001  | If the resId invalid.                       |
1519| 9001002  | If the resource not found by resId.         |
1520| 9001006  | If the resource re-ref too much.            |
1521
1522**示例:**
1523  ```ts
1524  import { BusinessError } from '@ohos.base';
1525
1526  try {
1527    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then((value: string) => {
1528      let str = value;
1529    }).catch((error: BusinessError) => {
1530      console.log("getPluralStringValue promise error is " + error);
1531    });
1532  } catch (error) {
1533    let code = (error as BusinessError).code;
1534    let message = (error as BusinessError).message;
1535    console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`);
1536  }
1537  ```
1538
1539### getPluralStringValue<sup>9+</sup>
1540
1541getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback&lt;string&gt;): void
1542
1543根据指定数量获取指定resource对象表示的单复数字符串,使用callback形式返回字符串。
1544
1545**系统能力**:SystemCapability.Global.ResourceManager
1546
1547**模型约束**:此接口仅可在Stage模型下使用。
1548
1549**参数:**
1550
1551| 参数名      | 类型                          | 必填   | 说明                                   |
1552| -------- | --------------------------- | ---- | ------------------------------------ |
1553| resource | [Resource](#resource9)      | 是    | 资源信息                                 |
1554| num      | number                      | 是    | 数量值                                  |
1555| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定resource对象表示的单复数字符串 |
1556
1557**错误码:**
1558
1559以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1560
1561| 错误码ID | 错误信息 |
1562| -------- | ---------------------------------------- |
1563| 9001001  | If the resId invalid.                       |
1564| 9001002  | If the resource not found by resId.         |
1565| 9001006  | If the resource re-ref too much.            |
1566
1567**示例:**
1568  ```ts
1569  import resourceManager from '@ohos.resourceManager';
1570  import { BusinessError } from '@ohos.base';
1571
1572  let resource: resourceManager.Resource = {
1573    bundleName: "com.example.myapplication",
1574    moduleName: "entry",
1575    id: $r('app.plural.test').id
1576  };
1577  try {
1578    this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => {
1579      if (error != null) {
1580        console.log("error is " + error);
1581      } else {
1582        let str = value;
1583      }
1584    });
1585  } catch (error) {
1586    let code = (error as BusinessError).code;
1587    let message = (error as BusinessError).message;
1588    console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`);
1589  }
1590  ```
1591
1592### getPluralStringValue<sup>9+</sup>
1593
1594getPluralStringValue(resource: Resource, num: number): Promise&lt;string&gt;
1595
1596根据指定数量获取对指定resource对象表示的单复数字符串,使用Promise形式返回字符串。
1597
1598**系统能力**:SystemCapability.Global.ResourceManager
1599
1600**模型约束**:此接口仅可在Stage模型下使用。
1601
1602**参数:**
1603
1604| 参数名      | 类型                     | 必填   | 说明   |
1605| -------- | ---------------------- | ---- | ---- |
1606| resource | [Resource](#resource9) | 是    | 资源信息 |
1607| num      | number                 | 是    | 数量值  |
1608
1609**返回值:**
1610
1611| 类型                    | 说明                             |
1612| --------------------- | ------------------------------ |
1613| Promise&lt;string&gt; | 根据提供的数量获取对应resource对象表示的单复数字符串 |
1614
1615**错误码:**
1616
1617以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1618
1619| 错误码ID | 错误信息 |
1620| -------- | ---------------------------------------- |
1621| 9001001  | If the resId invalid.                       |
1622| 9001002  | If the resource not found by resId.         |
1623| 9001006  | If the resource re-ref too much.            |
1624
1625**示例:**
1626  ```ts
1627  import resourceManager from '@ohos.resourceManager';
1628  import { BusinessError } from '@ohos.base';
1629
1630  let resource: resourceManager.Resource = {
1631    bundleName: "com.example.myapplication",
1632    moduleName: "entry",
1633    id: $r('app.plural.test').id
1634  };
1635  try {
1636    this.context.resourceManager.getPluralStringValue(resource, 1).then((value: string) => {
1637      let str = value;
1638    }).catch((error: BusinessError) => {
1639      console.log("getPluralStringValue promise error is " + error);
1640    });
1641  } catch (error) {
1642    let code = (error as BusinessError).code;
1643    let message = (error as BusinessError).message;
1644    console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`);
1645  }
1646  ```
1647
1648### getPluralStringByName<sup>9+</sup>
1649
1650getPluralStringByName(resName: string, num: number, callback: AsyncCallback&lt;string&gt;): void
1651
1652根据传入的数量值,获取资源名称对应的字符串资源,使用callback形式返回字符串。
1653
1654**系统能力**:SystemCapability.Global.ResourceManager
1655
1656**参数:**
1657
1658| 参数名      | 类型                          | 必填   | 说明                            |
1659| -------- | --------------------------- | ---- | ----------------------------- |
1660| resName  | string                      | 是    | 资源名称                          |
1661| num      | number                      | 是    | 数量值                           |
1662| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据传入的数量值获取资源名称对应的字符串资源 |
1663
1664**错误码:**
1665
1666以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1667
1668| 错误码ID | 错误信息 |
1669| -------- | ---------------------------------------- |
1670| 9001003  | If the resName invalid.                     |
1671| 9001004  | If the resource not found by resName.       |
1672| 9001006  | If the resource re-ref too much.            |
1673
1674**示例:**
1675  ```ts
1676  import { BusinessError } from '@ohos.base';
1677
1678  try {
1679    this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
1680      if (error != null) {
1681        console.log("error is " + error);
1682      } else {
1683        let str = value;
1684      }
1685    });
1686  } catch (error) {
1687    let code = (error as BusinessError).code;
1688    let message = (error as BusinessError).message;
1689    console.error(`callback getPluralStringByName failed, error code: ${code}, message: ${message}.`);
1690  }
1691  ```
1692
1693### getPluralStringByName<sup>9+</sup>
1694
1695getPluralStringByName(resName: string, num: number): Promise&lt;string&gt;
1696
1697根据传入的数量值,获取资源名称对应的字符串资源,使用Promise形式返回字符串。
1698
1699**系统能力**:SystemCapability.Global.ResourceManager
1700
1701**参数:**
1702
1703| 参数名     | 类型     | 必填   | 说明   |
1704| ------- | ------ | ---- | ---- |
1705| resName | string | 是    | 资源名称 |
1706| num     | number | 是    | 数量值  |
1707
1708**返回值:**
1709
1710| 类型                    | 说明                     |
1711| --------------------- | ---------------------- |
1712| Promise&lt;string&gt; | 根据传入的数量值获取资源名称对应的字符串资源 |
1713
1714**错误码:**
1715
1716以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1717
1718| 错误码ID | 错误信息 |
1719| -------- | ---------------------------------------- |
1720| 9001003  | If the resName invalid.                     |
1721| 9001004  | If the resource not found by resName.       |
1722| 9001006  | If the resource re-ref too much.            |
1723
1724**示例:**
1725  ```ts
1726  import { BusinessError } from '@ohos.base';
1727
1728  try {
1729    this.context.resourceManager.getPluralStringByName("test", 1).then((value: string) => {
1730      let str = value;
1731    }).catch((error: BusinessError) => {
1732      console.log("getPluralStringByName promise error is " + error);
1733    });
1734  } catch (error) {
1735    let code = (error as BusinessError).code;
1736    let message = (error as BusinessError).message;
1737    console.error(`promise getPluralStringByName failed, error code: ${code}, message: ${message}.`);
1738  }
1739  ```
1740
1741### getMediaContentSync<sup>10+</sup>
1742
1743getMediaContentSync(resId: number, density?: number): Uint8Array
1744
1745用户获取指定资源ID对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。
1746
1747**系统能力**:SystemCapability.Global.ResourceManager
1748
1749**参数:**
1750
1751| 参数名   | 类型     | 必填   | 说明    |
1752| ----- | ------ | ---- | ----- |
1753| resId | number | 是    | 资源ID值 |
1754| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
1755
1756**返回值:**
1757
1758| 类型                    | 说明          |
1759| -------- | ----------- |
1760| Uint8Array   | 资源ID对应的媒体文件内容 |
1761
1762**错误码:**
1763
1764以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1765
1766| 错误码ID | 错误信息 |
1767| -------- | ---------------------------------------- |
1768| 9001001  | If the resId invalid.                       |
1769| 9001002  | If the resource not found by resId.         |
1770
1771**示例:**
1772  ```ts
1773  import { BusinessError } from '@ohos.base';
1774
1775  try {
1776    this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // 默认屏幕密度
1777  } catch (error) {
1778    let code = (error as BusinessError).code;
1779    let message = (error as BusinessError).message;
1780    console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
1781  }
1782
1783  try {
1784    this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // 指定屏幕密度
1785  } catch (error) {
1786    let code = (error as BusinessError).code;
1787    let message = (error as BusinessError).message;
1788    console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
1789  }
1790  ```
1791
1792### getMediaContentSync<sup>10+</sup>
1793
1794getMediaContentSync(resource: Resource, density?: number): Uint8Array
1795
1796用户获取指定resource对象对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。
1797
1798**系统能力**:SystemCapability.Global.ResourceManager
1799
1800**模型约束**:此接口仅可在Stage模型下使用。
1801
1802**参数:**
1803
1804| 参数名   | 类型     | 必填   | 说明    |
1805| ----- | ------ | ---- | ----- |
1806| resource | [Resource](#resource9) | 是    | 资源信息 |
1807| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
1808
1809**返回值:**
1810
1811| 类型                    | 说明          |
1812| --------------------- | ----------- |
1813| Uint8Array | resource对象对应的媒体文件内容 |
1814
1815**错误码:**
1816
1817以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1818
1819| 错误码ID | 错误信息 |
1820| -------- | ---------------------------------------- |
1821| 9001001  | If the resId invalid.                       |
1822| 9001002  | If the resource not found by resId.         |
1823
1824**示例:**
1825  ```ts
1826  import resourceManager from '@ohos.resourceManager';
1827  import { BusinessError } from '@ohos.base';
1828
1829  let resource: resourceManager.Resource = {
1830    bundleName: "com.example.myapplication",
1831    moduleName: "entry",
1832    id: $r('app.media.test').id
1833  };
1834  try {
1835    this.context.resourceManager.getMediaContentSync(resource); // 默认屏幕密度
1836  } catch (error) {
1837    let code = (error as BusinessError).code;
1838    let message = (error as BusinessError).message;
1839    console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
1840  }
1841
1842  try {
1843    this.context.resourceManager.getMediaContentSync(resource, 120); // 指定屏幕密度
1844  } catch (error) {
1845    let code = (error as BusinessError).code;
1846    let message = (error as BusinessError).message;
1847    console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
1848  }
1849  ```
1850
1851### getMediaByNameSync<sup>10+</sup>
1852
1853getMediaByNameSync(resName: string, density?: number): Uint8Array
1854
1855用户获取指定资源名称对应的默认或指定的屏幕密度媒体文件内容,使用同步方式返回字节数组。
1856
1857**系统能力**:SystemCapability.Global.ResourceManager
1858
1859**参数:**
1860
1861| 参数名   | 类型     | 必填   | 说明    |
1862| ----- | ------ | ---- | ----- |
1863| resName | string | 是    | 资源名称 |
1864| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
1865
1866**返回值:**
1867
1868| 类型                    | 说明          |
1869| --------------------- | ----------- |
1870| Uint8Array | 对应资源名称的媒体文件内容 |
1871
1872**错误码:**
1873
1874以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1875
1876| 错误码ID | 错误信息 |
1877| -------- | ---------------------------------------- |
1878| 9001003  | If the resName invalid.                       |
1879| 9001004  | If the resource not found by resName.         |
1880
1881**示例:**
1882  ```ts
1883  import { BusinessError } from '@ohos.base';
1884
1885  try {
1886    this.context.resourceManager.getMediaByNameSync("test"); // 默认屏幕密度
1887  } catch (error) {
1888    let code = (error as BusinessError).code;
1889    let message = (error as BusinessError).message;
1890    console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
1891  }
1892
1893  try {
1894    this.context.resourceManager.getMediaByNameSync("test", 120); // 指定屏幕密度
1895  } catch (error) {
1896    let code = (error as BusinessError).code;
1897    let message = (error as BusinessError).message;
1898    console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
1899  }
1900  ```
1901
1902### getMediaContent<sup>9+</sup>
1903
1904getMediaContent(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
1905
1906用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
1907
1908**系统能力**:SystemCapability.Global.ResourceManager
1909
1910**参数:**
1911
1912| 参数名      | 类型                              | 必填   | 说明                 |
1913| -------- | ------------------------------- | ---- | ------------------ |
1914| resId    | number                          | 是    | 资源ID值              |
1915| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
1916
1917**错误码:**
1918
1919以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1920
1921| 错误码ID | 错误信息 |
1922| -------- | ---------------------------------------- |
1923| 9001001  | If the resId invalid.                       |
1924| 9001002  | If the resource not found by resId.         |
1925
1926**示例:**
1927  ```ts
1928  import { BusinessError } from '@ohos.base';
1929
1930  try {
1931    this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
1932      if (error != null) {
1933        console.log("error is " + error);
1934      } else {
1935        let media = value;
1936      }
1937    });
1938  } catch (error) {
1939    let code = (error as BusinessError).code;
1940    let message = (error as BusinessError).message;
1941    console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
1942  }
1943  ```
1944
1945### getMediaContent<sup>10+</sup>
1946
1947getMediaContent(resId: number, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
1948
1949用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
1950
1951**系统能力**:SystemCapability.Global.ResourceManager
1952
1953**参数:**
1954
1955| 参数名      | 类型                              | 必填   | 说明                 |
1956| -------- | ------------------------------- | ---- | ------------------ |
1957| resId    | number                          | 是    | 资源ID值              |
1958| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
1959| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
1960
1961**错误码:**
1962
1963以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
1964
1965| 错误码ID | 错误信息 |
1966| -------- | ---------------------------------------- |
1967| 9001001  | If the resId invalid.                       |
1968| 9001002  | If the resource not found by resId.         |
1969
1970**示例:**
1971  ```ts
1972  import { BusinessError } from '@ohos.base';
1973
1974  try {
1975    this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => {
1976      if (error != null) {
1977        console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
1978      } else {
1979        let media = value;
1980      }
1981    });
1982  } catch (error) {
1983    let code = (error as BusinessError).code;
1984    let message = (error as BusinessError).message;
1985    console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
1986  }
1987  ```
1988
1989### getMediaContent<sup>9+</sup>
1990
1991getMediaContent(resId: number): Promise&lt;Uint8Array&gt;
1992
1993用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。
1994
1995**系统能力**:SystemCapability.Global.ResourceManager
1996
1997**参数:**
1998
1999| 参数名   | 类型     | 必填   | 说明    |
2000| ----- | ------ | ---- | ----- |
2001| resId | number | 是    | 资源ID值 |
2002
2003**返回值:**
2004
2005| 类型                        | 说明             |
2006| ------------------------- | -------------- |
2007| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |
2008
2009**错误码:**
2010
2011以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2012
2013| 错误码ID | 错误信息 |
2014| -------- | ---------------------------------------- |
2015| 9001001  | If the resId invalid.                       |
2016| 9001002  | If the resource not found by resId.         |
2017
2018**示例:**
2019  ```ts
2020  import { BusinessError } from '@ohos.base';
2021
2022  try {
2023    this.context.resourceManager.getMediaContent($r('app.media.test').id).then((value: Uint8Array) => {
2024      let media = value;
2025    }).catch((error: BusinessError) => {
2026      console.log("getMediaContent promise error is " + error);
2027    });
2028  } catch (error) {
2029    let code = (error as BusinessError).code;
2030    let message = (error as BusinessError).message;
2031    console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
2032  }
2033  ```
2034
2035### getMediaContent<sup>10+</sup>
2036
2037getMediaContent(resId: number, density: number): Promise&lt;Uint8Array&gt;
2038
2039用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
2040
2041**系统能力**:SystemCapability.Global.ResourceManager
2042
2043**参数:**
2044
2045| 参数名   | 类型     | 必填   | 说明    |
2046| ----- | ------ | ---- | ----- |
2047| resId | number | 是    | 资源ID值 |
2048| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2049
2050**返回值:**
2051
2052| 类型                        | 说明             |
2053| ------------------------- | -------------- |
2054| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |
2055
2056**错误码:**
2057
2058以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2059
2060| 错误码ID | 错误信息 |
2061| -------- | ---------------------------------------- |
2062| 9001001  | If the resId invalid.                       |
2063| 9001002  | If the resource not found by resId.         |
2064
2065**示例:**
2066  ```ts
2067  import { BusinessError } from '@ohos.base';
2068
2069  try {
2070    this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then((value: Uint8Array) => {
2071      let media = value;
2072    }).catch((error: BusinessError) => {
2073      console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
2074    });
2075  } catch (error) {
2076    let code = (error as BusinessError).code;
2077    let message = (error as BusinessError).message;
2078    console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
2079  }
2080  ```
2081
2082### getMediaContent<sup>9+</sup>
2083
2084getMediaContent(resource: Resource, callback: AsyncCallback&lt;Uint8Array&gt;): void
2085
2086用户获取指定resource对象对应的媒体文件内容,使用callback形式返回字节数组。
2087
2088**系统能力**:SystemCapability.Global.ResourceManager
2089
2090**模型约束**:此接口仅可在Stage模型下使用。
2091
2092**参数:**
2093
2094| 参数名      | 类型                              | 必填   | 说明                 |
2095| -------- | ------------------------------- | ---- | ------------------ |
2096| resource | [Resource](#resource9)          | 是    | 资源信息               |
2097| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
2098
2099**错误码:**
2100
2101以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2102
2103| 错误码ID | 错误信息 |
2104| -------- | ---------------------------------------- |
2105| 9001001  | If the resId invalid.                       |
2106| 9001002  | If the resource not found by resId.         |
2107
2108**示例:**
2109  ```ts
2110  import resourceManager from '@ohos.resourceManager';
2111  import { BusinessError } from '@ohos.base';
2112
2113  let resource: resourceManager.Resource = {
2114    bundleName: "com.example.myapplication",
2115    moduleName: "entry",
2116    id: $r('app.media.test').id
2117  };
2118  try {
2119    this.context.resourceManager.getMediaContent(resource, (error, value) => {
2120      if (error != null) {
2121        console.log("error is " + error);
2122      } else {
2123        let media = value;
2124      }
2125    });
2126  } catch (error) {
2127    let code = (error as BusinessError).code;
2128    let message = (error as BusinessError).message;
2129    console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
2130  }
2131  ```
2132
2133### getMediaContent<sup>10+</sup>
2134
2135getMediaContent(resource: Resource, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
2136
2137用户获取指定resource对象对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
2138
2139**系统能力**:SystemCapability.Global.ResourceManager
2140
2141**模型约束**:此接口仅可在Stage模型下使用。
2142
2143**参数:**
2144
2145| 参数名      | 类型                              | 必填   | 说明                 |
2146| -------- | ------------------------------- | ---- | ------------------ |
2147| resource | [Resource](#resource9)          | 是    | 资源信息               |
2148| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2149| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
2150
2151**错误码:**
2152
2153以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2154
2155| 错误码ID | 错误信息 |
2156| -------- | ---------------------------------------- |
2157| 9001001  | If the resId invalid.                       |
2158| 9001002  | If the resource not found by resId.         |
2159
2160**示例:**
2161  ```ts
2162  import resourceManager from '@ohos.resourceManager';
2163  import { BusinessError } from '@ohos.base';
2164
2165  let resource: resourceManager.Resource = {
2166    bundleName: "com.example.myapplication",
2167    moduleName: "entry",
2168    id: $r('app.media.test').id
2169  };
2170  try {
2171    this.context.resourceManager.getMediaContent(resource, 120, (error, value) => {
2172      if (error != null) {
2173        console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
2174      } else {
2175        let media = value;
2176      }
2177    });
2178  } catch (error) {
2179    let code = (error as BusinessError).code;
2180    let message = (error as BusinessError).message;
2181    console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`);
2182  }
2183  ```
2184
2185### getMediaContent<sup>9+</sup>
2186
2187getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
2188
2189用户获取指定resource对象对应的媒体文件内容,使用Promise形式返回字节数组。
2190
2191**系统能力**:SystemCapability.Global.ResourceManager
2192
2193**模型约束**:此接口仅可在Stage模型下使用。
2194
2195**参数:**
2196
2197| 参数名      | 类型                     | 必填   | 说明   |
2198| -------- | ---------------------- | ---- | ---- |
2199| resource | [Resource](#resource9) | 是    | 资源信息 |
2200
2201**返回值:**
2202
2203| 类型                        | 说明                  |
2204| ------------------------- | ------------------- |
2205| Promise&lt;Uint8Array&gt; | resource对象对应的媒体文件内容 |
2206
2207**错误码:**
2208
2209以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2210
2211| 错误码ID | 错误信息 |
2212| -------- | ---------------------------------------- |
2213| 9001001  | If the resId invalid.                       |
2214| 9001002  | If the resource not found by resId.         |
2215
2216**示例:**
2217  ```ts
2218  import resourceManager from '@ohos.resourceManager';
2219  import { BusinessError } from '@ohos.base';
2220
2221  let resource: resourceManager.Resource = {
2222    bundleName: "com.example.myapplication",
2223    moduleName: "entry",
2224    id: $r('app.media.test').id
2225  };
2226  try {
2227    this.context.resourceManager.getMediaContent(resource).then((value: Uint8Array) => {
2228      let media = value;
2229    }).catch((error: BusinessError) => {
2230      console.log("getMediaContent promise error is " + error);
2231    });
2232  } catch (error) {
2233    let code = (error as BusinessError).code;
2234    let message = (error as BusinessError).message;
2235    console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
2236  }
2237  ```
2238
2239### getMediaContent<sup>10+</sup>
2240
2241getMediaContent(resource: Resource, density: number): Promise&lt;Uint8Array&gt;
2242
2243用户获取指定resource对象对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
2244
2245**系统能力**:SystemCapability.Global.ResourceManager
2246
2247**模型约束**:此接口仅可在Stage模型下使用。
2248
2249**参数:**
2250
2251| 参数名      | 类型                     | 必填   | 说明   |
2252| -------- | ---------------------- | ---- | ---- |
2253| resource | [Resource](#resource9) | 是    | 资源信息 |
2254| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2255
2256**返回值:**
2257
2258| 类型                        | 说明                  |
2259| ------------------------- | ------------------- |
2260| Promise&lt;Uint8Array&gt; | resource对象对应的媒体文件内容 |
2261
2262**错误码:**
2263
2264以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2265
2266| 错误码ID | 错误信息 |
2267| -------- | ---------------------------------------- |
2268| 9001001  | If the resId invalid.                       |
2269| 9001002  | If the resource not found by resId.         |
2270
2271**示例:**
2272  ```ts
2273  import resourceManager from '@ohos.resourceManager';
2274  import { BusinessError } from '@ohos.base';
2275
2276  let resource: resourceManager.Resource = {
2277    bundleName: "com.example.myapplication",
2278    moduleName: "entry",
2279    id: $r('app.media.test').id
2280  };
2281  try {
2282    this.context.resourceManager.getMediaContent(resource, 120).then((value: Uint8Array) => {
2283      let media = value;
2284    }).catch((error: BusinessError) => {
2285      console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
2286    });
2287  } catch (error) {
2288    let code = (error as BusinessError).code;
2289    let message = (error as BusinessError).message;
2290    console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`);
2291  }
2292  ```
2293
2294### getMediaByName<sup>9+</sup>
2295
2296getMediaByName(resName: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
2297
2298用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
2299
2300**系统能力**:SystemCapability.Global.ResourceManager
2301
2302**参数:**
2303
2304| 参数名      | 类型                              | 必填   | 说明                 |
2305| -------- | ------------------------------- | ---- | ------------------ |
2306| resName  | string                          | 是    | 资源名称               |
2307| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
2308
2309**错误码:**
2310
2311以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2312
2313| 错误码ID | 错误信息 |
2314| -------- | ---------------------------------------- |
2315| 9001003  | If the resName invalid.                     |
2316| 9001004  | If the resource not found by resName.       |
2317
2318**示例:**
2319  ```ts
2320  import { BusinessError } from '@ohos.base';
2321
2322  try {
2323    this.context.resourceManager.getMediaByName("test", (error, value) => {
2324      if (error != null) {
2325        console.log("error is " + error);
2326      } else {
2327        let media = value;
2328      }
2329    });
2330  } catch (error) {
2331    let code = (error as BusinessError).code;
2332    let message = (error as BusinessError).message;
2333    console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`);
2334  }
2335  ```
2336
2337### getMediaByName<sup>10+</sup>
2338
2339getMediaByName(resName: string, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
2340
2341用户获取指定资源ID对应的指定屏幕密度媒体文件内容,使用callback形式返回字节数组。
2342
2343**系统能力**:SystemCapability.Global.ResourceManager
2344
2345**参数:**
2346
2347| 参数名      | 类型                              | 必填   | 说明                 |
2348| -------- | ------------------------------- | ---- | ------------------ |
2349| resName  | string                          | 是    | 资源名称               |
2350| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2351| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
2352
2353**错误码:**
2354
2355以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2356
2357| 错误码ID | 错误信息 |
2358| -------- | ---------------------------------------- |
2359| 9001003  | If the resName invalid.                     |
2360| 9001004  | If the resource not found by resName.       |
2361
2362**示例:**
2363  ```ts
2364  import { BusinessError } from '@ohos.base';
2365
2366  try {
2367    this.context.resourceManager.getMediaByName("test", 120, (error, value) => {
2368      if (error != null) {
2369        console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
2370      } else {
2371        let media = value;
2372      }
2373    });
2374  } catch (error) {
2375    let code = (error as BusinessError).code;
2376    let message = (error as BusinessError).message;
2377    console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`);
2378  }
2379  ```
2380
2381### getMediaByName<sup>9+</sup>
2382
2383getMediaByName(resName: string): Promise&lt;Uint8Array&gt;
2384
2385用户获取指定资源名称对应的媒体文件内容,使用Promise形式返回字节数组。
2386
2387**系统能力**:SystemCapability.Global.ResourceManager
2388
2389**参数:**
2390
2391| 参数名     | 类型     | 必填   | 说明   |
2392| ------- | ------ | ---- | ---- |
2393| resName | string | 是    | 资源名称 |
2394
2395**返回值:**
2396
2397| 类型                        | 说明            |
2398| ------------------------- | ------------- |
2399| Promise&lt;Uint8Array&gt; | 资源名称对应的媒体文件内容 |
2400
2401**错误码:**
2402
2403以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2404
2405| 错误码ID | 错误信息 |
2406| -------- | ---------------------------------------- |
2407| 9001003  | If the resName invalid.                     |
2408| 9001004  | If the resource not found by resName.       |
2409
2410**示例:**
2411  ```ts
2412  import { BusinessError } from '@ohos.base';
2413
2414  try {
2415    this.context.resourceManager.getMediaByName("test").then((value: Uint8Array) => {
2416      let media = value;
2417    }).catch((error: BusinessError) => {
2418      console.log("getMediaByName promise error is " + error);
2419    });
2420  } catch (error) {
2421    let code = (error as BusinessError).code;
2422    let message = (error as BusinessError).message;
2423    console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`);
2424  }
2425  ```
2426
2427### getMediaByName<sup>10+</sup>
2428
2429getMediaByName(resName: string, density: number): Promise&lt;Uint8Array&gt;
2430
2431用户获取指定资源名称对应的指定屏幕密度媒体文件内容,使用Promise形式返回字节数组。
2432
2433**系统能力**:SystemCapability.Global.ResourceManager
2434
2435**参数:**
2436
2437| 参数名     | 类型     | 必填   | 说明   |
2438| ------- | ------ | ---- | ---- |
2439| resName | string | 是    | 资源名称 |
2440| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2441
2442**返回值:**
2443
2444| 类型                        | 说明            |
2445| ------------------------- | ------------- |
2446| Promise&lt;Uint8Array&gt; | 资源名称对应的媒体文件内容 |
2447
2448**错误码:**
2449
2450以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2451
2452| 错误码ID | 错误信息 |
2453| -------- | ---------------------------------------- |
2454| 9001003  | If the resName invalid.                     |
2455| 9001004  | If the resource not found by resName.       |
2456
2457**示例:**
2458  ```ts
2459  import { BusinessError } from '@ohos.base';
2460
2461  try {
2462    this.context.resourceManager.getMediaByName("test", 120).then((value: Uint8Array) => {
2463      let media = value;
2464    }).catch((error: BusinessError) => {
2465      console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
2466    });
2467  } catch (error) {
2468    let code = (error as BusinessError).code;
2469    let message = (error as BusinessError).message;
2470    console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`);
2471  }
2472  ```
2473
2474### getMediaContentBase64Sync<sup>10+</sup>
2475
2476getMediaContentBase64Sync(resId: number, density?: number): string
2477
2478用户获取指定资源ID对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。
2479
2480**系统能力**:SystemCapability.Global.ResourceManager
2481
2482**参数:**
2483
2484| 参数名   | 类型     | 必填   | 说明    |
2485| ----- | ------ | ---- | ----- |
2486| resId | number | 是    | 资源ID值 |
2487| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
2488
2489**返回值:**
2490
2491| 类型                    | 说明          |
2492| -------- | ----------- |
2493| string   | 资源ID对应的图片资源Base64编码 |
2494
2495**错误码:**
2496
2497以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2498
2499| 错误码ID | 错误信息 |
2500| -------- | ---------------------------------------- |
2501| 9001001  | If the resId invalid.                       |
2502| 9001002  | If the resource not found by resId.         |
2503
2504**示例:**
2505  ```ts
2506  import { BusinessError } from '@ohos.base';
2507
2508  try {
2509    this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // 默认屏幕密度
2510  } catch (error) {
2511    let code = (error as BusinessError).code;
2512    let message = (error as BusinessError).message;
2513    console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
2514  }
2515
2516  try {
2517    this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // 指定屏幕密度
2518  } catch (error) {
2519    let code = (error as BusinessError).code;
2520    let message = (error as BusinessError).message;
2521    console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
2522  }
2523  ```
2524
2525### getMediaContentBase64Sync<sup>10+</sup>
2526
2527getMediaContentBase64Sync(resource: Resource, density?: number): string
2528
2529用户获取指定resource对象对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。
2530
2531**系统能力**:SystemCapability.Global.ResourceManager
2532
2533**模型约束**:此接口仅可在Stage模型下使用。
2534
2535**参数:**
2536
2537| 参数名   | 类型     | 必填   | 说明    |
2538| ----- | ------ | ---- | ----- |
2539| resource | [Resource](#resource9) | 是    | 资源信息 |
2540| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
2541
2542**返回值:**
2543
2544| 类型                    | 说明          |
2545| --------------------- | ----------- |
2546| string | resource对象对应的图片资源Base64编码 |
2547
2548**错误码:**
2549
2550以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2551
2552| 错误码ID | 错误信息 |
2553| -------- | ---------------------------------------- |
2554| 9001001  | If the resId invalid.                       |
2555| 9001002  | If the resource not found by resId.         |
2556
2557**示例:**
2558  ```ts
2559  import resourceManager from '@ohos.resourceManager';
2560  import { BusinessError } from '@ohos.base';
2561
2562  let resource: resourceManager.Resource = {
2563    bundleName: "com.example.myapplication",
2564    moduleName: "entry",
2565    id: $r('app.media.test').id
2566  };
2567  try {
2568    this.context.resourceManager.getMediaContentBase64Sync(resource); // 默认屏幕密度
2569  } catch (error) {
2570    let code = (error as BusinessError).code;
2571    let message = (error as BusinessError).message;
2572    console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
2573  }
2574
2575  try {
2576    this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // 指定屏幕密度
2577  } catch (error) {
2578    let code = (error as BusinessError).code;
2579    let message = (error as BusinessError).message;
2580    console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
2581  }
2582  ```
2583
2584### getMediaBase64ByNameSync<sup>10+</sup>
2585
2586getMediaBase64ByNameSync(resName: string, density?: number): string
2587
2588用户获取指定资源名称对应的默认或指定的屏幕密度图片资源Base64编码,使用同步方式返回字符串。
2589
2590**系统能力**:SystemCapability.Global.ResourceManager
2591
2592**参数:**
2593
2594| 参数名   | 类型     | 必填   | 说明    |
2595| ----- | ------ | ---- | ----- |
2596| resName | string | 是    | 资源名称 |
2597| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
2598
2599**返回值:**
2600
2601| 类型                    | 说明          |
2602| --------------------- | ----------- |
2603| string | 资源名称对应的图片资源Base64编码 |
2604
2605**错误码:**
2606
2607以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2608
2609| 错误码ID | 错误信息 |
2610| -------- | ---------------------------------------- |
2611| 9001003  | If the resName invalid.                       |
2612| 9001004  | If the resource not found by resName.         |
2613
2614**示例:**
2615  ```ts
2616  import { BusinessError } from '@ohos.base';
2617
2618  try {
2619    this.context.resourceManager.getMediaBase64ByNameSync("test"); // 默认屏幕密度
2620  } catch (error) {
2621    let code = (error as BusinessError).code;
2622    let message = (error as BusinessError).message;
2623    console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
2624  }
2625
2626  try {
2627    this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // 指定屏幕密度
2628  } catch (error) {
2629    let code = (error as BusinessError).code;
2630    let message = (error as BusinessError).message;
2631    console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
2632  }
2633  ```
2634
2635### getMediaContentBase64<sup>9+</sup>
2636
2637getMediaContentBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void
2638
2639用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。
2640
2641**系统能力**:SystemCapability.Global.ResourceManager
2642
2643**参数:** Content
2644
2645| 参数名      | 类型                          | 必填   | 说明                       |
2646| -------- | --------------------------- | ---- | ------------------------ |
2647| resId    | number                      | 是    | 资源ID值                    |
2648| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
2649
2650**错误码:**
2651
2652以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2653
2654| 错误码ID | 错误信息 |
2655| -------- | ---------------------------------------- |
2656| 9001001  | If the resId invalid.                       |
2657| 9001002  | If the resource not found by resId.         |
2658
2659**示例:**
2660  ```ts
2661  import { BusinessError } from '@ohos.base';
2662
2663  try {
2664    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => {
2665      if (error != null) {
2666        console.log("error is " + error);
2667      } else {
2668        let media = value;
2669      }
2670    });
2671  } catch (error) {
2672    let code = (error as BusinessError).code;
2673    let message = (error as BusinessError).message;
2674    console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2675  }
2676  ```
2677
2678### getMediaContentBase64<sup>10+</sup>
2679
2680getMediaContentBase64(resId: number, density: number, callback: AsyncCallback&lt;string&gt;): void
2681
2682用户获取指定资源ID对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
2683
2684**系统能力**:SystemCapability.Global.ResourceManager
2685
2686**参数:**
2687
2688| 参数名      | 类型                          | 必填   | 说明                       |
2689| -------- | --------------------------- | ---- | ------------------------ |
2690| resId    | number                      | 是    | 资源ID值                    |
2691| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2692| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
2693
2694**错误码:**
2695
2696以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2697
2698| 错误码ID | 错误信息 |
2699| -------- | ---------------------------------------- |
2700| 9001001  | If the resId invalid.                       |
2701| 9001002  | If the resource not found by resId.         |
2702
2703**示例:**
2704  ```ts
2705  import { BusinessError } from '@ohos.base';
2706
2707  try {
2708    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => {
2709      if (error != null) {
2710        console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
2711      } else {
2712        let media = value;
2713      }
2714    });
2715  } catch (error) {
2716    let code = (error as BusinessError).code;
2717    let message = (error as BusinessError).message;
2718    console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2719  }
2720  ```
2721
2722### getMediaContentBase64<sup>9+</sup>
2723
2724getMediaContentBase64(resId: number): Promise&lt;string&gt;
2725
2726用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。
2727
2728**系统能力**:SystemCapability.Global.ResourceManager
2729
2730**参数:**
2731
2732| 参数名   | 类型     | 必填   | 说明    |
2733| ----- | ------ | ---- | ----- |
2734| resId | number | 是    | 资源ID值 |
2735
2736**返回值:**
2737
2738| 类型                    | 说明                   |
2739| --------------------- | -------------------- |
2740| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |
2741
2742**错误码:**
2743
2744以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2745
2746| 错误码ID | 错误信息 |
2747| -------- | ---------------------------------------- |
2748| 9001001  | If the resId invalid.                       |
2749| 9001002  | If the resource not found by resId.         |
2750
2751**示例:**
2752  ```ts
2753  import { BusinessError } from '@ohos.base';
2754
2755  try {
2756    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then((value: string) => {
2757      let media = value;
2758    }).catch((error: BusinessError) => {
2759      console.log("getMediaContentBase64 promise error is " + error);
2760    });
2761  } catch (error) {
2762    let code = (error as BusinessError).code;
2763    let message = (error as BusinessError).message;
2764    console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2765  }
2766  ```
2767
2768### getMediaContentBase64<sup>10+</sup>
2769
2770getMediaContentBase64(resId: number, density: number): Promise&lt;string&gt;
2771
2772用户获取指定资源ID对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
2773
2774**系统能力**:SystemCapability.Global.ResourceManager
2775
2776**参数:**
2777
2778| 参数名   | 类型     | 必填   | 说明    |
2779| ----- | ------ | ---- | ----- |
2780| resId | number | 是    | 资源ID值 |
2781| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2782
2783**返回值:**
2784
2785| 类型                    | 说明                   |
2786| --------------------- | -------------------- |
2787| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |
2788
2789**错误码:**
2790
2791以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2792
2793| 错误码ID | 错误信息 |
2794| -------- | ---------------------------------------- |
2795| 9001001  | If the resId invalid.                       |
2796| 9001002  | If the resource not found by resId.         |
2797
2798**示例:**
2799  ```ts
2800  import { BusinessError } from '@ohos.base';
2801
2802  try {
2803    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then((value: string) => {
2804      let media = value;
2805    }).catch((error: BusinessError) => {
2806      console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
2807    });
2808  } catch (error) {
2809    let code = (error as BusinessError).code;
2810    let message = (error as BusinessError).message;
2811    console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2812  }
2813  ```
2814
2815### getMediaContentBase64<sup>9+</sup>
2816
2817getMediaContentBase64(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
2818
2819用户获取指定resource对象对应的图片资源Base64编码,使用callback形式返回字符串。
2820
2821**系统能力**:SystemCapability.Global.ResourceManager
2822
2823**模型约束**:此接口仅可在Stage模型下使用。
2824
2825**参数:**
2826
2827| 参数名      | 类型                          | 必填   | 说明                       |
2828| -------- | --------------------------- | ---- | ------------------------ |
2829| resource | [Resource](#resource9)      | 是    | 资源信息                     |
2830| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
2831
2832**错误码:**
2833
2834以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2835
2836| 错误码ID | 错误信息 |
2837| -------- | ---------------------------------------- |
2838| 9001001  | If the resId invalid.                       |
2839| 9001002  | If the resource not found by resId.         |
2840
2841**示例:**
2842  ```ts
2843  import resourceManager from '@ohos.resourceManager';
2844  import { BusinessError } from '@ohos.base';
2845
2846  let resource: resourceManager.Resource = {
2847    bundleName: "com.example.myapplication",
2848    moduleName: "entry",
2849    id: $r('app.media.test').id
2850  };
2851  try {
2852    this.context.resourceManager.getMediaContentBase64(resource, (error, value) => {
2853      if (error != null) {
2854        console.log("error is " + error);
2855      } else {
2856        let media = value;
2857      }
2858    });
2859  } catch (error) {
2860    let code = (error as BusinessError).code;
2861    let message = (error as BusinessError).message;
2862    console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2863  }
2864  ```
2865
2866### getMediaContentBase64<sup>10+</sup>
2867
2868getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback&lt;string&gt;): void
2869
2870用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
2871
2872**系统能力**:SystemCapability.Global.ResourceManager
2873
2874**模型约束**:此接口仅可在Stage模型下使用。
2875
2876**参数:**
2877
2878| 参数名      | 类型                          | 必填   | 说明                       |
2879| -------- | --------------------------- | ---- | ------------------------ |
2880| resource | [Resource](#resource9)      | 是    | 资源信息                     |
2881| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2882| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
2883
2884**错误码:**
2885
2886以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2887
2888| 错误码ID | 错误信息 |
2889| -------- | ---------------------------------------- |
2890| 9001001  | If the resId invalid.                       |
2891| 9001002  | If the resource not found by resId.         |
2892
2893**示例:**
2894  ```ts
2895  import resourceManager from '@ohos.resourceManager';
2896  import { BusinessError } from '@ohos.base';
2897
2898  let resource: resourceManager.Resource = {
2899    bundleName: "com.example.myapplication",
2900    moduleName: "entry",
2901    id: $r('app.media.test').id
2902  };
2903  try {
2904    this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => {
2905      if (error != null) {
2906        console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
2907      } else {
2908        let media = value;
2909      }
2910    });
2911  } catch (error) {
2912    let code = (error as BusinessError).code;
2913    let message = (error as BusinessError).message;
2914    console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2915  }
2916  ```
2917
2918### getMediaContentBase64<sup>9+</sup>
2919
2920getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
2921
2922用户获取指定resource对象对应的图片资源Base64编码,使用Promise形式返回字符串。
2923
2924**系统能力**:SystemCapability.Global.ResourceManager
2925
2926**模型约束**:此接口仅可在Stage模型下使用。
2927
2928**参数:**
2929
2930| 参数名      | 类型                     | 必填   | 说明   |
2931| -------- | ---------------------- | ---- | ---- |
2932| resource | [Resource](#resource9) | 是    | 资源信息 |
2933
2934**返回值:**
2935
2936| 类型                    | 说明                        |
2937| --------------------- | ------------------------- |
2938| Promise&lt;string&gt; | resource对象对应的图片资源Base64编码 |
2939
2940**错误码:**
2941
2942以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2943
2944| 错误码ID | 错误信息 |
2945| -------- | ---------------------------------------- |
2946| 9001001  | If the resId invalid.                       |
2947| 9001002  | If the resource not found by resId.         |
2948
2949**示例:**
2950  ```ts
2951  import resourceManager from '@ohos.resourceManager';
2952  import { BusinessError } from '@ohos.base';
2953
2954  let resource: resourceManager.Resource = {
2955    bundleName: "com.example.myapplication",
2956    moduleName: "entry",
2957    id: $r('app.media.test').id
2958  };
2959  try {
2960    this.context.resourceManager.getMediaContentBase64(resource).then((value: string) => {
2961      let media = value;
2962    }).catch((error: BusinessError) => {
2963      console.log("getMediaContentBase64 promise error is " + error);
2964    });
2965  } catch (error) {
2966    let code = (error as BusinessError).code;
2967    let message = (error as BusinessError).message;
2968    console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
2969  }
2970  ```
2971
2972### getMediaContentBase64<sup>10+</sup>
2973
2974getMediaContentBase64(resource: Resource, density: number): Promise&lt;string&gt;
2975
2976用户获取指定resource对象对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
2977
2978**系统能力**:SystemCapability.Global.ResourceManager
2979
2980**模型约束**:此接口仅可在Stage模型下使用。
2981
2982**参数:**
2983
2984| 参数名      | 类型                     | 必填   | 说明   |
2985| -------- | ---------------------- | ---- | ---- |
2986| resource | [Resource](#resource9) | 是    | 资源信息 |
2987| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
2988
2989**返回值:**
2990
2991| 类型                    | 说明                        |
2992| --------------------- | ------------------------- |
2993| Promise&lt;string&gt; | resource对象对应的图片资源Base64编码 |
2994
2995**错误码:**
2996
2997以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
2998
2999| 错误码ID | 错误信息 |
3000| -------- | ---------------------------------------- |
3001| 9001001  | If the resId invalid.                       |
3002| 9001002  | If the resource not found by resId.         |
3003
3004**示例:**
3005  ```ts
3006  import resourceManager from '@ohos.resourceManager';
3007  import { BusinessError } from '@ohos.base';
3008
3009  let resource: resourceManager.Resource = {
3010    bundleName: "com.example.myapplication",
3011    moduleName: "entry",
3012    id: $r('app.media.test').id
3013  };
3014  try {
3015    this.context.resourceManager.getMediaContentBase64(resource, 120).then((value: string) => {
3016      let media = value;
3017    }).catch((error: BusinessError) => {
3018      console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
3019    });
3020  } catch (error) {
3021    let code = (error as BusinessError).code;
3022    let message = (error as BusinessError).message;
3023    console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`);
3024  }
3025  ```
3026
3027### getMediaBase64ByName<sup>9+</sup>
3028
3029getMediaBase64ByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
3030
3031用户获取指定资源名称对应的图片资源Base64编码,使用callback形式返回字符串。
3032
3033**系统能力**:SystemCapability.Global.ResourceManager
3034
3035**参数:**
3036
3037| 参数名      | 类型                          | 必填   | 说明                       |
3038| -------- | --------------------------- | ---- | ------------------------ |
3039| resName  | string                      | 是    | 资源名称                     |
3040| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
3041
3042**错误码:**
3043
3044以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3045
3046| 错误码ID | 错误信息 |
3047| -------- | ---------------------------------------- |
3048| 9001003  | If the resName invalid.                     |
3049| 9001004  | If the resource not found by resName.       |
3050
3051**示例:**
3052  ```ts
3053  import { BusinessError } from '@ohos.base';
3054
3055  try {
3056    this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
3057      if (error != null) {
3058        console.log("error is " + error);
3059      } else {
3060        let media = value;
3061      }
3062    });
3063  } catch (error) {
3064    let code = (error as BusinessError).code;
3065    let message = (error as BusinessError).message;
3066    console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
3067  }
3068  ```
3069
3070### getMediaBase64ByName<sup>10+</sup>
3071
3072getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback&lt;string&gt;): void
3073
3074用户获取指定资源名称对应的指定屏幕密度图片资源Base64编码,使用callback形式返回字符串。
3075
3076**系统能力**:SystemCapability.Global.ResourceManager
3077
3078**参数:**
3079
3080| 参数名      | 类型                          | 必填   | 说明                       |
3081| -------- | --------------------------- | ---- | ------------------------ |
3082| resName  | string                      | 是    | 资源名称                     |
3083| [density](#screendensity)  | number        | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
3084| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
3085
3086**错误码:**
3087
3088以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3089
3090| 错误码ID | 错误信息 |
3091| -------- | ---------------------------------------- |
3092| 9001003  | If the resName invalid.                     |
3093| 9001004  | If the resource not found by resName.       |
3094
3095**示例:**
3096  ```ts
3097  import { BusinessError } from '@ohos.base';
3098
3099  try {
3100    this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => {
3101      if (error != null) {
3102        console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
3103      } else {
3104        let media = value;
3105      }
3106    });
3107  } catch (error) {
3108    let code = (error as BusinessError).code;
3109    let message = (error as BusinessError).message;
3110    console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
3111  }
3112  ```
3113
3114### getMediaBase64ByName<sup>9+</sup>
3115
3116getMediaBase64ByName(resName: string): Promise&lt;string&gt;
3117
3118用户获取指定资源名称对应的图片资源Base64编码,使用Promise形式返回字符串。
3119
3120**系统能力**:SystemCapability.Global.ResourceManager
3121
3122**参数:**
3123
3124| 参数名     | 类型     | 必填   | 说明   |
3125| ------- | ------ | ---- | ---- |
3126| resName | string | 是    | 资源名称 |
3127
3128**返回值:**
3129
3130| 类型                    | 说明                  |
3131| --------------------- | ------------------- |
3132| Promise&lt;string&gt; | 资源名称对应的图片资源Base64编码 |
3133
3134**错误码:**
3135
3136以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3137
3138| 错误码ID | 错误信息 |
3139| -------- | ---------------------------------------- |
3140| 9001003  | If the resName invalid.                     |
3141| 9001004  | If the resource not found by resName.       |
3142
3143**示例:**
3144  ```ts
3145  import { BusinessError } from '@ohos.base';
3146
3147  try {
3148    this.context.resourceManager.getMediaBase64ByName("test").then((value: string) => {
3149      let media = value;
3150    }).catch((error: BusinessError) => {
3151      console.log("getMediaBase64ByName promise error is " + error);
3152    });
3153  } catch (error) {
3154    let code = (error as BusinessError).code;
3155    let message = (error as BusinessError).message;
3156    console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
3157  }
3158  ```
3159
3160### getMediaBase64ByName<sup>10+</sup>
3161
3162getMediaBase64ByName(resName: string, density: number): Promise&lt;string&gt;
3163
3164用户获取指定资源名称对应的指定屏幕密度图片资源Base64编码,使用Promise形式返回字符串。
3165
3166**系统能力**:SystemCapability.Global.ResourceManager
3167
3168**参数:**
3169
3170| 参数名     | 类型     | 必填   | 说明   |
3171| ------- | ------ | ---- | ---- |
3172| resName | string | 是    | 资源名称 |
3173| [density](#screendensity)  | number                          | 是    | 资源获取需要的屏幕密度,0表示默认屏幕密度    |
3174
3175**返回值:**
3176
3177| 类型                    | 说明                  |
3178| --------------------- | ------------------- |
3179| Promise&lt;string&gt; | 资源名称对应的图片资源Base64编码 |
3180
3181**错误码:**
3182
3183以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3184
3185| 错误码ID | 错误信息 |
3186| -------- | ---------------------------------------- |
3187| 9001003  | If the resName invalid.                     |
3188| 9001004  | If the resource not found by resName.       |
3189
3190**示例:**
3191  ```ts
3192  import { BusinessError } from '@ohos.base';
3193
3194  try {
3195    this.context.resourceManager.getMediaBase64ByName("test", 120).then((value: string) => {
3196      let media = value;
3197    }).catch((error: BusinessError) => {
3198      console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
3199    });
3200  } catch (error) {
3201    let code = (error as BusinessError).code;
3202    let message = (error as BusinessError).message;
3203    console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`);
3204  }
3205  ```
3206
3207### getDrawableDescriptor<sup>10+</sup>
3208
3209getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;
3210
3211用户获取指定资源ID对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
3212
3213**系统能力**:SystemCapability.Global.ResourceManager
3214
3215**参数:**
3216
3217| 参数名   | 类型     | 必填   | 说明    |
3218| ----- | ------ | ---- | ----- |
3219| resId | number | 是    | 资源ID值 |
3220| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
3221
3222**返回值:**
3223
3224| 类型     | 说明         |
3225| ------ | ---------- |
3226| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
3227
3228**错误码:**
3229
3230以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3231
3232| 错误码ID | 错误信息 |
3233| -------- | ---------------------------------------- |
3234| 9001001  | If the resId invalid.                       |
3235| 9001002  | If the resource not found by resId.         |
3236
3237**示例:**
3238  ```ts
3239  import { BusinessError } from '@ohos.base';
3240
3241  try {
3242    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
3243  } catch (error) {
3244    let code = (error as BusinessError).code;
3245    let message = (error as BusinessError).message;
3246    console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
3247  }
3248  try {
3249    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
3250  } catch (error) {
3251    let code = (error as BusinessError).code;
3252    let message = (error as BusinessError).message;
3253    console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
3254  }
3255  ```
3256
3257### getDrawableDescriptor<sup>10+</sup>
3258
3259getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;
3260
3261用户获取指定resource对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
3262
3263**系统能力**:SystemCapability.Global.ResourceManager
3264
3265**模型约束**:此接口仅可在Stage模型下使用。
3266
3267**参数:**
3268
3269| 参数名      | 类型                     | 必填   | 说明   |
3270| -------- | ---------------------- | ---- | ---- |
3271| resource | [Resource](#resource9) | 是    | 资源信息 |
3272| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
3273
3274**返回值:**
3275
3276| 类型      | 说明                |
3277| ------- | ----------------- |
3278| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
3279
3280**错误码:**
3281
3282以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3283
3284| 错误码ID | 错误信息 |
3285| -------- | ---------------------------------------- |
3286| 9001001  | If the resId invalid.                       |
3287| 9001002  | If the resource not found by resId.         |
3288
3289**示例:**
3290  ```ts
3291  import resourceManager from '@ohos.resourceManager';
3292  import { BusinessError } from '@ohos.base';
3293
3294  let resource: resourceManager.Resource = {
3295    bundleName: "com.example.myapplication",
3296    moduleName: "entry",
3297    id: $r('app.media.icon').id
3298  };
3299  try {
3300    this.context.resourceManager.getDrawableDescriptor(resource);
3301  } catch (error) {
3302    let code = (error as BusinessError).code;
3303    let message = (error as BusinessError).message;
3304    console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
3305  }
3306  try {
3307    this.context.resourceManager.getDrawableDescriptor(resource, 120);
3308  } catch (error) {
3309    let code = (error as BusinessError).code;
3310    let message = (error as BusinessError).message;
3311    console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`);
3312  }
3313  ```
3314
3315### getDrawableDescriptorByName<sup>10+</sup>
3316
3317getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor;
3318
3319用户获取指定资源名称对应的DrawableDescriptor对象,使用同步方式返回资源对应的DrawableDescriptor,用于图标的显示。
3320
3321**系统能力**:SystemCapability.Global.ResourceManager
3322
3323**参数:**
3324
3325| 参数名     | 类型     | 必填   | 说明   |
3326| ------- | ------ | ---- | ---- |
3327| resName | string | 是    | 资源名称 |
3328| [density](#screendensity) | number | 否    | 资源获取需要的屏幕密度,0或缺省表示默认屏幕密度 |
3329
3330**返回值:**
3331
3332| 类型     | 说明        |
3333| ------ | --------- |
3334| DrawableDescriptor | 资源ID值对应的DrawableDescriptor对象 |
3335
3336**错误码:**
3337
3338以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3339
3340| 错误码ID | 错误信息 |
3341| -------- | ---------------------------------------- |
3342| 9001003  | If the resName invalid.                     |
3343| 9001004  | If the resource not found by resName.       |
3344
3345**示例:**
3346  ```ts
3347  import { BusinessError } from '@ohos.base';
3348
3349  try {
3350    this.context.resourceManager.getDrawableDescriptorByName('icon');
3351  } catch (error) {
3352    let code = (error as BusinessError).code;
3353    let message = (error as BusinessError).message;
3354    console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`);
3355  }
3356  try {
3357    this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
3358  } catch (error) {
3359    let code = (error as BusinessError).code;
3360    let message = (error as BusinessError).message;
3361    console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`);
3362  }
3363  ```
3364
3365### getBoolean<sup>9+</sup>
3366
3367getBoolean(resId: number): boolean
3368
3369使用同步方式,返回获取指定资源ID对应的布尔结果。
3370
3371**系统能力**:SystemCapability.Global.ResourceManager
3372
3373**参数:**
3374
3375| 参数名   | 类型     | 必填   | 说明    |
3376| ----- | ------ | ---- | ----- |
3377| resId | number | 是    | 资源ID值 |
3378
3379**返回值:**
3380
3381| 类型      | 说明           |
3382| ------- | ------------ |
3383| boolean | 资源ID值对应的布尔结果 |
3384
3385**错误码:**
3386
3387以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3388
3389| 错误码ID | 错误信息 |
3390| -------- | ---------------------------------------- |
3391| 9001001  | If the resId invalid.                       |
3392| 9001002  | If the resource not found by resId.         |
3393| 9001006  | If the resource re-ref too much.            |
3394
3395**示例:**
3396  ```ts
3397  import { BusinessError } from '@ohos.base';
3398
3399  try {
3400    this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
3401  } catch (error) {
3402    let code = (error as BusinessError).code;
3403    let message = (error as BusinessError).message;
3404    console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
3405  }
3406  ```
3407### getBoolean<sup>9+</sup>
3408
3409getBoolean(resource: Resource): boolean
3410
3411使用同步方式,返回获取指定resource对象对应的布尔结果。
3412
3413**系统能力**:SystemCapability.Global.ResourceManager
3414
3415**模型约束**:此接口仅可在Stage模型下使用。
3416
3417**参数:**
3418
3419| 参数名      | 类型                     | 必填   | 说明   |
3420| -------- | ---------------------- | ---- | ---- |
3421| resource | [Resource](#resource9) | 是    | 资源信息 |
3422
3423**返回值:**
3424
3425| 类型      | 说明                |
3426| ------- | ----------------- |
3427| boolean | resource对象对应的布尔结果 |
3428
3429**错误码:**
3430
3431以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3432
3433| 错误码ID | 错误信息 |
3434| -------- | ---------------------------------------- |
3435| 9001001  | If the resId invalid.                       |
3436| 9001002  | If the resource not found by resId.         |
3437| 9001006  | If the resource re-ref too much.            |
3438
3439**示例:**
3440  ```ts
3441  import resourceManager from '@ohos.resourceManager';
3442  import { BusinessError } from '@ohos.base';
3443
3444  let resource: resourceManager.Resource = {
3445    bundleName: "com.example.myapplication",
3446    moduleName: "entry",
3447    id: $r('app.boolean.boolean_test').id
3448  };
3449  try {
3450    this.context.resourceManager.getBoolean(resource);
3451  } catch (error) {
3452    let code = (error as BusinessError).code;
3453    let message = (error as BusinessError).message;
3454    console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
3455  }
3456  ```
3457
3458### getBooleanByName<sup>9+</sup>
3459
3460getBooleanByName(resName: string): boolean
3461
3462使用同步方式,返回获取指定资源名称对应的布尔结果
3463
3464**系统能力**:SystemCapability.Global.ResourceManager
3465
3466**参数:**
3467
3468| 参数名     | 类型     | 必填   | 说明   |
3469| ------- | ------ | ---- | ---- |
3470| resName | string | 是    | 资源名称 |
3471
3472**返回值:**
3473
3474| 类型      | 说明          |
3475| ------- | ----------- |
3476| boolean | 资源名称对应的布尔结果 |
3477
3478**错误码:**
3479
3480以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3481
3482| 错误码ID | 错误信息 |
3483| -------- | ---------------------------------------- |
3484| 9001003  | If the resName invalid.                     |
3485| 9001004  | If the resource not found by resName.       |
3486| 9001006  | If the resource re-ref too much.            |
3487
3488**示例:**
3489  ```ts
3490  import { BusinessError } from '@ohos.base';
3491
3492  try {
3493    this.context.resourceManager.getBooleanByName("boolean_test");
3494  } catch (error) {
3495    let code = (error as BusinessError).code;
3496    let message = (error as BusinessError).message;
3497    console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`);
3498  }
3499  ```
3500
3501### getNumber<sup>9+</sup>
3502
3503getNumber(resId: number): number
3504
3505用户获取指定资源ID对应的integer数值或者float数值,使用同步方式返回资源对应的数值。
3506
3507**系统能力**:SystemCapability.Global.ResourceManager
3508
3509**参数:**
3510
3511| 参数名   | 类型     | 必填   | 说明    |
3512| ----- | ------ | ---- | ----- |
3513| resId | number | 是    | 资源ID值 |
3514
3515**返回值:**
3516
3517| 类型     | 说明         |
3518| ------ | ---------- |
3519| number | 资源ID值对应的数值。Integer对应的是原数值,float对应的是真实像素点值,具体参考示例代码 |
3520
3521**错误码:**
3522
3523以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3524
3525| 错误码ID | 错误信息 |
3526| -------- | ---------------------------------------- |
3527| 9001001  | If the resId invalid.                       |
3528| 9001002  | If the resource not found by resId.         |
3529| 9001006  | If the resource re-ref too much.            |
3530
3531**示例:**
3532  ```ts
3533  import { BusinessError } from '@ohos.base';
3534
3535  try {
3536    this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer对应返回的是原数值
3537  } catch (error) {
3538    let code = (error as BusinessError).code;
3539    let message = (error as BusinessError).message;
3540    console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
3541  }
3542
3543  try {
3544    this.context.resourceManager.getNumber($r('app.float.float_test').id); // float对应返回的是真实像素点值
3545  } catch (error) {
3546    let code = (error as BusinessError).code;
3547    let message = (error as BusinessError).message;
3548    console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
3549  }
3550  ```
3551
3552### getNumber<sup>9+</sup>
3553
3554getNumber(resource: Resource): number
3555
3556用户获取指定resource对象对应的integer数值或者float数值,使用同步方式返回资源对应的数值。
3557
3558**系统能力**:SystemCapability.Global.ResourceManager
3559
3560**模型约束**:此接口仅可在Stage模型下使用。
3561
3562**参数:**
3563
3564| 参数名      | 类型                     | 必填   | 说明   |
3565| -------- | ---------------------- | ---- | ---- |
3566| resource | [Resource](#resource9) | 是    | 资源信息 |
3567
3568**返回值:**
3569
3570| 类型     | 说明              |
3571| ------ | --------------- |
3572| number | resource对象对应的数值。Integer对应的是原数值,float对应的是真实像素点值, 具体参考示例代码 |
3573
3574**错误码:**
3575
3576以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3577
3578| 错误码ID | 错误信息 |
3579| -------- | ---------------------------------------- |
3580| 9001001  | If the resId invalid.                       |
3581| 9001002  | If the resource not found by resId.         |
3582| 9001006  | If the resource re-ref too much.            |
3583
3584**示例:**
3585  ```ts
3586  import resourceManager from '@ohos.resourceManager';
3587  import { BusinessError } from '@ohos.base';
3588
3589  let resource: resourceManager.Resource = {
3590    bundleName: "com.example.myapplication",
3591    moduleName: "entry",
3592    id: $r('app.integer.integer_test').id
3593  };
3594  try {
3595    this.context.resourceManager.getNumber(resource);// integer对应返回的是原数值, float对应返回的是真实像素点值
3596  } catch (error) {
3597    let code = (error as BusinessError).code;
3598    let message = (error as BusinessError).message;
3599    console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
3600  }
3601  ```
3602
3603### getNumberByName<sup>9+</sup>
3604
3605getNumberByName(resName: string): number
3606
3607用户获取指定资源名称对应的integer数值或者float数值,使用同步方式资源对应的数值。
3608
3609**系统能力**:SystemCapability.Global.ResourceManager
3610
3611**参数:**
3612
3613| 参数名     | 类型     | 必填   | 说明   |
3614| ------- | ------ | ---- | ---- |
3615| resName | string | 是    | 资源名称 |
3616
3617**返回值:**
3618
3619| 类型     | 说明        |
3620| ------ | --------- |
3621| number | 资源名称对应的数值 |
3622
3623**错误码:**
3624
3625以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3626
3627| 错误码ID | 错误信息 |
3628| -------- | ---------------------------------------- |
3629| 9001003  | If the resName invalid.                     |
3630| 9001004  | If the resource not found by resName.       |
3631| 9001006  | If the resource re-ref too much.            |
3632
3633**示例:**
3634  ```ts
3635  import { BusinessError } from '@ohos.base';
3636
3637  try {
3638    this.context.resourceManager.getNumberByName("integer_test");
3639  } catch (error) {
3640    let code = (error as BusinessError).code;
3641    let message = (error as BusinessError).message;
3642    console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
3643  }
3644
3645  try {
3646    this.context.resourceManager.getNumberByName("float_test");
3647  } catch (error) {
3648    let code = (error as BusinessError).code;
3649    let message = (error as BusinessError).message;
3650    console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
3651  }
3652  ```
3653
3654### getColorSync<sup>10+</sup>
3655
3656getColorSync(resId: number) : number;
3657
3658用户获取指定资源ID对应的颜色值,使用同步方式返回其对应的颜色值。
3659
3660**系统能力**:SystemCapability.Global.ResourceManager
3661
3662**参数:**
3663
3664| 参数名   | 类型     | 必填   | 说明    |
3665| ----- | ------ | ---- | ----- |
3666| resId | number | 是    | 资源ID值 |
3667
3668**返回值:**
3669
3670| 类型     | 说明          |
3671| ------ | ----------- |
3672| number | 资源ID值对应的颜色值(十进制) |
3673
3674**错误码:**
3675
3676以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3677
3678| 错误码ID | 错误信息 |
3679| -------- | ---------------------------------------- |
3680| 9001001  | If the resId invalid.                       |
3681| 9001002  | If the resource not found by resId.         |
3682| 9001006  | If the resource re-ref too much.            |
3683
3684**示例:**
3685  ```ts
3686  import { BusinessError } from '@ohos.base';
3687
3688  try {
3689    this.context.resourceManager.getColorSync($r('app.color.test').id);
3690  } catch (error) {
3691    let code = (error as BusinessError).code;
3692    let message = (error as BusinessError).message;
3693    console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
3694  }
3695  ```
3696
3697### getColorSync<sup>10+</sup>
3698
3699getColorSync(resource: Resource): number
3700
3701用户获取指定resource对象对应的颜色值,使用同步方式返回其对应的颜色值。
3702
3703**系统能力**:SystemCapability.Global.ResourceManager
3704
3705**模型约束**:此接口仅可在Stage模型下使用。
3706
3707**参数:**
3708
3709| 参数名      | 类型                     | 必填   | 说明   |
3710| -------- | ---------------------- | ---- | ---- |
3711| resource | [Resource](#resource9) | 是    | 资源信息 |
3712
3713**返回值:**
3714
3715| 类型     | 说明               |
3716| ------ | ---------------- |
3717| number | resource对象对应的颜色值(十进制) |
3718
3719**错误码:**
3720
3721以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3722
3723| 错误码ID | 错误信息 |
3724| -------- | ---------------------------------------- |
3725| 9001001  | If the resId invalid.                       |
3726| 9001002  | If the resource not found by resId.         |
3727| 9001006  | If the resource re-ref too much.            |
3728
3729**示例:**
3730  ```ts
3731  import resourceManager from '@ohos.resourceManager';
3732  import { BusinessError } from '@ohos.base';
3733
3734  let resource: resourceManager.Resource = {
3735    bundleName: "com.example.myapplication",
3736    moduleName: "entry",
3737    id: $r('app.color.test').id
3738  };
3739  try {
3740    this.context.resourceManager.getColorSync(resource);
3741  } catch (error) {
3742    let code = (error as BusinessError).code;
3743    let message = (error as BusinessError).message;
3744    console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
3745  }
3746  ```
3747
3748### getColorByNameSync<sup>10+</sup>
3749
3750getColorByNameSync(resName: string) : number;
3751
3752用户获取指定资源名称对应的颜色值,使用同步方式返回其对应的颜色值。
3753
3754**系统能力**:SystemCapability.Global.ResourceManager
3755
3756**参数:**
3757
3758| 参数名     | 类型     | 必填   | 说明   |
3759| ------- | ------ | ---- | ---- |
3760| resName | string | 是    | 资源名称 |
3761
3762**返回值:**
3763
3764| 类型     | 说明         |
3765| ------ | ---------- |
3766| number | 资源名称对应的颜色值(十进制) |
3767
3768**错误码:**
3769
3770以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3771
3772| 错误码ID | 错误信息 |
3773| -------- | ---------------------------------------- |
3774| 9001003  | If the resName invalid.                     |
3775| 9001004  | If the resource not found by resName.       |
3776| 9001006  | If the resource re-ref too much.            |
3777
3778**示例:**
3779  ```ts
3780  import { BusinessError } from '@ohos.base';
3781
3782  try {
3783    this.context.resourceManager.getColorByNameSync("test");
3784  } catch (error) {
3785    let code = (error as BusinessError).code;
3786    let message = (error as BusinessError).message;
3787    console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`);
3788  }
3789  ```
3790
3791### getColor<sup>10+</sup>
3792
3793getColor(resId: number, callback: AsyncCallback&lt;number&gt;): void;
3794
3795用户获取指定资源ID对应的颜色值,使用callback形式返回其对应的颜色值。
3796
3797**系统能力:** SystemCapability.Global.ResourceManager
3798
3799**参数:**
3800
3801| 参数名      | 类型                          | 必填   | 说明              |
3802| -------- | --------------------------- | ---- | --------------- |
3803| resId    | number                      | 是    | 资源ID值           |
3804| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |
3805
3806**错误码:**
3807
3808以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3809
3810| 错误码ID | 错误信息 |
3811| -------- | ---------------------------------------- |
3812| 9001001  | If the module resId invalid.             |
3813| 9001002  | If the resource not found by resId.      |
3814| 9001006  | If the resource re-ref too much.         |
3815
3816**示例Stage:**
3817  ```ts
3818  import { BusinessError } from '@ohos.base';
3819
3820  try {
3821    this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => {
3822      if (error != null) {
3823        console.log("error is " + error);
3824      } else {
3825        let str = value;
3826      }
3827    });
3828  } catch (error) {
3829    let code = (error as BusinessError).code;
3830    let message = (error as BusinessError).message;
3831    console.error(`callback getColor failed, error code: ${code}, message: ${message}.`);
3832  }
3833  ```
3834
3835### getColor<sup>10+</sup>
3836
3837getColor(resId: number): Promise&lt;number&gt;
3838
3839用户获取指定资源ID对应的颜色值,使用Promise形式返回对应其对应的颜色值。
3840
3841**系统能力**:SystemCapability.Global.ResourceManager
3842
3843**参数:**
3844
3845| 参数名   | 类型     | 必填   | 说明    |
3846| ----- | ------ | ---- | ----- |
3847| resId | number | 是    | 资源ID值 |
3848
3849**返回值:**
3850
3851| 类型                    | 说明          |
3852| --------------------- | ----------- |
3853| Promise&lt;number&gt; | 资源ID值对应的颜色值(十进制) |
3854
3855**错误码:**
3856
3857以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3858
3859| 错误码ID | 错误信息 |
3860| -------- | ---------------------------------------- |
3861| 9001001  | If the resId invalid.                       |
3862| 9001002  | If the resource not found by resId.         |
3863| 9001006  | If the resource re-ref too much.            |
3864
3865**示例:**
3866  ```ts
3867  import { BusinessError } from '@ohos.base';
3868
3869  try {
3870    this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => {
3871      let str = value;
3872    }).catch((error: BusinessError) => {
3873      console.log("getColor promise error is " + error);
3874    });
3875  } catch (error) {
3876    let code = (error as BusinessError).code;
3877    let message = (error as BusinessError).message;
3878    console.error(`promise getColor failed, error code: ${code}, message: ${message}.`);
3879  }
3880  ```
3881
3882### getColor<sup>10+</sup>
3883
3884getColor(resource: Resource, callback: AsyncCallback&lt;number&gt;): void;
3885
3886用户获取指定resource对象对应的颜色值,使用callback形式返回其对应的颜色值。
3887
3888**系统能力:** SystemCapability.Global.ResourceManager
3889
3890**模型约束**:此接口仅可在Stage模型下使用。
3891
3892**参数:**
3893
3894| 参数名      | 类型                          | 必填   | 说明              |
3895| -------- | --------------------------- | ---- | --------------- |
3896| resource | [Resource](#resource9)      | 是    | 资源信息            |
3897| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |
3898
3899**错误码:**
3900
3901以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3902
3903| 错误码ID | 错误信息 |
3904| -------- | ---------------------------------------- |
3905| 9001001  | If the resId invalid.                       |
3906| 9001002  | If the resource not found by resId.         |
3907| 9001006  | If the resource re-ref too much.            |
3908
3909**示例:**
3910  ```ts
3911  import resourceManager from '@ohos.resourceManager';
3912  import { BusinessError } from '@ohos.base';
3913
3914  let resource: resourceManager.Resource = {
3915    bundleName: "com.example.myapplication",
3916    moduleName: "entry",
3917    id: $r('app.color.test').id
3918  };
3919  try {
3920    this.context.resourceManager.getColor(resource, (error, value) => {
3921      if (error != null) {
3922        console.log("error is " + error);
3923      } else {
3924        let str = value;
3925      }
3926    });
3927  } catch (error) {
3928    let code = (error as BusinessError).code;
3929    let message = (error as BusinessError).message;
3930    console.error(`callback getColor failed, error code: ${code}, message: ${message}.`);
3931  }
3932  ```
3933
3934### getColor<sup>10+</sup>
3935
3936getColor(resource: Resource): Promise&lt;number&gt;;
3937
3938用户获取指定resource对象对应的颜色值,使用Promise形式返回其对应的颜色值。
3939
3940**系统能力**:SystemCapability.Global.ResourceManager
3941
3942**模型约束**:此接口仅可在Stage模型下使用。
3943
3944**参数:**
3945
3946| 参数名      | 类型                     | 必填   | 说明   |
3947| -------- | ---------------------- | ---- | ---- |
3948| resource | [Resource](#resource9) | 是    | 资源信息 |
3949
3950**返回值:**
3951
3952| 类型                    | 说明               |
3953| --------------------- | ---------------- |
3954| Promise&lt;number&gt; | resource对象对应的颜色值(十进制) |
3955
3956**错误码:**
3957
3958以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
3959
3960| 错误码ID | 错误信息 |
3961| -------- | ---------------------------------------- |
3962| 9001001  | If the resId invalid.                       |
3963| 9001002  | If the resource not found by resId.         |
3964| 9001006  | If the resource re-ref too much.            |
3965
3966**示例:**
3967  ```ts
3968  import resourceManager from '@ohos.resourceManager';
3969  import { BusinessError } from '@ohos.base';
3970
3971  let resource: resourceManager.Resource = {
3972    bundleName: "com.example.myapplication",
3973    moduleName: "entry",
3974    id: $r('app.color.test').id
3975  };
3976  try {
3977    this.context.resourceManager.getColor(resource).then((value: number) => {
3978      let str = value;
3979    }).catch((error: BusinessError) => {
3980      console.log("getColor promise error is " + error);
3981    });
3982  } catch (error) {
3983    let code = (error as BusinessError).code;
3984    let message = (error as BusinessError).message;
3985    console.error(`promise getColor failed, error code: ${code}, message: ${message}.`);
3986  }
3987  ```
3988
3989### getColorByName<sup>10+</sup>
3990
3991getColorByName(resName: string, callback: AsyncCallback&lt;number&gt;): void
3992
3993用户获取指定资源名称对应的颜色值,使用callback形式返回其对应的颜色值。
3994
3995**系统能力**:SystemCapability.Global.ResourceManager
3996
3997**参数:**
3998
3999| 参数名      | 类型                          | 必填   | 说明              |
4000| -------- | --------------------------- | ---- | --------------- |
4001| resName  | string                      | 是    | 资源名称            |
4002| callback | AsyncCallback&lt;number&gt; | 是    | 异步回调,用于返回获取的颜色值(十进制) |
4003
4004**错误码:**
4005
4006以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4007
4008| 错误码ID | 错误信息 |
4009| -------- | ---------------------------------------- |
4010| 9001003  | If the resName invalid.                     |
4011| 9001004  | If the resource not found by resName.       |
4012| 9001006  | If the resource re-ref too much.            |
4013
4014**示例:**
4015  ```ts
4016  import { BusinessError } from '@ohos.base';
4017
4018  try {
4019    this.context.resourceManager.getColorByName("test", (error, value) => {
4020      if (error != null) {
4021        console.log("error is " + error);
4022      } else {
4023        let string = value;
4024      }
4025    });
4026  } catch (error) {
4027    let code = (error as BusinessError).code;
4028    let message = (error as BusinessError).message;
4029    console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`);
4030  }
4031  ```
4032
4033### getColorByName<sup>10+</sup>
4034
4035getColorByName(resName: string): Promise&lt;number&gt;
4036
4037用户获取指定资源名称对应的颜色值,使用Promise形式返回其对应的颜色值。
4038
4039**系统能力**:SystemCapability.Global.ResourceManager
4040
4041**参数:**
4042
4043| 参数名     | 类型     | 必填   | 说明   |
4044| ------- | ------ | ---- | ---- |
4045| resName | string | 是    | 资源名称 |
4046
4047**返回值:**
4048
4049| 类型                    | 说明         |
4050| --------------------- | ---------- |
4051| Promise&lt;number&gt; | 资源名称对应的颜色值(十进制) |
4052
4053**错误码:**
4054
4055以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4056
4057| 错误码ID | 错误信息 |
4058| -------- | ---------------------------------------- |
4059| 9001003  | If the resName invalid.                     |
4060| 9001004  | If the resource not found by resName.       |
4061| 9001006  | If the resource re-ref too much.            |
4062
4063**示例:**
4064  ```ts
4065  import { BusinessError } from '@ohos.base';
4066
4067  try {
4068    this.context.resourceManager.getColorByName("test").then((value: number) => {
4069      let string = value;
4070    }).catch((error: BusinessError) => {
4071      console.log("getColorByName promise error is " + error);
4072    });
4073  } catch (error) {
4074    let code = (error as BusinessError).code;
4075    let message = (error as BusinessError).message;
4076    console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`);
4077  }
4078  ```
4079
4080### getRawFileContentSync<sup>10+</sup>
4081
4082getRawFileContentSync(path: string): Uint8Array
4083
4084用户获取resources/rawfile目录下对应的rawfile文件内容,使用同步形式返回字节数组。
4085
4086**系统能力:** SystemCapability.Global.ResourceManager
4087
4088**参数:**
4089
4090| 参数名      | 类型                              | 必填   | 说明                      |
4091| -------- | ------------------------------- | ---- | ----------------------- |
4092| path     | string                          | 是    | rawfile文件路径             |
4093
4094**返回值:**
4095
4096| 类型                    | 说明         |
4097| --------------------- | ---------- |
4098| Uint8Array | 返回获取的rawfile文件内容 |
4099
4100**错误码:**
4101
4102以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4103
4104| 错误码ID | 错误信息 |
4105| -------- | ---------------------------------------- |
4106| 9001005  | If the resource not found by path.          |
4107
4108**示例:**
4109  ```ts
4110  import { BusinessError } from '@ohos.base';
4111
4112  try {
4113    this.context.resourceManager.getRawFileContentSync("test.txt");
4114  } catch (error) {
4115    let code = (error as BusinessError).code;
4116    let message = (error as BusinessError).message;
4117    console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`);
4118  }
4119  ```
4120
4121### getRawFileContent<sup>9+</sup>
4122
4123getRawFileContent(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
4124
4125用户获取resources/rawfile目录下对应的rawfile文件内容,使用callback形式返回字节数组。
4126
4127**系统能力**:SystemCapability.Global.ResourceManager
4128
4129**参数:**
4130
4131| 参数名      | 类型                              | 必填   | 说明                      |
4132| -------- | ------------------------------- | ---- | ----------------------- |
4133| path     | string                          | 是    | rawfile文件路径             |
4134| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的rawfile文件内容 |
4135
4136**错误码:**
4137
4138以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4139
4140| 错误码ID | 错误信息 |
4141| -------- | ---------------------------------------- |
4142| 9001005  | If the resource not found by path.          |
4143
4144**示例:**
4145  ```ts
4146  import { BusinessError } from '@ohos.base';
4147
4148  try {
4149    this.context.resourceManager.getRawFileContent("test.txt", (error, value) => {
4150      if (error != null) {
4151        console.log("error is " + error);
4152      } else {
4153        let rawFile = value;
4154      }
4155    });
4156  } catch (error) {
4157    let code = (error as BusinessError).code;
4158    let message = (error as BusinessError).message;
4159    console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`);
4160  }
4161  ```
4162
4163### getRawFileContent<sup>9+</sup>
4164
4165getRawFileContent(path: string): Promise&lt;Uint8Array&gt;
4166
4167用户获取resources/rawfile目录下对应的rawfile文件内容,使用Promise形式返回字节数组。
4168
4169**系统能力**:SystemCapability.Global.ResourceManager
4170
4171**参数:**
4172
4173| 参数名  | 类型     | 必填   | 说明          |
4174| ---- | ------ | ---- | ----------- |
4175| path | string | 是    | rawfile文件路径 |
4176
4177**返回值:**
4178
4179| 类型                        | 说明          |
4180| ------------------------- | ----------- |
4181| Promise&lt;Uint8Array&gt; | rawfile文件内容 |
4182
4183**错误码:**
4184
4185以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4186
4187| 错误码ID | 错误信息 |
4188| -------- | ---------------------------------------- |
4189| 9001005  | If the resource not found by path.          |
4190
4191**示例:**
4192  ```ts
4193  import { BusinessError } from '@ohos.base';
4194
4195  try {
4196    this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => {
4197      let rawFile = value;
4198    }).catch((error: BusinessError) => {
4199      console.log("getRawFileContent promise error is " + error);
4200    });
4201  } catch (error) {
4202    let code = (error as BusinessError).code;
4203    let message = (error as BusinessError).message;
4204    console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`);
4205  }
4206  ```
4207
4208### getRawFileListSync<sup>10+</sup>
4209
4210getRawFileListSync(path: string): Array\<string\>
4211
4212用户获取resources/rawfile目录下文件夹及文件列表,使用同步形式返回文件列表的字符串数组。
4213
4214**系统能力:** SystemCapability.Global.ResourceManager
4215
4216**参数:**
4217
4218| 参数名      | 类型                              | 必填   | 说明                      |
4219| -------- | ------------------------------- | ---- | ----------------------- |
4220| path     | string                          | 是    | rawfile文件夹路径             |
4221
4222**返回值:**
4223
4224| 类型                        | 说明          |
4225| ------------------------- | ----------- |
4226| Array\<string\> | rawfile文件夹下的列表(包含子文件夹和文件) |
4227
4228**错误码:**
4229
4230以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4231
4232| 错误码ID | 错误信息 |
4233| -------- | ---------------------------------------- |
4234| 9001005  | If the resource not found by path.       |
4235
4236**示例:**
4237  ```ts
4238  import { BusinessError } from '@ohos.base';
4239
4240  try { // 传入""表示获取rawfile根目录下的文件列表
4241    this.context.resourceManager.getRawFileListSync("")
4242  } catch (error) {
4243    let code = (error as BusinessError).code;
4244    let message = (error as BusinessError).message;
4245    console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`);
4246  }
4247  ```
4248
4249### getRawFileList<sup>10+</sup>
4250
4251getRawFileList(path: string, callback: AsyncCallback&lt;Array\<string\>&gt;): void;
4252
4253用户获取resources/rawfile目录下文件夹及文件列表,使用callback形式返回文件列表的字符串数组。
4254
4255**系统能力**:SystemCapability.Global.ResourceManager
4256
4257**参数:**
4258
4259| 参数名      | 类型                              | 必填   | 说明                      |
4260| -------- | ------------------------------- | ---- | ----------------------- |
4261| path     | string                          | 是    | rawfile文件夹路径             |
4262| callback | AsyncCallback&lt;Array\<string\>&gt; | 是 | 异步回调,用于返回获取rawfile文件目录下的文件列表 |
4263
4264**错误码:**
4265
4266以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4267
4268| 错误码ID | 错误信息 |
4269| -------- | ---------------------------------------- |
4270| 9001005  | If the resource not found by path.       |
4271
4272**示例:**
4273  ```ts
4274  import { BusinessError } from '@ohos.base';
4275
4276  try { // 传入""表示获取rawfile根目录下的文件列表
4277    this.context.resourceManager.getRawFileList("", (error, value) => {
4278      if (error != null) {
4279        console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
4280      } else {
4281        let rawFile = value;
4282      }
4283    });
4284  } catch (error) {
4285    let code = (error as BusinessError).code;
4286    let message = (error as BusinessError).message;
4287    console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`);
4288  }
4289  ```
4290
4291### getRawFileList<sup>10+</sup>
4292
4293getRawFileList(path: string): Promise&lt;Array\<string\>&gt;
4294
4295用户获取resources/rawfile目录下文件夹及文件列表,使用Promise形式返回文件列表字符串数组。
4296
4297**系统能力**:SystemCapability.Global.ResourceManager
4298
4299**参数:**
4300
4301| 参数名  | 类型     | 必填   | 说明          |
4302| ---- | ------ | ---- | ----------- |
4303| path | string | 是    | rawfile文件夹路径 |
4304
4305**返回值:**
4306
4307| 类型                        | 说明          |
4308| ------------------------- | ----------- |
4309| Promise&lt;Array\<string\>&gt; | rawfile文件目录下的文件列表 |
4310
4311**错误码:**
4312
4313以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4314
4315| 错误码ID | 错误信息 |
4316| -------- | ---------------------------------------- |
4317| 9001005  | If the resource not found by path.          |
4318
4319**示例:**
4320  ```ts
4321  import { BusinessError } from '@ohos.base';
4322
4323  try { // 传入""表示获取rawfile根目录下的文件列表
4324    this.context.resourceManager.getRawFileList("").then((value: Array<string>) => {
4325      let rawFile = value;
4326    }).catch((error: BusinessError) => {
4327      console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
4328    });
4329  } catch (error) {
4330    let code = (error as BusinessError).code;
4331    let message = (error as BusinessError).message;
4332    console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`);
4333  }
4334  ```
4335
4336### getRawFdSync<sup>10+</sup>
4337
4338getRawFdSync(path: string): RawFileDescriptor
4339
4340用户获取resources/rawfile目录下对应rawfile文件的descriptor。
4341
4342**系统能力:** SystemCapability.Global.ResourceManager
4343
4344**参数:**
4345
4346| 参数名      | 类型                                       | 必填   | 说明                               |
4347| -------- | ---------------------------------------- | ---- | -------------------------------- |
4348| path     | string                                   | 是    | rawfile文件路径                      |
4349
4350**返回值:**
4351
4352| 类型                        | 说明          |
4353| ------------------------- | ----------- |
4354| [RawFileDescriptor](#rawfiledescriptor8) | rawfile文件的descriptor |
4355
4356**错误码:**
4357
4358以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4359
4360| 错误码ID | 错误信息 |
4361| -------- | ---------------------------------------- |
4362| 9001005  | If the resource not found by path.          |
4363
4364**示例:**
4365  ```ts
4366  import { BusinessError } from '@ohos.base';
4367
4368  try {
4369    this.context.resourceManager.getRawFdSync("test.txt");
4370  } catch (error) {
4371    let code = (error as BusinessError).code;
4372    let message = (error as BusinessError).message;
4373    console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`);
4374  }
4375  ```
4376
4377### getRawFd<sup>9+</sup>
4378
4379getRawFd(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void
4380
4381用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回。
4382
4383**系统能力**:SystemCapability.Global.ResourceManager
4384
4385**参数:**
4386
4387| 参数名      | 类型                                       | 必填   | 说明                               |
4388| -------- | ---------------------------------------- | ---- | -------------------------------- |
4389| path     | string                                   | 是    | rawfile文件路径                      |
4390| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | 是    | 异步回调,用于返回获取的rawfile文件的descriptor |
4391
4392**错误码:**
4393
4394以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4395
4396| 错误码ID | 错误信息 |
4397| -------- | ---------------------------------------- |
4398| 9001005  | If the resource not found by path.          |
4399
4400**示例:**
4401  ```ts
4402  import { BusinessError } from '@ohos.base';
4403
4404  try {
4405    this.context.resourceManager.getRawFd("test.txt", (error, value) => {
4406      if (error != null) {
4407        console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
4408      } else {
4409        let fd = value.fd;
4410        let offset = value.offset;
4411        let length = value.length;
4412      }
4413    });
4414  } catch (error) {
4415    let code = (error as BusinessError).code;
4416    let message = (error as BusinessError).message;
4417    console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`);
4418  }
4419  ```
4420
4421### getRawFd<sup>9+</sup>
4422
4423getRawFd(path: string): Promise&lt;RawFileDescriptor&gt;
4424
4425用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回。
4426
4427**系统能力**:SystemCapability.Global.ResourceManager
4428
4429**参数:**
4430
4431| 参数名  | 类型     | 必填   | 说明          |
4432| ---- | ------ | ---- | ----------- |
4433| path | string | 是    | rawfile文件路径 |
4434
4435**返回值:**
4436
4437| 类型                                       | 说明                  |
4438| ---------------------------------------- | ------------------- |
4439| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | rawfile文件descriptor |
4440
4441**错误码:**
4442
4443以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4444
4445| 错误码ID | 错误信息 |
4446| -------- | ---------------------------------------- |
4447| 9001005  | If the resource not found by path.          |
4448
4449**示例:**
4450  ```ts
4451  import { BusinessError } from '@ohos.base';
4452
4453  try {
4454    this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => {
4455      let fd = value.fd;
4456      let offset = value.offset;
4457      let length = value.length;
4458    }).catch((error: BusinessError) => {
4459      console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
4460    });
4461  } catch (error) {
4462    let code = (error as BusinessError).code;
4463    let message = (error as BusinessError).message;
4464    console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`);
4465  }
4466  ```
4467
4468### closeRawFdSync<sup>10+</sup>
4469
4470closeRawFdSync(path: string): void
4471
4472用户关闭resources/rawfile目录下rawfile文件的descriptor。
4473
4474**系统能力**:SystemCapability.Global.ResourceManager
4475
4476**参数:**
4477
4478| 参数名      | 类型                        | 必填   | 说明          |
4479| -------- | ------------------------- | ---- | ----------- |
4480| path     | string                    | 是    | rawfile文件路径 |
4481
4482**错误码:**
4483
4484以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4485
4486| 错误码ID | 错误信息 |
4487| -------- | ---------------------------------------- |
4488| 9001005  | The resource not found by path.          |
4489
4490**示例:**
4491  ```ts
4492  import { BusinessError } from '@ohos.base';
4493
4494  try {
4495    this.context.resourceManager.closeRawFdSync("test.txt");
4496  } catch (error) {
4497    let code = (error as BusinessError).code;
4498    let message = (error as BusinessError).message;
4499    console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`);
4500  }
4501  ```
4502
4503### closeRawFd<sup>9+</sup>
4504
4505closeRawFd(path: string, callback: AsyncCallback&lt;void&gt;): void
4506
4507用户关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回。
4508
4509**系统能力**:SystemCapability.Global.ResourceManager
4510
4511**参数:**
4512
4513| 参数名      | 类型                        | 必填   | 说明          |
4514| -------- | ------------------------- | ---- | ----------- |
4515| path     | string                    | 是    | rawfile文件路径 |
4516| callback | AsyncCallback&lt;void&gt; | 是    | 异步回调        |
4517
4518**错误码:**
4519
4520以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4521
4522| 错误码ID | 错误信息 |
4523| -------- | ---------------------------------------- |
4524| 9001005  | The resource not found by path.          |
4525
4526**示例:**
4527  ```ts
4528  import { BusinessError } from '@ohos.base';
4529
4530  try {
4531    this.context.resourceManager.closeRawFd("test.txt", (error, value) => {
4532      if (error != null) {
4533        console.log("error is " + error);
4534      }
4535    });
4536  } catch (error) {
4537    let code = (error as BusinessError).code;
4538    let message = (error as BusinessError).message;
4539    console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`);
4540  }
4541  ```
4542
4543### closeRawFd<sup>9+</sup>
4544
4545closeRawFd(path: string): Promise&lt;void&gt;
4546
4547用户关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回。
4548
4549**系统能力**:SystemCapability.Global.ResourceManager
4550
4551**参数:**
4552
4553| 参数名  | 类型     | 必填   | 说明          |
4554| ---- | ------ | ---- | ----------- |
4555| path | string | 是    | rawfile文件路径 |
4556
4557**返回值:**
4558
4559| 类型                  | 说明   |
4560| ------------------- | ---- |
4561| Promise&lt;void&gt; | 无返回值 |
4562
4563**错误码:**
4564
4565以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4566
4567| 错误码ID | 错误信息 |
4568| -------- | ---------------------------------------- |
4569| 9001005  | If the resource not found by path.          |
4570
4571**示例:**
4572  ```ts
4573  import { BusinessError } from '@ohos.base';
4574
4575  try {
4576    this.context.resourceManager.closeRawFd("test.txt");
4577  } catch (error) {
4578    let code = (error as BusinessError).code;
4579    let message = (error as BusinessError).message;
4580    console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`);
4581  }
4582  ```
4583
4584### getConfigurationSync
4585
4586getConfigurationSync(): Configuration
4587
4588用户获取设备的Configuration,使用同步形式返回Configuration对象。
4589
4590**系统能力**:SystemCapability.Global.ResourceManager
4591
4592**返回值:**
4593
4594| 类型                                       | 说明               |
4595| ---------------------------------------- | ---------------- |
4596| [Configuration](#configuration) | 设备的Configuration |
4597
4598**示例:**
4599  ```ts
4600  try {
4601    let value = this.context.resourceManager.getConfigurationSync();
4602    let direction = value.direction;
4603    let locale = value.locale;
4604  } catch (error) {
4605    console.error("getConfigurationSync error is " + error);
4606  }
4607  ```
4608
4609### getConfiguration
4610
4611getConfiguration(callback: AsyncCallback&lt;Configuration&gt;): void
4612
4613用户获取设备的Configuration,使用callback形式返回Configuration对象。
4614
4615**系统能力**:SystemCapability.Global.ResourceManager
4616
4617**参数:**
4618
4619| 参数名      | 类型                                       | 必填   | 说明                        |
4620| -------- | ---------------------------------------- | ---- | ------------------------- |
4621| callback | AsyncCallback&lt;[Configuration](#configuration)&gt; | 是    | 异步回调,用于返回设备的Configuration |
4622
4623**示例:**
4624  ```ts
4625  try {
4626    this.context.resourceManager.getConfiguration((error, value) => {
4627      if (error != null) {
4628        console.error("getConfiguration callback error is " + error);
4629      } else {
4630        let direction = value.direction;
4631        let locale = value.locale;
4632      }
4633    });
4634  } catch (error) {
4635    console.error("getConfiguration callback error is " + error);
4636  }
4637  ```
4638
4639### getConfiguration
4640
4641getConfiguration(): Promise&lt;Configuration&gt;
4642
4643用户获取设备的Configuration,使用Promise形式返回Configuration对象。
4644
4645**系统能力**:SystemCapability.Global.ResourceManager
4646
4647**返回值:**
4648
4649| 类型                                       | 说明               |
4650| ---------------------------------------- | ---------------- |
4651| Promise&lt;[Configuration](#configuration)&gt; | 设备的Configuration |
4652
4653**示例:**
4654  ```ts
4655  import { BusinessError } from '@ohos.base';
4656
4657  try {
4658    this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => {
4659      let direction = value.direction;
4660      let locale = value.locale;
4661    }).catch((error: BusinessError) => {
4662      console.error("getConfiguration promise error is " + error);
4663    });
4664  } catch (error) {
4665    console.error("getConfiguration promise error is " + error);
4666  }
4667  ```
4668
4669### getDeviceCapabilitySync
4670
4671getDeviceCapabilitySync(): DeviceCapability
4672
4673用户获取设备的DeviceCapability,使用同步形式返回DeviceCapability对象。
4674
4675**系统能力**:SystemCapability.Global.ResourceManager
4676
4677**返回值:**
4678
4679| 类型                                       | 说明                  |
4680| ---------------------------------------- | ------------------- |
4681| [DeviceCapability](#devicecapability) | 设备的DeviceCapability |
4682
4683**示例:**
4684  ```ts
4685  try {
4686    let value = this.context.resourceManager.getDeviceCapabilitySync();
4687    let screenDensity = value.screenDensity;
4688    let deviceType = value.deviceType;
4689  } catch (error) {
4690    console.error("getDeviceCapabilitySync error is " + error);
4691  }
4692  ```
4693
4694### getDeviceCapability
4695
4696getDeviceCapability(callback: AsyncCallback&lt;DeviceCapability&gt;): void
4697
4698用户获取设备的DeviceCapability,使用callback形式返回DeviceCapability对象。
4699
4700**系统能力**:SystemCapability.Global.ResourceManager
4701
4702**参数:**
4703
4704| 参数名      | 类型                                       | 必填   | 说明                           |
4705| -------- | ---------------------------------------- | ---- | ---------------------------- |
4706| callback | AsyncCallback&lt;[DeviceCapability](#devicecapability)&gt; | 是    | 异步回调,用于返回设备的DeviceCapability |
4707
4708**示例:**
4709  ```ts
4710  try {
4711    this.context.resourceManager.getDeviceCapability((error, value) => {
4712      if (error != null) {
4713        console.error("getDeviceCapability callback error is " + error);
4714      } else {
4715        let screenDensity = value.screenDensity;
4716        let deviceType = value.deviceType;
4717      }
4718    });
4719  } catch (error) {
4720    console.error("getDeviceCapability callback error is " + error);
4721  }
4722  ```
4723
4724### getDeviceCapability
4725
4726getDeviceCapability(): Promise&lt;DeviceCapability&gt;
4727
4728用户获取设备的DeviceCapability,使用Promise形式返回DeviceCapability对象。
4729
4730**系统能力**:SystemCapability.Global.ResourceManager
4731
4732**返回值:**
4733
4734| 类型                                       | 说明                  |
4735| ---------------------------------------- | ------------------- |
4736| Promise&lt;[DeviceCapability](#devicecapability)&gt; | 设备的DeviceCapability |
4737
4738**示例:**
4739  ```ts
4740  import { BusinessError } from '@ohos.base';
4741
4742  try {
4743    this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => {
4744      let screenDensity = value.screenDensity;
4745      let deviceType = value.deviceType;
4746    }).catch((error: BusinessError) => {
4747      console.error("getDeviceCapability promise error is " + error);
4748    });
4749  } catch (error) {
4750    console.error("getDeviceCapability promise error is " + error);
4751  }
4752  ```
4753
4754### release<sup>7+</sup>
4755
4756release()
4757
4758用户释放创建的resourceManager, 此接口暂不支持。
4759
4760**系统能力**:SystemCapability.Global.ResourceManager
4761
4762**示例:**
4763  ```ts
4764  try {
4765    this.context.resourceManager.release();
4766  } catch (error) {
4767    console.error("release error is " + error);
4768  }
4769  ```
4770
4771### addResource<sup>10+</sup>
4772
4773addResource(path: string) : void;
4774
4775应用运行时,加载指定的资源路径,实现资源覆盖。
4776
4777**系统能力**:SystemCapability.Global.ResourceManager
4778
4779**参数:**
4780
4781| 参数名      | 类型                     | 必填   | 说明   |
4782| -------- | ---------------------- | ---- | ---- |
4783| path | string | 是    | 资源路径 |
4784
4785**错误码:**
4786
4787以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4788
4789| 错误码ID | 错误信息 |
4790| -------- | ---------------------------------------- |
4791| 9001010  | If the overlay path is invalid.            |
4792
4793**示例:**
4794  ```ts
4795  import { BusinessError } from '@ohos.base';
4796
4797  let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
4798  try {
4799    this.context.resourceManager.addResource(path);
4800  } catch (error) {
4801    let code = (error as BusinessError).code;
4802    let message = (error as BusinessError).message;
4803    console.error(`addResource failed, error code: ${code}, message: ${message}.`);
4804  }
4805  ```
4806
4807### removeResource<sup>10+</sup>
4808
4809removeResource(path: string) : void;
4810
4811用户运行时,移除指定的资源路径,还原被覆盖前的资源。
4812
4813**系统能力**:SystemCapability.Global.ResourceManager
4814
4815**参数:**
4816
4817| 参数名      | 类型            | 必填   | 说明   |
4818| -------- | ---------------------- | ---- | ---- |
4819| path | string | 是    | 资源路径 |
4820
4821**错误码:**
4822
4823以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
4824
4825| 错误码ID | 错误信息 |
4826| -------- | ---------------------------------------- |
4827| 9001010  | If the overlay path is invalid.            |
4828
4829**示例:**
4830  ```ts
4831  import { BusinessError } from '@ohos.base';
4832
4833  let path = getContext().bundleCodeDir + "/library1-default-signed.hsp";
4834  try {
4835    this.context.resourceManager.removeResource(path);
4836  } catch (error) {
4837    let code = (error as BusinessError).code;
4838    let message = (error as BusinessError).message;
4839    console.error(`removeResource failed, error code: ${code}, message: ${message}.`);
4840  }
4841  ```
4842
4843### getString<sup>(deprecated)</sup>
4844
4845getString(resId: number, callback: AsyncCallback&lt;string&gt;): void
4846
4847用户获取指定资源ID对应的字符串,使用callback形式返回字符串。
4848
4849从API version 9开始不再维护,建议使用[getStringValue](#getstringvalue9)代替。
4850
4851**系统能力**:SystemCapability.Global.ResourceManager
4852
4853**参数:**
4854
4855| 参数名      | 类型                          | 必填   | 说明              |
4856| -------- | --------------------------- | ---- | --------------- |
4857| resId    | number                      | 是    | 资源ID值           |
4858| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的字符串 |
4859
4860**示例:**
4861  ```ts
4862  resourceManager.getResourceManager((error, mgr) => {
4863      mgr.getString($r('app.string.test').id, (error, value) => {
4864          if (error != null) {
4865              console.log("error is " + error);
4866          } else {
4867              let str = value;
4868          }
4869      });
4870  });
4871  ```
4872
4873
4874### getString<sup>(deprecated)</sup>
4875
4876getString(resId: number): Promise&lt;string&gt;
4877
4878用户获取指定资源ID对应的字符串,使用Promise形式返回字符串。
4879
4880从API version 9开始不再维护,建议使用[getStringValue](#getstringvalue9-1)代替。
4881
4882**系统能力**:SystemCapability.Global.ResourceManager
4883
4884**参数:**
4885
4886| 参数名   | 类型     | 必填   | 说明    |
4887| ----- | ------ | ---- | ----- |
4888| resId | number | 是    | 资源ID值 |
4889
4890**返回值:**
4891
4892| 类型                    | 说明          |
4893| --------------------- | ----------- |
4894| Promise&lt;string&gt; | 资源ID值对应的字符串 |
4895
4896**示例:**
4897  ```ts
4898  import { BusinessError } from '@ohos.base';
4899
4900  resourceManager.getResourceManager((error, mgr) => {
4901      mgr.getString($r('app.string.test').id).then((value: string) => {
4902          let str = value;
4903      }).catch((error: BusinessError) => {
4904          console.log("getstring promise error is " + error);
4905      });
4906  });
4907  ```
4908
4909
4910### getStringArray<sup>(deprecated)</sup>
4911
4912getStringArray(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
4913
4914用户获取指定资源ID对应的字符串数组,使用callback形式返回字符串数组。
4915
4916从API version 9开始不再维护,建议使用[getStringArrayValue](#getstringarrayvalue9)代替。
4917
4918**系统能力**:SystemCapability.Global.ResourceManager
4919
4920**参数:**
4921
4922| 参数名      | 类型                                       | 必填   | 说明                |
4923| -------- | ---------------------------------------- | ---- | ----------------- |
4924| resId    | number                                   | 是    | 资源ID值             |
4925| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 异步回调,用于返回获取的字符串数组 |
4926
4927**示例:**
4928  ```ts
4929  resourceManager.getResourceManager((error, mgr) => {
4930      mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
4931          if (error != null) {
4932              console.log("error is " + error);
4933          } else {
4934              let strArray = value;
4935          }
4936      });
4937  });
4938  ```
4939
4940
4941### getStringArray<sup>(deprecated)</sup>
4942
4943getStringArray(resId: number): Promise&lt;Array&lt;string&gt;&gt;
4944
4945用户获取指定资源ID对应的字符串数组,使用Promise形式返回字符串数组。
4946
4947从API version 9开始不再维护,建议使用[getStringArrayValue](#getstringarrayvalue9-1)代替。
4948
4949**系统能力**:SystemCapability.Global.ResourceManager
4950
4951**参数:**
4952
4953| 参数名   | 类型     | 必填   | 说明    |
4954| ----- | ------ | ---- | ----- |
4955| resId | number | 是    | 资源ID值 |
4956
4957**返回值:**
4958
4959| 类型                                 | 说明            |
4960| ---------------------------------- | ------------- |
4961| Promise&lt;Array&lt;string&gt;&gt; | 资源ID值对应的字符串数组 |
4962
4963**示例:**
4964  ```ts
4965  import { BusinessError } from '@ohos.base';
4966
4967  resourceManager.getResourceManager((error, mgr) => {
4968       mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => {
4969          let strArray = value;
4970      }).catch((error: BusinessError) => {
4971          console.log("getStringArray promise error is " + error);
4972      });
4973  });
4974  ```
4975
4976
4977### getMedia<sup>(deprecated)</sup>
4978
4979getMedia(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
4980
4981用户获取指定资源ID对应的媒体文件内容,使用callback形式返回字节数组。
4982
4983从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9)代替。
4984
4985**系统能力**:SystemCapability.Global.ResourceManager
4986
4987**参数:**
4988
4989| 参数名      | 类型                              | 必填   | 说明                 |
4990| -------- | ------------------------------- | ---- | ------------------ |
4991| resId    | number                          | 是    | 资源ID值              |
4992| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的媒体文件内容 |
4993
4994**示例:**
4995  ```ts
4996  resourceManager.getResourceManager((error, mgr) => {
4997      mgr.getMedia($r('app.media.test').id, (error, value) => {
4998          if (error != null) {
4999              console.log("error is " + error);
5000          } else {
5001              let media = value;
5002          }
5003      });
5004  });
5005  ```
5006
5007
5008### getMedia<sup>(deprecated)</sup>
5009
5010getMedia(resId: number): Promise&lt;Uint8Array&gt;
5011
5012用户获取指定资源ID对应的媒体文件内容,使用Promise形式返回字节数组。
5013
5014从API version 9开始不再维护,建议使用[getMediaContent](#getmediacontent9-1)代替。
5015
5016**系统能力**:SystemCapability.Global.ResourceManager
5017
5018**参数:**
5019
5020| 参数名   | 类型     | 必填   | 说明    |
5021| ----- | ------ | ---- | ----- |
5022| resId | number | 是    | 资源ID值 |
5023
5024**返回值:**
5025
5026| 类型                        | 说明             |
5027| ------------------------- | -------------- |
5028| Promise&lt;Uint8Array&gt; | 资源ID值对应的媒体文件内容 |
5029
5030**示例:**
5031  ```ts
5032  import { BusinessError } from '@ohos.base';
5033
5034  resourceManager.getResourceManager((error, mgr) => {
5035      mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => {
5036          let media = value;
5037      }).catch((error: BusinessError) => {
5038          console.log("getMedia promise error is " + error);
5039      });
5040  });
5041  ```
5042
5043
5044### getMediaBase64<sup>(deprecated)</sup>
5045
5046getMediaBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void
5047
5048用户获取指定资源ID对应的图片资源Base64编码,使用callback形式返回字符串。
5049
5050从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649)代替。
5051
5052**系统能力**:SystemCapability.Global.ResourceManager
5053
5054**参数:**
5055
5056| 参数名      | 类型                          | 必填   | 说明                       |
5057| -------- | --------------------------- | ---- | ------------------------ |
5058| resId    | number                      | 是    | 资源ID值                    |
5059| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,用于返回获取的图片资源Base64编码 |
5060
5061**示例:**
5062  ```ts
5063  resourceManager.getResourceManager((error, mgr) => {
5064      mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
5065          if (error != null) {
5066              console.log("error is " + error);
5067          } else {
5068              let media = value;
5069          }
5070      });
5071  });
5072  ```
5073
5074
5075### getMediaBase64<sup>(deprecated)</sup>
5076
5077getMediaBase64(resId: number): Promise&lt;string&gt;
5078
5079用户获取指定资源ID对应的图片资源Base64编码,使用Promise形式返回字符串。
5080
5081从API version 9开始不再维护,建议使用[getMediaContentBase64](#getmediacontentbase649-1)代替。
5082
5083**系统能力**:SystemCapability.Global.ResourceManager
5084
5085**参数:**
5086
5087| 参数名   | 类型     | 必填   | 说明    |
5088| ----- | ------ | ---- | ----- |
5089| resId | number | 是    | 资源ID值 |
5090
5091**返回值:**
5092
5093| 类型                    | 说明                   |
5094| --------------------- | -------------------- |
5095| Promise&lt;string&gt; | 资源ID值对应的图片资源Base64编码 |
5096
5097**示例:**
5098  ```ts
5099  import { BusinessError } from '@ohos.base';
5100
5101  resourceManager.getResourceManager((error, mgr) => {
5102      mgr.getMediaBase64($r('app.media.test').id).then((value: string) => {
5103          let media = value;
5104      }).catch((error: BusinessError) => {
5105          console.log("getMediaBase64 promise error is " + error);
5106      });
5107  });
5108  ```
5109
5110
5111### getPluralString<sup>(deprecated)</sup>
5112
5113getPluralString(resId: number, num: number): Promise&lt;string&gt;
5114
5115根据指定数量获取对指定ID字符串表示的单复数字符串,使用Promise形式返回字符串。
5116
5117从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9)代替。
5118
5119**系统能力**:SystemCapability.Global.ResourceManager
5120
5121**参数:**
5122
5123| 参数名   | 类型     | 必填   | 说明    |
5124| ----- | ------ | ---- | ----- |
5125| resId | number | 是    | 资源ID值 |
5126| num   | number | 是    | 数量值   |
5127
5128**返回值:**
5129
5130| 类型                    | 说明                        |
5131| --------------------- | ------------------------- |
5132| Promise&lt;string&gt; | 根据提供的数量获取对应ID字符串表示的单复数字符串 |
5133
5134**示例:**
5135  ```ts
5136  import { BusinessError } from '@ohos.base';
5137
5138  resourceManager.getResourceManager((error, mgr) => {
5139      mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => {
5140          let str = value;
5141      }).catch((error: BusinessError) => {
5142          console.log("getPluralString promise error is " + error);
5143      });
5144  });
5145  ```
5146
5147
5148### getPluralString<sup>(deprecated)</sup>
5149
5150getPluralString(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
5151
5152根据指定数量获取指定ID字符串表示的单复数字符串,使用callback形式返回字符串。
5153
5154从API version 9开始不再维护,建议使用[getPluralStringValue](#getpluralstringvalue9-1)代替。
5155
5156**系统能力**:SystemCapability.Global.ResourceManager
5157
5158**参数:**
5159
5160| 参数名      | 类型                          | 必填   | 说明                              |
5161| -------- | --------------------------- | ---- | ------------------------------- |
5162| resId    | number                      | 是    | 资源ID值                           |
5163| num      | number                      | 是    | 数量值                             |
5164| callback | AsyncCallback&lt;string&gt; | 是    | 异步回调,返回根据指定数量获取指定ID字符串表示的单复数字符串 |
5165
5166**示例:**
5167  ```ts
5168  resourceManager.getResourceManager((error, mgr) => {
5169      mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
5170          if (error != null) {
5171              console.log("error is " + error);
5172          } else {
5173              let str = value;
5174          }
5175      });
5176  });
5177  ```
5178
5179
5180### getRawFile<sup>(deprecated)</sup>
5181
5182getRawFile(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
5183
5184用户获取resources/rawfile目录下对应的rawfile文件内容,使用callback形式返回字节数组。
5185
5186从API version 9开始不再维护,建议使用[getRawFileContent](#getrawfilecontent9)代替。
5187
5188**系统能力**:SystemCapability.Global.ResourceManager
5189
5190**参数:**
5191
5192| 参数名      | 类型                              | 必填   | 说明                      |
5193| -------- | ------------------------------- | ---- | ----------------------- |
5194| path     | string                          | 是    | rawfile文件路径             |
5195| callback | AsyncCallback&lt;Uint8Array&gt; | 是    | 异步回调,用于返回获取的rawfile文件内容 |
5196
5197**示例:**
5198  ```ts
5199  resourceManager.getResourceManager((error, mgr) => {
5200      mgr.getRawFile("test.txt", (error, value) => {
5201          if (error != null) {
5202              console.log("error is " + error);
5203          } else {
5204              let rawFile = value;
5205          }
5206      });
5207  });
5208  ```
5209
5210
5211### getRawFile<sup>(deprecated)</sup>
5212
5213getRawFile(path: string): Promise&lt;Uint8Array&gt;
5214
5215用户获取resources/rawfile目录下对应的rawfile文件内容,使用Promise形式返回字节数组。
5216
5217从API version 9开始不再维护,建议使用[getRawFileContent](#getrawfilecontent9-1)代替。
5218
5219**系统能力**:SystemCapability.Global.ResourceManager
5220
5221**参数:**
5222
5223| 参数名  | 类型     | 必填   | 说明          |
5224| ---- | ------ | ---- | ----------- |
5225| path | string | 是    | rawfile文件路径 |
5226
5227**返回值:**
5228
5229| 类型                        | 说明          |
5230| ------------------------- | ----------- |
5231| Promise&lt;Uint8Array&gt; | rawfile文件内容 |
5232
5233**示例:**
5234  ```ts
5235  import { BusinessError } from '@ohos.base';
5236
5237  resourceManager.getResourceManager((error, mgr) => {
5238      mgr.getRawFile("test.txt").then((value: Uint8Array) => {
5239          let rawFile = value;
5240      }).catch((error: BusinessError) => {
5241          console.log("getRawFile promise error is " + error);
5242      });
5243  });
5244  ```
5245
5246
5247### getRawFileDescriptor<sup>(deprecated)</sup>
5248
5249getRawFileDescriptor(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void
5250
5251用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用callback形式返回。
5252
5253从API version 9开始不再维护,建议使用[getRawFd](#getrawfd9)代替。
5254
5255**系统能力**:SystemCapability.Global.ResourceManager
5256
5257**参数:**
5258
5259| 参数名      | 类型                                       | 必填   | 说明                               |
5260| -------- | ---------------------------------------- | ---- | -------------------------------- |
5261| path     | string                                   | 是    | rawfile文件路径                      |
5262| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | 是    | 异步回调,用于返回获取的rawfile文件的descriptor |
5263
5264**示例:**
5265  ```ts
5266  resourceManager.getResourceManager((error, mgr) => {
5267      mgr.getRawFileDescriptor("test.txt", (error, value) => {
5268          if (error != null) {
5269              console.log("error is " + error);
5270          } else {
5271              let fd = value.fd;
5272              let offset = value.offset;
5273              let length = value.length;
5274          }
5275      });
5276  });
5277  ```
5278
5279### getRawFileDescriptor<sup>(deprecated)</sup>
5280
5281getRawFileDescriptor(path: string): Promise&lt;RawFileDescriptor&gt;
5282
5283用户获取resources/rawfile目录下对应rawfile文件的descriptor,使用Promise形式返回。
5284
5285从API version 9开始不再维护,建议使用[getRawFd](#getrawfd9-1)代替。
5286
5287**系统能力**:SystemCapability.Global.ResourceManager
5288
5289**参数:**
5290
5291| 参数名  | 类型     | 必填   | 说明          |
5292| ---- | ------ | ---- | ----------- |
5293| path | string | 是    | rawfile文件路径 |
5294
5295**返回值:**
5296
5297| 类型                                       | 说明                  |
5298| ---------------------------------------- | ------------------- |
5299| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | rawfile文件descriptor |
5300
5301**示例:**
5302  ```ts
5303  import { BusinessError } from '@ohos.base';
5304
5305  resourceManager.getResourceManager((error, mgr) => {
5306      mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => {
5307          let fd = value.fd;
5308          let offset = value.offset;
5309          let length = value.length;
5310      }).catch((error: BusinessError) => {
5311          console.log("getRawFileDescriptor promise error is " + error);
5312      });
5313  });
5314  ```
5315
5316### closeRawFileDescriptor<sup>(deprecated)</sup>
5317
5318closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void
5319
5320用户关闭resources/rawfile目录下rawfile文件的descriptor,使用callback形式返回。
5321
5322从API version 9开始不再维护,建议使用[closeRawFd](#closerawfd9)代替。
5323
5324**系统能力**:SystemCapability.Global.ResourceManager
5325
5326**参数:**
5327
5328| 参数名      | 类型                        | 必填   | 说明          |
5329| -------- | ------------------------- | ---- | ----------- |
5330| path     | string                    | 是    | rawfile文件路径 |
5331| callback | AsyncCallback&lt;void&gt; | 是    | 异步回调        |
5332
5333**示例:**
5334  ```ts
5335  resourceManager.getResourceManager((error, mgr) => {
5336      mgr.closeRawFileDescriptor("test.txt", (error, value) => {
5337          if (error != null) {
5338              console.log("error is " + error);
5339          }
5340      });
5341  });
5342  ```
5343
5344### closeRawFileDescriptor<sup>(deprecated)</sup>
5345
5346closeRawFileDescriptor(path: string): Promise&lt;void&gt;
5347
5348用户关闭resources/rawfile目录下rawfile文件的descriptor,使用Promise形式返回。
5349
5350从API version 9开始不再维护,建议使用[closeRawFd](#closerawfd9-1)代替。
5351
5352**系统能力**:SystemCapability.Global.ResourceManager
5353
5354**参数:**
5355
5356| 参数名  | 类型     | 必填   | 说明          |
5357| ---- | ------ | ---- | ----------- |
5358| path | string | 是    | rawfile文件路径 |
5359
5360**返回值:**
5361
5362| 类型                  | 说明   |
5363| ------------------- | ---- |
5364| Promise&lt;void&gt; | 无返回值 |
5365
5366**示例:**
5367  ```ts
5368  resourceManager.getResourceManager((error, mgr) => {
5369      mgr.closeRawFileDescriptor("test.txt");
5370  });
5371  ```