js-apis-resource-manager.md 25.8 KB
Newer Older
A
annie_wangli 已提交
1
# Resource Management
Z
zengyawen 已提交
2

A
annie_wangli 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> 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.
Z
zengyawen 已提交
5 6


A
annie_wangli 已提交
7
## Modules to Import
Z
zengyawen 已提交
8 9 10 11 12

```
import resourceManager from '@ohos.resourceManager';
```

A
annie_wangli 已提交
13 14 15 16 17 18 19 20
## resourceManager.getResourceManager

getResourceManager(callback: AsyncCallback&lt;ResourceManager&gt;): void

Obtains the **ResourceManager** object of this application. This method uses a callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
21
**Parameters**
A
annie_wangli 已提交
22 23 24
| Name     | Type                                      | Mandatory  | Description                           |
| -------- | ---------------------------------------- | ---- | ----------------------------- |
| callback | AsyncCallback&lt;[ResourceManager](#resourcemanager)&gt; | Yes   | Callback used to return the **ResourceManager** object obtained.|
A
annie_wangli 已提交
25

A
annie_wangli 已提交
26
**Example**
A
annie_wangli 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  ```
  resourceManager.getResourceManager((error, mgr) => {
      if (error != null) {
          console.log("error occurs" + error);
          return; 
      }
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


## resourceManager.getResourceManager

getResourceManager(bundleName: string, callback: AsyncCallback&lt;ResourceManager&gt;): void

Obtains the **ResourceManager** object of an application. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
52
**Parameters**
A
annie_wangli 已提交
53 54 55 56
| Name       | Type                                      | Mandatory  | Description                           |
| ---------- | ---------------------------------------- | ---- | ----------------------------- |
| bundleName | string                                   | Yes   | Bundle name of the target application.                |
| callback   | AsyncCallback&lt;[ResourceManager](#resourcemanager)&gt; | Yes   | Callback used to return the **ResourceManager** object obtained.|
A
annie_wangli 已提交
57

A
annie_wangli 已提交
58
**Example**
A
annie_wangli 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72
  ```
  resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
  });
  ```


## resourceManager.getResourceManager

getResourceManager(): Promise&lt;ResourceManager&gt;

Obtains the **ResourceManager** object of this application. This method uses a promise to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
73
**Return value**
A
annie_wangli 已提交
74 75 76
| Type                                      | Description               |
| ---------------------------------------- | ----------------- |
| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the **ResourceManager** object obtained.|
A
annie_wangli 已提交
77

A
annie_wangli 已提交
78
**Example**
A
annie_wangli 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  ```
  resourceManager.getResourceManager().then(mgr => {
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  }).catch(error => {
      console.log(error);
  });
  ```


## resourceManager.getResourceManager

getResourceManager(bundleName: string): Promise&lt;ResourceManager&gt;

Obtains the **ResourceManager** object of an application. This method uses a promise to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
102
**Parameters**
A
annie_wangli 已提交
103 104 105
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
| bundleName | string | Yes   | Bundle name of the target application.|
A
annie_wangli 已提交
106

A
annie_wangli 已提交
107
**Return value**
A
annie_wangli 已提交
108 109 110
| Type                                      | Description                |
| ---------------------------------------- | ------------------ |
| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the **ResourceManager** object obtained.|
A
annie_wangli 已提交
111

A
annie_wangli 已提交
112
**Example**
A
annie_wangli 已提交
113 114
  ```
  resourceManager.getResourceManager("com.example.myapplication").then(mgr => {
A
annie_wangli 已提交
115

A
annie_wangli 已提交
116
  }).catch(error => {
A
annie_wangli 已提交
117

A
annie_wangli 已提交
118 119 120 121 122 123 124 125
  });
  ```


## Direction

Enumerates the screen directions.

A
annie_wangli 已提交
126 127
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
128 129 130 131
| Name                  | Default Value | Description  |
| -------------------- | ---- | ---- |
| DIRECTION_VERTICAL   | 0    | Portrait  |
| DIRECTION_HORIZONTAL | 1    | Landscape  |
A
annie_wangli 已提交
132 133 134 135 136 137


## DeviceType

Enumerates the device types.

A
annie_wangli 已提交
138 139
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
140 141 142 143 144 145 146 147
| Name                  | Default Value | Description  |
| -------------------- | ---- | ---- |
| DEVICE_TYPE_PHONE    | 0x00 | Mobile phone.  |
| DEVICE_TYPE_TABLET   | 0x01 | Tablet.  |
| DEVICE_TYPE_CAR      | 0x02 | Automobile.  |
| DEVICE_TYPE_PC       | 0x03 | Computer.  |
| DEVICE_TYPE_TV       | 0x04 | TV.  |
| DEVICE_TYPE_WEARABLE | 0x06 | Wearable.  |
A
annie_wangli 已提交
148 149 150 151 152 153


## ScreenDensity

Enumerates the screen density types.

A
annie_wangli 已提交
154 155
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
156 157 158 159 160 161 162 163
| Name            | Default Value | Description        |
| -------------- | ---- | ---------- |
| SCREEN_SDPI    | 120  | Screen density with small-scale dots per inch (SDPI).  |
| SCREEN_MDPI    | 160  | Screen density with medium-scale dots per inch (MDPI).  |
| SCREEN_LDPI    | 240  | Screen density with large-scale dots per inch (LDPI).  |
| SCREEN_XLDPI   | 320  | Screen density with extra-large-scale dots per inch (XLDPI). |
| SCREEN_XXLDPI  | 480  | Screen density with extra-extra-large-scale dots per inch (XXLDPI). |
| SCREEN_XXXLDPI | 640  | Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).|
A
annie_wangli 已提交
164 165 166 167 168 169


## Configuration

Defines the device configuration.

A
annie_wangli 已提交
170 171
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
172

A
annie_wangli 已提交
173 174 175 176
| Name       | Type                   | Readable  | Writable  | Description      |
| --------- | ----------------------- | ---- | ---- | -------- |
| direction | [Direction](#direction) | Yes   | No   | Screen direction of the device.|
| locale    | string                  | Yes   | No   | Current system language.  |
A
annie_wangli 已提交
177 178 179 180 181 182


## DeviceCapability

Defines the device capability.

A
annie_wangli 已提交
183 184
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
185

A
annie_wangli 已提交
186 187 188 189
| Name           | Type                           | Readable  | Writable  | Description      |
| ------------- | ------------------------------- | ---- | ---- | -------- |
| screenDensity | [ScreenDensity](#screendensity) | Yes   | No   | Screen density of the device.|
| deviceType    | [DeviceType](#devicetype)       | Yes   | No   | Type of the device.  |
A
annie_wangli 已提交
190 191 192 193


## RawFileDescriptor<sup>8+</sup>

A
annie_wangli 已提交
194 195
Defines the descriptor information of the raw file.<br>
**System capability**: SystemCapability.Global.ResourceManager
A
annie_wangli 已提交
196

A
annie_wangli 已提交
197 198 199 200 201
| Name    | Type    | Description                |
| ------ | ------ | ------------------ |
| fd     | number | Descriptor of a raw file.|
| offset | number | Offset to the start position of the raw file.     |
| length | number | Length of the raw file.      |
A
annie_wangli 已提交
202 203 204 205 206 207 208 209


## ResourceManager

Defines the capability of accessing application resources.

> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
A
annie_wangli 已提交
210
>
A
annie_wangli 已提交
211 212 213 214 215 216 217 218 219 220 221
> - 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**.


### getString

getString(resId: number, callback: AsyncCallback&lt;string&gt;): void

Obtains the string corresponding to the specified resource ID. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
222
**Parameters**
A
annie_wangli 已提交
223 224 225 226
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | Yes   | Resource ID.          |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the string obtained.|
A
annie_wangli 已提交
227

A
annie_wangli 已提交
228
**Example**
A
annie_wangli 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getString($r('app.string.test').id, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getString

getString(resId: number): Promise&lt;string&gt;
Z
zengyawen 已提交
245 246 247

Obtains the string corresponding to the specified resource ID. This method uses a promise to return the result.

A
annie_wangli 已提交
248 249
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
250
**Parameters**
A
annie_wangli 已提交
251 252 253
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
254

A
annie_wangli 已提交
255
**Return value**
A
annie_wangli 已提交
256 257 258
| Type                   | Description         |
| --------------------- | ----------- |
| Promise&lt;string&gt; | Promise used to return the string obtained.|
A
annie_wangli 已提交
259

A
annie_wangli 已提交
260
**Example**
A
annie_wangli 已提交
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getString($r('app.string.test').id).then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getStringArray

getStringArray(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

Obtains the array of strings corresponding to the specified resource ID. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
280
**Parameters**
A
annie_wangli 已提交
281 282 283 284
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId    | number                                   | Yes   | Resource ID.            |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the obtained array of strings.|
A
annie_wangli 已提交
285

A
annie_wangli 已提交
286
**Example**
A
annie_wangli 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getStringArray

getStringArray(resId: number): Promise&lt;Array&lt;string&gt;&gt;
Z
zengyawen 已提交
303 304 305

Obtains the array of strings corresponding to the specified resource ID. This method uses a promise to return the result.

A
annie_wangli 已提交
306 307
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
308
**Parameters**
A
annie_wangli 已提交
309 310 311
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
312

A
annie_wangli 已提交
313
**Return value**
A
annie_wangli 已提交
314 315 316
| Type                                | Description           |
| ---------------------------------- | ------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the array of strings obtained.|
A
annie_wangli 已提交
317

A
annie_wangli 已提交
318
**Example**
A
annie_wangli 已提交
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
  ```
  resourceManager.getResourceManager((error, mgr) => {
       mgr.getStringArray($r('app.strarray.test').id).then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getMedia

getMedia(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void

Obtains the content of the media file corresponding to the specified resource ID. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
338
**Parameters**
A
annie_wangli 已提交
339 340 341 342
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | Yes   | Resource ID.             |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the content of the media file obtained.|
A
annie_wangli 已提交
343

A
annie_wangli 已提交
344
**Example**
A
annie_wangli 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMedia($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getMedia

getMedia(resId: number): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
361 362 363

Obtains the content of the media file corresponding to the specified resource ID. This method uses a promise to return the result.

A
annie_wangli 已提交
364 365
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
366
**Parameters**
A
annie_wangli 已提交
367 368 369
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
370

A
annie_wangli 已提交
371
**Return value**
A
annie_wangli 已提交
372 373 374
| Type                       | Description            |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the content of the media file obtained.|
A
annie_wangli 已提交
375

A
annie_wangli 已提交
376
**Example**
A
annie_wangli 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMedia($r('app.media.test').id).then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getMediaBase64

getMediaBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void

Obtains the Base64 code of the image corresponding to the specified resource ID. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
396
**Parameters**
A
annie_wangli 已提交
397 398 399 400
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the Base64 code of the image obtained.|
A
annie_wangli 已提交
401

A
annie_wangli 已提交
402
**Example**
A
annie_wangli 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getMediaBase64

getMediaBase64(resId: number): Promise&lt;string&gt;
Z
zengyawen 已提交
419 420 421

Obtains the Base64 code of the image corresponding to the specified resource ID. This method uses a promise to return the result.

A
annie_wangli 已提交
422 423
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
424
**Parameters**
A
annie_wangli 已提交
425 426 427
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
428

A
annie_wangli 已提交
429
**Return value**
A
annie_wangli 已提交
430 431 432
| Type                   | Description                  |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | Promise used to return the Base64 code of the image obtained.|
A
annie_wangli 已提交
433

A
annie_wangli 已提交
434
**Example**
A
annie_wangli 已提交
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMediaBase64($r('app.media.test').id).then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getConfiguration

getConfiguration(callback: AsyncCallback&lt;Configuration&gt;): void

Obtains the device configuration. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
454
**Parameters**
A
annie_wangli 已提交
455 456 457
| Name     | Type                                      | Mandatory  | Description                       |
| -------- | ---------------------------------------- | ---- | ------------------------- |
| callback | AsyncCallback&lt;[Configuration](#configuration)&gt; | Yes   | Callback used to return the obtained device configuration.|
A
annie_wangli 已提交
458

A
annie_wangli 已提交
459
**Example**
A
annie_wangli 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration((error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getConfiguration

getConfiguration(): Promise&lt;Configuration&gt;
Z
zengyawen 已提交
476 477 478

Obtains the device configuration. This method uses a promise to return the result.

A
annie_wangli 已提交
479 480
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
481
**Return value**
A
annie_wangli 已提交
482 483 484
| Type                                      | Description              |
| ---------------------------------------- | ---------------- |
| Promise&lt;[Configuration](#configuration)&gt; | Promise used to return the device configuration.|
A
annie_wangli 已提交
485

A
annie_wangli 已提交
486
**Example**
A
annie_wangli 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration().then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getDeviceCapability

getDeviceCapability(callback: AsyncCallback&lt;DeviceCapability&gt;): void

Obtains the device capability. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
506
**Parameters**
A
annie_wangli 已提交
507 508 509
| Name     | Type                                      | Mandatory  | Description                          |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;[DeviceCapability](#devicecapability)&gt; | Yes   | Callback used to return the obtained device capability.|
A
annie_wangli 已提交
510

A
annie_wangli 已提交
511
**Example**
A
annie_wangli 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability((error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getDeviceCapability

getDeviceCapability(): Promise&lt;DeviceCapability&gt;
Z
zengyawen 已提交
528 529 530

Obtains the device capability. This method uses a promise to return the result.

A
annie_wangli 已提交
531
**System capability**: SystemCapability.Global.ResourceManager
Z
zengyawen 已提交
532

A
annie_wangli 已提交
533
**Return value**
A
annie_wangli 已提交
534 535 536
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
| Promise&lt;[DeviceCapability](#devicecapability)&gt; | Promise used to return the obtained device capability.|
A
annie_wangli 已提交
537

A
annie_wangli 已提交
538
**Example**
A
annie_wangli 已提交
539 540 541 542 543 544 545 546 547 548 549 550
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability().then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```


### getPluralString
Z
zengyawen 已提交
551

A
annie_wangli 已提交
552 553 554 555 556 557
getPluralString(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void

Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
558
**Parameters**
A
annie_wangli 已提交
559 560 561 562 563
| Name     | Type                         | Mandatory  | Description                             |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | Yes   | Resource ID.                          |
| num      | number                      | Yes   | Number that determines the plural or singular form.                            |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the singular-plural string obtained.|
A
annie_wangli 已提交
564

A
annie_wangli 已提交
565
**Example**
A
annie_wangli 已提交
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```


### getPluralString

getPluralString(resId: number, num: number): Promise&lt;string&gt;

Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method uses a promise to return the result.
Z
zengyawen 已提交
584

A
annie_wangli 已提交
585 586
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
587
**Parameters**
A
annie_wangli 已提交
588 589 590 591
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
| num   | number | Yes   | Number that determines the plural or singular form.  |
A
annie_wangli 已提交
592

A
annie_wangli 已提交
593
**Return value**
A
annie_wangli 已提交
594 595 596
| Type                   | Description                       |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | Promise used to return the singular-plural string obtained.|
A
annie_wangli 已提交
597

A
annie_wangli 已提交
598
**Example**
A
annie_wangli 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getPluralString($r("app.plural.test").id, 1).then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getstring promise " + error);
      });
  });
  ```

### getRawFile<sup>8+</sup>

getRawFile(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void

Obtains the content of the raw file in the specified path. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
617
**Parameters**
A
annie_wangli 已提交
618 619 620 621
| Name     | Type                             | Mandatory  | Description                     |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | Yes   | Path of the raw file.            |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the raw file content, in byte arrays.|
A
annie_wangli 已提交
622

A
annie_wangli 已提交
623
**Example**
A
annie_wangli 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFile("test.xml", (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              console.log(value);
          }
      });
  });
  ```

### getRawFile<sup>8+</sup>

getRawFile(path: string): Promise&lt;Uint8Array&gt;

Obtains the content of the raw file in the specified path. This method uses a promise to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
644
**Parameters**
A
annie_wangli 已提交
645 646 647
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
648

A
annie_wangli 已提交
649
**Return value**
A
annie_wangli 已提交
650 651 652
| Type                       | Description         |
| ------------------------- | ----------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the raw file content, in byte arrays.|
A
annie_wangli 已提交
653

A
annie_wangli 已提交
654
**Example**
A
annie_wangli 已提交
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFile("test.xml").then(value => {
          console.log(value);
      }).catch(error => {
          console.log("getrawfile promise " + error);
      });
  });
  ```

### getRawFileDescriptor<sup>8+</sup>

getRawFileDescriptor(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void

Obtains the descriptor of the raw file in the specified path. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
673
**Parameters**
A
annie_wangli 已提交
674 675 676 677
| Name     | Type                                      | Mandatory  | Description                              |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | Yes   | Path of the raw file.                     |
| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Yes   | Callback used to return the raw file descriptor.|
A
annie_wangli 已提交
678

A
annie_wangli 已提交
679
**Example**
A
annie_wangli 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
              console.log(value);
          } else {
              let fd = value.fd;
              let offset = value.offset;
              let length = value.length;
          }
      });
  });
  ```

### getRawFileDescriptor<sup>8+</sup>

getRawFileDescriptor(path: string): Promise&lt;RawFileDescriptor&gt;

Obtains the descriptor of the raw file in the specified path. This method uses a promise to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
702
**Parameters**
A
annie_wangli 已提交
703 704 705
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
706

A
annie_wangli 已提交
707
**Return value**
A
annie_wangli 已提交
708 709 710
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the raw file descriptor.|
A
annie_wangli 已提交
711

A
annie_wangli 已提交
712
**Example**
A
annie_wangli 已提交
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFileDescriptor("test.xml").then(value => {
          let fd = value.fd;
          let offset = value.offset;
          let length = value.length;
      }).catch(error => {
          console.log("getRawFileDescriptor promise " + error);
      });
  });
  ```

### closeRawFileDescriptor<sup>8+</sup>

closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void

Closes the descriptor of the raw file in the specified path. This method uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
733
**Parameters**
A
annie_wangli 已提交
734 735 736 737
| Name     | Type                       | Mandatory  | Description         |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | Yes   | Path of the raw file.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.       |
A
annie_wangli 已提交
738

A
annie_wangli 已提交
739
**Example**
A
annie_wangli 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
              console.log(value);
          }
      });
  });
  ```

### closeRawFileDescriptor<sup>8+</sup>

closeRawFileDescriptor(path: string): Promise&lt;void&gt;

Closes the descriptor of the raw file in the specified path. This method uses a promise to return the result.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
758
**Parameters**
A
annie_wangli 已提交
759 760 761
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
762

A
annie_wangli 已提交
763
**Return value**
A
annie_wangli 已提交
764 765 766
| Type                 | Description  |
| ------------------- | ---- |
| Promise&lt;void&gt; | No value is returned.|
A
annie_wangli 已提交
767

A
annie_wangli 已提交
768
**Example**
A
annie_wangli 已提交
769 770 771 772 773 774 775 776 777 778 779 780
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml").then(value => {
          console.log(value);
      }).catch(error => {
          console.log("closeRawFileDescriptor promise " + error);
      });
  });
  ```

### release<sup>7+</sup>

A
annie_wangli 已提交
781
release()
A
annie_wangli 已提交
782 783 784 785 786

Releases the created **resourceManager**.

**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
787
**Example**
A
annie_wangli 已提交
788 789 790 791 792 793 794 795 796
  ```
  resourceManager.getResourceManager((error, mgr) => {
      mgr.release((error, value) => {
          if (error != null) {
              console.log(value);
          }
      });
  });
  ```