js-apis-resource-manager.md 92.4 KB
Newer Older
S
shawn_he 已提交
1
# Resource Manager
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
The Resource Manager module provides APIs to obtain information about application resources based on the current configuration, including the language, region, screen direction, MCC/MNC, as well as device capability and density.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6
> **NOTE**
>
A
annie_wangli 已提交
7
> 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 已提交
8 9


A
annie_wangli 已提交
10
## Modules to Import
Z
zengyawen 已提交
11

S
shawn_he 已提交
12
```js
Z
zengyawen 已提交
13 14 15
import resourceManager from '@ohos.resourceManager';
```

S
shawn_he 已提交
16
## Instruction
S
shawn_he 已提交
17

S
shawn_he 已提交
18
Since API version 9, the 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 approach, however, is not applicable to the FA model.
S
shawn_he 已提交
19
For details about how to reference **context** in the stage model, see [Context in the Stage Model].
S
shawn_he 已提交
20

S
shawn_he 已提交
21 22 23 24 25 26 27 28
```ts
import Ability from '@ohos.application.Ability';
class MainAbility extends Ability {
    onWindowStageCreate(windowStage) {
        let context = this.context;
        let resourceManager = context.resourceManager;
    }
}
S
shawn_he 已提交
29 30
```

A
annie_wangli 已提交
31 32 33 34
## resourceManager.getResourceManager

getResourceManager(callback: AsyncCallback<ResourceManager>): void

S
shawn_he 已提交
35 36
Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
37
**Model restriction**: This API can be used only in the FA model.
A
annie_wangli 已提交
38 39 40

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

A
annie_wangli 已提交
41
**Parameters**
S
shawn_he 已提交
42

A
annie_wangli 已提交
43 44
| Name     | Type                                      | Mandatory  | Description                           |
| -------- | ---------------------------------------- | ---- | ----------------------------- |
S
shawn_he 已提交
45
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
46

A
annie_wangli 已提交
47
**Example**
S
shawn_he 已提交
48
  ```js
A
annie_wangli 已提交
49 50
  resourceManager.getResourceManager((error, mgr) => {
      if (error != null) {
S
shawn_he 已提交
51
          console.log("error is " + error);
A
annie_wangli 已提交
52 53 54 55
          return; 
      }
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
S
shawn_he 已提交
56
              console.log("error is " + error);
A
annie_wangli 已提交
57
          } else {
S
shawn_he 已提交
58
              let str = value;
A
annie_wangli 已提交
59 60 61 62 63 64 65 66 67 68
          }
      });
  });
  ```


## resourceManager.getResourceManager

getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void

S
shawn_he 已提交
69 70
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
71
**Model restriction**: This API can be used only in the FA model.
A
annie_wangli 已提交
72 73 74

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

A
annie_wangli 已提交
75
**Parameters**
S
shawn_he 已提交
76

A
annie_wangli 已提交
77 78
| Name       | Type                                      | Mandatory  | Description                           |
| ---------- | ---------------------------------------- | ---- | ----------------------------- |
S
shawn_he 已提交
79
| bundleName | string                                   | Yes   | Bundle name of the application.                |
S
shawn_he 已提交
80
| callback   | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
81

A
annie_wangli 已提交
82
**Example**
S
shawn_he 已提交
83
  ```js
A
annie_wangli 已提交
84 85 86 87 88 89 90 91 92
  resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
  });
  ```


## resourceManager.getResourceManager

getResourceManager(): Promise<ResourceManager>

S
shawn_he 已提交
93
Obtains the **ResourceManager** object of this application. This API uses a promise to return the result.
A
annie_wangli 已提交
94

S
shawn_he 已提交
95
**Model restriction**: This API can be used only in the FA model.
S
shawn_he 已提交
96

A
annie_wangli 已提交
97 98
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
99
**Return value**
A
annie_wangli 已提交
100 101
| Type                                      | Description               |
| ---------------------------------------- | ----------------- |
S
shawn_he 已提交
102
| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.|
A
annie_wangli 已提交
103

A
annie_wangli 已提交
104
**Example**
S
shawn_he 已提交
105
  ```js
A
annie_wangli 已提交
106 107 108
  resourceManager.getResourceManager().then(mgr => {
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
S
shawn_he 已提交
109
              console.log("error is " + error);
A
annie_wangli 已提交
110
          } else {
S
shawn_he 已提交
111
              let str = value;
A
annie_wangli 已提交
112 113 114
          }
      });
  }).catch(error => {
S
shawn_he 已提交
115
      console.log("error is " + error);
A
annie_wangli 已提交
116 117 118 119 120 121 122 123
  });
  ```


## resourceManager.getResourceManager

getResourceManager(bundleName: string): Promise<ResourceManager>

S
shawn_he 已提交
124 125
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result.

S
shawn_he 已提交
126
**Model restriction**: This API can be used only in the FA model.
A
annie_wangli 已提交
127 128 129

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

A
annie_wangli 已提交
130
**Parameters**
S
shawn_he 已提交
131

A
annie_wangli 已提交
132 133
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
S
shawn_he 已提交
134
| bundleName | string | Yes   | Bundle name of the application.|
A
annie_wangli 已提交
135

A
annie_wangli 已提交
136
**Return value**
A
annie_wangli 已提交
137 138
| Type                                      | Description                |
| ---------------------------------------- | ------------------ |
S
shawn_he 已提交
139
| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.|
A
annie_wangli 已提交
140

A
annie_wangli 已提交
141
**Example**
S
shawn_he 已提交
142
  ```js
A
annie_wangli 已提交
143 144 145 146 147 148 149 150 151 152
  resourceManager.getResourceManager("com.example.myapplication").then(mgr => {
  }).catch(error => {
  });
  ```


## Direction

Enumerates the screen directions.

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

S
shawn_he 已提交
155
| Name                  | Value | Description  |
A
annie_wangli 已提交
156
| -------------------- | ---- | ---- |
S
shawn_he 已提交
157 158
| DIRECTION_VERTICAL   | 0    | Portrait.  |
| DIRECTION_HORIZONTAL | 1    | Landscape.  |
A
annie_wangli 已提交
159 160 161 162 163 164


## DeviceType

Enumerates the device types.

A
annie_wangli 已提交
165 166
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
167
| Name                  | Value | Description  |
A
annie_wangli 已提交
168
| -------------------- | ---- | ---- |
S
shawn_he 已提交
169 170 171 172 173 174
| DEVICE_TYPE_PHONE    | 0x00 | Phone  |
| DEVICE_TYPE_TABLET   | 0x01 | Tablet  |
| DEVICE_TYPE_CAR      | 0x02 | Head unit  |
| DEVICE_TYPE_PC       | 0x03 | PC  |
| DEVICE_TYPE_TV       | 0x04 | TV  |
| DEVICE_TYPE_WEARABLE | 0x06 | Wearable  |
A
annie_wangli 已提交
175 176 177 178 179 180


## ScreenDensity

Enumerates the screen density types.

A
annie_wangli 已提交
181 182
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
183
| Name            | Value | Description        |
A
annie_wangli 已提交
184 185 186 187 188 189 190
| -------------- | ---- | ---------- |
| 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 已提交
191 192 193 194 195 196


## Configuration

Defines the device configuration.

A
annie_wangli 已提交
197 198
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
199
**Parameters**
A
annie_wangli 已提交
200

A
annie_wangli 已提交
201 202 203 204
| 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 已提交
205

S
shawn_he 已提交
206 207
**Example**

S
shawn_he 已提交
208
  ```js
S
shawn_he 已提交
209 210
resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration((error, value) => {
S
shawn_he 已提交
211 212
          let direction = value.direction;
          let locale = value.locale;
S
shawn_he 已提交
213 214 215
      });
  });
  ```
A
annie_wangli 已提交
216 217 218 219 220

## DeviceCapability

Defines the device capability.

A
annie_wangli 已提交
221 222
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
223
**Parameters**
A
annie_wangli 已提交
224

A
annie_wangli 已提交
225 226 227 228
| 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 已提交
229

S
shawn_he 已提交
230 231
**Example**

S
shawn_he 已提交
232
  ```js
S
shawn_he 已提交
233 234
resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability((error, value) => {
S
shawn_he 已提交
235 236
          let screenDensity = value.screenDensity;
          let deviceType = value.deviceType;
S
shawn_he 已提交
237 238 239
      });
  });
  ```
A
annie_wangli 已提交
240 241 242

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

S
shawn_he 已提交
243 244
Defines the descriptor of the raw file.

A
annie_wangli 已提交
245
**System capability**: SystemCapability.Global.ResourceManager
A
annie_wangli 已提交
246

S
shawn_he 已提交
247 248 249 250 251 252 253
**Parameters**

| Name    | Type   | Readable  | Writable | Description          |
| ------ | ------  | ---- | ---- | ------------------ |
| fd     | number  | Yes   | No| Descriptor of the raw file.|
| offset | number  | Yes   | No| Start offset of the raw file.     |
| length | number  | Yes   | No| Length of the raw file.      |
A
annie_wangli 已提交
254

S
shawn_he 已提交
255 256 257 258 259 260
## Resource<sup>9+</sup>

Defines the resource information of an application.

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

S
shawn_he 已提交
261 262 263 264 265 266 267
**Parameters**

| Name        | Type    | Readable  | Writable |Description         |
| ---------- | ------ | ----- | ----  | ---------------|
| bundleName | string | Yes   | No| Bundle name of the application.|
| moduleName | string | Yes   | No| Module name of the application.|
| id         | number | Yes   | No| Resource ID.     |
S
shawn_he 已提交
268

A
annie_wangli 已提交
269 270 271 272 273

## ResourceManager

Defines the capability of accessing application resources.

S
shawn_he 已提交
274 275
> **NOTE**
>
S
shawn_he 已提交
276
> - The APIs involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
A
annie_wangli 已提交
277
>
A
annie_wangli 已提交
278 279
> - 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**.

S
shawn_he 已提交
280
### getStringValue<sup>9+</sup>
A
annie_wangli 已提交
281

S
shawn_he 已提交
282
getStringValue(resId: number, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
283

S
shawn_he 已提交
284
Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
285 286 287

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

A
annie_wangli 已提交
288
**Parameters**
S
shawn_he 已提交
289

A
annie_wangli 已提交
290 291 292
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | Yes   | Resource ID.          |
S
shawn_he 已提交
293
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
294

S
shawn_he 已提交
295 296 297 298 299 300 301 302 303 304
**Error codes**

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the module resId invalid.             |
| 9001002  | If the resource not found by resId.      |
| 9001006  | If the resource re-ref too much.         |

S
shawn_he 已提交
305
**Example (stage)**
S
shawn_he 已提交
306 307 308
  ```ts
    try {
        this.context.getStringValue($r('app.string.test').id, (error, value) => {
A
annie_wangli 已提交
309
          if (error != null) {
S
shawn_he 已提交
310
              console.log("error is " + error);
A
annie_wangli 已提交
311
          } else {
S
shawn_he 已提交
312
              let str = value;
A
annie_wangli 已提交
313 314
          }
      });
S
shawn_he 已提交
315 316 317
    } catch (error) {
        console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
    }
A
annie_wangli 已提交
318 319 320
  ```


S
shawn_he 已提交
321
### getStringValue<sup>9+</sup>
A
annie_wangli 已提交
322

S
shawn_he 已提交
323
getStringValue(resId: number): Promise&lt;string&gt;
Z
zengyawen 已提交
324

S
shawn_he 已提交
325
Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result.
Z
zengyawen 已提交
326

A
annie_wangli 已提交
327 328
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
329
**Parameters**
S
shawn_he 已提交
330

A
annie_wangli 已提交
331 332 333
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
334

A
annie_wangli 已提交
335
**Return value**
A
annie_wangli 已提交
336 337
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
338
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
339

S
shawn_he 已提交
340 341 342 343 344 345 346 347 348 349
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

A
annie_wangli 已提交
350
**Example**
S
shawn_he 已提交
351 352 353 354 355 356 357 358 359 360
  ```ts
  try {
    this.context.resourceManager.getStringValue($r('app.string.test').id).then(value => {
        let str = value;
    }).catch(error => {
        console.log("getStringValue promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
361 362 363
  ```


S
shawn_he 已提交
364
### getStringValue<sup>9+</sup>
S
shawn_he 已提交
365

S
shawn_he 已提交
366
getStringValue(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
S
shawn_he 已提交
367 368 369 370 371 372

Obtains the string corresponding to the specified resource object. This API uses an asynchronous callback to return the result.

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

**Parameters**
S
shawn_he 已提交
373

S
shawn_he 已提交
374 375
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
S
shawn_he 已提交
376
| resource | [Resource](#resource9)      | Yes   | Resource object.           |
S
shawn_he 已提交
377 378
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

S
shawn_he 已提交
379 380 381 382 383 384 385 386 387 388
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
389
**Example**
S
shawn_he 已提交
390
  ```ts
S
shawn_he 已提交
391 392 393 394 395
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
396 397 398 399 400 401 402 403 404 405 406 407
  try {
    this.context.resourceManager.getStringValue(resource, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let str = value;
        }
    });
  } catch (error) {
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
  
S
shawn_he 已提交
408 409 410
  ```


S
shawn_he 已提交
411 412 413
### getStringValue<sup>9+</sup>

getStringValue(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
414 415 416 417 418 419

Obtains the string corresponding to the specified resource object. This API uses a promise to return the result.

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

**Parameters**
S
shawn_he 已提交
420 421 422

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
423 424 425
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
426 427
| Type                   | Description              |
| --------------------- | ---------------- |
S
shawn_he 已提交
428 429
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
430 431 432 433 434 435 436 437 438 439
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
440
**Example**
S
shawn_he 已提交
441
  ```ts
S
shawn_he 已提交
442 443 444 445 446
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
447 448
  try {
    this.context.resourceManager.getStringValue(resource).then(value => {
S
shawn_he 已提交
449
      let str = value;
S
shawn_he 已提交
450 451 452 453 454 455
    }).catch(error => {
      console.log("getStringValue promise error is " + error);
    });
  } catch (error) {
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
456 457
  ```

A
annie_wangli 已提交
458

S
shawn_he 已提交
459 460 461
### getStringArrayValue<sup>9+</sup>

getStringArrayValue(resId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
462

S
shawn_he 已提交
463
Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
464 465 466

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

A
annie_wangli 已提交
467
**Parameters**
S
shawn_he 已提交
468

A
annie_wangli 已提交
469 470 471
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId    | number                                   | Yes   | Resource ID.            |
S
shawn_he 已提交
472
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
473

S
shawn_he 已提交
474 475 476 477 478 479 480 481 482 483
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

A
annie_wangli 已提交
484
**Example**
S
shawn_he 已提交
485 486 487 488 489 490 491 492 493 494 495 496
  ```ts
  try {
    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let strArray = value;
        }
    });
  } catch (error) {
    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
497 498 499
  ```


S
shawn_he 已提交
500
### getStringArrayValue<sup>9+</sup>
A
annie_wangli 已提交
501

S
shawn_he 已提交
502
getStringArrayValue(resId: number): Promise&lt;Array&lt;string&gt;&gt;
Z
zengyawen 已提交
503

S
shawn_he 已提交
504
Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result.
Z
zengyawen 已提交
505

A
annie_wangli 已提交
506 507
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
508
**Parameters**
S
shawn_he 已提交
509

A
annie_wangli 已提交
510 511 512
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
513

A
annie_wangli 已提交
514
**Return value**
A
annie_wangli 已提交
515 516
| Type                                | Description           |
| ---------------------------------- | ------------- |
S
shawn_he 已提交
517
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
518

S
shawn_he 已提交
519 520 521 522 523 524 525 526 527 528
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

A
annie_wangli 已提交
529
**Example**
S
shawn_he 已提交
530 531 532 533 534 535 536 537 538 539
  ```ts
  try {
    this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then(value => {
        let strArray = value;
    }).catch(error => {
        console.log("getStringArrayValue promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
540 541
  ```

S
shawn_he 已提交
542
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
543

S
shawn_he 已提交
544
getStringArrayValue(resource: Resource, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
S
shawn_he 已提交
545 546 547 548 549 550

Obtains the string array corresponding to the specified resource object. This API uses an asynchronous callback to return the result.

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

**Parameters**
S
shawn_he 已提交
551 552 553 554

| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resource | [Resource](#resource9)                   | Yes   | Resource object.             |
S
shawn_he 已提交
555 556
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|

S
shawn_he 已提交
557 558 559 560 561 562 563 564 565 566
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
567
**Example**
S
shawn_he 已提交
568
  ```ts
S
shawn_he 已提交
569 570 571 572 573
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.strarray.test').id
  };
S
shawn_he 已提交
574 575
  try {
    this.context.resourceManager.getStringArrayValue(resource, (error, value) => {
S
shawn_he 已提交
576 577 578 579 580
      if (error != null) {
          console.log("error is " + error);
      } else {
          let strArray = value;
      }
S
shawn_he 已提交
581 582 583 584
    });
  } catch (error) {
    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
585 586
  ```

S
shawn_he 已提交
587
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
588

S
shawn_he 已提交
589
getStringArrayValue(resource: Resource): Promise&lt;Array&lt;string&gt;&gt;
S
shawn_he 已提交
590 591 592 593 594 595

Obtains the string array corresponding to the specified resource object. This API uses a promise to return the result.

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

**Parameters**
S
shawn_he 已提交
596 597 598

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
599 600 601
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
602 603
| Type                                | Description                |
| ---------------------------------- | ------------------ |
S
shawn_he 已提交
604
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
S
shawn_he 已提交
605

S
shawn_he 已提交
606 607 608 609 610 611 612 613 614 615
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
616
**Example**
S
shawn_he 已提交
617
  ```ts
S
shawn_he 已提交
618 619 620 621 622
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.strarray.test').id
  };
S
shawn_he 已提交
623 624
  try {
    this.context.resourceManager.getStringArrayValue(resource).then(value => {
S
shawn_he 已提交
625
      let strArray = value;
S
shawn_he 已提交
626 627 628 629 630 631
    }).catch(error => {
        console.log("getStringArray promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
632
  ```
A
annie_wangli 已提交
633 634


S
shawn_he 已提交
635 636 637
### getMediaContent<sup>9+</sup>

getMediaContent(resId: number, callback: AsyncCallback&lt;Uint8Array&gt;): void
A
annie_wangli 已提交
638

S
shawn_he 已提交
639
Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
640 641 642

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

A
annie_wangli 已提交
643
**Parameters**
S
shawn_he 已提交
644

A
annie_wangli 已提交
645 646 647
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | Yes   | Resource ID.             |
S
shawn_he 已提交
648
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
649

S
shawn_he 已提交
650 651 652 653 654 655 656 657 658
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
659
**Example**
S
shawn_he 已提交
660 661 662 663 664 665 666 667 668 669 670 671
  ```ts
  try {
    this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
672 673 674
  ```


S
shawn_he 已提交
675
### getMediaContent<sup>9+</sup>
A
annie_wangli 已提交
676

S
shawn_he 已提交
677
getMediaContent(resId: number): Promise&lt;Uint8Array&gt;
Z
zengyawen 已提交
678

S
shawn_he 已提交
679
Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result.
Z
zengyawen 已提交
680

A
annie_wangli 已提交
681 682
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
683
**Parameters**
S
shawn_he 已提交
684

A
annie_wangli 已提交
685 686 687
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
688

A
annie_wangli 已提交
689
**Return value**
A
annie_wangli 已提交
690 691
| Type                       | Description            |
| ------------------------- | -------------- |
S
shawn_he 已提交
692
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
693

S
shawn_he 已提交
694 695 696 697 698 699 700 701 702
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
703
**Example**
S
shawn_he 已提交
704 705 706
  ```ts
  try {
      this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => {
S
shawn_he 已提交
707
          let media = value;
A
annie_wangli 已提交
708
      }).catch(error => {
S
shawn_he 已提交
709
          console.log("getMediaContent promise error is " + error);
A
annie_wangli 已提交
710
      });
S
shawn_he 已提交
711 712 713
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
714 715
  ```

S
shawn_he 已提交
716
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
717

S
shawn_he 已提交
718
getMediaContent(resource: Resource, callback: AsyncCallback&lt;Uint8Array&gt;): void
S
shawn_he 已提交
719 720 721 722 723 724

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

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

**Parameters**
S
shawn_he 已提交
725 726 727 728

| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resource | [Resource](#resource9)          | Yes   | Resource object.              |
S
shawn_he 已提交
729 730
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

S
shawn_he 已提交
731 732 733 734 735 736 737 738 739
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

S
shawn_he 已提交
740
**Example**
S
shawn_he 已提交
741
  ```ts
S
shawn_he 已提交
742 743 744 745 746
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
747 748 749
  try {
    this.context.resourceManager.getMediaContent(resource, (error, value) => {
        if (error != null) {
S
shawn_he 已提交
750
          console.log("error is " + error);
S
shawn_he 已提交
751
        } else {
S
shawn_he 已提交
752
          let media = value;
S
shawn_he 已提交
753 754 755 756 757
        }
    });
  } catch (error) {
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
758 759
  ```

S
shawn_he 已提交
760
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
761

S
shawn_he 已提交
762
getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
S
shawn_he 已提交
763 764 765 766 767 768

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

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

**Parameters**
S
shawn_he 已提交
769 770 771

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
772 773 774
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
775 776
| Type                       | Description                 |
| ------------------------- | ------------------- |
S
shawn_he 已提交
777
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
S
shawn_he 已提交
778

S
shawn_he 已提交
779 780 781 782 783 784 785 786 787
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

S
shawn_he 已提交
788
**Example**
S
shawn_he 已提交
789
  ```ts
S
shawn_he 已提交
790 791 792 793 794
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
795 796
  try {
    this.context.resourceManager.getMediaContent(resource).then(value => {
S
shawn_he 已提交
797
      let media = value;
S
shawn_he 已提交
798 799 800 801 802 803
    }).catch(error => {
      console.log("getMediaContent promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
804
  ```
A
annie_wangli 已提交
805 806


S
shawn_he 已提交
807 808 809
### getMediaContentBase64<sup>9+</sup>

getMediaContentBase64(resId: number, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
810

S
shawn_he 已提交
811
Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
812 813 814

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

A
annie_wangli 已提交
815
**Parameters**
S
shawn_he 已提交
816

A
annie_wangli 已提交
817 818 819
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
S
shawn_he 已提交
820
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
821

S
shawn_he 已提交
822 823 824 825 826 827 828 829 830
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
831
**Example**
S
shawn_he 已提交
832 833 834 835 836 837 838 839 840 841 842 843
  ```ts
  try {
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let media = value;
        }
    });       
  } catch (error) {
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
844 845 846
  ```


S
shawn_he 已提交
847
### getMediaContentBase64<sup>9+</sup>
A
annie_wangli 已提交
848

S
shawn_he 已提交
849
getMediaContentBase64(resId: number): Promise&lt;string&gt;
Z
zengyawen 已提交
850

S
shawn_he 已提交
851
Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result.
Z
zengyawen 已提交
852

A
annie_wangli 已提交
853 854
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
855
**Parameters**
S
shawn_he 已提交
856

A
annie_wangli 已提交
857 858 859
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
860

A
annie_wangli 已提交
861
**Return value**
A
annie_wangli 已提交
862 863
| Type                   | Description                  |
| --------------------- | -------------------- |
S
shawn_he 已提交
864
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
865

S
shawn_he 已提交
866 867 868 869 870 871 872 873 874
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
875
**Example**
S
shawn_he 已提交
876 877 878 879 880 881 882 883 884 885
  ```ts
  try {
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then(value => {
        let media = value;
    }).catch(error => {
        console.log("getMediaContentBase64 promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  } 
A
annie_wangli 已提交
886 887
  ```

S
shawn_he 已提交
888
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
889

S
shawn_he 已提交
890
getMediaContentBase64(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
S
shawn_he 已提交
891 892 893 894 895 896

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

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

**Parameters**
S
shawn_he 已提交
897

S
shawn_he 已提交
898 899
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
S
shawn_he 已提交
900
| resource | [Resource](#resource9)      | Yes   | Resource object.                    |
S
shawn_he 已提交
901 902
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

S
shawn_he 已提交
903 904 905 906 907 908 909 910 911
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

S
shawn_he 已提交
912
**Example**
S
shawn_he 已提交
913
  ```ts
S
shawn_he 已提交
914 915 916 917 918
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
919 920 921 922 923 924 925 926 927 928 929
  try {
    this.context.resourceManager.getMediaContentBase64(resource, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
930 931
  ```

S
shawn_he 已提交
932
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
933

S
shawn_he 已提交
934
getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
935 936 937 938 939 940

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

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

**Parameters**
S
shawn_he 已提交
941 942 943

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
944 945 946
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
947 948 949 950 951 952 953 954 955 956 957 958
| Type                   | Description                       |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; |  Promise used to return the result.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
S
shawn_he 已提交
959 960

**Example**
S
shawn_he 已提交
961
  ```ts
S
shawn_he 已提交
962 963 964 965 966
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
967 968 969 970 971 972 973 974 975
  try {
    this.context.resourceManager.getMediaContentBase64(resource).then(value => {
        let media = value;
    }).catch(error => {
        console.log("getMediaContentBase64 promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
976 977
  ```

A
annie_wangli 已提交
978 979 980 981 982

### getConfiguration

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

S
shawn_he 已提交
983
Obtains the device configuration. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
984 985 986

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

A
annie_wangli 已提交
987
**Parameters**
S
shawn_he 已提交
988

A
annie_wangli 已提交
989 990
| Name     | Type                                      | Mandatory  | Description                       |
| -------- | ---------------------------------------- | ---- | ------------------------- |
S
shawn_he 已提交
991
| callback | AsyncCallback&lt;[Configuration](#configuration)&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
992

A
annie_wangli 已提交
993
**Example**
S
shawn_he 已提交
994
  ```ts
A
annie_wangli 已提交
995 996 997
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration((error, value) => {
          if (error != null) {
S
shawn_he 已提交
998
              console.log("error is " + error);
A
annie_wangli 已提交
999
          } else {
S
shawn_he 已提交
1000 1001
              let direction = value.direction;
              let locale = value.locale;
A
annie_wangli 已提交
1002 1003 1004 1005 1006 1007 1008 1009 1010
          }
      });
  });
  ```


### getConfiguration

getConfiguration(): Promise&lt;Configuration&gt;
Z
zengyawen 已提交
1011

S
shawn_he 已提交
1012
Obtains the device configuration. This API uses a promise to return the result.
Z
zengyawen 已提交
1013

A
annie_wangli 已提交
1014 1015
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1016
**Return value**
A
annie_wangli 已提交
1017 1018
| Type                                      | Description              |
| ---------------------------------------- | ---------------- |
S
shawn_he 已提交
1019
| Promise&lt;[Configuration](#configuration)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1020

A
annie_wangli 已提交
1021
**Example**
S
shawn_he 已提交
1022
  ```ts
A
annie_wangli 已提交
1023 1024
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration().then(value => {
S
shawn_he 已提交
1025 1026
          let direction = value.direction;
          let locale = value.locale;
A
annie_wangli 已提交
1027
      }).catch(error => {
S
shawn_he 已提交
1028
          console.log("getConfiguration promise error is " + error);
A
annie_wangli 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037
      });
  });
  ```


### getDeviceCapability

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

S
shawn_he 已提交
1038
Obtains the device capability. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1039 1040 1041

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

A
annie_wangli 已提交
1042
**Parameters**
S
shawn_he 已提交
1043

A
annie_wangli 已提交
1044 1045
| Name     | Type                                      | Mandatory  | Description                          |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
S
shawn_he 已提交
1046
| callback | AsyncCallback&lt;[DeviceCapability](#devicecapability)&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1047

A
annie_wangli 已提交
1048
**Example**
S
shawn_he 已提交
1049
  ```ts
A
annie_wangli 已提交
1050 1051 1052
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability((error, value) => {
          if (error != null) {
S
shawn_he 已提交
1053
              console.log("error is " + error);
A
annie_wangli 已提交
1054
          } else {
S
shawn_he 已提交
1055 1056
              let screenDensity = value.screenDensity;
              let deviceType = value.deviceType;
A
annie_wangli 已提交
1057 1058 1059 1060 1061 1062 1063 1064 1065
          }
      });
  });
  ```


### getDeviceCapability

getDeviceCapability(): Promise&lt;DeviceCapability&gt;
Z
zengyawen 已提交
1066

S
shawn_he 已提交
1067
Obtains the device capability. This API uses a promise to return the result.
Z
zengyawen 已提交
1068

A
annie_wangli 已提交
1069
**System capability**: SystemCapability.Global.ResourceManager
Z
zengyawen 已提交
1070

A
annie_wangli 已提交
1071
**Return value**
A
annie_wangli 已提交
1072 1073
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1074
| Promise&lt;[DeviceCapability](#devicecapability)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1075

A
annie_wangli 已提交
1076
**Example**
S
shawn_he 已提交
1077
  ```ts
A
annie_wangli 已提交
1078 1079
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability().then(value => {
S
shawn_he 已提交
1080 1081
          let screenDensity = value.screenDensity;
          let deviceType = value.deviceType;
A
annie_wangli 已提交
1082
      }).catch(error => {
S
shawn_he 已提交
1083
          console.log("getDeviceCapability promise error is " + error);
A
annie_wangli 已提交
1084 1085 1086 1087 1088
      });
  });
  ```


S
shawn_he 已提交
1089
### getPluralStringValue<sup>9+</sup>
Z
zengyawen 已提交
1090

S
shawn_he 已提交
1091
getPluralStringValue(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1092

S
shawn_he 已提交
1093
Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1094 1095 1096

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

A
annie_wangli 已提交
1097
**Parameters**
S
shawn_he 已提交
1098

A
annie_wangli 已提交
1099 1100 1101
| Name     | Type                         | Mandatory  | Description                             |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | Yes   | Resource ID.                          |
S
shawn_he 已提交
1102 1103
| num      | number                      | Yes   | Number.                            |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1104

S
shawn_he 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

A
annie_wangli 已提交
1115
**Example**
S
shawn_he 已提交
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
  ```ts
  try {
    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let str = value;
        }
    });
  } catch (error) {
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }   
A
annie_wangli 已提交
1128 1129 1130
  ```


S
shawn_he 已提交
1131
### getPluralStringValue<sup>9+</sup>
A
annie_wangli 已提交
1132

S
shawn_he 已提交
1133
getPluralStringValue(resId: number, num: number): Promise&lt;string&gt;
A
annie_wangli 已提交
1134

S
shawn_he 已提交
1135
Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result.
Z
zengyawen 已提交
1136

A
annie_wangli 已提交
1137 1138
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1139
**Parameters**
S
shawn_he 已提交
1140

A
annie_wangli 已提交
1141 1142 1143
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
1144
| num   | number | Yes   | Number.  |
A
annie_wangli 已提交
1145

A
annie_wangli 已提交
1146
**Return value**
A
annie_wangli 已提交
1147 1148
| Type                   | Description                       |
| --------------------- | ------------------------- |
S
shawn_he 已提交
1149
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1150

S
shawn_he 已提交
1151
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
A
annie_wangli 已提交
1152

S
shawn_he 已提交
1153
**Error codes**
S
shawn_he 已提交
1154

S
shawn_he 已提交
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

**Example**
  ```ts
  try {
    this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then(value => {
        let str = value;
    }).catch(error => {
        console.log("getPluralStringValue promise error is " + error);
    });
  } catch (error) {
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }  
  ```

### getPluralStringValue<sup>9+</sup>

getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback&lt;string&gt;): void
S
shawn_he 已提交
1177 1178 1179 1180 1181 1182

Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses an asynchronous callback to return the result.

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

**Parameters**
S
shawn_he 已提交
1183 1184 1185 1186 1187

| Name     | Type                         | Mandatory  | Description                                  |
| -------- | --------------------------- | ---- | ------------------------------------ |
| resource | [Resource](#resource9)      | Yes   | Resource object.                                |
| num      | number                      | Yes   | Number.                                 |
S
shawn_he 已提交
1188 1189
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

S
shawn_he 已提交
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1200
**Example**
S
shawn_he 已提交
1201
  ```ts
S
shawn_he 已提交
1202 1203 1204 1205 1206
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
  try {
    this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let str = value;
        }
    });
  } catch (error) {
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }  
  
S
shawn_he 已提交
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
  ```

### getPluralString<sup>9+</sup>

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

Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses a promise to return the result.

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

**Parameters**
S
shawn_he 已提交
1230 1231 1232

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
1233
| resource | [Resource](#resource9) | Yes   | Resource object.|
S
shawn_he 已提交
1234
| num      | number                 | Yes   | Number. |
S
shawn_he 已提交
1235 1236

**Return value**
S
shawn_he 已提交
1237 1238
| Type                   | Description                            |
| --------------------- | ------------------------------ |
S
shawn_he 已提交
1239 1240
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1251
**Example**
S
shawn_he 已提交
1252
  ```ts
S
shawn_he 已提交
1253 1254 1255 1256 1257
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1258 1259 1260 1261 1262 1263 1264 1265 1266
  try {
    this.context.resourceManager.getPluralString(resource, 1).then(value => {
        let str = value;
    }).catch(error => {
        console.log("getPluralString promise error is " + error);
    });
  } catch (error) {
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1267 1268
  ```

A
annie_wangli 已提交
1269

S
shawn_he 已提交
1270 1271 1272
### getRawFileContent<sup>9+</sup>

getRawFileContent(path: string, callback: AsyncCallback&lt;Uint8Array&gt;): void
A
annie_wangli 已提交
1273

S
shawn_he 已提交
1274
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1275 1276 1277

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

A
annie_wangli 已提交
1278
**Parameters**
S
shawn_he 已提交
1279

A
annie_wangli 已提交
1280 1281 1282
| Name     | Type                             | Mandatory  | Description                     |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | Yes   | Path of the raw file.            |
S
shawn_he 已提交
1283
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1284

S
shawn_he 已提交
1285 1286 1287 1288 1289 1290 1291 1292
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1293
**Example**
S
shawn_he 已提交
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
  ```ts
  try {
    this.context.resourceManager.getRawFileContent("test.xml", (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let rawFile = value;
        }
    });
  } catch (error) {
    console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
      
A
annie_wangli 已提交
1307 1308
  ```

S
shawn_he 已提交
1309
### getRawFileContent<sup>9+</sup>
A
annie_wangli 已提交
1310

S
shawn_he 已提交
1311
getRawFileContent(path: string): Promise&lt;Uint8Array&gt;
A
annie_wangli 已提交
1312

S
shawn_he 已提交
1313
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1314 1315 1316

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

A
annie_wangli 已提交
1317
**Parameters**
S
shawn_he 已提交
1318

A
annie_wangli 已提交
1319 1320 1321
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1322

A
annie_wangli 已提交
1323
**Return value**
A
annie_wangli 已提交
1324 1325
| Type                       | Description         |
| ------------------------- | ----------- |
S
shawn_he 已提交
1326
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1327

S
shawn_he 已提交
1328 1329 1330 1331 1332 1333 1334 1335
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1336
**Example**
S
shawn_he 已提交
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
  ```ts
  try {
    this.context.resourceManager.getRawFileContent("test.xml").then(value => {
        let rawFile = value;
    }).catch(error => {
        console.log("getRawFileContent promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
1347 1348 1349
  ```


S
shawn_he 已提交
1350 1351 1352
### getRawFd<sup>9+</sup>

getRawFd(path: string, callback: AsyncCallback&lt;RawFileDescriptor&gt;): void
A
annie_wangli 已提交
1353

S
shawn_he 已提交
1354
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1355 1356 1357

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

A
annie_wangli 已提交
1358
**Parameters**
S
shawn_he 已提交
1359

A
annie_wangli 已提交
1360 1361 1362
| Name     | Type                                      | Mandatory  | Description                              |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | Yes   | Path of the raw file.                     |
S
shawn_he 已提交
1363
| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1364

S
shawn_he 已提交
1365 1366 1367 1368 1369 1370 1371 1372
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1373
**Example**
S
shawn_he 已提交
1374 1375 1376 1377
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml", (error, value) => {
        if (error != null) {
S
shawn_he 已提交
1378
            console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1379 1380 1381 1382 1383
        } else {
            let fd = value.fd;
            let offset = value.offset;
            let length = value.length;
        }
S
shawn_he 已提交
1384 1385 1386 1387
    });
  } catch (error) {
      console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`)
  };
A
annie_wangli 已提交
1388 1389
  ```

S
shawn_he 已提交
1390
### getRawFd<sup>9+</sup>
A
annie_wangli 已提交
1391

S
shawn_he 已提交
1392
getRawFd(path: string): Promise&lt;RawFileDescriptor&gt;
A
annie_wangli 已提交
1393

S
shawn_he 已提交
1394
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1395 1396 1397

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

A
annie_wangli 已提交
1398
**Parameters**
S
shawn_he 已提交
1399

A
annie_wangli 已提交
1400 1401 1402
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1403

A
annie_wangli 已提交
1404
**Return value**
A
annie_wangli 已提交
1405 1406
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1407
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1408

S
shawn_he 已提交
1409 1410 1411 1412 1413 1414 1415 1416
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1417
**Example**
S
shawn_he 已提交
1418 1419 1420 1421 1422 1423 1424
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml").then(value => {
        let fd = value.fd;
        let offset = value.offset;
        let length = value.length;
    }).catch(error => {
S
shawn_he 已提交
1425
        console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1426 1427
    });
  } catch (error) {
S
shawn_he 已提交
1428
    console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1429
  };
A
annie_wangli 已提交
1430 1431 1432 1433 1434 1435
  ```

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

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

S
shawn_he 已提交
1436
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1437 1438 1439

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

A
annie_wangli 已提交
1440
**Parameters**
S
shawn_he 已提交
1441

A
annie_wangli 已提交
1442 1443 1444
| Name     | Type                       | Mandatory  | Description         |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | Yes   | Path of the raw file.|
S
shawn_he 已提交
1445
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.       |
A
annie_wangli 已提交
1446

A
annie_wangli 已提交
1447
**Example**
S
shawn_he 已提交
1448
  ```ts
A
annie_wangli 已提交
1449 1450 1451
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
S
shawn_he 已提交
1452
              console.log("error is " + error);
A
annie_wangli 已提交
1453 1454 1455 1456 1457 1458 1459 1460 1461
          }
      });
  });
  ```

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

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

S
shawn_he 已提交
1462
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1463 1464 1465

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

A
annie_wangli 已提交
1466
**Parameters**
S
shawn_he 已提交
1467

A
annie_wangli 已提交
1468 1469 1470
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1471

A
annie_wangli 已提交
1472
**Return value**
A
annie_wangli 已提交
1473 1474
| Type                 | Description  |
| ------------------- | ---- |
S
shawn_he 已提交
1475
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
1476

A
annie_wangli 已提交
1477
**Example**
S
shawn_he 已提交
1478
  ```ts
A
annie_wangli 已提交
1479 1480
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml").then(value => {
S
shawn_he 已提交
1481
          let result = value;
A
annie_wangli 已提交
1482
      }).catch(error => {
S
shawn_he 已提交
1483
          console.log("closeRawFileDescriptor promise error is " + error);
A
annie_wangli 已提交
1484 1485 1486 1487
      });
  });
  ```

S
shawn_he 已提交
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565

### closeRawFd<sup>9+</sup>

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

Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name     | Type                       | Mandatory  | Description         |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | Yes   | Path of the raw file.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.       |

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | The resource not found by path.          |

**Example**
  ```ts
  try {
    this.context.resourceManager.closeRawFd("test.xml", (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        }
    });
  } catch (error) {
    console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`)
  }
      
  ```

### closeRawFd<sup>8+</sup>

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

Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.

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

**Parameters**

| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|

**Return value**
| Type                 | Description  |
| ------------------- | ---- |
| Promise&lt;void&gt; | Promise that returns no value.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

**Example**
  ```ts
  try {
    this.context.resourceManager.closeRawFd("test.xml").then(value => {
        let result = value;
    }).catch(error => {
        console.log("closeRawFd promise error is " + error);
    });
  } catch (error) {
    console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

A
annie_wangli 已提交
1566 1567
### release<sup>7+</sup>

A
annie_wangli 已提交
1568
release()
A
annie_wangli 已提交
1569

S
shawn_he 已提交
1570
Releases a created **resourceManager** object.
A
annie_wangli 已提交
1571 1572 1573

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

A
annie_wangli 已提交
1574
**Example**
S
shawn_he 已提交
1575
  ```ts
A
annie_wangli 已提交
1576
  resourceManager.getResourceManager((error, mgr) => {
S
shawn_he 已提交
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
      mgr.release();
  });
  ```

### getStringByName<sup>9+</sup>

getStringByName(resName: string, callback: AsyncCallback&lt;string&gt;): void

Obtains the string corresponding to the specified resource name. This API uses an asynchronous callback to return the result.

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

**Parameters**
S
shawn_he 已提交
1590

S
shawn_he 已提交
1591 1592
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
S
shawn_he 已提交
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
| resName  | string                      | Yes   | Resource name.           |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
S
shawn_he 已提交
1605 1606

**Example**
S
shawn_he 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
  ```ts
  try {
    this.context.resourceManager.getStringByName("test", (error, value) => {
        if (error != null) {
             console.log("error is " + error);
        } else {
            let string = value;
        }
    });
  } catch (error) {
    console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  
S
shawn_he 已提交
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
  ```

### getStringByName<sup>9+</sup>

getStringByName(resName: string): Promise&lt;string&gt;

Obtains the string corresponding to the specified resource name. This API uses a promise to return the result.

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

**Parameters**
S
shawn_he 已提交
1631 1632

| Name    | Type    | Mandatory  | Description  |
S
shawn_he 已提交
1633
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1634
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1635 1636

**Return value**
S
shawn_he 已提交
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
| Type                   | Description        |
| --------------------- | ---------- |
| Promise&lt;string&gt; | String corresponding to the resource name.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
S
shawn_he 已提交
1650 1651

**Example**
S
shawn_he 已提交
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661
  ```ts
  try {
    this.context.resourceManager.getStringByName("test").then(value => {
        let string = value;
    }).catch(error => {
        console.log("getStringByName promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
  ```

### getStringArrayByName<sup>9+</sup>

getStringArrayByName(resName: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

Obtains the string array corresponding to the specified resource name. This API uses an asynchronous callback to return the result.

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

**Parameters**
S
shawn_he 已提交
1673

S
shawn_he 已提交
1674 1675
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
S
shawn_he 已提交
1676
| resName  | string                                   | Yes   | Resource name.             |
S
shawn_he 已提交
1677
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1678

S
shawn_he 已提交
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1689
**Example**
S
shawn_he 已提交
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
  ```ts
  try {
    this.context.resourceManager.getStringArrayByName("test", (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let strArray = value;
        }
    });
  } catch (error) {
    console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712
  ```

### getStringArrayByName<sup>9+</sup>

getStringArrayByName(resName: string): Promise&lt;Array&lt;string&gt;&gt;

Obtains the string array corresponding to the specified resource name. This API uses a promise to return the result.

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

**Parameters**
S
shawn_he 已提交
1713 1714 1715 1716

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1717 1718

**Return value**
S
shawn_he 已提交
1719 1720
| Type                                | Description          |
| ---------------------------------- | ------------ |
S
shawn_he 已提交
1721 1722
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|

S
shawn_he 已提交
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1733
**Example**
S
shawn_he 已提交
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
  ```ts
  try {
    this.context.resourceManager.getStringArrayByName("test").then(value => {
        let strArray = value;
    }).catch(error => {
        console.log("getStringArrayByName promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
  ```

### getMediaByName<sup>9+</sup>

getMediaByName(resName: string, callback: AsyncCallback&lt;Uint8Array&gt;): void

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

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

**Parameters**
S
shawn_he 已提交
1755

S
shawn_he 已提交
1756 1757
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
S
shawn_he 已提交
1758
| resName  | string                          | Yes   | Resource name.              |
S
shawn_he 已提交
1759
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1760

S
shawn_he 已提交
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1771
**Example**
S
shawn_he 已提交
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
  ```ts
  try {
    this.context.resourceManager.getMediaByName("test", (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
  ```

### getMediaByName<sup>9+</sup>

getMediaByName(resName: string): Promise&lt;Uint8Array&gt;

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

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

**Parameters**
S
shawn_he 已提交
1795 1796 1797

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1798 1799 1800
| resName | string | Yes   | Resource name.|

**Return value**
S
shawn_he 已提交
1801 1802
| Type                       | Description           |
| ------------------------- | ------------- |
S
shawn_he 已提交
1803 1804
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

S
shawn_he 已提交
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1815
**Example**
S
shawn_he 已提交
1816 1817 1818 1819 1820 1821 1822 1823 1824 1825
  ```ts
  try {
    this.context.resourceManager.getMediaByName("test").then(value => {
        let media = value;
    }).catch(error => {
        console.log("getMediaByName promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
  ```

### getMediaBase64ByName<sup>9+</sup>

getMediaBase64ByName(resName: string, callback: AsyncCallback&lt;string&gt;): void

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

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

**Parameters**
S
shawn_he 已提交
1837

S
shawn_he 已提交
1838 1839
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
S
shawn_he 已提交
1840
| resName  | string                      | Yes   | Resource name.                    |
S
shawn_he 已提交
1841
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1842

S
shawn_he 已提交
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1853
**Example**
S
shawn_he 已提交
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
  ```ts
  try {
    this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
1866
  ```
S
shawn_he 已提交
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876

### getMediaBase64ByName<sup>9+</sup>

getMediaBase64ByName(resName: string): Promise&lt;string&gt;

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

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

**Parameters**
S
shawn_he 已提交
1877 1878 1879 1880

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1881 1882

**Return value**
S
shawn_he 已提交
1883 1884
| Type                   | Description                 |
| --------------------- | ------------------- |
S
shawn_he 已提交
1885 1886
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1897
**Example**
S
shawn_he 已提交
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907
  ```ts
  try {
    this.context.resourceManager.getMediaBase64ByName("test").then(value => {
        let media = value;
    }).catch(error => {
        console.log("getMediaBase64ByName promise error is " + error);
    });
  } catch (error) {
    console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1908 1909 1910 1911 1912 1913
  ```

### getPluralStringByName<sup>9+</sup>

getPluralStringByName(resName: string, num: number, callback: AsyncCallback&lt;string&gt;): void

S
shawn_he 已提交
1914
Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
1915 1916 1917 1918

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

**Parameters**
S
shawn_he 已提交
1919 1920 1921 1922 1923

| Name     | Type                         | Mandatory  | Description                           |
| -------- | --------------------------- | ---- | ----------------------------- |
| resName  | string                      | Yes   | Resource name.                         |
| num      | number                      | Yes   | Number.                          |
S
shawn_he 已提交
1924
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1925

S
shawn_he 已提交
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1936
**Example**
S
shawn_he 已提交
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
  ```ts
  try {
    this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
        if (error != null) {
            console.log("error is " + error);
        } else {
            let str = value;
        }
    });
  } catch (error) {
    console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  
S
shawn_he 已提交
1950 1951 1952 1953 1954 1955
  ```

### getPluralStringByName<sup>9+</sup>

getPluralStringByName(resName: string, num: number): Promise&lt;string&gt;

S
shawn_he 已提交
1956
Obtains the plural string corresponding to the specified resource name based on the specified number. This API uses a promise to return the result.
S
shawn_he 已提交
1957 1958 1959 1960

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

**Parameters**
S
shawn_he 已提交
1961 1962 1963

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1964
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1965
| num     | number | Yes   | Number. |
S
shawn_he 已提交
1966 1967

**Return value**
S
shawn_he 已提交
1968 1969
| Type                   | Description                    |
| --------------------- | ---------------------- |
S
shawn_he 已提交
1970 1971
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
1982
**Example**
S
shawn_he 已提交
1983 1984 1985
  ```ts
  try {
    this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
S
shawn_he 已提交
1986
      let str = value;
S
shawn_he 已提交
1987
    }).catch(error => {
S
shawn_he 已提交
1988
      console.log("getPluralStringByName promise error is " + error);
S
shawn_he 已提交
1989 1990 1991 1992
    });
  } catch (error) {
    console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
  ```

### getStringSync<sup>9+</sup>

getStringSync(resId: number): string

Obtains the string corresponding to the specified resource ID. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2004

S
shawn_he 已提交
2005 2006 2007 2008 2009
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
| Type    | Description         |
| ------ | ----------- |
| string | Promise used to return the result.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
S
shawn_he 已提交
2023 2024

**Example**
S
shawn_he 已提交
2025 2026 2027 2028 2029 2030
  ```ts
  try {
    this.context.resourceManager.getStringSync($r('app.string.test').id);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041
  ```

### getStringSync<sup>9+</sup>

getStringSync(resource: Resource): string

Obtains the string corresponding to the specified resource object. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2042 2043 2044

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2045 2046 2047
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060
| Type    | Description              |
| ------ | ---------------- |
| string | Promise used to return the result.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
S
shawn_he 已提交
2061 2062

**Example**
S
shawn_he 已提交
2063
  ```ts
S
shawn_he 已提交
2064 2065 2066 2067 2068
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
2069 2070 2071 2072 2073
  try {
    this.context.resourceManager.getStringSync(resource);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
  ```

### getStringByNameSync<sup>9+</sup>

getStringByNameSync(resName: string): string

Obtains the string corresponding to the specified resource name. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2085 2086 2087

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2088 2089 2090
| resName | string | Yes   | Resource name.|

**Return value**
S
shawn_he 已提交
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
| Type    | Description        |
| ------ | ---------- |
| string | String corresponding to the specified resource name.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
S
shawn_he 已提交
2104 2105

**Example**
S
shawn_he 已提交
2106 2107 2108 2109 2110 2111
  ```ts
  try {
    this.context.resourceManager.getStringByNameSync("test");
  } catch (error) {
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2112 2113
  ```

S
shawn_he 已提交
2114
### getBoolean<sup>9+</sup>
S
shawn_he 已提交
2115 2116 2117 2118 2119 2120 2121 2122

getBoolean(resId: number): boolean

Obtains the Boolean result corresponding to the specified resource ID. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2123

S
shawn_he 已提交
2124 2125 2126 2127 2128
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2129 2130
| Type     | Description          |
| ------- | ------------ |
S
shawn_he 已提交
2131 2132
| boolean | Boolean result corresponding to the specified resource ID.|

S
shawn_he 已提交
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
2143
**Example**
S
shawn_he 已提交
2144 2145 2146 2147 2148 2149
  ```ts
  try {
    this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
  } catch (error) {
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159
  ```
### getBoolean<sup>9+</sup>

getBoolean(resource: Resource): boolean

Obtains the Boolean result corresponding to the specified resource object. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2160 2161 2162

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2163 2164 2165
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2166 2167
| Type     | Description               |
| ------- | ----------------- |
S
shawn_he 已提交
2168 2169
| boolean | Boolean result corresponding to the specified resource object.|

S
shawn_he 已提交
2170 2171 2172 2173 2174 2175 2176 2177 2178 2179
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
2180
**Example**
S
shawn_he 已提交
2181
  ```ts
S
shawn_he 已提交
2182 2183 2184 2185 2186
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.boolean.boolean_test').id
  };
S
shawn_he 已提交
2187 2188 2189 2190 2191
  try {
    this.context.resourceManager.getBoolean(resource);
  } catch (error) {
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202
  ```

### getBooleanByName<sup>9+</sup>

getBooleanByName(resName: string): boolean

Obtains the Boolean result corresponding to the specified resource name. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2203 2204 2205 2206

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
2207 2208

**Return value**
S
shawn_he 已提交
2209 2210
| Type     | Description         |
| ------- | ----------- |
S
shawn_he 已提交
2211 2212
| boolean | Boolean result corresponding to the specified resource name.|

S
shawn_he 已提交
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
2223
**Example**
S
shawn_he 已提交
2224 2225 2226 2227 2228 2229
  ```ts
  try {
    this.context.resourceManager.getBooleanByName("boolean_test");
  } catch (error) {
    console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2230 2231
  ```

S
shawn_he 已提交
2232
### getNumber<sup>9+</sup>
S
shawn_he 已提交
2233 2234 2235 2236 2237 2238 2239 2240

getNumber(resId: number): number

Obtains the integer or float value corresponding to the specified resource ID. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2241

S
shawn_he 已提交
2242 2243 2244 2245 2246
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2247 2248
| Type    | Description        |
| ------ | ---------- |
S
shawn_he 已提交
2249 2250
| number | Integer or float value corresponding to the specified resource ID.|

S
shawn_he 已提交
2251 2252 2253 2254 2255 2256 2257 2258 2259 2260
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
2261
**Example**
S
shawn_he 已提交
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273
  ```ts
  try {
    this.context.resourceManager.getNumber($r('app.integer.integer_test').id);
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }

  try {
    this.context.resourceManager.getNumber($r('app.float.float_test').id);
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
  ```

### getNumber<sup>9+</sup>

getNumber(resource: Resource): number

Obtains the integer or float value corresponding to the specified resource object. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2285 2286 2287

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2288 2289 2290
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2291 2292
| Type    | Description             |
| ------ | --------------- |
S
shawn_he 已提交
2293 2294
| number | Integer or float value corresponding to the specified resource object.|

S
shawn_he 已提交
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304
For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |

S
shawn_he 已提交
2305
**Example**
S
shawn_he 已提交
2306
  ```ts
S
shawn_he 已提交
2307 2308 2309 2310 2311
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.integer.integer_test').id
  };
S
shawn_he 已提交
2312 2313 2314 2315 2316
  try {
    this.context.resourceManager.getNumber(resource);
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
  ```

### getNumberByName<sup>9+</sup>

getNumberByName(resName: string): number

Obtains the integer or float value corresponding to the specified resource name. This API returns the result synchronously.

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

**Parameters**
S
shawn_he 已提交
2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|

**Return value**
| Type    | Description       |
| ------ | --------- |
| number | Integer or float value corresponding to the specified resource name.|

For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).

**Error codes**

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |

**Example**
  ```ts
  try {
    this.context.resourceManager.getNumberByName("integer_test");
  } catch (error) {
    console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`)
  }

  try {
    this.context.resourceManager.getNumberByName("float_test");
  } catch (error) {
    console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```


### getString<sup>(deprecated)</sup>

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

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

This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9) instead.

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

**Parameters**

| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
| resId    | number                      | Yes   | Resource ID.          |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getString($r('app.string.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let str = value;
          }
      });
  });
  ```


### getString<sup>(deprecated)</sup>

getString(resId: number): Promise&lt;string&gt;

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

This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1) instead.

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

**Parameters**

S
shawn_he 已提交
2407 2408
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
S
shawn_he 已提交
2409
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
2410 2411 2412 2413

**Return value**
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443
| Promise&lt;string&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getString($r('app.string.test').id).then(value => {
          let str = value;
      }).catch(error => {
          console.log("getstring promise error is " + error);
      });
  });
  ```


### getStringArray<sup>(deprecated)</sup>

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

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

This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9) instead.

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

**Parameters**

| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId    | number                                   | Yes   | Resource ID.            |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
2444 2445

**Example**
S
shawn_he 已提交
2446 2447 2448 2449 2450 2451 2452 2453 2454 2455
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let strArray = value;
          }
      });
  });
S
shawn_he 已提交
2456
  ```
S
shawn_he 已提交
2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813


### getStringArray<sup>(deprecated)</sup>

getStringArray(resId: number): Promise&lt;Array&lt;string&gt;&gt;

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

This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1) instead.

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
| Type                                | Description           |
| ---------------------------------- | ------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
       mgr.getStringArray($r('app.strarray.test').id).then(value => {
          let strArray = value;
      }).catch(error => {
          console.log("getStringArray promise error is " + error);
      });
  });
  ```


### getMedia<sup>(deprecated)</sup>

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

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

This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent) instead.

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

**Parameters**

| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | Yes   | Resource ID.             |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMedia($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let media = value;
          }
      });
  });
  ```


### getMedia<sup>(deprecated)</sup>

getMedia(resId: number): Promise&lt;Uint8Array&gt;

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

This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent-1) instead.

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
| Type                       | Description            |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMedia($r('app.media.test').id).then(value => {
          let media = value;
      }).catch(error => {
          console.log("getMedia promise error is " + error);
      });
  });
  ```


### getMediaBase64<sup>(deprecated)</sup>

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

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

This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64) instead.

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

**Parameters**

| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let media = value;
          }
      });
  });
  ```


### getMediaBase64<sup>(deprecated)</sup>

getMediaBase64(resId: number): Promise&lt;string&gt;

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

This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64-1) instead.

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
| Type                   | Description                  |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getMediaBase64($r('app.media.test').id).then(value => {
          let media = value;
      }).catch(error => {
          console.log("getMediaBase64 promise error is " + error);
      });
  });
  ```


### getPluralString<sup>(deprecated)</sup>

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

Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue) instead.

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
| num   | number | Yes   | Number.  |

**Return value**
| Type                   | Description                       |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getPluralString($r("app.plural.test").id, 1).then(value => {
          let str = value;
      }).catch(error => {
          console.log("getPluralString promise error is " + error);
      });
  });
  ```


### getPluralString<sup>(deprecated)</sup>

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

Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue-1) instead.

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

**Parameters**

| Name     | Type                         | Mandatory  | Description                             |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | Yes   | Resource ID.                          |
| num      | number                      | Yes   | Number.                            |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let str = value;
          }
      });
  });
  ```


### getRawFile<sup>(deprecated)</sup>

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

Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9) instead.

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

**Parameters**

| Name     | Type                             | Mandatory  | Description                     |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | Yes   | Path of the raw file.            |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFile("test.xml", (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let rawFile = value;
          }
      });
  });
  ```


### getRawFile<sup>(deprecated)</sup>

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

Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1) instead.

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

**Parameters**

| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|

**Return value**
| Type                       | Description         |
| ------------------------- | ----------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFile("test.xml").then(value => {
          let rawFile = value;
      }).catch(error => {
          console.log("getRawFile promise error is " + error);
      });
  });
  ```


### getRawFileDescriptor<sup>(deprecated)</sup>

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

Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.

This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9) instead.

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

**Parameters**

| Name     | Type                                      | Mandatory  | Description                              |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path     | string                                   | Yes   | Path of the raw file.                     |
| callback | AsyncCallback&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Yes   | Callback used to return the result.|

**Example**
  ```ts
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
              console.log("error is " + error);
          } else {
              let fd = value.fd;
              let offset = value.offset;
              let length = value.length;
          }
      });
  });
  ```

### getRawFileDescriptor<sup>(deprecated)</sup>

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

Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.

This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1) instead.

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

**Parameters**

| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|

**Return value**
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the result.|

**Example**
  ```ts
  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 is " + error);
      });
  });
S
shawn_he 已提交
2814
  ```