js-apis-resource-manager.md 125.1 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.resourceManager (Resource Manager)
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
The **resourceManager** 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
## How to Use
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**
S
shawn_he 已提交
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**
S
shawn_he 已提交
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
**Parameters**

| Name    | Type   | Readable  | Writable | Description          |
| ------ | ------  | ---- | ---- | ------------------ |
S
shawn_he 已提交
256
| fd     | number  | Yes   | No| File descriptor of the HAP where the raw file is located.|
S
shawn_he 已提交
257 258
| 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 methods 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 {
S
shawn_he 已提交
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**
S
shawn_he 已提交
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
**Error codes**

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

S
shawn_he 已提交
350 351 352 353 354 355
| 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
**Error codes**

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

S
shawn_he 已提交
389 390 391 392 393 394
| 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**
S
shawn_he 已提交
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
**Error codes**

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

S
shawn_he 已提交
441 442 443 444 445 446
| 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
**Error codes**

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

S
shawn_he 已提交
485 486 487 488 489 490
| 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**
S
shawn_he 已提交
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
**Error codes**

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

S
shawn_he 已提交
531 532 533 534 535 536
| 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
**Error codes**

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

S
shawn_he 已提交
569 570 571 572 573 574
| 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**
S
shawn_he 已提交
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
**Error codes**

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

S
shawn_he 已提交
619 620 621 622 623 624
| 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

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

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

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

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

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

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

S
shawn_he 已提交
658 659
**Error codes**

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

S
shawn_he 已提交
662 663 664 665 666
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
667
**Example**
S
shawn_he 已提交
668 669 670 671 672 673 674 675 676 677 678 679
  ```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 已提交
680 681
  ```

S
shawn_he 已提交
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
### getMediaContent<sup>10+</sup>

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

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

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

**Parameters**

| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resId    | number                          | Yes   | Resource ID.             |
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

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

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error, value) => {
        if (error != null) {
            console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
A
annie_wangli 已提交
721

S
shawn_he 已提交
722
### getMediaContent<sup>9+</sup>
A
annie_wangli 已提交
723

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

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

A
annie_wangli 已提交
728 729
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
730
**Parameters**
S
shawn_he 已提交
731

A
annie_wangli 已提交
732 733 734
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
735

A
annie_wangli 已提交
736
**Return value**
S
shawn_he 已提交
737

A
annie_wangli 已提交
738 739
| Type                       | Description            |
| ------------------------- | -------------- |
S
shawn_he 已提交
740
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
741

S
shawn_he 已提交
742 743
**Error codes**

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

S
shawn_he 已提交
746 747 748 749 750
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
751
**Example**
S
shawn_he 已提交
752 753 754
  ```ts
  try {
      this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => {
S
shawn_he 已提交
755
          let media = value;
A
annie_wangli 已提交
756
      }).catch(error => {
S
shawn_he 已提交
757
          console.log("getMediaContent promise error is " + error);
A
annie_wangli 已提交
758
      });
S
shawn_he 已提交
759 760 761
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
762 763
  ```

S
shawn_he 已提交
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
### getMediaContent<sup>10+</sup>

getMediaContent(resId: number, density: number): Promise&lt;Uint8Array&gt;

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

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

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

**Example**
  ```ts
  try {
      this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then(value => {
          let media = value;
      }).catch(error => {
          console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
      });
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

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

S
shawn_he 已提交
809
getMediaContent(resource: Resource, callback: AsyncCallback&lt;Uint8Array&gt;): void
S
shawn_he 已提交
810 811 812 813 814 815

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 已提交
816 817 818 819

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

S
shawn_he 已提交
822 823
**Error codes**

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

S
shawn_he 已提交
826 827 828 829 830
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

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

S
shawn_he 已提交
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
### getMediaContent<sup>10+</sup>

getMediaContent(resource: Resource, density: number, callback: AsyncCallback&lt;Uint8Array&gt;): void

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

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

**Parameters**

| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resource | [Resource](#resource9)          | Yes   | Resource object.              |
| [density](#screendensity)  | number        | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

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

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
  try {
    this.context.resourceManager.getMediaContent(resource, 120, (error, value) => {
        if (error != null) {
          console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
          let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
896
### getMediaContent<sup>9+</sup>
S
shawn_he 已提交
897

S
shawn_he 已提交
898
getMediaContent(resource: Resource): Promise&lt;Uint8Array&gt;
S
shawn_he 已提交
899 900 901 902 903 904

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

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
908 909 910
| resource | [Resource](#resource9) | Yes   | Resource object.|

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

S
shawn_he 已提交
912 913
| Type                       | Description                 |
| ------------------------- | ------------------- |
S
shawn_he 已提交
914
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
S
shawn_he 已提交
915

S
shawn_he 已提交
916 917
**Error codes**

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

S
shawn_he 已提交
920 921 922 923 924
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

S
shawn_he 已提交
925
**Example**
S
shawn_he 已提交
926
  ```ts
S
shawn_he 已提交
927 928 929 930 931
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
932 933
  try {
    this.context.resourceManager.getMediaContent(resource).then(value => {
S
shawn_he 已提交
934
      let media = value;
S
shawn_he 已提交
935 936 937 938 939 940
    }).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 已提交
941
  ```
A
annie_wangli 已提交
942

S
shawn_he 已提交
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
### getMediaContent<sup>10+</sup>

getMediaContent(resource: Resource, density: number): Promise&lt;Uint8Array&gt;

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

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

**Parameters**

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes   | Resource object.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

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

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
  try {
    this.context.resourceManager.getMediaContent(resource, 120).then(value => {
      let media = value;
    }).catch(error => {
      console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
A
annie_wangli 已提交
990

S
shawn_he 已提交
991 992 993
### getMediaContentBase64<sup>9+</sup>

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

S
shawn_he 已提交
995
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 已提交
996 997 998

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

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

A
annie_wangli 已提交
1001 1002 1003
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
S
shawn_he 已提交
1004
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1005

S
shawn_he 已提交
1006 1007
**Error codes**

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

S
shawn_he 已提交
1010 1011 1012 1013 1014
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
1015
**Example**
S
shawn_he 已提交
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
  ```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 已提交
1028 1029
  ```

S
shawn_he 已提交
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
### getMediaContentBase64<sup>10+</sup>

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

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

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

**Parameters**

| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resId    | number                      | Yes   | Resource ID.                   |
| [density](#screendensity)  | number        | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

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

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error, value) => {
        if (error != null) {
            console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
            let media = value;
        }
    });       
  } catch (error) {
    console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
A
annie_wangli 已提交
1069

S
shawn_he 已提交
1070
### getMediaContentBase64<sup>9+</sup>
A
annie_wangli 已提交
1071

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

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

A
annie_wangli 已提交
1076 1077
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1078
**Parameters**
S
shawn_he 已提交
1079

A
annie_wangli 已提交
1080 1081 1082
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
A
annie_wangli 已提交
1083

A
annie_wangli 已提交
1084
**Return value**
S
shawn_he 已提交
1085

A
annie_wangli 已提交
1086 1087
| Type                   | Description                  |
| --------------------- | -------------------- |
S
shawn_he 已提交
1088
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1089

S
shawn_he 已提交
1090 1091
**Error codes**

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

S
shawn_he 已提交
1094 1095 1096 1097 1098
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

A
annie_wangli 已提交
1099
**Example**
S
shawn_he 已提交
1100 1101 1102 1103 1104 1105 1106 1107 1108
  ```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}.`)
S
shawn_he 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
  }
  ```

### getMediaContentBase64<sup>10+</sup>

getMediaContentBase64(resId: number, density: number): Promise&lt;string&gt;

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

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

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

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then(value => {
        let media = value;
    }).catch(error => {
        console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
A
annie_wangli 已提交
1153 1154
  ```

S
shawn_he 已提交
1155
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
1156

S
shawn_he 已提交
1157
getMediaContentBase64(resource: Resource, callback: AsyncCallback&lt;string&gt;): void
S
shawn_he 已提交
1158 1159 1160 1161 1162 1163

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

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

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

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

S
shawn_he 已提交
1174 1175 1176 1177 1178
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

S
shawn_he 已提交
1179
**Example**
S
shawn_he 已提交
1180
  ```ts
S
shawn_he 已提交
1181 1182 1183 1184 1185
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
  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 已提交
1197 1198
  ```

S
shawn_he 已提交
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
### getMediaContentBase64<sup>10+</sup>

getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback&lt;string&gt;): void

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

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

**Parameters**

| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resource | [Resource](#resource9)      | Yes   | Resource object.                    |
| [density](#screendensity)  | number        | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

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

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
  try {
    this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => {
        if (error != null) {
            console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
1244
### getMediaContentBase64<sup>9+</sup>
S
shawn_he 已提交
1245

S
shawn_he 已提交
1246
getMediaContentBase64(resource: Resource): Promise&lt;string&gt;
S
shawn_he 已提交
1247 1248 1249 1250 1251 1252

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 已提交
1253 1254 1255

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
1256 1257 1258
| resource | [Resource](#resource9) | Yes   | Resource object.|

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

S
shawn_he 已提交
1260 1261 1262 1263 1264 1265
| Type                   | Description                       |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; |  Promise used to return the result.|

**Error codes**

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

S
shawn_he 已提交
1268 1269 1270 1271
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
S
shawn_he 已提交
1272 1273

**Example**
S
shawn_he 已提交
1274
  ```ts
S
shawn_he 已提交
1275 1276 1277 1278 1279
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
S
shawn_he 已提交
1280 1281 1282 1283 1284 1285 1286 1287 1288
  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 已提交
1289 1290
  ```

S
shawn_he 已提交
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
### getMediaContentBase64<sup>10+</sup>

getMediaContentBase64(resource: Resource, density: number): Promise&lt;string&gt;

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

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

**Parameters**

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes   | Resource object.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

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

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.test').id
  };
  try {
    this.context.resourceManager.getMediaContentBase64(resource, 120).then(value => {
        let media = value;
    }).catch(error => {
        console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
A
annie_wangli 已提交
1338 1339 1340 1341 1342

### getConfiguration

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

S
shawn_he 已提交
1343
Obtains the device configuration. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1344 1345 1346

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

A
annie_wangli 已提交
1347
**Parameters**
S
shawn_he 已提交
1348

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

A
annie_wangli 已提交
1353
**Example**
S
shawn_he 已提交
1354
  ```ts
A
annie_wangli 已提交
1355 1356 1357
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration((error, value) => {
          if (error != null) {
S
shawn_he 已提交
1358
              console.log("error is " + error);
A
annie_wangli 已提交
1359
          } else {
S
shawn_he 已提交
1360 1361
              let direction = value.direction;
              let locale = value.locale;
A
annie_wangli 已提交
1362 1363 1364 1365 1366 1367 1368 1369 1370
          }
      });
  });
  ```


### getConfiguration

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

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

A
annie_wangli 已提交
1374 1375
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1376
**Return value**
S
shawn_he 已提交
1377

A
annie_wangli 已提交
1378 1379
| Type                                      | Description              |
| ---------------------------------------- | ---------------- |
S
shawn_he 已提交
1380
| Promise&lt;[Configuration](#configuration)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1381

A
annie_wangli 已提交
1382
**Example**
S
shawn_he 已提交
1383
  ```ts
A
annie_wangli 已提交
1384 1385
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getConfiguration().then(value => {
S
shawn_he 已提交
1386 1387
          let direction = value.direction;
          let locale = value.locale;
A
annie_wangli 已提交
1388
      }).catch(error => {
S
shawn_he 已提交
1389
          console.log("getConfiguration promise error is " + error);
A
annie_wangli 已提交
1390 1391 1392 1393 1394 1395 1396 1397 1398
      });
  });
  ```


### getDeviceCapability

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

S
shawn_he 已提交
1399
Obtains the device capability. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1400 1401 1402

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

A
annie_wangli 已提交
1403
**Parameters**
S
shawn_he 已提交
1404

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

A
annie_wangli 已提交
1409
**Example**
S
shawn_he 已提交
1410
  ```ts
A
annie_wangli 已提交
1411 1412 1413
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability((error, value) => {
          if (error != null) {
S
shawn_he 已提交
1414
              console.log("error is " + error);
A
annie_wangli 已提交
1415
          } else {
S
shawn_he 已提交
1416 1417
              let screenDensity = value.screenDensity;
              let deviceType = value.deviceType;
A
annie_wangli 已提交
1418 1419 1420 1421 1422 1423 1424 1425 1426
          }
      });
  });
  ```


### getDeviceCapability

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

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

A
annie_wangli 已提交
1430
**System capability**: SystemCapability.Global.ResourceManager
Z
zengyawen 已提交
1431

A
annie_wangli 已提交
1432
**Return value**
S
shawn_he 已提交
1433

A
annie_wangli 已提交
1434 1435
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1436
| Promise&lt;[DeviceCapability](#devicecapability)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1437

A
annie_wangli 已提交
1438
**Example**
S
shawn_he 已提交
1439
  ```ts
A
annie_wangli 已提交
1440 1441
  resourceManager.getResourceManager((error, mgr) => {
      mgr.getDeviceCapability().then(value => {
S
shawn_he 已提交
1442 1443
          let screenDensity = value.screenDensity;
          let deviceType = value.deviceType;
A
annie_wangli 已提交
1444
      }).catch(error => {
S
shawn_he 已提交
1445
          console.log("getDeviceCapability promise error is " + error);
A
annie_wangli 已提交
1446 1447 1448 1449 1450
      });
  });
  ```


S
shawn_he 已提交
1451
### getPluralStringValue<sup>9+</sup>
Z
zengyawen 已提交
1452

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

S
shawn_he 已提交
1455
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 已提交
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                             |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId    | number                      | Yes   | Resource ID.                          |
S
shawn_he 已提交
1464 1465
| num      | number                      | Yes   | Number.                            |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1466

S
shawn_he 已提交
1467 1468
**Error codes**

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

S
shawn_he 已提交
1471 1472 1473 1474 1475 1476
| 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 已提交
1477
**Example**
S
shawn_he 已提交
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
  ```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 已提交
1490 1491 1492
  ```


S
shawn_he 已提交
1493
### getPluralStringValue<sup>9+</sup>
A
annie_wangli 已提交
1494

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

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

A
annie_wangli 已提交
1499 1500
**System capability**: SystemCapability.Global.ResourceManager

A
annie_wangli 已提交
1501
**Parameters**
S
shawn_he 已提交
1502

A
annie_wangli 已提交
1503 1504 1505
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
1506
| num   | number | Yes   | Number.  |
A
annie_wangli 已提交
1507

A
annie_wangli 已提交
1508
**Return value**
S
shawn_he 已提交
1509

A
annie_wangli 已提交
1510 1511
| Type                   | Description                       |
| --------------------- | ------------------------- |
S
shawn_he 已提交
1512
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1513

S
shawn_he 已提交
1514
**Error codes**
S
shawn_he 已提交
1515

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

S
shawn_he 已提交
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
| 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 已提交
1540 1541 1542 1543 1544 1545

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 已提交
1546 1547 1548 1549 1550

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

S
shawn_he 已提交
1553 1554
**Error codes**

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

S
shawn_he 已提交
1557 1558 1559 1560 1561 1562
| 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 已提交
1563
**Example**
S
shawn_he 已提交
1564
  ```ts
S
shawn_he 已提交
1565 1566 1567 1568 1569
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581
  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 已提交
1582 1583
  ```

S
shawn_he 已提交
1584
### getPluralStringValue<sup>9+</sup>
S
shawn_he 已提交
1585

S
shawn_he 已提交
1586
getPluralStringValue(resource: Resource, num: number): Promise&lt;string&gt;
S
shawn_he 已提交
1587 1588 1589 1590 1591 1592

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 已提交
1593 1594 1595

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
1596
| resource | [Resource](#resource9) | Yes   | Resource object.|
S
shawn_he 已提交
1597
| num      | number                 | Yes   | Number. |
S
shawn_he 已提交
1598 1599

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

S
shawn_he 已提交
1601 1602
| Type                   | Description                            |
| --------------------- | ------------------------------ |
S
shawn_he 已提交
1603 1604
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
1605 1606
**Error codes**

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

S
shawn_he 已提交
1609 1610 1611 1612 1613 1614
| 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 已提交
1615
**Example**
S
shawn_he 已提交
1616
  ```ts
S
shawn_he 已提交
1617 1618 1619 1620 1621
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.plural.test').id
  };
S
shawn_he 已提交
1622
  try {
S
shawn_he 已提交
1623
    this.context.resourceManager.getPluralStringValue(resource, 1).then(value => {
S
shawn_he 已提交
1624 1625
        let str = value;
    }).catch(error => {
S
shawn_he 已提交
1626
        console.log("getPluralStringValue promise error is " + error);
S
shawn_he 已提交
1627 1628 1629 1630
    });
  } catch (error) {
    console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
1631 1632
  ```

A
annie_wangli 已提交
1633

S
shawn_he 已提交
1634 1635 1636
### getRawFileContent<sup>9+</sup>

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

S
shawn_he 已提交
1638
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 已提交
1639 1640 1641

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

A
annie_wangli 已提交
1642
**Parameters**
S
shawn_he 已提交
1643

A
annie_wangli 已提交
1644 1645 1646
| Name     | Type                             | Mandatory  | Description                     |
| -------- | ------------------------------- | ---- | ----------------------- |
| path     | string                          | Yes   | Path of the raw file.            |
S
shawn_he 已提交
1647
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
1648

S
shawn_he 已提交
1649 1650
**Error codes**

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

S
shawn_he 已提交
1653 1654 1655 1656
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1657
**Example**
S
shawn_he 已提交
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
  ```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 已提交
1671 1672
  ```

S
shawn_he 已提交
1673
### getRawFileContent<sup>9+</sup>
A
annie_wangli 已提交
1674

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

S
shawn_he 已提交
1677
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1678 1679 1680

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

A
annie_wangli 已提交
1681
**Parameters**
S
shawn_he 已提交
1682

A
annie_wangli 已提交
1683 1684 1685
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1686

A
annie_wangli 已提交
1687
**Return value**
S
shawn_he 已提交
1688

A
annie_wangli 已提交
1689 1690
| Type                       | Description         |
| ------------------------- | ----------- |
S
shawn_he 已提交
1691
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1692

S
shawn_he 已提交
1693 1694
**Error codes**

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

S
shawn_he 已提交
1697 1698 1699 1700
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1701
**Example**
S
shawn_he 已提交
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
  ```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 已提交
1712 1713 1714
  ```


S
shawn_he 已提交
1715 1716 1717
### getRawFd<sup>9+</sup>

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

S
shawn_he 已提交
1719
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 已提交
1720 1721 1722

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

A
annie_wangli 已提交
1723
**Parameters**
S
shawn_he 已提交
1724

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

S
shawn_he 已提交
1730 1731
**Error codes**

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

S
shawn_he 已提交
1734 1735 1736 1737
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1738
**Example**
S
shawn_he 已提交
1739 1740 1741 1742
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml", (error, value) => {
        if (error != null) {
S
shawn_he 已提交
1743
            console.log(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1744 1745 1746 1747 1748
        } else {
            let fd = value.fd;
            let offset = value.offset;
            let length = value.length;
        }
S
shawn_he 已提交
1749 1750 1751 1752
    });
  } catch (error) {
      console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`)
  };
A
annie_wangli 已提交
1753 1754
  ```

S
shawn_he 已提交
1755
### getRawFd<sup>9+</sup>
A
annie_wangli 已提交
1756

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

S
shawn_he 已提交
1759
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1760 1761 1762

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

A
annie_wangli 已提交
1763
**Parameters**
S
shawn_he 已提交
1764

A
annie_wangli 已提交
1765 1766 1767
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1768

A
annie_wangli 已提交
1769
**Return value**
S
shawn_he 已提交
1770

A
annie_wangli 已提交
1771 1772
| Type                                      | Description                 |
| ---------------------------------------- | ------------------- |
S
shawn_he 已提交
1773
| Promise&lt;[RawFileDescriptor](#rawfiledescriptor8)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1774

S
shawn_he 已提交
1775 1776
**Error codes**

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

S
shawn_he 已提交
1779 1780 1781 1782
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001005  | If the resource not found by path.          |

A
annie_wangli 已提交
1783
**Example**
S
shawn_he 已提交
1784 1785 1786 1787 1788 1789 1790
  ```ts
  try {
    this.context.resourceManager.getRawFd("test.xml").then(value => {
        let fd = value.fd;
        let offset = value.offset;
        let length = value.length;
    }).catch(error => {
S
shawn_he 已提交
1791
        console.log(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1792 1793
    });
  } catch (error) {
S
shawn_he 已提交
1794
    console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
1795
  };
A
annie_wangli 已提交
1796 1797
  ```

S
shawn_he 已提交
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
### getRawFileList<sup>10+</sup>

getRawFileList(path: string, callback: AsyncCallback&lt;Array\<string\>&gt;): void;

Obtains the list of files 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 **rawfile** folder.            |
| callback | AsyncCallback&lt;Array\<string\>&gt; | Yes| Callback used to return the result.|

**Error codes**

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

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

**Example**
  ```ts
  try { // Passing "" means to obtain the list of files in the root directory of the raw file.
    this.context.resourceManager.getRawFileList("", (error, value) => {
        if (error != null) {
            console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`)
        } else {
            let rawFile = value;
        }
    });
  } catch (error) {
    console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`)
  }
      
  ```

### getRawFileList<sup>10+</sup>

getRawFileList(path: string): Promise&lt;Array\<string\>&gt;

Obtains the list of files 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 **rawfile** folder.|

**Return value**

| Type                       | Description         |
| ------------------------- | ----------- |
| Promise&lt;Array\<string\>&gt; | List of files in the **rawfile** folder.|

**Error codes**

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

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

**Example**
  ```ts
  try { // Passing "" means to obtain the list of files in the root directory of the raw file.
    this.context.resourceManager.getRawFileList("").then(value => {
        let rawFile = value;
    }).catch(error => {
        console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`)
    });
  } catch (error) {
    console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

A
annie_wangli 已提交
1878 1879 1880 1881
### closeRawFileDescriptor<sup>8+</sup>

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

S
shawn_he 已提交
1882
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 已提交
1883 1884 1885

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

A
annie_wangli 已提交
1886
**Parameters**
S
shawn_he 已提交
1887

A
annie_wangli 已提交
1888 1889 1890
| Name     | Type                       | Mandatory  | Description         |
| -------- | ------------------------- | ---- | ----------- |
| path     | string                    | Yes   | Path of the raw file.|
S
shawn_he 已提交
1891
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.       |
A
annie_wangli 已提交
1892

A
annie_wangli 已提交
1893
**Example**
S
shawn_he 已提交
1894
  ```ts
A
annie_wangli 已提交
1895 1896 1897
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml", (error, value) => {
          if (error != null) {
S
shawn_he 已提交
1898
              console.log("error is " + error);
A
annie_wangli 已提交
1899 1900 1901 1902 1903 1904 1905 1906 1907
          }
      });
  });
  ```

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

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

S
shawn_he 已提交
1908
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
A
annie_wangli 已提交
1909 1910 1911

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

A
annie_wangli 已提交
1912
**Parameters**
S
shawn_he 已提交
1913

A
annie_wangli 已提交
1914 1915 1916
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| path | string | Yes   | Path of the raw file.|
A
annie_wangli 已提交
1917

A
annie_wangli 已提交
1918
**Return value**
S
shawn_he 已提交
1919

A
annie_wangli 已提交
1920 1921
| Type                 | Description  |
| ------------------- | ---- |
S
shawn_he 已提交
1922
| Promise&lt;void&gt; | Promise that returns no value.|
A
annie_wangli 已提交
1923

A
annie_wangli 已提交
1924
**Example**
S
shawn_he 已提交
1925
  ```ts
A
annie_wangli 已提交
1926 1927
  resourceManager.getResourceManager((error, mgr) => {
      mgr.closeRawFileDescriptor("test.xml").then(value => {
S
shawn_he 已提交
1928
          let result = value;
A
annie_wangli 已提交
1929
      }).catch(error => {
S
shawn_he 已提交
1930
          console.log("closeRawFileDescriptor promise error is " + error);
A
annie_wangli 已提交
1931 1932 1933 1934
      });
  });
  ```

S
shawn_he 已提交
1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952

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

**Error codes**

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

S
shawn_he 已提交
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
| 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 已提交
1973
### closeRawFd<sup>9+</sup>
S
shawn_he 已提交
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987

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

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

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

**Parameters**

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

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

S
shawn_he 已提交
1989 1990 1991 1992 1993 1994
| Type                 | Description  |
| ------------------- | ---- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

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

S
shawn_he 已提交
1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
| 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 已提交
2014 2015
### release<sup>7+</sup>

A
annie_wangli 已提交
2016
release()
A
annie_wangli 已提交
2017

S
shawn_he 已提交
2018
Releases a created **resourceManager** object.
A
annie_wangli 已提交
2019 2020 2021

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

A
annie_wangli 已提交
2022
**Example**
S
shawn_he 已提交
2023
  ```ts
A
annie_wangli 已提交
2024
  resourceManager.getResourceManager((error, mgr) => {
S
shawn_he 已提交
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
      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 已提交
2038

S
shawn_he 已提交
2039 2040
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
S
shawn_he 已提交
2041 2042 2043 2044 2045
| resName  | string                      | Yes   | Resource name.           |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

S
shawn_he 已提交
2048 2049 2050 2051 2052
| 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 已提交
2053 2054

**Example**
S
shawn_he 已提交
2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
  ```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 已提交
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
  ```

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

| Name    | Type    | Mandatory  | Description  |
S
shawn_he 已提交
2081
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2082
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
2083 2084

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

S
shawn_he 已提交
2086 2087
| Type                   | Description        |
| --------------------- | ---------- |
S
shawn_he 已提交
2088
| Promise&lt;string&gt; | Promise used to return the result.|
S
shawn_he 已提交
2089 2090 2091

**Error codes**

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

S
shawn_he 已提交
2094 2095 2096 2097 2098
| 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 已提交
2099 2100

**Example**
S
shawn_he 已提交
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
  ```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 已提交
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
  ```

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

S
shawn_he 已提交
2123 2124
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
S
shawn_he 已提交
2125
| resName  | string                                   | Yes   | Resource name.             |
S
shawn_he 已提交
2126
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
2127

S
shawn_he 已提交
2128 2129
**Error codes**

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

S
shawn_he 已提交
2132 2133 2134 2135 2136 2137
| 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 已提交
2138
**Example**
S
shawn_he 已提交
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150
  ```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 已提交
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
  ```

### 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 已提交
2162 2163 2164 2165

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

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

S
shawn_he 已提交
2169 2170
| Type                                | Description          |
| ---------------------------------- | ------------ |
S
shawn_he 已提交
2171 2172
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|

S
shawn_he 已提交
2173 2174
**Error codes**

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

S
shawn_he 已提交
2177 2178 2179 2180 2181 2182
| 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 已提交
2183
**Example**
S
shawn_he 已提交
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
  ```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 已提交
2194 2195 2196 2197 2198 2199
  ```

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

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

S
shawn_he 已提交
2200
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 已提交
2201 2202 2203 2204

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

**Parameters**
S
shawn_he 已提交
2205

S
shawn_he 已提交
2206 2207
| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
S
shawn_he 已提交
2208
| resName  | string                          | Yes   | Resource name.              |
S
shawn_he 已提交
2209
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
2210

S
shawn_he 已提交
2211 2212
**Error codes**

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

S
shawn_he 已提交
2215 2216 2217 2218 2219
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

S
shawn_he 已提交
2220
**Example**
S
shawn_he 已提交
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232
  ```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 已提交
2233 2234
  ```

S
shawn_he 已提交
2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
### getMediaByName<sup>10+</sup>

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

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

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

**Parameters**

| Name     | Type                             | Mandatory  | Description                |
| -------- | ------------------------------- | ---- | ------------------ |
| resName  | string                          | Yes   | Resource name.              |
| [density](#screendensity)  | number        | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;Uint8Array&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaByName("test", 120, (error, value) => {
        if (error != null) {
            console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
2275 2276 2277 2278 2279 2280 2281 2282 2283
### 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 已提交
2284 2285 2286

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2287 2288 2289
| resName | string | Yes   | Resource name.|

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

S
shawn_he 已提交
2291 2292
| Type                       | Description           |
| ------------------------- | ------------- |
S
shawn_he 已提交
2293 2294
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

S
shawn_he 已提交
2295 2296
**Error codes**

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

S
shawn_he 已提交
2299 2300 2301 2302 2303
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

S
shawn_he 已提交
2304
**Example**
S
shawn_he 已提交
2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
  ```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 已提交
2315 2316
  ```

S
shawn_he 已提交
2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
### getMediaByName<sup>10+</sup>

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

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

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

**Parameters**

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaByName("test", 120).then(value => {
        let media = value;
    }).catch(error => {
        console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
2360 2361 2362 2363 2364 2365 2366 2367 2368
### 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 已提交
2369

S
shawn_he 已提交
2370 2371
| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
S
shawn_he 已提交
2372
| resName  | string                      | Yes   | Resource name.                    |
S
shawn_he 已提交
2373
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|
S
shawn_he 已提交
2374

S
shawn_he 已提交
2375 2376
**Error codes**

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

S
shawn_he 已提交
2379 2380 2381 2382 2383
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

S
shawn_he 已提交
2384
**Example**
S
shawn_he 已提交
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
  ```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 已提交
2397
  ```
S
shawn_he 已提交
2398

S
shawn_he 已提交
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
### getMediaBase64ByName<sup>10+</sup>

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

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

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

**Parameters**

| Name     | Type                         | Mandatory  | Description                      |
| -------- | --------------------------- | ---- | ------------------------ |
| resName  | string                      | Yes   | Resource name.                    |
| [density](#screendensity)  | number        | Yes   | Screen density. The value **0** indicates the default screen density.   |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback used to return the result.|

**Error codes**

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

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaBase64ByName("test", 120, (error, value) => {
        if (error != null) {
            console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
        } else {
            let media = value;
        }
    });
  } catch (error) {
    console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
2439 2440 2441 2442 2443 2444 2445 2446 2447
### 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 已提交
2448 2449 2450 2451

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

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

S
shawn_he 已提交
2455 2456
| Type                   | Description                 |
| --------------------- | ------------------- |
S
shawn_he 已提交
2457 2458
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
2459 2460
**Error codes**

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

S
shawn_he 已提交
2463 2464 2465 2466 2467
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

S
shawn_he 已提交
2468
**Example**
S
shawn_he 已提交
2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
  ```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 已提交
2479 2480
  ```

S
shawn_he 已提交
2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
### getMediaBase64ByName<sup>10+</sup>

getMediaBase64ByName(resName: string, density: number): Promise&lt;string&gt;

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

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

**Parameters**

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
| [density](#screendensity)  | number                          | Yes   | Screen density. The value **0** indicates the default screen density.   |

**Return value**

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

**Error codes**

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

| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

**Example**
  ```ts
  try {
    this.context.resourceManager.getMediaBase64ByName("test", 120).then(value => {
        let media = value;
    }).catch(error => {
        console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
    });
  } catch (error) {
    console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
2524 2525 2526 2527
### getPluralStringByName<sup>9+</sup>

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

S
shawn_he 已提交
2528
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 已提交
2529 2530 2531 2532

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

**Parameters**
S
shawn_he 已提交
2533 2534 2535 2536 2537

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

S
shawn_he 已提交
2540 2541
**Error codes**

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

S
shawn_he 已提交
2544 2545 2546 2547 2548 2549
| 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 已提交
2550
**Example**
S
shawn_he 已提交
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563
  ```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 已提交
2564 2565 2566 2567 2568 2569
  ```

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

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

S
shawn_he 已提交
2570
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 已提交
2571 2572 2573 2574

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

**Parameters**
S
shawn_he 已提交
2575 2576 2577

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2578
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
2579
| num     | number | Yes   | Number. |
S
shawn_he 已提交
2580 2581

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

S
shawn_he 已提交
2583 2584
| Type                   | Description                    |
| --------------------- | ---------------------- |
S
shawn_he 已提交
2585 2586
| Promise&lt;string&gt; | Promise used to return the result.|

S
shawn_he 已提交
2587 2588
**Error codes**

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

S
shawn_he 已提交
2591 2592 2593 2594 2595 2596
| 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 已提交
2597
**Example**
S
shawn_he 已提交
2598 2599 2600
  ```ts
  try {
    this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
S
shawn_he 已提交
2601
      let str = value;
S
shawn_he 已提交
2602
    }).catch(error => {
S
shawn_he 已提交
2603
      console.log("getPluralStringByName promise error is " + error);
S
shawn_he 已提交
2604 2605 2606 2607
    });
  } catch (error) {
    console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
  ```

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

S
shawn_he 已提交
2620 2621 2622 2623 2624
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

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

S
shawn_he 已提交
2626 2627
| Type    | Description         |
| ------ | ----------- |
S
shawn_he 已提交
2628
| string | String corresponding to the specified resource ID.|
S
shawn_he 已提交
2629 2630 2631

**Error codes**

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

S
shawn_he 已提交
2634 2635 2636 2637 2638
| 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 已提交
2639 2640

**Example**
S
shawn_he 已提交
2641 2642 2643 2644 2645 2646
  ```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 已提交
2647 2648
  ```

S
shawn_he 已提交
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
### getStringSync<sup>10+</sup>

getStringSync(resId: number, ...args: Array<string | number>): string

Obtains the string corresponding to the specified resource ID and formats the string based on **args**. This API returns the result synchronously.

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
2662
| args | Array<string \| number> | No   | Arguments for formatting strings.<br> Supported arguments:<br> -%d, %f, %s, and %%<br> Note: **%%** is used to translate **%**.<br>Example: **%%d** is translated into the **%d** string.|
S
shawn_he 已提交
2663 2664 2665 2666 2667 2668 2669 2670 2671

**Return value**

| Type    | Description         |
| ------ | ---------------------------- |
| string | Formatted string.|

**Error codes**

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

S
shawn_he 已提交
2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689
| ID| Error Message|
| -------- | ----------------------------------------------- |
| 9001001  | If the resId invalid.                               |
| 9001002  | If the resource not found by resId.                 |
| 9001006  | If the resource re-ref too much.                    |
| 9001007  | If the resource obtained by resId formatting error. |

**Example**
  ```ts
  try {
    this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

S
shawn_he 已提交
2690 2691 2692 2693 2694 2695 2696 2697 2698
### 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 已提交
2699 2700 2701

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2702 2703 2704
| resource | [Resource](#resource9) | Yes   | Resource object.|

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

S
shawn_he 已提交
2706 2707
| Type    | Description              |
| ------ | ---------------- |
S
shawn_he 已提交
2708
| string | String corresponding to the specified resource object.|
S
shawn_he 已提交
2709 2710 2711

**Error codes**

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

S
shawn_he 已提交
2714 2715 2716 2717 2718
| 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 已提交
2719 2720

**Example**
S
shawn_he 已提交
2721
  ```ts
S
shawn_he 已提交
2722 2723 2724 2725 2726
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
S
shawn_he 已提交
2727 2728 2729 2730 2731
  try {
    this.context.resourceManager.getStringSync(resource);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2732 2733
  ```

S
shawn_he 已提交
2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746
### getStringSync<sup>10+</sup>

getStringSync(resource: Resource, ...args: Array<string | number>): string

Obtains the string corresponding to the specified resource object and formats the string based on **args**. This API returns the result synchronously.

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

**Parameters**

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes   | Resource object.|
S
shawn_he 已提交
2747
| args | Array<string \| number> | No   | Arguments for formatting strings.<br> Supported arguments:<br> -%d, %f, %s, and %%<br> Note: **%%** is used to translate **%**.<br>Example: **%%d** is translated into the **%d** string.|
S
shawn_he 已提交
2748 2749 2750 2751 2752 2753 2754 2755 2756

**Return value**

| Type    | Description         |
| ------ | ---------------------------- |
| string | Formatted string.|

**Error codes**

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

S
shawn_he 已提交
2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |
| 9001006  | If the resource re-ref too much.            |
| 9001007  | If the resource obtained by resId formatting error. |

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.string.test').id
  };
  try {
    this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
  } catch (error) {
    console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
 ```

S
shawn_he 已提交
2780 2781 2782 2783 2784 2785 2786 2787 2788
### 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 已提交
2789 2790 2791

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
S
shawn_he 已提交
2792 2793 2794
| resName | string | Yes   | Resource name.|

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

S
shawn_he 已提交
2796 2797
| Type    | Description        |
| ------ | ---------- |
S
shawn_he 已提交
2798
| string | String corresponding to the specified resource name.|
S
shawn_he 已提交
2799 2800 2801

**Error codes**

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

S
shawn_he 已提交
2804 2805 2806 2807 2808
| 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 已提交
2809 2810

**Example**
S
shawn_he 已提交
2811 2812 2813 2814 2815 2816
  ```ts
  try {
    this.context.resourceManager.getStringByNameSync("test");
  } catch (error) {
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2817 2818
  ```

S
shawn_he 已提交
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
### getStringByNameSync<sup>10+</sup>

getStringByNameSync(resName: string, ...args: Array<string | number>): string

Obtains the string corresponding to the specified resource name and formats the string based on **args**. This API returns the result synchronously.

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

**Parameters**

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
S
shawn_he 已提交
2832
| args | Array<string \| number> | No   | Arguments for formatting strings.<br> Supported arguments:<br> -%d, %f, %s, and %%<br> Note: **%%** is used to translate **%**.<br>Example: **%%d** is translated into the **%d** string.|
S
shawn_he 已提交
2833 2834 2835 2836 2837 2838 2839 2840 2841

**Return value**

| Type    | Description         |
| ------ | ---------------------------- |
| string | Formatted string.|

**Error codes**

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

S
shawn_he 已提交
2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |
| 9001006  | If the resource re-ref too much.            |
| 9001008  | If the resource obtained by resName formatting error. |

**Example**
  ```ts
  try {
    this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
  } catch (error) {
    console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`)
  }
 ```

S
shawn_he 已提交
2860
### getBoolean<sup>9+</sup>
S
shawn_he 已提交
2861 2862 2863 2864 2865 2866 2867 2868

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

S
shawn_he 已提交
2870 2871 2872 2873 2874
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

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

S
shawn_he 已提交
2876 2877
| Type     | Description          |
| ------- | ------------ |
S
shawn_he 已提交
2878 2879
| boolean | Boolean result corresponding to the specified resource ID.|

S
shawn_he 已提交
2880 2881
**Error codes**

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

S
shawn_he 已提交
2884 2885 2886 2887 2888 2889
| 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 已提交
2890
**Example**
S
shawn_he 已提交
2891 2892 2893 2894 2895 2896
  ```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 已提交
2897 2898 2899 2900 2901 2902 2903 2904 2905 2906
  ```
### 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 已提交
2907 2908 2909

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
2910 2911 2912
| resource | [Resource](#resource9) | Yes   | Resource object.|

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

S
shawn_he 已提交
2914 2915
| Type     | Description               |
| ------- | ----------------- |
S
shawn_he 已提交
2916 2917
| boolean | Boolean result corresponding to the specified resource object.|

S
shawn_he 已提交
2918 2919
**Error codes**

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

S
shawn_he 已提交
2922 2923 2924 2925 2926 2927
| 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 已提交
2928
**Example**
S
shawn_he 已提交
2929
  ```ts
S
shawn_he 已提交
2930 2931 2932 2933 2934
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.boolean.boolean_test').id
  };
S
shawn_he 已提交
2935 2936 2937 2938 2939
  try {
    this.context.resourceManager.getBoolean(resource);
  } catch (error) {
    console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950
  ```

### 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 已提交
2951 2952 2953 2954

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

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

S
shawn_he 已提交
2958 2959
| Type     | Description         |
| ------- | ----------- |
S
shawn_he 已提交
2960 2961
| boolean | Boolean result corresponding to the specified resource name.|

S
shawn_he 已提交
2962 2963
**Error codes**

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

S
shawn_he 已提交
2966 2967 2968 2969 2970 2971
| 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 已提交
2972
**Example**
S
shawn_he 已提交
2973 2974 2975 2976 2977 2978
  ```ts
  try {
    this.context.resourceManager.getBooleanByName("boolean_test");
  } catch (error) {
    console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
2979 2980
  ```

S
shawn_he 已提交
2981
### getNumber<sup>9+</sup>
S
shawn_he 已提交
2982 2983 2984 2985 2986 2987 2988 2989

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

S
shawn_he 已提交
2991 2992 2993 2994 2995
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|

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

S
shawn_he 已提交
2997
| Type    | Description        |
S
shawn_he 已提交
2998
| ------ | ---------- | 
S
shawn_he 已提交
2999
| number | Integer or float value corresponding to the specified resource ID. Wherein, the integer value is the original value, and the float value is the actual pixel value. For details, see the sample code.|
S
shawn_he 已提交
3000 3001 3002

**Error codes**

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

S
shawn_he 已提交
3005 3006 3007 3008 3009 3010
| 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 已提交
3011
**Example**
S
shawn_he 已提交
3012 3013
  ```ts
  try {
S
shawn_he 已提交
3014
    this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value.
S
shawn_he 已提交
3015 3016 3017 3018 3019
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }

  try {
S
shawn_he 已提交
3020
    this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value.
S
shawn_he 已提交
3021 3022 3023
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034
  ```

### 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 已提交
3035 3036 3037

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
S
shawn_he 已提交
3038 3039 3040
| resource | [Resource](#resource9) | Yes   | Resource object.|

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

S
shawn_he 已提交
3042 3043
| Type    | Description             |
| ------ | --------------- |
S
shawn_he 已提交
3044
| number | Integer or float value corresponding to the specified resource object. Wherein, the integer value is the original value, and the float value is the actual pixel value. For details, see the sample code.|
S
shawn_he 已提交
3045 3046 3047

**Error codes**

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

S
shawn_he 已提交
3050 3051 3052 3053 3054 3055
| 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 已提交
3056
**Example**
S
shawn_he 已提交
3057
  ```ts
S
shawn_he 已提交
3058 3059 3060 3061 3062
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.integer.integer_test').id
  };
S
shawn_he 已提交
3063
  try {
S
shawn_he 已提交
3064
    this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value.
S
shawn_he 已提交
3065 3066 3067
  } catch (error) {
    console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078
  ```

### 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 已提交
3079 3080 3081 3082 3083 3084

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

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

S
shawn_he 已提交
3086 3087 3088 3089 3090 3091
| Type    | Description       |
| ------ | --------- |
| number | Integer or float value corresponding to the specified resource name.|

**Error codes**

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

S
shawn_he 已提交
3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114
| 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}.`)
  }
  ```

S
shawn_he 已提交
3115 3116 3117 3118
### getDrawableDescriptor<sup>10+</sup>

getDrawableDescriptor(resId: number, density?: number): DrawableDescriptor;

S
shawn_he 已提交
3119
Obtains the **DrawableDescriptor** object corresponding to the specified resource ID. This API returns the result synchronously.
S
shawn_he 已提交
3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133

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

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| resId | number | Yes   | Resource ID.|
| [density](#screendensity) | number | No   | Screen density. The default value is **0**.|

**Return value**

| Type    | Description        |
| ------ | ---------- |
S
shawn_he 已提交
3134
| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.|
S
shawn_he 已提交
3135 3136 3137

**Error codes**

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

S
shawn_he 已提交
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

**Example**
  ```ts
  try {
    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  try {
    this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

### getDrawableDescriptor<sup>10+</sup>

getDrawableDescriptor(resource: Resource, density?: number): DrawableDescriptor;

S
shawn_he 已提交
3163
Obtains the **DrawableDescriptor** object corresponding to the specified resource object. This API returns the result synchronously.
S
shawn_he 已提交
3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177

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

**Parameters**

| Name     | Type                    | Mandatory  | Description  |
| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes   | Resource object.|
| [density](#screendensity) | number | No   | Screen density. The default value is **0**.|

**Return value**

| Type     | Description               |
| ------- | ----------------- |
S
shawn_he 已提交
3178
| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.|
S
shawn_he 已提交
3179 3180 3181

**Error codes**

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

S
shawn_he 已提交
3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001001  | If the resId invalid.                       |
| 9001002  | If the resource not found by resId.         |

**Example**
  ```ts
  let resource = {
      bundleName: "com.example.myapplication",
      moduleName: "entry",
      id: $r('app.media.icon').id
  };
  try {
    this.context.resourceManager.getDrawableDescriptor(resource);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  try {
    this.context.resourceManager.getDrawableDescriptor(resource, 120);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

### getDrawableDescriptorByName<sup>10+</sup>

getDrawableDescriptorByName(resName: string, density?: number): DrawableDescriptor;

S
shawn_he 已提交
3212
Obtains the **DrawableDescriptor** object corresponding to the specified resource name. This API returns the result synchronously.
S
shawn_he 已提交
3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226

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

**Parameters**

| Name    | Type    | Mandatory  | Description  |
| ------- | ------ | ---- | ---- |
| resName | string | Yes   | Resource name.|
| [density](#screendensity) | number | No   | Screen density. The default value is **0**.|

**Return value**

| Type    | Description       |
| ------ | --------- |
S
shawn_he 已提交
3227
| DrawableDescriptor | **DrawableDescriptor** object corresponding to the specified resource ID.|
S
shawn_he 已提交
3228 3229 3230

**Error codes**

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

S
shawn_he 已提交
3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250
| ID| Error Message|
| -------- | ---------------------------------------- |
| 9001003  | If the resName invalid.                     |
| 9001004  | If the resource not found by resName.       |

**Example**
  ```ts
  try {
    this.context.resourceManager.getDrawableDescriptorByName('icon');
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  try {
    this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
  } catch (error) {
    console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
S
shawn_he 已提交
3251 3252 3253 3254 3255 3256 3257

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

S
shawn_he 已提交
3258
This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9) instead.
S
shawn_he 已提交
3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288

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

S
shawn_he 已提交
3289
This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1) instead.
S
shawn_he 已提交
3290 3291 3292 3293 3294

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

**Parameters**

S
shawn_he 已提交
3295 3296
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
S
shawn_he 已提交
3297
| resId | number | Yes   | Resource ID.|
S
shawn_he 已提交
3298 3299

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

S
shawn_he 已提交
3301 3302
| Type                   | Description         |
| --------------------- | ----------- |
S
shawn_he 已提交
3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322
| 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.

S
shawn_he 已提交
3323
This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9) instead.
S
shawn_he 已提交
3324 3325 3326 3327 3328 3329 3330 3331 3332

**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 已提交
3333 3334

**Example**
S
shawn_he 已提交
3335 3336 3337 3338 3339 3340 3341 3342 3343 3344
  ```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 已提交
3345
  ```
S
shawn_he 已提交
3346 3347 3348 3349 3350 3351 3352 3353


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

S
shawn_he 已提交
3354
This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1) instead.
S
shawn_he 已提交
3355 3356 3357 3358 3359 3360 3361 3362 3363 3364

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

**Parameters**

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

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

S
shawn_he 已提交
3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385
| 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

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

S
shawn_he 已提交
3388
This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9) instead.
S
shawn_he 已提交
3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418

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

**Parameters**

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

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


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

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

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

S
shawn_he 已提交
3419
This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1) instead.
S
shawn_he 已提交
3420 3421 3422 3423 3424 3425 3426 3427 3428 3429

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

**Parameters**

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

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

S
shawn_he 已提交
3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452
| Type                       | Description            |
| ------------------------- | -------------- |
| Promise&lt;Uint8Array&gt; | Promise used to return the result.|

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


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

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

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

S
shawn_he 已提交
3453
This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649) instead.
S
shawn_he 已提交
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483

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

**Parameters**

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

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


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

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

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

S
shawn_he 已提交
3484
This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1) instead.
S
shawn_he 已提交
3485 3486 3487 3488 3489 3490 3491 3492 3493 3494

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

**Parameters**

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

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

S
shawn_he 已提交
3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517
| Type                   | Description                  |
| --------------------- | -------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|

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


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

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

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

S
shawn_he 已提交
3518
This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9) instead.
S
shawn_he 已提交
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529

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

**Parameters**

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

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

S
shawn_he 已提交
3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552
| Type                   | Description                       |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|

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


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

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

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

S
shawn_he 已提交
3553
This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1) instead.
S
shawn_he 已提交
3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584

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

S
shawn_he 已提交
3585
This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9) instead.
S
shawn_he 已提交
3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615

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

S
shawn_he 已提交
3616
This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1) instead.
S
shawn_he 已提交
3617 3618 3619 3620 3621 3622 3623 3624 3625 3626

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

**Parameters**

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

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

S
shawn_he 已提交
3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649
| 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.

S
shawn_he 已提交
3650
This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9) instead.
S
shawn_he 已提交
3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681

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

S
shawn_he 已提交
3682
This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1) instead.
S
shawn_he 已提交
3683 3684 3685 3686 3687 3688 3689 3690 3691 3692

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

**Parameters**

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

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

S
shawn_he 已提交
3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708
| 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 已提交
3709
  ```