• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Resource Manager Development
2
3## How do I read an XML file in rawfile and convert the data in it to the string type?
4
5Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
6
7**Solution**
8
9Call **getRawFileContent** of the **ResourceManager** module to obtain the data in the XML file, and then use **String.fromCharCode** to convert the data to the string type.
10
11**Sample Code**
12
13```
14resourceManager.getRawFileContent('test.xml', (error, value) => {
15  if (error != null) {
16    console.log("error is " + error);
17  } else {
18    let rawFile = value;
19    let xml = String.fromCharCode.apply(null, rawFile)
20  }
21});
22```
23
24**Reference**
25
26[Resource Manager](../reference/apis/js-apis-resource-manager.md)
27
28## How do I obtain resources in the stage model?
29
30Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
31
32**Solution**
33
34The stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This mode does not apply to the FA model.
35
36**Sample Code**
37
38```
39const context = getContext(this) as any
40context
41  .resourceManager
42  .getString($r('app.string.entry_desc').id)
43  .then(value => {
44    this.message = value.toString()
45})
46```
47
48## How do I obtain the path of the resource directory by using an API?
49
50Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
51
52**Symptom**
53
54How do I obtain the path of the **resource** directory so that I can manage the files in it by using the file management API?
55
56**Solution**
57
58Because the application is installed in HAP mode and the HAP package is not decompressed after the installation is complete, the resource path cannot be obtained when the program is running.
59
60To obtain the path of the **resource** directory, try either of the following ways:
61
621. Use **\$r** or **\$rawfile** for access. This method applies to static access, during which the **resource** directory remains unchanged when the application is running.
63
642. Use **ResourceManager** for access. This method applies to dynamic access, during which the **resource** directory dynamically changes when the application is running.
65
66**Reference**
67
68[Resource Categories and Access](../quick-start/resource-categories-and-access.md) and [Resource Manager](../reference/apis/js-apis-resource-manager.md)
69
70## Why does getPluralString return an incorrect value?
71
72Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
73
74**Symptom**
75
76The value obtained by the **getPluralString** is **other**, which is incorrect.
77
78**Solution**
79
80The **getPluralString** API is effective only when the system language is English.
81
82## How do I obtain the customized string fields in the resources directory?
83
84Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
85
86**Solution**
87
88Use **getStringValue** of the **ResourceManager** module.
89
90**Reference**
91
92[Resource Manager](../reference/apis/js-apis-resource-manager.md#getstringvalue9)
93
94## How do I reference resources such as images and text in AppScope?
95
96Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
97
98**Solution**
99
100Reference resources in the **\$r\('app.type.name'\)** format. Wherein, **type** indicates the resource type, such as color, string, and media, and **name** indicates the resource name.
101
102## How do I convert resources to strings?
103
104Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
105
106**Solution**
107
108For a qualifier directory, use **this.context.resourceManager.getStringSync\(\$r\('app.string.test'\).id\)** to covert resources to strings synchronously. Note that the **\$r\('app.string.test', 2\)** mode is not supported.
109
110**Reference**
111
112[Resource Manager](../reference/apis/js-apis-resource-manager.md#getstringsync9)
113
114## Can $ be used to reference constants in the form\_config.json file?
115
116Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
117
118**\$** cannot be used to reference constants in the **form\_config.json** file.
119