js-apis-resource-manager.md 93.0 KB
Newer Older
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 19
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. For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object.
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
```ts
S
shawn_he 已提交
22 23 24
import UIAbility from '@ohos.app.ability.UIAbility';

export default class EntryAbility extends UIAbility {
S
shawn_he 已提交
25 26 27 28 29
    onWindowStageCreate(windowStage) {
        let context = this.context;
        let resourceManager = context.resourceManager;
    }
}
S
shawn_he 已提交
30 31
```

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

getResourceManager(callback: AsyncCallback<ResourceManager>): void

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

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

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

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

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

A
annie_wangli 已提交
48
**Example**
S
shawn_he 已提交
49
  ```js
A
annie_wangli 已提交
50 51
  resourceManager.getResourceManager((error, mgr) => {
      if (error != null) {
S
shawn_he 已提交
52
          console.log("error is " + error);
A
annie_wangli 已提交
53 54 55 56
          return; 
      }
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
S
shawn_he 已提交
57
              console.log("error is " + error);
A
annie_wangli 已提交
58
          } else {
S
shawn_he 已提交
59
              let str = value;
A
annie_wangli 已提交
60 61 62 63
          }
      });
  });
  ```
S
shawn_he 已提交
64
> **NOTE**<br>In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file.
A
annie_wangli 已提交
65 66 67 68 69 70


## resourceManager.getResourceManager

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

S
shawn_he 已提交
71 72
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 已提交
73
**Model restriction**: This API can be used only in the FA model.
A
annie_wangli 已提交
74 75 76

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

A
annie_wangli 已提交
77
**Parameters**
S
shawn_he 已提交
78

A
annie_wangli 已提交
79 80
| Name       | Type                                      | Mandatory  | Description                           |
| ---------- | ---------------------------------------- | ---- | ----------------------------- |
S
shawn_he 已提交
81
| bundleName | string                                   | Yes   | Bundle name of the application.                |
S
shawn_he 已提交
82
| callback   | AsyncCallback&lt;[ResourceManager](#resourcemanager)&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
83

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


## resourceManager.getResourceManager

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

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

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

A
annie_wangli 已提交
99 100
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
101
**Return value**
102

A
annie_wangli 已提交
103 104
| Type                                      | Description               |
| ---------------------------------------- | ----------------- |
S
shawn_he 已提交
105
| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
106

A
annie_wangli 已提交
107
**Example**
S
shawn_he 已提交
108
  ```js
A
annie_wangli 已提交
109 110 111
  resourceManager.getResourceManager().then(mgr => {
      mgr.getString(0x1000000, (error, value) => {
          if (error != null) {
S
shawn_he 已提交
112
              console.log("error is " + error);
A
annie_wangli 已提交
113
          } else {
S
shawn_he 已提交
114
              let str = value;
A
annie_wangli 已提交
115 116 117
          }
      });
  }).catch(error => {
S
shawn_he 已提交
118
      console.log("error is " + error);
A
annie_wangli 已提交
119 120
  });
  ```
S
shawn_he 已提交
121
> **NOTE**<br>In the sample code, **0x1000000** indicates the resource ID, which can be found in the compiled **ResourceTable.txt** file.
A
annie_wangli 已提交
122 123 124 125 126 127


## resourceManager.getResourceManager

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

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

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

A
annie_wangli 已提交
134
**Parameters**
S
shawn_he 已提交
135

A
annie_wangli 已提交
136 137
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
S
shawn_he 已提交
138
| bundleName | string | Yes   | Bundle name of the application.|
A
annie_wangli 已提交
139

A
annie_wangli 已提交
140
**Return value**
141

A
annie_wangli 已提交
142 143
| Type                                      | Description                |
| ---------------------------------------- | ------------------ |
S
shawn_he 已提交
144
| Promise&lt;[ResourceManager](#resourcemanager)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
145

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


## Direction

Enumerates the screen directions.

A
annie_wangli 已提交
158 159
**System capability**: SystemCapability.Global.ResourceManager

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


## DeviceType

Enumerates the device types.

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

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


## ScreenDensity

Enumerates the screen density types.

A
annie_wangli 已提交
186 187
**System capability**: SystemCapability.Global.ResourceManager

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


## Configuration

Defines the device configuration.

A
annie_wangli 已提交
202 203
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
204
**Parameters**
A
annie_wangli 已提交
205

A
annie_wangli 已提交
206 207 208 209
| 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 已提交
210

S
shawn_he 已提交
211 212
**Example**

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

## DeviceCapability

Defines the device capability.

A
annie_wangli 已提交
226 227
**System capability**: SystemCapability.Global.ResourceManager

S
shawn_he 已提交
228
**Parameters**
A
annie_wangli 已提交
229

A
annie_wangli 已提交
230 231 232 233
| 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 已提交
234

S
shawn_he 已提交
235 236
**Example**

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

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

S
shawn_he 已提交
248 249
Defines the descriptor of the raw file.

A
annie_wangli 已提交
250
**System capability**: SystemCapability.Global.ResourceManager
A
annie_wangli 已提交
251

S
shawn_he 已提交
252 253 254 255 256 257 258
**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 已提交
259

S
shawn_he 已提交
260 261 262 263 264 265
## Resource<sup>9+</sup>

Defines the resource information of an application.

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

S
shawn_he 已提交
266 267 268 269 270 271 272
**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 已提交
273

A
annie_wangli 已提交
274 275 276 277 278

## ResourceManager

Defines the capability of accessing application resources.

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

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

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

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

A
annie_wangli 已提交
293
**Parameters**
S
shawn_he 已提交
294

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

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


S
shawn_he 已提交
326
### getStringValue<sup>9+</sup>
A
annie_wangli 已提交
327

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

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

A
annie_wangli 已提交
332 333
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
334
**Parameters**
S
shawn_he 已提交
335

A
annie_wangli 已提交
336 337 338
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
339

A
annie_wangli 已提交
340
**Return value**
341

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

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


S
shawn_he 已提交
370
### getStringValue<sup>9+</sup>
S
shawn_he 已提交
371

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

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

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

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


S
shawn_he 已提交
417 418 419
### getStringValue<sup>9+</sup>

getStringValue(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
420 421 422 423 424 425

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 已提交
426 427 428

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
429 430 431
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
432

S
shawn_he 已提交
433 434
| Type                   | Description              |
| --------------------- | ---------------- |
S
shawn_he 已提交
435 436
| Promise&lt;string&gt; | Promise used to return the result.|

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

A
annie_wangli 已提交
465

S
shawn_he 已提交
466 467 468
### getStringArrayValue<sup>9+</sup>

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

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

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

A
annie_wangli 已提交
474
**Parameters**
S
shawn_he 已提交
475

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

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


S
shawn_he 已提交
507
### getStringArrayValue<sup>9+</sup>
A
annie_wangli 已提交
508

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

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

A
annie_wangli 已提交
513 514
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
515
**Parameters**
S
shawn_he 已提交
516

A
annie_wangli 已提交
517 518 519
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
520

A
annie_wangli 已提交
521
**Return value**
522

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

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

S
shawn_he 已提交
550
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
551

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

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 已提交
559 560 561 562

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

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

S
shawn_he 已提交
595
### getStringArrayValue<sup>9+</sup>
S
shawn_he 已提交
596

S
shawn_he 已提交
597
getStringArrayValue(resource: Resource): Promise&lt;Array&lt;string&gt;&gt;
S
shawn_he 已提交
598 599 600 601 602 603

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 已提交
604 605 606

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
607 608 609
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
610

S
shawn_he 已提交
611 612
| Type                                | Description                |
| ---------------------------------- | ------------------ |
S
shawn_he 已提交
613
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
S
shawn_he 已提交
614

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


S
shawn_he 已提交
644 645 646
### getMediaContent<sup>9+</sup>

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

S
shawn_he 已提交
648
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 已提交
649 650 651

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

A
annie_wangli 已提交
652
**Parameters**
S
shawn_he 已提交
653

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

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


S
shawn_he 已提交
684
### getMediaContent<sup>9+</sup>
A
annie_wangli 已提交
685

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

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

A
annie_wangli 已提交
690 691
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
692
**Parameters**
S
shawn_he 已提交
693

A
annie_wangli 已提交
694 695 696
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
697

A
annie_wangli 已提交
698
**Return value**
699

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

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

S
shawn_he 已提交
726
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
727

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

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 已提交
735 736 737 738

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

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

S
shawn_he 已提交
770
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
771

S
shawn_he 已提交
772
getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
S
shawn_he 已提交
773 774 775 776 777 778

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 已提交
779 780 781

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
782 783 784
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
785

S
shawn_he 已提交
786 787
| Type                       | Description                 |
| ------------------------- | ------------------- |
S
shawn_he 已提交
788
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
S
shawn_he 已提交
789

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


S
shawn_he 已提交
818 819 820
### getMediaContentBase64<sup>9+</sup>

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

S
shawn_he 已提交
822
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 已提交
823 824 825

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

A
annie_wangli 已提交
826
**Parameters**
S
shawn_he 已提交
827

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

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


S
shawn_he 已提交
858
### getMediaContentBase64<sup>9+</sup>
A
annie_wangli 已提交
859

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

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

A
annie_wangli 已提交
864 865
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
866
**Parameters**
S
shawn_he 已提交
867

A
annie_wangli 已提交
868 869 870
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
871

A
annie_wangli 已提交
872
**Return value**
873

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

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

S
shawn_he 已提交
900
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
901

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

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

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

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

S
shawn_he 已提交
944
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
945

S
shawn_he 已提交
946
getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
947 948 949 950 951 952

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 已提交
953 954 955

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
956 957 958
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
959

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

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

A
annie_wangli 已提交
991 992 993 994 995

### getConfiguration

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

S
shawn_he 已提交
996
Obtains the device configuration. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
997 998 999

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

A
annie_wangli 已提交
1000
**Parameters**
S
shawn_he 已提交
1001

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

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


### getConfiguration

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

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

A
annie_wangli 已提交
1027 1028
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1029
**Return value**
1030

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

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


### getDeviceCapability

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

S
shawn_he 已提交
1052
Obtains the device capability. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1053 1054 1055

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

A
annie_wangli 已提交
1056
**Parameters**
S
shawn_he 已提交
1057

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

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


### getDeviceCapability

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

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

A
annie_wangli 已提交
1083
**System capability**: SystemCapability.Global.ResourceManager
Z
zengyawen 已提交
1084

A
annie_wangli 已提交
1085
**Return value**
1086

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

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


S
shawn_he 已提交
1104
### getPluralStringValue<sup>9+</sup>
Z
zengyawen 已提交
1105

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

S
shawn_he 已提交
1108
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 已提交
1109 1110 1111

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

A
annie_wangli 已提交
1112
**Parameters**
S
shawn_he 已提交
1113

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

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


S
shawn_he 已提交
1146
### getPluralStringValue<sup>9+</sup>
A
annie_wangli 已提交
1147

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

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

A
annie_wangli 已提交
1152 1153
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1154
**Parameters**
S
shawn_he 已提交
1155

A
annie_wangli 已提交
1156 1157 1158
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
1159
| num   | number | Yes   | Number.  |
A
annie_wangli 已提交
1160

A
annie_wangli 已提交
1161
**Return value**
1162

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

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

S
shawn_he 已提交
1169
**Error codes**
S
shawn_he 已提交
1170

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

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 已提交
1199 1200 1201 1202 1203

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

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

### 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 已提交
1246 1247 1248

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

**Return value**
1253

S
shawn_he 已提交
1254 1255
| Type                   | Description                            |
| --------------------- | ------------------------------ |
S
shawn_he 已提交
1256 1257
| Promise&lt;string&gt; | Promise used to return the result.|

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

A
annie_wangli 已提交
1286

S
shawn_he 已提交
1287 1288 1289
### getRawFileContent<sup>9+</sup>

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

S
shawn_he 已提交
1291
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 已提交
1292 1293 1294

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

A
annie_wangli 已提交
1295
**Parameters**
S
shawn_he 已提交
1296

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

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

S
shawn_he 已提交
1326
### getRawFileContent<sup>9+</sup>
A
annie_wangli 已提交
1327

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

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

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

A
annie_wangli 已提交
1334
**Parameters**
S
shawn_he 已提交
1335

A
annie_wangli 已提交
1336 1337 1338
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1339

A
annie_wangli 已提交
1340
**Return value**
1341

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

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


S
shawn_he 已提交
1368 1369 1370
### getRawFd<sup>9+</sup>

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

S
shawn_he 已提交
1372
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 已提交
1373 1374 1375

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

A
annie_wangli 已提交
1376
**Parameters**
S
shawn_he 已提交
1377

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

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

S
shawn_he 已提交
1408
### getRawFd<sup>9+</sup>
A
annie_wangli 已提交
1409

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

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

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

A
annie_wangli 已提交
1416
**Parameters**
S
shawn_he 已提交
1417

A
annie_wangli 已提交
1418 1419 1420
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1421

A
annie_wangli 已提交
1422
**Return value**
1423

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

S
shawn_he 已提交
1428 1429 1430 1431 1432 1433 1434 1435
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 已提交
1436
**Example**
S
shawn_he 已提交
1437 1438 1439 1440 1441 1442 1443
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml").then(value => {
        let fd = value.fd;
        let offset = value.offset;
        let length = value.length;
    }).catch(error => {
1444
        console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1445 1446
    });
  } catch (error) {
1447
    console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1448
  };
A
annie_wangli 已提交
1449 1450 1451 1452 1453 1454
  ```

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

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

S
shawn_he 已提交
1455
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 已提交
1456 1457 1458

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

A
annie_wangli 已提交
1459
**Parameters**
S
shawn_he 已提交
1460

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

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

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

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

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

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

A
annie_wangli 已提交
1485
**Parameters**
S
shawn_he 已提交
1486

A
annie_wangli 已提交
1487 1488 1489
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1490

A
annie_wangli 已提交
1491
**Return value**
1492

A
annie_wangli 已提交
1493 1494
| Type                 | Description  |
| ------------------- | ---- |
S
shawn_he 已提交
1495
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
1496

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

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

### 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}.`)
  }
      
  ```

S
shawn_he 已提交
1546
### closeRawFd<sup>9+</sup>
S
shawn_he 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560

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

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

A
annie_wangli 已提交
1589
release()
A
annie_wangli 已提交
1590

S
shawn_he 已提交
1591
Releases a created **resourceManager** object.
A
annie_wangli 已提交
1592 1593 1594

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

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

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

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

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

| Name    | Type    | Mandatory  | Description  |
S
shawn_he 已提交
1654
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1655
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1656 1657

**Return value**
1658

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

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

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

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

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

### 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 已提交
1735 1736 1737 1738

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

**Return value**
1741

S
shawn_he 已提交
1742 1743
| Type                                | Description          |
| ---------------------------------- | ------------ |
S
shawn_he 已提交
1744 1745
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|

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

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

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

S
shawn_he 已提交
1773
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 已提交
1774 1775 1776 1777

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

**Parameters**
S
shawn_he 已提交
1778

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

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

### 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 已提交
1818 1819 1820

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1821 1822 1823
| resName | string | Yes   | Resource name.|

**Return value**
1824

S
shawn_he 已提交
1825 1826
| Type                       | Description           |
| ------------------------- | ------------- |
S
shawn_he 已提交
1827 1828
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

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

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

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

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

### 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 已提交
1901 1902 1903 1904

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

**Return value**
1907

S
shawn_he 已提交
1908 1909
| Type                   | Description                 |
| --------------------- | ------------------- |
S
shawn_he 已提交
1910 1911
| Promise&lt;string&gt; | Promise used to return the result.|

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

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

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

S
shawn_he 已提交
1939
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 已提交
1940 1941 1942 1943

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

**Parameters**
S
shawn_he 已提交
1944 1945 1946 1947 1948

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

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

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

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

S
shawn_he 已提交
1981
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 已提交
1982 1983 1984 1985

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

**Parameters**
S
shawn_he 已提交
1986 1987 1988

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
1989
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
1990
| num     | number | Yes   | Number. |
S
shawn_he 已提交
1991 1992

**Return value**
1993

S
shawn_he 已提交
1994 1995
| Type                   | Description                    |
| --------------------- | ---------------------- |
S
shawn_he 已提交
1996 1997
| Promise&lt;string&gt; | Promise used to return the result.|

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

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

S
shawn_he 已提交
2031 2032 2033 2034 2035
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
2036

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

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

### 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 已提交
2069 2070 2071

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2072 2073 2074
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
2075

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

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

### 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 已提交
2113 2114 2115

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2116 2117 2118
| resName | string | Yes   | Resource name.|

**Return value**
2119

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

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

S
shawn_he 已提交
2143
### getBoolean<sup>9+</sup>
S
shawn_he 已提交
2144 2145 2146 2147 2148 2149 2150 2151

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

S
shawn_he 已提交
2153 2154 2155 2156 2157
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
2158

S
shawn_he 已提交
2159 2160
| Type     | Description          |
| ------- | ------------ |
S
shawn_he 已提交
2161 2162
| boolean | Boolean result corresponding to the specified resource ID.|

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

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2193 2194 2195
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
2196

S
shawn_he 已提交
2197 2198
| Type     | Description               |
| ------- | ----------------- |
S
shawn_he 已提交
2199 2200
| boolean | Boolean result corresponding to the specified resource object.|

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

### 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 已提交
2234 2235 2236 2237

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

**Return value**
2240

S
shawn_he 已提交
2241 2242
| Type     | Description         |
| ------- | ----------- |
S
shawn_he 已提交
2243 2244
| boolean | Boolean result corresponding to the specified resource name.|

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

S
shawn_he 已提交
2264
### getNumber<sup>9+</sup>
S
shawn_he 已提交
2265 2266 2267 2268 2269 2270 2271 2272

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

S
shawn_he 已提交
2274 2275 2276 2277 2278
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

**Return value**
2279

S
shawn_he 已提交
2280 2281
| Type    | Description        |
| ------ | ---------- |
S
shawn_he 已提交
2282 2283
| number | Integer or float value corresponding to the specified resource ID.|

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

### 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 已提交
2318 2319 2320

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2321 2322 2323
| resource | [Resource](#resource9) | Yes   | Resource object.|

**Return value**
2324

S
shawn_he 已提交
2325 2326
| Type    | Description             |
| ------ | --------------- |
S
shawn_he 已提交
2327 2328
| number | Integer or float value corresponding to the specified resource object.|

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

### 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 已提交
2362 2363 2364 2365 2366 2367

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

**Return value**
2368

S
shawn_he 已提交
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 2439 2440 2441
| 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 已提交
2442 2443
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
S
shawn_he 已提交
2444
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
2445 2446

**Return value**
2447

S
shawn_he 已提交
2448 2449
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
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 2477 2478 2479
| 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 已提交
2480 2481

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


### 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**
2512

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

2535
This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead.
S
shawn_he 已提交
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565

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

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

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

**Parameters**

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

**Return value**
2577

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

2600
This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649) instead.
S
shawn_he 已提交
2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630

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

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

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

**Parameters**

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

**Return value**
2642

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

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

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

**Parameters**

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

**Return value**
2677

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

2700
This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1) instead.
S
shawn_he 已提交
2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773

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

S
shawn_he 已提交
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 2837 2838 2839
| 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**
2840

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