• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Resource Management
2
3The resource management module provides APIs to obtain information about the current device configuration (including the language, region, screen direction, and MCC/MNC) and device capability (including the device type and resolution).
4
5> **NOTE**<br>
6> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
7
8
9## Modules to Import
10
11```
12import resourceManager from '@ohos.resourceManager';
13```
14
15## Usage
16
17Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its APIs without first importing the required bundle. This method, however, is not applicable to the FA model.
18
19```
20this.context.resourceManager;
21```
22
23## resourceManager.getResourceManager
24
25getResourceManager(callback: AsyncCallback&lt;ResourceManager&gt;): void
26
27Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result.
28
29This API is used only in the FA model.
30
31**System capability**: SystemCapability.Global.ResourceManager
32
33**Parameters**
34| Name     | Type                                      | Mandatory  | Description                           |
35| -------- | ---------------------------------------- | ---- | ----------------------------- |
36| callback | AsyncCallback&lt;[ResourceManager](#resourcemanager)&gt; | Yes   | Asynchronous callback used to return the result.|
37
38**Example**
39  ```
40  resourceManager.getResourceManager((error, mgr) => {
41      if (error != null) {
42          console.log("error is " + error);
43          return;
44      }
45      mgr.getString(0x1000000, (error, value) => {
46          if (error != null) {
47              console.log("error is " + error);
48          } else {
49              let str = value;
50          }
51      });
52  });
53  ```
54
55
56## resourceManager.getResourceManager
57
58getResourceManager(bundleName: string, callback: AsyncCallback&lt;ResourceManager&gt;): void
59
60Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result.
61
62This API is used only in the FA model.
63
64**System capability**: SystemCapability.Global.ResourceManager
65
66**Parameters**
67| Name       | Type                                      | Mandatory  | Description                           |
68| ---------- | ---------------------------------------- | ---- | ----------------------------- |
69| bundleName | string                                   | Yes   | Bundle name of the target application.                |
70| callback   | AsyncCallback&lt;[ResourceManager](#resourcemanager)&gt; | Yes   | Asynchronous callback used to return the result.|
71
72**Example**
73  ```
74  resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
75  });
76  ```
77
78
79## resourceManager.getResourceManager
80
81getResourceManager(): Promise&lt;ResourceManager&gt;
82
83Obtains the **ResourceManager** object of this application. This API uses a promise to return the result.
84
85This API is used only in the FA model.
86
87**System capability**: SystemCapability.Global.ResourceManager
88
89**Return value**
90| Type                                      | Description               |
91| ---------------------------------------- | ----------------- |
92| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the result.|
93
94**Example**
95  ```
96  resourceManager.getResourceManager().then(mgr => {
97      mgr.getString(0x1000000, (error, value) => {
98          if (error != null) {
99              console.log("error is " + error);
100          } else {
101              let str = value;
102          }
103      });
104  }).catch(error => {
105      console.log("error is " + error);
106  });
107  ```
108
109
110## resourceManager.getResourceManager
111
112getResourceManager(bundleName: string): Promise&lt;ResourceManager&gt;
113
114Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result.
115
116This API is used only in the FA model.
117
118**System capability**: SystemCapability.Global.ResourceManager
119
120**Parameters**
121| Name       | Type    | Mandatory  | Description           |
122| ---------- | ------ | ---- | ------------- |
123| bundleName | string | Yes   | Bundle name of the target application.|
124
125**Return value**
126| Type                                      | Description                |
127| ---------------------------------------- | ------------------ |
128| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the result.|
129
130**Example**
131  ```
132  resourceManager.getResourceManager("com.example.myapplication").then(mgr => {
133
134  }).catch(error => {
135
136  });
137  ```
138
139
140## Direction
141
142Enumerates the screen directions.
143
144**System capability**: SystemCapability.Global.ResourceManager
145
146| Name                  | Default Value | Description  |
147| -------------------- | ---- | ---- |
148| DIRECTION_VERTICAL   | 0    | Portrait.  |
149| DIRECTION_HORIZONTAL | 1    | Landscape.  |
150
151
152## DeviceType
153
154Enumerates the device types.
155
156**System capability**: SystemCapability.Global.ResourceManager
157
158| Name                  | Default Value | Description  |
159| -------------------- | ---- | ---- |
160| DEVICE_TYPE_PHONE    | 0x00 | Phone.  |
161| DEVICE_TYPE_TABLET   | 0x01 | Tablet.  |
162| DEVICE_TYPE_CAR      | 0x02 | Head unit.  |
163| DEVICE_TYPE_PC       | 0x03 | PC.  |
164| DEVICE_TYPE_TV       | 0x04 | TV.  |
165| DEVICE_TYPE_WEARABLE | 0x06 | Wearable.  |
166
167
168## ScreenDensity
169
170Enumerates the screen density types.
171
172**System capability**: SystemCapability.Global.ResourceManager
173
174| Name            | Default Value | Description        |
175| -------------- | ---- | ---------- |
176| SCREEN_SDPI    | 120  | Screen density with small-scale dots per inch (SDPI).  |
177| SCREEN_MDPI    | 160  | Screen density with medium-scale dots per inch (MDPI).  |
178| SCREEN_LDPI    | 240  | Screen density with large-scale dots per inch (LDPI).  |
179| SCREEN_XLDPI   | 320  | Screen density with extra-large-scale dots per inch (XLDPI). |
180| SCREEN_XXLDPI  | 480  | Screen density with extra-extra-large-scale dots per inch (XXLDPI). |
181| SCREEN_XXXLDPI | 640  | Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).|
182
183
184## Configuration
185
186Defines the device configuration.
187
188**System capability**: SystemCapability.Global.ResourceManager
189
190
191| Name       | Type                   | Readable  | Writable  | Description      |
192| --------- | ----------------------- | ---- | ---- | -------- |
193| direction | [Direction](#direction) | Yes   | No   | Screen direction of the device.|
194| locale    | string                  | Yes   | No   | Current system language.  |
195
196**Example**
197
198  ```
199resourceManager.getResourceManager((error, mgr) => {
200      mgr.getConfiguration((error, value) => {
201          let direction = value.direction;
202          let locale = value.locale;
203      });
204  });
205  ```
206
207## DeviceCapability
208
209Defines the device capability.
210
211**System capability**: SystemCapability.Global.ResourceManager
212
213
214| Name           | Type                           | Readable  | Writable  | Description      |
215| ------------- | ------------------------------- | ---- | ---- | -------- |
216| screenDensity | [ScreenDensity](#screendensity) | Yes   | No   | Screen density of the device.|
217| deviceType    | [DeviceType](#devicetype)       | Yes   | No   | Type of the device.  |
218
219**Example**
220
221  ```
222resourceManager.getResourceManager((error, mgr) => {
223      mgr.getDeviceCapability((error, value) => {
224          let screenDensity = value.screenDensity;
225          let deviceType = value.deviceType;
226      });
227  });
228  ```
229
230## RawFileDescriptor<sup>8+</sup>
231
232Defines the descriptor information of the raw file.<br>
233**System capability**: SystemCapability.Global.ResourceManager
234
235| Name    | Type    | Description                |
236| ------ | ------ | ------------------ |
237| fd     | number | Descriptor of a raw file.|
238| offset | number | Offset to the start position of the raw file.     |
239| length | number | Length of the raw file.      |
240
241
242## ResourceManager
243
244Defines the capability of accessing application resources.
245
246> **NOTE**<br>
247> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
248>
249> - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**.
250
251
252### getString
253
254getString(resId: number, callback: AsyncCallback&lt;string&gt;): void
255
256Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
257
258**System capability**: SystemCapability.Global.ResourceManager
259
260**Parameters**
261| Name     | Type                         | Mandatory  | Description             |
262| -------- | --------------------------- | ---- | --------------- |
263| resId    | number                      | Yes   | Resource ID.          |
264| callback | AsyncCallback&lt;string&gt; | Yes   | Asynchronous callback used to return the result.|
265
266**Example**
267  ```
268  resourceManager.getResourceManager((error, mgr) => {
269      mgr.getString($r('app.string.test').id, (error, value) => {
270          if (error != null) {
271              console.log("error is " + error);
272          } else {
273              let str = value;
274          }
275      });
276  });
277  ```
278
279
280### getString
281
282getString(resId: number): Promise&lt;string&gt;
283
284Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result.
285
286**System capability**: SystemCapability.Global.ResourceManager
287
288**Parameters**
289| Name  | Type    | Mandatory  | Description   |
290| ----- | ------ | ---- | ----- |
291| resId | number | Yes   | Resource ID.|
292
293**Return value**
294| Type                   | Description         |
295| --------------------- | ----------- |
296| Promise&lt;string&gt; | Promise used to return the result.|
297
298**Example**
299  ```
300  resourceManager.getResourceManager((error, mgr) => {
301      mgr.getString($r('app.string.test').id).then(value => {
302          let str = value;
303      }).catch(error => {
304          console.log("getstring promise error is " + error);
305      });
306  });
307  ```
308
309
310### getStringArray
311
312getStringArray(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
313
314Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
315
316**System capability**: SystemCapability.Global.ResourceManager
317
318**Parameters**
319| Name     | Type                                      | Mandatory  | Description               |
320| -------- | ---------------------------------------- | ---- | ----------------- |
321| resId    | number                                   | Yes   | Resource ID.            |
322| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Asynchronous callback used to return the result.|
323
324**Example**
325  ```
326  resourceManager.getResourceManager((error, mgr) => {
327      mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
328          if (error != null) {
329              console.log("error is " + error);
330          } else {
331              let strArray = value;
332          }
333      });
334  });
335  ```
336
337
338### getStringArray
339
340getStringArray(resId: number): Promise&lt;Array&lt;string&gt;&gt;
341
342Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result.
343
344**System capability**: SystemCapability.Global.ResourceManager
345
346**Parameters**
347| Name  | Type    | Mandatory  | Description   |
348| ----- | ------ | ---- | ----- |
349| resId | number | Yes   | Resource ID.|
350
351**Return value**
352| Type                                | Description           |
353| ---------------------------------- | ------------- |
354| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
355
356**Example**
357  ```
358  resourceManager.getResourceManager((error, mgr) => {
359       mgr.getStringArray($r('app.strarray.test').id).then(value => {
360          let strArray = value;
361      }).catch(error => {
362          console.log("getStringArray promise error is " + error);
363      });
364  });
365  ```
366
367
368### getMedia
369
370getMedia(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
371
372Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
373
374**System capability**: SystemCapability.Global.ResourceManager
375
376**Parameters**
377| Name     | Type                             | Mandatory  | Description                |
378| -------- | ------------------------------- | ---- | ------------------ |
379| resId    | number                          | Yes   | Resource ID.             |
380| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Asynchronous callback used to return the result.|
381
382**Example**
383  ```
384  resourceManager.getResourceManager((error, mgr) => {
385      mgr.getMedia($r('app.media.test').id, (error, value) => {
386          if (error != null) {
387              console.log("error is " + error);
388          } else {
389              let media = value;
390          }
391      });
392  });
393  ```
394
395
396### getMedia
397
398getMedia(resId: number): Promise&lt;Uint8Array&gt;
399
400Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result.
401
402**System capability**: SystemCapability.Global.ResourceManager
403
404**Parameters**
405| Name  | Type    | Mandatory  | Description   |
406| ----- | ------ | ---- | ----- |
407| resId | number | Yes   | Resource ID.|
408
409**Return value**
410| Type                       | Description            |
411| ------------------------- | -------------- |
412| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
413
414**Example**
415  ```
416  resourceManager.getResourceManager((error, mgr) => {
417      mgr.getMedia($r('app.media.test').id).then(value => {
418          let media = value;
419      }).catch(error => {
420          console.log("getMedia promise error is " + error);
421      });
422  });
423  ```
424
425
426### getMediaBase64
427
428getMediaBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void
429
430Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
431
432**System capability**: SystemCapability.Global.ResourceManager
433
434**Parameters**
435| Name     | Type                         | Mandatory  | Description                      |
436| -------- | --------------------------- | ---- | ------------------------ |
437| resId    | number                      | Yes   | Resource ID.                   |
438| callback | AsyncCallback&lt;string&gt; | Yes   | Asynchronous callback used to return the result.|
439
440**Example**
441  ```
442  resourceManager.getResourceManager((error, mgr) => {
443      mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
444          if (error != null) {
445              console.log("error is " + error);
446          } else {
447              let media = value;
448          }
449      });
450  });
451  ```
452
453
454### getMediaBase64
455
456getMediaBase64(resId: number): Promise&lt;string&gt;
457
458Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result.
459
460**System capability**: SystemCapability.Global.ResourceManager
461
462**Parameters**
463| Name  | Type    | Mandatory  | Description   |
464| ----- | ------ | ---- | ----- |
465| resId | number | Yes   | Resource ID.|
466
467**Return value**
468| Type                   | Description                  |
469| --------------------- | -------------------- |
470| Promise&lt;string&gt; | Promise used to return the result.|
471
472**Example**
473  ```
474  resourceManager.getResourceManager((error, mgr) => {
475      mgr.getMediaBase64($r('app.media.test').id).then(value => {
476          let media = value;
477      }).catch(error => {
478          console.log("getMediaBase64 promise error is " + error);
479      });
480  });
481  ```
482
483
484### getConfiguration
485
486getConfiguration(callback: AsyncCallback&lt;Configuration&gt;): void
487
488Obtains the device configuration. This API uses an asynchronous callback to return the result.
489
490**System capability**: SystemCapability.Global.ResourceManager
491
492**Parameters**
493| Name     | Type                                      | Mandatory  | Description                       |
494| -------- | ---------------------------------------- | ---- | ------------------------- |
495| callback | AsyncCallback&lt;[Configuration](#configuration)&gt; | Yes   | Asynchronous callback used to return the result.|
496
497**Example**
498  ```
499  resourceManager.getResourceManager((error, mgr) => {
500      mgr.getConfiguration((error, value) => {
501          if (error != null) {
502              console.log("error is " + error);
503          } else {
504              let direction = value.direction;
505              let locale = value.locale;
506          }
507      });
508  });
509  ```
510
511
512### getConfiguration
513
514getConfiguration(): Promise&lt;Configuration&gt;
515
516Obtains the device configuration. This API uses a promise to return the result.
517
518**System capability**: SystemCapability.Global.ResourceManager
519
520**Return value**
521| Type                                      | Description              |
522| ---------------------------------------- | ---------------- |
523| Promise&lt;[Configuration](#configuration)&gt; | Promise used to return the result.|
524
525**Example**
526  ```
527  resourceManager.getResourceManager((error, mgr) => {
528      mgr.getConfiguration().then(value => {
529          let direction = value.direction;
530          let locale = value.locale;
531      }).catch(error => {
532          console.log("getConfiguration promise error is " + error);
533      });
534  });
535  ```
536
537
538### getDeviceCapability
539
540getDeviceCapability(callback: AsyncCallback&lt;DeviceCapability&gt;): void
541
542Obtains the device capability. This API uses an asynchronous callback to return the result.
543
544**System capability**: SystemCapability.Global.ResourceManager
545
546**Parameters**
547| Name     | Type                                      | Mandatory  | Description                          |
548| -------- | ---------------------------------------- | ---- | ---------------------------- |
549| callback | AsyncCallback&lt;[DeviceCapability](#devicecapability)&gt; | Yes   | Asynchronous callback used to return the result.|
550
551**Example**
552  ```
553  resourceManager.getResourceManager((error, mgr) => {
554      mgr.getDeviceCapability((error, value) => {
555          if (error != null) {
556              console.log("error is " + error);
557          } else {
558              let screenDensity = value.screenDensity;
559              let deviceType = value.deviceType;
560          }
561      });
562  });
563  ```
564
565
566### getDeviceCapability
567
568getDeviceCapability(): Promise&lt;DeviceCapability&gt;
569
570Obtains the device capability. This API uses a promise to return the result.
571
572**System capability**: SystemCapability.Global.ResourceManager
573
574**Return value**
575| Type                                      | Description                 |
576| ---------------------------------------- | ------------------- |
577| Promise&lt;[DeviceCapability](#devicecapability)&gt; | Promise used to return the result.|
578
579**Example**
580  ```
581  resourceManager.getResourceManager((error, mgr) => {
582      mgr.getDeviceCapability().then(value => {
583          let screenDensity = value.screenDensity;
584          let deviceType = value.deviceType;
585      }).catch(error => {
586          console.log("getDeviceCapability promise error is " + error);
587      });
588  });
589  ```
590
591
592### getPluralString
593
594getPluralString(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
595
596Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
597
598**System capability**: SystemCapability.Global.ResourceManager
599
600**Parameters**
601| Name     | Type                         | Mandatory  | Description                             |
602| -------- | --------------------------- | ---- | ------------------------------- |
603| resId    | number                      | Yes   | Resource ID.                          |
604| num      | number                      | Yes   | Number that determines the plural or singular form.                            |
605| callback | AsyncCallback&lt;string&gt; | Yes   | Asynchronous callback used to return the result.|
606
607**Example**
608  ```
609  resourceManager.getResourceManager((error, mgr) => {
610      mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
611          if (error != null) {
612              console.log("error is " + error);
613          } else {
614              let str = value;
615          }
616      });
617  });
618  ```
619
620
621### getPluralString
622
623getPluralString(resId: number, num: number): Promise&lt;string&gt;
624
625Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This API uses a promise to return the result.
626
627**System capability**: SystemCapability.Global.ResourceManager
628
629**Parameters**
630| Name  | Type    | Mandatory  | Description   |
631| ----- | ------ | ---- | ----- |
632| resId | number | Yes   | Resource ID.|
633| num   | number | Yes   | Number that determines the plural or singular form.  |
634
635**Return value**
636| Type                   | Description                       |
637| --------------------- | ------------------------- |
638| Promise&lt;string&gt; | Promise used to return the result.|
639
640**Example**
641  ```
642  resourceManager.getResourceManager((error, mgr) => {
643      mgr.getPluralString($r("app.plural.test").id, 1).then(value => {
644          let str = value;
645      }).catch(error => {
646          console.log("getPluralString promise error is " + error);
647      });
648  });
649  ```
650
651### getRawFile<sup>8+</sup>
652
653getRawFile(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
654
655Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
656
657**System capability**: SystemCapability.Global.ResourceManager
658
659**Parameters**
660| Name     | Type                             | Mandatory  | Description                     |
661| -------- | ------------------------------- | ---- | ----------------------- |
662| path     | string                          | Yes   | Path of the raw file.            |
663| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Asynchronous callback used to return the result.|
664
665**Example**
666  ```
667  resourceManager.getResourceManager((error, mgr) => {
668      mgr.getRawFile("test.xml", (error, value) => {
669          if (error != null) {
670              console.log("error is " + error);
671          } else {
672              let rawFile = value;
673          }
674      });
675  });
676  ```
677
678### getRawFile<sup>8+</sup>
679
680getRawFile(path: string): Promise&lt;Uint8Array&gt;
681
682Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
683
684**System capability**: SystemCapability.Global.ResourceManager
685
686**Parameters**
687| Name | Type    | Mandatory  | Description         |
688| ---- | ------ | ---- | ----------- |
689| path | string | Yes   | Path of the raw file.|
690
691**Return value**
692| Type                       | Description         |
693| ------------------------- | ----------- |
694| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
695
696**Example**
697  ```
698  resourceManager.getResourceManager((error, mgr) => {
699      mgr.getRawFile("test.xml").then(value => {
700          let rawFile = value;
701      }).catch(error => {
702          console.log("getRawFile promise error is " + error);
703      });
704  });
705  ```
706
707### getRawFileDescriptor<sup>8+</sup>
708
709getRawFileDescriptor(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void
710
711Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
712
713**System capability**: SystemCapability.Global.ResourceManager
714
715**Parameters**
716| Name     | Type                                      | Mandatory  | Description                              |
717| -------- | ---------------------------------------- | ---- | -------------------------------- |
718| path     | string                                   | Yes   | Path of the raw file.                     |
719| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Yes   | Asynchronous callback used to return the result.|
720
721**Example**
722  ```
723  resourceManager.getResourceManager((error, mgr) => {
724      mgr.getRawFileDescriptor("test.xml", (error, value) => {
725          if (error != null) {
726              console.log("error is " + error);
727          } else {
728              let fd = value.fd;
729              let offset = value.offset;
730              let length = value.length;
731          }
732      });
733  });
734  ```
735
736### getRawFileDescriptor<sup>8+</sup>
737
738getRawFileDescriptor(path: string): Promise&lt;RawFileDescriptor&gt;
739
740Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
741
742**System capability**: SystemCapability.Global.ResourceManager
743
744**Parameters**
745| Name | Type    | Mandatory  | Description         |
746| ---- | ------ | ---- | ----------- |
747| path | string | Yes   | Path of the raw file.|
748
749**Return value**
750| Type                                      | Description                 |
751| ---------------------------------------- | ------------------- |
752| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the result.|
753
754**Example**
755  ```
756  resourceManager.getResourceManager((error, mgr) => {
757      mgr.getRawFileDescriptor("test.xml").then(value => {
758          let fd = value.fd;
759          let offset = value.offset;
760          let length = value.length;
761      }).catch(error => {
762          console.log("getRawFileDescriptor promise error is " + error);
763      });
764  });
765  ```
766
767### closeRawFileDescriptor<sup>8+</sup>
768
769closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void
770
771Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
772
773**System capability**: SystemCapability.Global.ResourceManager
774
775**Parameters**
776| Name     | Type                       | Mandatory  | Description         |
777| -------- | ------------------------- | ---- | ----------- |
778| path     | string                    | Yes   | Path of the raw file.|
779| callback | AsyncCallback&lt;void&gt; | Yes   | Asynchronous callback used to return the result.       |
780
781**Example**
782  ```
783  resourceManager.getResourceManager((error, mgr) => {
784      mgr.closeRawFileDescriptor("test.xml", (error, value) => {
785          if (error != null) {
786              console.log("error is " + error);
787          }
788      });
789  });
790  ```
791
792### closeRawFileDescriptor<sup>8+</sup>
793
794closeRawFileDescriptor(path: string): Promise&lt;void&gt;
795
796Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
797
798**System capability**: SystemCapability.Global.ResourceManager
799
800**Parameters**
801| Name | Type    | Mandatory  | Description         |
802| ---- | ------ | ---- | ----------- |
803| path | string | Yes   | Path of the raw file.|
804
805**Return value**
806| Type                 | Description  |
807| ------------------- | ---- |
808| Promise&lt;void&gt; | No value is returned.|
809
810**Example**
811  ```
812  resourceManager.getResourceManager((error, mgr) => {
813      mgr.closeRawFileDescriptor("test.xml").then(value => {
814          let result = value;
815      }).catch(error => {
816          console.log("closeRawFileDescriptor promise error is " + error);
817      });
818  });
819  ```
820
821### release<sup>7+</sup>
822
823release()
824
825Releases the created **resourceManager**.
826
827**System capability**: SystemCapability.Global.ResourceManager
828
829**Example**
830  ```
831  resourceManager.getResourceManager((error, mgr) => {
832      mgr.release();
833  });
834  ```
835
836### getStringByName<sup>9+</sup>
837
838getStringByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
839
840Obtains the string corresponding to the specified resource name. This API uses an asynchronous callback to return the result.
841
842**System capability**: SystemCapability.Global.ResourceManager
843
844**Parameters**
845| Name     | Type                         | Mandatory  | Description             |
846| -------- | --------------------------- | ---- | --------------- |
847| resName  | string                      | Yes  | Resource name.       |
848| callback | AsyncCallback&lt;string&gt; | Yes  | Asynchronous callback used to return the result.|
849
850**Example**
851  ```
852  resourceManager.getStringByName("test", (error, value) => {
853      if (error != null) {
854          console.log("error is " + error);
855      } else {
856          let string = value;
857      }
858  });
859  ```
860
861### getStringByName<sup>9+</sup>
862
863getStringByName(resName: string): Promise&lt;string&gt;
864
865Obtains the string corresponding to the specified resource name. This API uses a promise to return the result.
866
867**System capability**: SystemCapability.Global.ResourceManager
868
869**Parameters**
870| Name  | Type    | Mandatory  | Description   |
871| ------- | ------ | ---- | ---- |
872| resName | string | Yes  | Resource name.|
873
874**Return value**
875| Type                   | Description         |
876| --------------------- | ----------- |
877| Promise&lt;string&gt; | String corresponding to the resource name.|
878
879**Example**
880  ```
881  resourceManager.getStringByName("test").then(value => {
882      let string = value;
883  }).catch(error => {
884      console.log("getStringByName promise error is " + error);
885  });
886  ```
887
888### getStringArrayByName<sup>9+</sup>
889
890getStringArrayByName(resName: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
891
892Obtains the string array corresponding to the specified resource name. This API uses an asynchronous callback to return the result.
893
894**System capability**: SystemCapability.Global.ResourceManager
895
896**Parameters**
897| Name     | Type                                      | Mandatory  | Description               |
898| -------- | ---------------------------------------- | ---- | ----------------- |
899| resName  | string                                   | Yes   | Resource name.            |
900| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Asynchronous callback used to return the result.|
901
902**Example**
903  ```
904  resourceManager.getStringArrayByName("test", (error, value) => {
905      if (error != null) {
906          console.log("error is " + error);
907      } else {
908          let strArray = value;
909      }
910  });
911  ```
912
913### getStringArrayByName<sup>9+</sup>
914
915getStringArrayByName(resName: string): Promise&lt;Array&lt;string&gt;&gt;
916
917Obtains the string array corresponding to the specified resource name. This API uses a promise to return the result.
918
919**System capability**: SystemCapability.Global.ResourceManager
920
921**Parameters**
922| Name  | Type    | Mandatory  | Description   |
923| ------- | ------ | ---- | ----- |
924| resName | string | Yes  | Resource name.|
925
926**Return value**
927| Type                                | Description           |
928| ---------------------------------- | ------------- |
929| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
930
931**Example**
932  ```
933  resourceManager.getStringArrayByName("test").then(value => {
934      let strArray = value;
935  }).catch(error => {
936      console.log("getStringArrayByName promise error is " + error);
937  });
938  ```
939
940### getMediaByName<sup>9+</sup>
941
942getMediaByName(resName: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
943
944Obtains the content of the media file corresponding to the specified resource name. This API uses an asynchronous callback to return the result.
945
946**System capability**: SystemCapability.Global.ResourceManager
947
948**Parameters**
949| Name     | Type                             | Mandatory  | Description                |
950| -------- | ------------------------------- | ---- | ------------------ |
951| resName  | string                          | Yes   | Resource name.             |
952| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Asynchronous callback used to return the result.|
953
954**Example**
955  ```
956  resourceManager.getMediaByName("test", (error, value) => {
957      if (error != null) {
958          console.log("error is " + error);
959      } else {
960          let media = value;
961      }
962  });
963  ```
964
965### getMediaByName<sup>9+</sup>
966
967getMediaByName(resName: string): Promise&lt;Uint8Array&gt;
968
969Obtains the content of the media file corresponding to the specified resource name. This API uses a promise to return the result.
970
971**System capability**: SystemCapability.Global.ResourceManager
972
973**Parameters**
974| Name  | Type    | Mandatory  | Description   |
975| -----   | ------ | ---- | ----- |
976| resName | string | Yes   | Resource name.|
977
978**Return value**
979| Type                       | Description            |
980| ------------------------- | -------------- |
981| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
982
983**Example**
984  ```
985  resourceManager.getMediaByName("test").then(value => {
986      let media = value;
987  }).catch(error => {
988      console.log("getMediaByName promise error is " + error);
989  });
990  ```
991
992### getMediaBase64ByName<sup>9+</sup>
993
994getMediaBase64ByName(resName: string, callback: AsyncCallback&lt;string&gt;): void
995
996Obtains the Base64 code of the image corresponding to the specified resource name. This API uses an asynchronous callback to return the result.
997
998**System capability**: SystemCapability.Global.ResourceManager
999
1000**Parameters**
1001| Name     | Type                         | Mandatory  | Description                      |
1002| -------- | --------------------------- | ---- | ------------------------ |
1003| resName  | string                      | Yes   | Resource name.                   |
1004| callback | AsyncCallback&lt;string&gt; | Yes   | Asynchronous callback used to return the result.|
1005
1006**Example**
1007  ```
1008  resourceManager.getMediaBase64ByName("test", (error, value) => {
1009      if (error != null) {
1010          console.log("error is " + error);
1011      } else {
1012          let media = value;
1013      }
1014  });
1015  ```
1016
1017### getMediaBase64ByName<sup>9+</sup>
1018
1019getMediaBase64ByName(resName: string): Promise&lt;string&gt;
1020
1021Obtains the Base64 code of the image corresponding to the specified resource name. This API uses a promise to return the result.
1022
1023**System capability**: SystemCapability.Global.ResourceManager
1024
1025**Parameters**
1026| Name  | Type    | Mandatory  | Description   |
1027| ------- | ------ | ---- | ----- |
1028| resName | string | Yes  | Resource name.|
1029
1030**Return value**
1031| Type                   | Description                  |
1032| --------------------- | -------------------- |
1033| Promise&lt;string&gt; | Promise used to return the result.|
1034
1035**Example**
1036  ```
1037  resourceManager.getMediaByName("test").then(value => {
1038      let media = value;
1039  }).catch(error => {
1040      console.log("getMediaBase64ByName promise error is " + error);
1041  });
1042  ```
1043
1044### getPluralStringByName<sup>9+</sup>
1045
1046getPluralStringByName(resName: string, num: number, callback: AsyncCallback&lt;string&gt;): void
1047
1048Obtains the plural string corresponding to the specified resource name. This API uses an asynchronous callback to return the result.
1049
1050**System capability**: SystemCapability.Global.ResourceManager
1051
1052**Parameters**
1053| Name     | Type                         | Mandatory  | Description                             |
1054| -------- | --------------------------- | ---- | ------------------------------- |
1055| resName  | string                      | Yes   | Resource name.                          |
1056| num      | number                      | Yes   | Number that determines the plural or singular form.                            |
1057| callback | AsyncCallback&lt;string&gt; | Yes   | Asynchronous callback used to return the result.|
1058
1059**Example**
1060  ```
1061  resourceManager.getPluralStringByName("test", 1, (error, value) => {
1062      if (error != null) {
1063          console.log("error is " + error);
1064      } else {
1065          let str = value;
1066      }
1067  });
1068  ```
1069
1070### getPluralStringByName<sup>9+</sup>
1071
1072getPluralStringByName(resName: string, num: number): Promise&lt;string&gt;
1073
1074Obtains the plural string corresponding to the specified resource name. This API uses a promise to return the result.
1075
1076**System capability**: SystemCapability.Global.ResourceManager
1077
1078**Parameters**
1079| Name  | Type    | Mandatory  | Description   |
1080| ------- | ------ | ---- | ----- |
1081| resName | string | Yes   | Resource name.|
1082| num     | number | Yes   | Number that determines the plural or singular form.  |
1083
1084**Return value**
1085| Type                   | Description                       |
1086| --------------------- | ------------------------- |
1087| Promise&lt;string&gt; | Promise used to return the result.|
1088
1089**Example**
1090  ```
1091  resourceManager.getPluralStringByName("test", 1).then(value => {
1092      let str = value;
1093  }).catch(error => {
1094      console.log("getPluralStringByName promise error is " + error);
1095  });
1096  ```
1097
1098### getStringSync<sup>9+</sup>
1099
1100getStringSync(resId: number): string
1101
1102Obtains the string corresponding to the specified resource ID. This API returns the result synchronously.
1103
1104**System capability**: SystemCapability.Global.ResourceManager
1105
1106**Parameters**
1107| Name  | Type    | Mandatory  | Description   |
1108| ----- | ------ | ---- | ----- |
1109| resId | number | Yes   | Resource ID.|
1110
1111**Return value**
1112| Type                   | Description         |
1113| --------------------- | ----------- |
1114| string | String corresponding to the specified resource ID.|
1115
1116**Example**
1117  ```
1118  resourceManager.getStringSync($r('app.string.test').id);
1119  ```
1120
1121### getStringByNameSync<sup>9+</sup>
1122
1123getStringByNameSync(resName: string): string
1124
1125Obtains the string corresponding to the specified resource name. This API returns the result synchronously.
1126
1127**System capability**: SystemCapability.Global.ResourceManager
1128
1129**Parameters**
1130| Name  | Type    | Mandatory  | Description   |
1131| ----- | ------ | ---- | ----- |
1132| resName | string | Yes   | Resource name.|
1133
1134**Return value**
1135| Type                   | Description         |
1136| --------------------- | ----------- |
1137| string | String corresponding to the resource name.|
1138
1139**Example**
1140  ```
1141  resourceManager.getStringByNameSync("test");
1142  ```
1143
1144 ### getBoolean<sup>9+</sup>
1145
1146getBoolean(resId: number): boolean
1147
1148Obtains the Boolean result corresponding to the specified resource ID. This API returns the result synchronously.
1149
1150**System capability**: SystemCapability.Global.ResourceManager
1151
1152**Parameters**
1153| Name  | Type    | Mandatory  | Description   |
1154| ----- | ------ | ---- | ----- |
1155| resId | number | Yes   | Resource ID.|
1156
1157**Return value**
1158| Type                   | Description         |
1159| --------------------- | ----------- |
1160| boolean | Boolean result corresponding to the specified resource ID.|
1161
1162**Example**
1163  ```
1164  resourceManager.getBoolean($r('app.boolean.boolean_test').id);
1165  ```
1166
1167### getBooleanByName<sup>9+</sup>
1168
1169getBooleanByName(resName: string): boolean
1170
1171Obtains the Boolean result corresponding to the specified resource name. This API returns the result synchronously.
1172
1173**System capability**: SystemCapability.Global.ResourceManager
1174
1175**Parameters**
1176| Name  | Type    | Mandatory  | Description   |
1177| ------- | ------ | ---- | ----- |
1178| resName | string | Yes  | Resource name.|
1179
1180**Return value**
1181| Type                   | Description         |
1182| --------------------- | ----------- |
1183| boolean | Boolean result corresponding to the specified resource name.|
1184
1185**Example**
1186  ```
1187  resourceManager.getBooleanByName("boolean_test");
1188  ```
1189
1190 ### getNumber<sup>9+</sup>
1191
1192getNumber(resId: number): number
1193
1194Obtains the integer or float value corresponding to the specified resource ID. This API returns the result synchronously.
1195
1196**System capability**: SystemCapability.Global.ResourceManager
1197
1198**Parameters**
1199| Name  | Type    | Mandatory  | Description   |
1200| ----- | ------ | ---- | ----- |
1201| resId | number | Yes   | Resource ID.|
1202
1203**Return value**
1204| Type                   | Description         |
1205| --------------------- | ----------- |
1206| number | Integer or float value corresponding to the specified resource ID.|
1207
1208**Example**
1209  ```
1210  resourceManager.getNumber($r('app.integer.integer_test').id);
1211  resourceManager.getNumber($r('app.float.float_test').id);
1212  ```
1213
1214### getNumberByName<sup>9+</sup>
1215
1216getNumberByName(resName: string): number
1217
1218Obtains the integer or float value corresponding to the specified resource name. This API returns the result synchronously.
1219
1220**System capability**: SystemCapability.Global.ResourceManager
1221
1222**Parameters**
1223| Name  | Type    | Mandatory  | Description   |
1224| ----- | ------ | ---- | ----- |
1225| resName | string | Yes   | Resource name.|
1226
1227**Return value**
1228| Type                   | Description         |
1229| --------------------- | ----------- |
1230| number | Integer or float value corresponding to the specified resource name.|
1231
1232**Example**
1233  ```
1234  resourceManager.getNumberByName("integer_test");
1235  resourceManager.getNumberByName("float_test");
1236  ```
1237