js-apis-resource-manager.md 92.6 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.resourceManager (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](../../application-models/application-context-stage.md).
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**
S
shawn_he 已提交
100

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

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


## resourceManager.getResourceManager

getResourceManager(bundleName: string): Promise<ResourceManager>

S
shawn_he 已提交
125 126
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 已提交
127
**Model restriction**: This API can be used only in the FA model.
A
annie_wangli 已提交
128 129 130

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

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

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

A
annie_wangli 已提交
137
**Return value**
S
shawn_he 已提交
138

A
annie_wangli 已提交
139 140
| Type                                      | Description                |
| ---------------------------------------- | ------------------ |
S
shawn_he 已提交
141
| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.|
A
annie_wangli 已提交
142

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


## Direction

Enumerates the screen directions.

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

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


## DeviceType

Enumerates the device types.

A
annie_wangli 已提交
167 168
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
169
| Name                  | Value | Description  |
A
annie_wangli 已提交
170
| -------------------- | ---- | ---- |
S
shawn_he 已提交
171 172 173 174 175 176
| 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 已提交
177 178 179 180 181 182


## ScreenDensity

Enumerates the screen density types.

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

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


## Configuration

Defines the device configuration.

A
annie_wangli 已提交
199 200
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
201
**Parameters**
A
annie_wangli 已提交
202

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

S
shawn_he 已提交
208 209
**Example**

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

## DeviceCapability

Defines the device capability.

A
annie_wangli 已提交
223 224
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
225
**Parameters**
A
annie_wangli 已提交
226

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

S
shawn_he 已提交
232 233
**Example**

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

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

S
shawn_he 已提交
245 246
Defines the descriptor of the raw file.

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

S
shawn_he 已提交
249 250 251 252 253 254 255
**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 已提交
256

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

Defines the resource information of an application.

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

S
shawn_he 已提交
263 264 265 266 267 268 269
**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 已提交
270

A
annie_wangli 已提交
271 272 273 274 275

## ResourceManager

Defines the capability of accessing application resources.

S
shawn_he 已提交
276 277
> **NOTE**
>
S
shawn_he 已提交
278
> - The APIs involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
A
annie_wangli 已提交
279
>
A
annie_wangli 已提交
280 281
> - 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 已提交
282
### getStringValue<sup>9+</sup>
A
annie_wangli 已提交
283

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

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

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

A
annie_wangli 已提交
290
**Parameters**
S
shawn_he 已提交
291

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

S
shawn_he 已提交
297 298 299 300 301 302 303 304 305 306
**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 已提交
307
**Example (stage)**
S
shawn_he 已提交
308 309
  ```ts
    try {
S
shawn_he 已提交
310
        this.context.resourceManager.getStringValue($r('app.string.test').id, (error, value) => {
A
annie_wangli 已提交
311
          if (error != null) {
S
shawn_he 已提交
312
              console.log("error is " + error);
A
annie_wangli 已提交
313
          } else {
S
shawn_he 已提交
314
              let str = value;
A
annie_wangli 已提交
315 316
          }
      });
S
shawn_he 已提交
317 318 319
    } catch (error) {
        console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
    }
A
annie_wangli 已提交
320 321 322
  ```


S
shawn_he 已提交
323
### getStringValue<sup>9+</sup>
A
annie_wangli 已提交
324

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

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

A
annie_wangli 已提交
329 330
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
331
**Parameters**
S
shawn_he 已提交
332

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

A
annie_wangli 已提交
337
**Return value**
S
shawn_he 已提交
338

A
annie_wangli 已提交
339 340
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
341
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
342

S
shawn_he 已提交
343 344 345 346 347 348 349 350 351 352
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 已提交
353
**Example**
S
shawn_he 已提交
354 355 356 357 358 359 360 361 362 363
  ```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 已提交
364 365 366
  ```


S
shawn_he 已提交
367
### getStringValue<sup>9+</sup>
S
shawn_he 已提交
368

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

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 已提交
376

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

S
shawn_he 已提交
382 383 384 385 386 387 388 389 390 391
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 已提交
392
**Example**
S
shawn_he 已提交
393
  ```ts
S
shawn_he 已提交
394 395 396 397 398
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
399 400 401 402 403 404 405 406 407 408 409 410
  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 已提交
411 412 413
  ```


S
shawn_he 已提交
414 415 416
### getStringValue<sup>9+</sup>

getStringValue(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
417 418 419 420 421 422

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 已提交
423 424 425

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
426 427 428
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
429

S
shawn_he 已提交
430 431
| Type                   | Description              |
| --------------------- | ---------------- |
S
shawn_he 已提交
432 433
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
434 435 436 437 438 439 440 441 442 443
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 已提交
444
**Example**
S
shawn_he 已提交
445
  ```ts
S
shawn_he 已提交
446 447 448 449 450
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
451 452
  try {
    this.context.resourceManager.getStringValue(resource).then(value => {
S
shawn_he 已提交
453
      let str = value;
S
shawn_he 已提交
454 455 456 457 458 459
    }).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 已提交
460 461
  ```

A
annie_wangli 已提交
462

S
shawn_he 已提交
463 464 465
### getStringArrayValue<sup>9+</sup>

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

S
shawn_he 已提交
467
Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
468 469 470

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

A
annie_wangli 已提交
471
**Parameters**
S
shawn_he 已提交
472

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

S
shawn_he 已提交
478 479 480 481 482 483 484 485 486 487
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 已提交
488
**Example**
S
shawn_he 已提交
489 490 491 492 493 494 495 496 497 498 499 500
  ```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 已提交
501 502 503
  ```


S
shawn_he 已提交
504
### getStringArrayValue<sup>9+</sup>
A
annie_wangli 已提交
505

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

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

A
annie_wangli 已提交
510 511
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
512
**Parameters**
S
shawn_he 已提交
513

A
annie_wangli 已提交
514 515 516
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
517

A
annie_wangli 已提交
518
**Return value**
S
shawn_he 已提交
519

A
annie_wangli 已提交
520 521
| Type                                | Description           |
| ---------------------------------- | ------------- |
S
shawn_he 已提交
522
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
523

S
shawn_he 已提交
524 525 526 527 528 529 530 531 532 533
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 已提交
534
**Example**
S
shawn_he 已提交
535 536 537 538 539 540 541 542 543 544
  ```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 已提交
545 546
  ```

S
shawn_he 已提交
547
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
548

S
shawn_he 已提交
549
getStringArrayValue(resource: Resource, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
S
shawn_he 已提交
550 551 552 553 554 555

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 已提交
556 557 558 559

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

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

S
shawn_he 已提交
592
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
593

S
shawn_he 已提交
594
getStringArrayValue(resource: Resource): Promise&lt;Array&lt;string&gt;&gt;
S
shawn_he 已提交
595 596 597 598 599 600

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 已提交
601 602 603

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
604 605 606
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
607

S
shawn_he 已提交
608 609
| Type                                | Description                |
| ---------------------------------- | ------------------ |
S
shawn_he 已提交
610
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
S
shawn_he 已提交
611

S
shawn_he 已提交
612 613 614 615 616 617 618 619 620 621
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 已提交
622
**Example**
S
shawn_he 已提交
623
  ```ts
S
shawn_he 已提交
624 625 626 627 628
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.strarray.test').id
  };
S
shawn_he 已提交
629 630
  try {
    this.context.resourceManager.getStringArrayValue(resource).then(value => {
S
shawn_he 已提交
631
      let strArray = value;
S
shawn_he 已提交
632 633 634 635 636 637
    }).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 已提交
638
  ```
A
annie_wangli 已提交
639 640


S
shawn_he 已提交
641 642 643
### getMediaContent<sup>9+</sup>

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

S
shawn_he 已提交
645
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 已提交
646 647 648

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

A
annie_wangli 已提交
649
**Parameters**
S
shawn_he 已提交
650

A
annie_wangli 已提交
651 652 653
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | Yes   | Resource ID.             |
S
shawn_he 已提交
654
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
655

S
shawn_he 已提交
656 657 658 659 660 661 662 663 664
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 已提交
665
**Example**
S
shawn_he 已提交
666 667 668 669 670 671 672 673 674 675 676 677
  ```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 已提交
678 679 680
  ```


S
shawn_he 已提交
681
### getMediaContent<sup>9+</sup>
A
annie_wangli 已提交
682

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

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

A
annie_wangli 已提交
687 688
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
689
**Parameters**
S
shawn_he 已提交
690

A
annie_wangli 已提交
691 692 693
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
694

A
annie_wangli 已提交
695
**Return value**
S
shawn_he 已提交
696

A
annie_wangli 已提交
697 698
| Type                       | Description            |
| ------------------------- | -------------- |
S
shawn_he 已提交
699
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
700

S
shawn_he 已提交
701 702 703 704 705 706 707 708 709
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 已提交
710
**Example**
S
shawn_he 已提交
711 712 713
  ```ts
  try {
      this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => {
S
shawn_he 已提交
714
          let media = value;
A
annie_wangli 已提交
715
      }).catch(error => {
S
shawn_he 已提交
716
          console.log("getMediaContent promise error is " + error);
A
annie_wangli 已提交
717
      });
S
shawn_he 已提交
718 719 720
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
721 722
  ```

S
shawn_he 已提交
723
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
724

S
shawn_he 已提交
725
getMediaContent(resource: Resource, callback: AsyncCallback&lt;Uint8Array&gt;): void
S
shawn_he 已提交
726 727 728 729 730 731

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 已提交
732 733 734 735

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

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

S
shawn_he 已提交
767
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
768

S
shawn_he 已提交
769
getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
S
shawn_he 已提交
770 771 772 773 774 775

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 已提交
776 777 778

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
779 780 781
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
782

S
shawn_he 已提交
783 784
| Type                       | Description                 |
| ------------------------- | ------------------- |
S
shawn_he 已提交
785
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
S
shawn_he 已提交
786

S
shawn_he 已提交
787 788 789 790 791 792 793 794 795
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 已提交
796
**Example**
S
shawn_he 已提交
797
  ```ts
S
shawn_he 已提交
798 799 800 801 802
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
803 804
  try {
    this.context.resourceManager.getMediaContent(resource).then(value => {
S
shawn_he 已提交
805
      let media = value;
S
shawn_he 已提交
806 807 808 809 810 811
    }).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 已提交
812
  ```
A
annie_wangli 已提交
813 814


S
shawn_he 已提交
815 816 817
### getMediaContentBase64<sup>9+</sup>

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

S
shawn_he 已提交
819
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 已提交
820 821 822

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

A
annie_wangli 已提交
823
**Parameters**
S
shawn_he 已提交
824

A
annie_wangli 已提交
825 826 827
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
S
shawn_he 已提交
828
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
829

S
shawn_he 已提交
830 831 832 833 834 835 836 837 838
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 已提交
839
**Example**
S
shawn_he 已提交
840 841 842 843 844 845 846 847 848 849 850 851
  ```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 已提交
852 853 854
  ```


S
shawn_he 已提交
855
### getMediaContentBase64<sup>9+</sup>
A
annie_wangli 已提交
856

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

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

A
annie_wangli 已提交
861 862
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
863
**Parameters**
S
shawn_he 已提交
864

A
annie_wangli 已提交
865 866 867
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
868

A
annie_wangli 已提交
869
**Return value**
S
shawn_he 已提交
870

A
annie_wangli 已提交
871 872
| Type                   | Description                  |
| --------------------- | -------------------- |
S
shawn_he 已提交
873
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
874

S
shawn_he 已提交
875 876 877 878 879 880 881 882 883
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 已提交
884
**Example**
S
shawn_he 已提交
885 886 887 888 889 890 891 892 893 894
  ```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 已提交
895 896
  ```

S
shawn_he 已提交
897
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
898

S
shawn_he 已提交
899
getMediaContentBase64(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
S
shawn_he 已提交
900 901 902 903 904 905

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 已提交
906

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

S
shawn_he 已提交
912 913 914 915 916 917 918 919 920
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 已提交
921
**Example**
S
shawn_he 已提交
922
  ```ts
S
shawn_he 已提交
923 924 925 926 927
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
928 929 930 931 932 933 934 935 936 937 938
  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 已提交
939 940
  ```

S
shawn_he 已提交
941
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
942

S
shawn_he 已提交
943
getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
944 945 946 947 948 949

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 已提交
950 951 952

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
953 954 955
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
956

S
shawn_he 已提交
957 958 959 960 961 962 963 964 965 966 967 968
| 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 已提交
969 970

**Example**
S
shawn_he 已提交
971
  ```ts
S
shawn_he 已提交
972 973 974 975 976
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
977 978 979 980 981 982 983 984 985
  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 已提交
986 987
  ```

A
annie_wangli 已提交
988 989 990 991 992

### getConfiguration

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

S
shawn_he 已提交
993
Obtains the device configuration. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
994 995 996

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

A
annie_wangli 已提交
997
**Parameters**
S
shawn_he 已提交
998

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

A
annie_wangli 已提交
1003
**Example**
S
shawn_he 已提交
1004
  ```ts
A
annie_wangli 已提交
1005 1006 1007
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration((error, value) => {
          if (error != null) {
S
shawn_he 已提交
1008
              console.log("error is " + error);
A
annie_wangli 已提交
1009
          } else {
S
shawn_he 已提交
1010 1011
              let direction = value.direction;
              let locale = value.locale;
A
annie_wangli 已提交
1012 1013 1014 1015 1016 1017 1018 1019 1020
          }
      });
  });
  ```


### getConfiguration

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

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

A
annie_wangli 已提交
1024 1025
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1026
**Return value**
S
shawn_he 已提交
1027

A
annie_wangli 已提交
1028 1029
| Type                                      | Description              |
| ---------------------------------------- | ---------------- |
S
shawn_he 已提交
1030
| Promise&lt;[Configuration](#configuration)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1031

A
annie_wangli 已提交
1032
**Example**
S
shawn_he 已提交
1033
  ```ts
A
annie_wangli 已提交
1034 1035
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration().then(value => {
S
shawn_he 已提交
1036 1037
          let direction = value.direction;
          let locale = value.locale;
A
annie_wangli 已提交
1038
      }).catch(error => {
S
shawn_he 已提交
1039
          console.log("getConfiguration promise error is " + error);
A
annie_wangli 已提交
1040 1041 1042 1043 1044 1045 1046 1047 1048
      });
  });
  ```


### getDeviceCapability

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

S
shawn_he 已提交
1049
Obtains the device capability. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1050 1051 1052

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

A
annie_wangli 已提交
1053
**Parameters**
S
shawn_he 已提交
1054

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

A
annie_wangli 已提交
1059
**Example**
S
shawn_he 已提交
1060
  ```ts
A
annie_wangli 已提交
1061 1062 1063
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability((error, value) => {
          if (error != null) {
S
shawn_he 已提交
1064
              console.log("error is " + error);
A
annie_wangli 已提交
1065
          } else {
S
shawn_he 已提交
1066 1067
              let screenDensity = value.screenDensity;
              let deviceType = value.deviceType;
A
annie_wangli 已提交
1068 1069 1070 1071 1072 1073 1074 1075 1076
          }
      });
  });
  ```


### getDeviceCapability

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

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

A
annie_wangli 已提交
1080
**System capability**: SystemCapability.Global.ResourceManager
Z
zengyawen 已提交
1081

A
annie_wangli 已提交
1082
**Return value**
S
shawn_he 已提交
1083

A
annie_wangli 已提交
1084 1085
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1086
| Promise&lt;[DeviceCapability](#devicecapability)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1087

A
annie_wangli 已提交
1088
**Example**
S
shawn_he 已提交
1089
  ```ts
A
annie_wangli 已提交
1090 1091
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability().then(value => {
S
shawn_he 已提交
1092 1093
          let screenDensity = value.screenDensity;
          let deviceType = value.deviceType;
A
annie_wangli 已提交
1094
      }).catch(error => {
S
shawn_he 已提交
1095
          console.log("getDeviceCapability promise error is " + error);
A
annie_wangli 已提交
1096 1097 1098 1099 1100
      });
  });
  ```


S
shawn_he 已提交
1101
### getPluralStringValue<sup>9+</sup>
Z
zengyawen 已提交
1102

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

S
shawn_he 已提交
1105
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 已提交
1106 1107 1108

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

A
annie_wangli 已提交
1109
**Parameters**
S
shawn_he 已提交
1110

A
annie_wangli 已提交
1111 1112 1113
| Name     | Type                         | Mandatory  | Description                             |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | Yes   | Resource ID.                          |
S
shawn_he 已提交
1114 1115
| num      | number                      | Yes   | Number.                            |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1116

S
shawn_he 已提交
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
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 已提交
1127
**Example**
S
shawn_he 已提交
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
  ```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 已提交
1140 1141 1142
  ```


S
shawn_he 已提交
1143
### getPluralStringValue<sup>9+</sup>
A
annie_wangli 已提交
1144

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

S
shawn_he 已提交
1147
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 已提交
1148

A
annie_wangli 已提交
1149 1150
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1151
**Parameters**
S
shawn_he 已提交
1152

A
annie_wangli 已提交
1153 1154 1155
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
1156
| num   | number | Yes   | Number.  |
A
annie_wangli 已提交
1157

A
annie_wangli 已提交
1158
**Return value**
S
shawn_he 已提交
1159

A
annie_wangli 已提交
1160 1161
| Type                   | Description                       |
| --------------------- | ------------------------- |
S
shawn_he 已提交
1162
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1163

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

S
shawn_he 已提交
1166
**Error codes**
S
shawn_he 已提交
1167

S
shawn_he 已提交
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
| 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 已提交
1190 1191 1192 1193 1194 1195

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 已提交
1196 1197 1198 1199 1200

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

S
shawn_he 已提交
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
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 已提交
1213
**Example**
S
shawn_he 已提交
1214
  ```ts
S
shawn_he 已提交
1215 1216 1217 1218 1219
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
  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 已提交
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
  ```

### 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 已提交
1243 1244 1245

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
1246
| resource | [Resource](#resource9) | Yes   | Resource object.|
S
shawn_he 已提交
1247
| num      | number                 | Yes   | Number. |
S
shawn_he 已提交
1248 1249

**Return value**
S
shawn_he 已提交
1250

S
shawn_he 已提交
1251 1252
| Type                   | Description                            |
| --------------------- | ------------------------------ |
S
shawn_he 已提交
1253 1254
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
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 已提交
1265
**Example**
S
shawn_he 已提交
1266
  ```ts
S
shawn_he 已提交
1267 1268 1269 1270 1271
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1272 1273 1274 1275 1276 1277 1278 1279 1280
  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 已提交
1281 1282
  ```

A
annie_wangli 已提交
1283

S
shawn_he 已提交
1284 1285 1286
### getRawFileContent<sup>9+</sup>

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

S
shawn_he 已提交
1288
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 已提交
1289 1290 1291

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

A
annie_wangli 已提交
1292
**Parameters**
S
shawn_he 已提交
1293

A
annie_wangli 已提交
1294 1295 1296
| Name     | Type                             | Mandatory  | Description                     |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | Yes   | Path of the raw file.            |
S
shawn_he 已提交
1297
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1298

S
shawn_he 已提交
1299 1300 1301 1302 1303 1304 1305 1306
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 已提交
1307
**Example**
S
shawn_he 已提交
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
  ```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 已提交
1321 1322
  ```

S
shawn_he 已提交
1323
### getRawFileContent<sup>9+</sup>
A
annie_wangli 已提交
1324

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

S
shawn_he 已提交
1327
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1328 1329 1330

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

A
annie_wangli 已提交
1331
**Parameters**
S
shawn_he 已提交
1332

A
annie_wangli 已提交
1333 1334 1335
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1336

A
annie_wangli 已提交
1337
**Return value**
S
shawn_he 已提交
1338

A
annie_wangli 已提交
1339 1340
| Type                       | Description         |
| ------------------------- | ----------- |
S
shawn_he 已提交
1341
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1342

S
shawn_he 已提交
1343 1344 1345 1346 1347 1348 1349 1350
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 已提交
1351
**Example**
S
shawn_he 已提交
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
  ```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 已提交
1362 1363 1364
  ```


S
shawn_he 已提交
1365 1366 1367
### getRawFd<sup>9+</sup>

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

S
shawn_he 已提交
1369
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 已提交
1370 1371 1372

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

A
annie_wangli 已提交
1373
**Parameters**
S
shawn_he 已提交
1374

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

S
shawn_he 已提交
1380 1381 1382 1383 1384 1385 1386 1387
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 已提交
1388
**Example**
S
shawn_he 已提交
1389 1390 1391 1392
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml", (error, value) => {
        if (error != null) {
S
shawn_he 已提交
1393
            console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1394 1395 1396 1397 1398
        } else {
            let fd = value.fd;
            let offset = value.offset;
            let length = value.length;
        }
S
shawn_he 已提交
1399 1400 1401 1402
    });
  } catch (error) {
      console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`)
  };
A
annie_wangli 已提交
1403 1404
  ```

S
shawn_he 已提交
1405
### getRawFd<sup>9+</sup>
A
annie_wangli 已提交
1406

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

S
shawn_he 已提交
1409
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1410 1411 1412

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

A
annie_wangli 已提交
1413
**Parameters**
S
shawn_he 已提交
1414

A
annie_wangli 已提交
1415 1416 1417
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1418

A
annie_wangli 已提交
1419
**Return value**
S
shawn_he 已提交
1420

A
annie_wangli 已提交
1421 1422
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1423
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1424

S
shawn_he 已提交
1425 1426 1427 1428 1429 1430 1431 1432
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 已提交
1433
**Example**
S
shawn_he 已提交
1434 1435 1436 1437 1438 1439 1440
  ```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 已提交
1441
        console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1442 1443
    });
  } catch (error) {
S
shawn_he 已提交
1444
    console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1445
  };
A
annie_wangli 已提交
1446 1447 1448 1449 1450 1451
  ```

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

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

S
shawn_he 已提交
1452
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 已提交
1453 1454 1455

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

A
annie_wangli 已提交
1456
**Parameters**
S
shawn_he 已提交
1457

A
annie_wangli 已提交
1458 1459 1460
| Name     | Type                       | Mandatory  | Description         |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | Yes   | Path of the raw file.|
S
shawn_he 已提交
1461
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.       |
A
annie_wangli 已提交
1462

A
annie_wangli 已提交
1463
**Example**
S
shawn_he 已提交
1464
  ```ts
A
annie_wangli 已提交
1465 1466 1467
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
S
shawn_he 已提交
1468
              console.log("error is " + error);
A
annie_wangli 已提交
1469 1470 1471 1472 1473 1474 1475 1476 1477
          }
      });
  });
  ```

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

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

S
shawn_he 已提交
1478
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1479 1480 1481

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

A
annie_wangli 已提交
1482
**Parameters**
S
shawn_he 已提交
1483

A
annie_wangli 已提交
1484 1485 1486
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1487

A
annie_wangli 已提交
1488
**Return value**
S
shawn_he 已提交
1489

A
annie_wangli 已提交
1490 1491
| Type                 | Description  |
| ------------------- | ---- |
S
shawn_he 已提交
1492
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
1493

A
annie_wangli 已提交
1494
**Example**
S
shawn_he 已提交
1495
  ```ts
A
annie_wangli 已提交
1496 1497
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml").then(value => {
S
shawn_he 已提交
1498
          let result = value;
A
annie_wangli 已提交
1499
      }).catch(error => {
S
shawn_he 已提交
1500
          console.log("closeRawFileDescriptor promise error is " + error);
A
annie_wangli 已提交
1501 1502 1503 1504
      });
  });
  ```

S
shawn_he 已提交
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

### 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**
S
shawn_he 已提交
1558

S
shawn_he 已提交
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
| 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 已提交
1584 1585
### release<sup>7+</sup>

A
annie_wangli 已提交
1586
release()
A
annie_wangli 已提交
1587

S
shawn_he 已提交
1588
Releases a created **resourceManager** object.
A
annie_wangli 已提交
1589 1590 1591

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

A
annie_wangli 已提交
1592
**Example**
S
shawn_he 已提交
1593
  ```ts
A
annie_wangli 已提交
1594
  resourceManager.getResourceManager((error, mgr) => {
S
shawn_he 已提交
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607
      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 已提交
1608

S
shawn_he 已提交
1609 1610
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
S
shawn_he 已提交
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
| 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 已提交
1623 1624

**Example**
S
shawn_he 已提交
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
  ```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 已提交
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
  ```

### 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 已提交
1649 1650

| Name    | Type    | Mandatory  | Description  |
S
shawn_he 已提交
1651
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1652
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1653 1654

**Return value**
S
shawn_he 已提交
1655

S
shawn_he 已提交
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668
| 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 已提交
1669 1670

**Example**
S
shawn_he 已提交
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
  ```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 已提交
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
  ```

### 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 已提交
1692

S
shawn_he 已提交
1693 1694
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
S
shawn_he 已提交
1695
| resName  | string                                   | Yes   | Resource name.             |
S
shawn_he 已提交
1696
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1697

S
shawn_he 已提交
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
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 已提交
1708
**Example**
S
shawn_he 已提交
1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
  ```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 已提交
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731
  ```

### 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 已提交
1732 1733 1734 1735

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

**Return value**
S
shawn_he 已提交
1738

S
shawn_he 已提交
1739 1740
| Type                                | Description          |
| ---------------------------------- | ------------ |
S
shawn_he 已提交
1741 1742
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|

S
shawn_he 已提交
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752
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 已提交
1753
**Example**
S
shawn_he 已提交
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
  ```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 已提交
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774
  ```

### 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 已提交
1775

S
shawn_he 已提交
1776 1777
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
S
shawn_he 已提交
1778
| resName  | string                          | Yes   | Resource name.              |
S
shawn_he 已提交
1779
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1780

S
shawn_he 已提交
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790
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 已提交
1791
**Example**
S
shawn_he 已提交
1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
  ```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 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
  ```

### 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 已提交
1815 1816 1817

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1818 1819 1820
| resName | string | Yes   | Resource name.|

**Return value**
S
shawn_he 已提交
1821

S
shawn_he 已提交
1822 1823
| Type                       | Description           |
| ------------------------- | ------------- |
S
shawn_he 已提交
1824 1825
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

S
shawn_he 已提交
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
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 已提交
1836
**Example**
S
shawn_he 已提交
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846
  ```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 已提交
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
  ```

### 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 已提交
1858

S
shawn_he 已提交
1859 1860
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
S
shawn_he 已提交
1861
| resName  | string                      | Yes   | Resource name.                    |
S
shawn_he 已提交
1862
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
1863

S
shawn_he 已提交
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873
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 已提交
1874
**Example**
S
shawn_he 已提交
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886
  ```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 已提交
1887
  ```
S
shawn_he 已提交
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897

### 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 已提交
1898 1899 1900 1901

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

**Return value**
S
shawn_he 已提交
1904

S
shawn_he 已提交
1905 1906
| Type                   | Description                 |
| --------------------- | ------------------- |
S
shawn_he 已提交
1907 1908
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
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 已提交
1919
**Example**
S
shawn_he 已提交
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
  ```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 已提交
1930 1931 1932 1933 1934 1935
  ```

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

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

S
shawn_he 已提交
1936
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 已提交
1937 1938 1939 1940

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

**Parameters**
S
shawn_he 已提交
1941 1942 1943 1944 1945

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

S
shawn_he 已提交
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
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 已提交
1958
**Example**
S
shawn_he 已提交
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
  ```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 已提交
1972 1973 1974 1975 1976 1977
  ```

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

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

S
shawn_he 已提交
1978
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 已提交
1979 1980 1981 1982

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

**Parameters**
S
shawn_he 已提交
1983 1984 1985

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1986
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1987
| num     | number | Yes   | Number. |
S
shawn_he 已提交
1988 1989

**Return value**
S
shawn_he 已提交
1990

S
shawn_he 已提交
1991 1992
| Type                   | Description                    |
| --------------------- | ---------------------- |
S
shawn_he 已提交
1993 1994
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
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 已提交
2005
**Example**
S
shawn_he 已提交
2006 2007 2008
  ```ts
  try {
    this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
S
shawn_he 已提交
2009
      let str = value;
S
shawn_he 已提交
2010
    }).catch(error => {
S
shawn_he 已提交
2011
      console.log("getPluralStringByName promise error is " + error);
S
shawn_he 已提交
2012 2013 2014 2015
    });
  } catch (error) {
    console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026
  ```

### 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 已提交
2027

S
shawn_he 已提交
2028 2029 2030 2031 2032
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2033

S
shawn_he 已提交
2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
| 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 已提交
2047 2048

**Example**
S
shawn_he 已提交
2049 2050 2051 2052 2053 2054
  ```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 已提交
2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
  ```

### 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 已提交
2066 2067 2068

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2069 2070 2071
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2072

S
shawn_he 已提交
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085
| 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 已提交
2086 2087

**Example**
S
shawn_he 已提交
2088
  ```ts
S
shawn_he 已提交
2089 2090 2091 2092 2093
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
2094 2095 2096 2097 2098
  try {
    this.context.resourceManager.getStringSync(resource);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
  ```

### 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 已提交
2110 2111 2112

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2113 2114 2115
| resName | string | Yes   | Resource name.|

**Return value**
S
shawn_he 已提交
2116

S
shawn_he 已提交
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129
| 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 已提交
2130 2131

**Example**
S
shawn_he 已提交
2132 2133 2134 2135 2136 2137
  ```ts
  try {
    this.context.resourceManager.getStringByNameSync("test");
  } catch (error) {
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2138 2139
  ```

S
shawn_he 已提交
2140
### getBoolean<sup>9+</sup>
S
shawn_he 已提交
2141 2142 2143 2144 2145 2146 2147 2148

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 已提交
2149

S
shawn_he 已提交
2150 2151 2152 2153 2154
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2155

S
shawn_he 已提交
2156 2157
| Type     | Description          |
| ------- | ------------ |
S
shawn_he 已提交
2158 2159
| boolean | Boolean result corresponding to the specified resource ID.|

S
shawn_he 已提交
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169
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 已提交
2170
**Example**
S
shawn_he 已提交
2171 2172 2173 2174 2175 2176
  ```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 已提交
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186
  ```
### 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 已提交
2187 2188 2189

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2190 2191 2192
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2193

S
shawn_he 已提交
2194 2195
| Type     | Description               |
| ------- | ----------------- |
S
shawn_he 已提交
2196 2197
| boolean | Boolean result corresponding to the specified resource object.|

S
shawn_he 已提交
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207
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 已提交
2208
**Example**
S
shawn_he 已提交
2209
  ```ts
S
shawn_he 已提交
2210 2211 2212 2213 2214
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.boolean.boolean_test').id
  };
S
shawn_he 已提交
2215 2216 2217 2218 2219
  try {
    this.context.resourceManager.getBoolean(resource);
  } catch (error) {
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230
  ```

### 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 已提交
2231 2232 2233 2234

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

**Return value**
S
shawn_he 已提交
2237

S
shawn_he 已提交
2238 2239
| Type     | Description         |
| ------- | ----------- |
S
shawn_he 已提交
2240 2241
| boolean | Boolean result corresponding to the specified resource name.|

S
shawn_he 已提交
2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
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 已提交
2252
**Example**
S
shawn_he 已提交
2253 2254 2255 2256 2257 2258
  ```ts
  try {
    this.context.resourceManager.getBooleanByName("boolean_test");
  } catch (error) {
    console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2259 2260
  ```

S
shawn_he 已提交
2261
### getNumber<sup>9+</sup>
S
shawn_he 已提交
2262 2263 2264 2265 2266 2267 2268 2269

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 已提交
2270

S
shawn_he 已提交
2271 2272 2273 2274 2275
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
S
shawn_he 已提交
2276

S
shawn_he 已提交
2277 2278
| Type    | Description        |
| ------ | ---------- |
S
shawn_he 已提交
2279 2280
| number | Integer or float value corresponding to the specified resource ID.|

S
shawn_he 已提交
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290
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 已提交
2291
**Example**
S
shawn_he 已提交
2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303
  ```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 已提交
2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
  ```

### 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 已提交
2315 2316 2317

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2318 2319 2320
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
S
shawn_he 已提交
2321

S
shawn_he 已提交
2322 2323
| Type    | Description             |
| ------ | --------------- |
S
shawn_he 已提交
2324 2325
| number | Integer or float value corresponding to the specified resource object.|

S
shawn_he 已提交
2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
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 已提交
2336
**Example**
S
shawn_he 已提交
2337
  ```ts
S
shawn_he 已提交
2338 2339 2340 2341 2342
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.integer.integer_test').id
  };
S
shawn_he 已提交
2343 2344 2345 2346 2347
  try {
    this.context.resourceManager.getNumber(resource);
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
  ```

### 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 已提交
2359 2360 2361 2362 2363 2364

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

**Return value**
S
shawn_he 已提交
2365

S
shawn_he 已提交
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 2407 2408 2409 2410 2411 2412 2413 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
| 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 已提交
2439 2440
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
S
shawn_he 已提交
2441
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
2442 2443

**Return value**
S
shawn_he 已提交
2444

S
shawn_he 已提交
2445 2446
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476
| 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 已提交
2477 2478

**Example**
S
shawn_he 已提交
2479 2480 2481 2482 2483 2484 2485 2486 2487 2488
  ```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 已提交
2489
  ```
S
shawn_he 已提交
2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508


### 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**
S
shawn_he 已提交
2509

S
shawn_he 已提交
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
| 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.

S
shawn_he 已提交
2532
This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead.
S
shawn_he 已提交
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

**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.

S
shawn_he 已提交
2563
This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1) instead.
S
shawn_he 已提交
2564 2565 2566 2567 2568 2569 2570 2571 2572 2573

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

**Parameters**

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

**Return value**
S
shawn_he 已提交
2574

S
shawn_he 已提交
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
| 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.

S
shawn_he 已提交
2597
This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649) instead.
S
shawn_he 已提交
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

**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.

S
shawn_he 已提交
2628
This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1) instead.
S
shawn_he 已提交
2629 2630 2631 2632 2633 2634 2635 2636 2637 2638

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

**Parameters**

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

**Return value**
S
shawn_he 已提交
2639

S
shawn_he 已提交
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
| 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.

S
shawn_he 已提交
2662
This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9) instead.
S
shawn_he 已提交
2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673

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

**Parameters**

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

**Return value**
S
shawn_he 已提交
2674

S
shawn_he 已提交
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696
| 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.

S
shawn_he 已提交
2697
This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1) instead.
S
shawn_he 已提交
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

**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**
S
shawn_he 已提交
2771

S
shawn_he 已提交
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 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836
| 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**
S
shawn_he 已提交
2837

S
shawn_he 已提交
2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852
| 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 已提交
2853
  ```