1# @ohos.resourceManager (Resource Management) 2 3The **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. 4 5> **NOTE** 6> 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. 8 9## Modules to Import 10 11```js 12import { resourceManager } from '@kit.LocalizationKit' 13``` 14 15## How to Use 16 17Since 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. 18For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object. 19For details about how to reference context in the stage model, see [Context in the Stage Model](../../application-models/application-context-stage.md). 20 21```ts 22import { UIAbility } from '@kit.AbilityKit'; 23import { window } from '@kit.ArkUI'; 24 25export default class EntryAbility extends UIAbility { 26 onWindowStageCreate(windowStage: window.WindowStage) { 27 let context = this.context; 28 let resourceManager = context.resourceManager; 29 } 30} 31``` 32 33## resourceManager.getResourceManager 34 35getResourceManager(callback: AsyncCallback<ResourceManager>): void 36 37Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result. 38 39**System capability**: SystemCapability.Global.ResourceManager 40 41**Model restriction**: This API can be used only in the FA model. 42 43**Parameters** 44 45| Name | Type | Mandatory | Description | 46| -------- | ---------------------------------------- | ---- | ----------------------------- | 47| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes |Callback used to return the result, which is a **ResourceManager** object.| 48 49**Example** 50 <!--code_no_check_fa--> 51 ```js 52 resourceManager.getResourceManager((error, mgr) => { 53 if (error != null) { 54 console.error("error is " + error); 55 return; 56 } 57 mgr.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { 58 if (error != null) { 59 console.error("error is " + error); 60 } else { 61 let str = value; 62 } 63 }); 64 }); 65 ``` 66 67## resourceManager.getResourceManager 68 69getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void 70 71Obtains the **ResourceManager** object of the specified application. This API uses an asynchronous callback to return the result. 72 73**System capability**: SystemCapability.Global.ResourceManager 74 75**Model restriction**: This API can be used only in the FA model. 76 77**Parameters** 78 79| Name | Type | Mandatory | Description | 80| ---------- | ---------------------------------------- | ---- | ----------------------------- | 81| bundleName | string | Yes | Bundle name of an application. | 82| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result, which is a **ResourceManager** object.| 83 84**Example** 85 <!--code_no_check_fa--> 86 ```js 87 resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => { 88 }); 89 ``` 90 91## resourceManager.getResourceManager 92 93getResourceManager(): Promise<ResourceManager> 94 95Obtains the **ResourceManager** object of this application. This API uses a promise to return the result. 96 97**System capability**: SystemCapability.Global.ResourceManager 98 99**Model restriction**: This API can be used only in the FA model. 100 101**Return value** 102 103| Type | Description | 104| ---------------------------------------- | ----------------- | 105| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result, which is a **ResourceManager** object.| 106 107**Example** 108 <!--code_no_check_fa--> 109 ```js 110 import { resourceManager } from '@kit.LocalizationKit' 111 import { BusinessError } from '@kit.BasicServicesKit'; 112 113 resourceManager.getResourceManager().then((mgr: resourceManager.ResourceManager) => { 114 mgr.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { 115 if (error != null) { 116 console.error("error is " + error); 117 } else { 118 let str = value; 119 } 120 }); 121 }).catch((error: BusinessError) => { 122 console.error("error is " + error); 123 }); 124 ``` 125 126## resourceManager.getResourceManager 127 128getResourceManager(bundleName: string): Promise<ResourceManager> 129 130Obtains the **ResourceManager** object of the specified application. This API uses a promise to return the result. 131 132**System capability**: SystemCapability.Global.ResourceManager 133 134**Model restriction**: This API can be used only in the FA model. 135 136**Parameters** 137 138| Name | Type | Mandatory | Description | 139| ---------- | ------ | ---- | ------------- | 140| bundleName | string | Yes | Bundle name of an application.| 141 142**Return value** 143 144| Type | Description | 145| ---------------------------------------- | ------------------ | 146| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result, which is a **ResourceManager** object.| 147 148**Example** 149 <!--code_no_check_fa--> 150 ```js 151 import { resourceManager } from '@kit.LocalizationKit' 152 import { BusinessError } from '@kit.BasicServicesKit'; 153 154 resourceManager.getResourceManager("com.example.myapplication").then((mgr: resourceManager.ResourceManager) => { 155 }).catch((error: BusinessError) => { 156 }); 157 ``` 158 159## resourceManager.getSystemResourceManager<sup>10+</sup> 160 161getSystemResourceManager(): ResourceManager 162 163Obtains a **ResourceManager** object. 164 165**Atomic service API**: This API can be used in atomic services since API version 11. 166 167**System capability**: SystemCapability.Global.ResourceManager 168 169**Return value** 170 171| Type | Description | 172| ---------------------------------------- | ------------------ | 173| [Resourcemanager](#resourcemanager) | **ResourceManager** object.| 174 175**Error codes** 176 177For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 178 179| ID| Error Message| 180| -------- | ---------------------------------------- | 181| 9001009 | Failed to access the system resource.which is not mapped to application sandbox, This error code will be thrown. | 182 183**Example** 184 ```js 185import { resourceManager } from '@kit.LocalizationKit' 186import { BusinessError } from '@kit.BasicServicesKit'; 187 188 try { 189 let systemResourceManager = resourceManager.getSystemResourceManager(); 190 systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then((value: string) => { 191 let str = value; 192 }).catch((error: BusinessError) => { 193 console.error("systemResourceManager getStringValue promise error is " + error); 194 }); 195 } catch (error) { 196 let code = (error as BusinessError).code; 197 let message = (error as BusinessError).message; 198 console.error(`systemResourceManager getStringValue failed, error code: ${code}, message: ${message}.`); 199 } 200 ``` 201 202## Direction 203 204Enumerates the screen directions. 205 206**Atomic service API**: This API can be used in atomic services since API version 11. 207 208**System capability**: SystemCapability.Global.ResourceManager 209 210| Name | Value | Description | 211| -------------------- | ---- | ---- | 212| DIRECTION_VERTICAL | 0 | Portrait | 213| DIRECTION_HORIZONTAL | 1 | Landscape | 214 215 216## DeviceType 217 218Enumerates the device types. 219 220**Atomic service API**: This API can be used in atomic services since API version 11. 221 222**System capability**: SystemCapability.Global.ResourceManager 223<!--RP1--> 224| Name | Value | Description | 225| -------------------- | ---- | ---- | 226| DEVICE_TYPE_PHONE | 0x00 | Phone | 227| DEVICE_TYPE_TABLET | 0x01 | Tablet | 228| DEVICE_TYPE_CAR | 0x02 | Automobile | 229| DEVICE_TYPE_TV | 0x04 | TV | 230| DEVICE_TYPE_WEARABLE | 0x06 | Wearable | 231| DEVICE_TYPE_2IN1<sup>11+</sup> | 0x07 | 2-in-1 | 232<!--RP1End--> 233 234## ScreenDensity 235 236Enumerates the screen density types. 237 238**Atomic service API**: This API can be used in atomic services since API version 11. 239 240**System capability**: SystemCapability.Global.ResourceManager 241 242| Name | Value | Description | 243| -------------- | ---- | ---------- | 244| SCREEN_SDPI | 120 | Screen density with small-scale dots per inch (SDPI). | 245| SCREEN_MDPI | 160 | Screen density with medium-scale dots per inch (MDPI). | 246| SCREEN_LDPI | 240 | Screen density with large-scale dots per inch (LDPI). | 247| SCREEN_XLDPI | 320 | Screen density with extra-large-scale dots per inch (XLDPI). | 248| SCREEN_XXLDPI | 480 | Screen density with extra-extra-large-scale dots per inch (XXLDPI). | 249| SCREEN_XXXLDPI | 640 | Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).| 250 251 252## ColorMode<sup>12+</sup> 253 254Defines the color mode of the current device. 255 256**Atomic service API**: This API can be used in atomic services since API version 12. 257 258**System capability**: SystemCapability.Global.ResourceManager 259 260| Name | Value | Description | 261| ----- | ---- | ---------- | 262| DARK | 0 | Dark mode.| 263| LIGHT | 1 | Light mode.| 264 265 266## Configuration 267 268Defines the device configuration. 269 270**System capability**: SystemCapability.Global.ResourceManager 271 272| Name | Type | Readable| Writable| Description | 273| --------------------------- | ------------------------------- | ---- | ---- | ------------------ | 274| direction | [Direction](#direction) | Yes | Yes | Screen orientation.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 275| locale | string | Yes | Yes | Country or region.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 276| deviceType<sup>12+</sup> | [DeviceType](#devicetype) | Yes | Yes | Device type.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 277| screenDensity<sup>12+</sup> | [ScreenDensity](#screendensity) | Yes | Yes | Screen density.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 278| colorMode<sup>12+</sup> | [ColorMode](#colormode12) | Yes | Yes | Color mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 279| mcc<sup>12+</sup> | number | Yes | Yes | Mobile country code.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 280| mnc<sup>12+</sup> | number | Yes | Yes | Mobile network code (MNC).<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 281 282 283 284## DeviceCapability 285 286Defines the device capability. 287 288**Atomic service API**: This API can be used in atomic services since API version 11. 289 290**System capability**: SystemCapability.Global.ResourceManager 291 292| Name | Type | Readable | Writable | Description | 293| ------------- | ------------------------------- | ---- | ---- | -------- | 294| screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density of the device.| 295| deviceType | [DeviceType](#devicetype) | Yes | No | Device type. | 296 297 298## RawFileDescriptor<sup>8+</sup> 299 300Defines the descriptor of the HAP where the raw file is located. 301 302**Atomic service API**: This API can be used in atomic services since API version 11. 303 304**System capability**: SystemCapability.Global.ResourceManager 305 306| Name | Type | Readable | Writable | Description | 307| ------ | ------ | ---- | ---- | ------------------ | 308| fd | number | Yes | No| File descriptor.| 309| offset | number | Yes | No| Start offset of the raw file. | 310| length | number | Yes | No| File length. | 311 312## Resource<sup>9+</sup> 313 314Defines the resource information of an application. 315 316**Atomic service API**: This API can be used in atomic services since API version 11. 317 318**System capability**: SystemCapability.Global.ResourceManager 319 320| Name | Type | Readable | Writable |Description | 321| ---------- | ------ | ----- | ---- | ---------------| 322| bundleName | string | Yes | No| Bundle name of the application.| 323| moduleName | string | Yes | No| Module name of the application.| 324| id | number | Yes | No| Resource ID. | 325| params | any[] | Yes | No| Other resource parameters, which are optional. | 326| type | number | Yes | No| Resource type, which is optional. | 327 328## ResourceManager 329 330Defines the capability of accessing application resources. 331 332> **NOTE** 333> 334> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. 335> 336> - Resource files are defined in the **resources** directory of the project. You can obtain the corresponding strings and string arrays based on the specified resource ID, resource name, or resource object. You can use **$r(resource address).id**, for example, **$r('app.string.test').id**, to obtain the resource ID. 337> 338> - Use the resource object for cross-package access in a multi-project application. It works by creating the context of the corresponding module to obtain required resources. Therefore, it takes a longer time than using the resource ID or resource name. 339> 340> - For details about intra-HAP and cross-HAP/HSP resource access modes, see [Resource Access](../../quick-start/resource-categories-and-access.md#resource-access). 341> 342> - For details about the content of the test files used in the sample code, see [Appendix](#appendix). 343 344### getStringSync<sup>9+</sup> 345 346getStringSync(resId: number): string 347 348Obtains a string based on the specified resource ID. This API returns the result synchronously. 349 350**Atomic service API**: This API can be used in atomic services since API version 11. 351 352**System capability**: SystemCapability.Global.ResourceManager 353 354**Parameters** 355 356| Name | Type | Mandatory | Description | 357| ----- | ------ | ---- | ----- | 358| resId | number | Yes | Resource ID.| 359 360**Return value** 361 362| Type | Description | 363| ------ | ----------- | 364| string | String corresponding to the specified resource ID.| 365 366**Error codes** 367 368For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 369 370| ID| Error Message| 371| -------- | ---------------------------------------- | 372| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 373| 9001001 | Invalid resource ID. | 374| 9001002 | No matching resource is found based on the resource ID. | 375| 9001006 | The resource is referenced cyclically. | 376 377**Example** 378 ```ts 379 import { BusinessError } from '@kit.BasicServicesKit'; 380 381 try { 382 this.context.resourceManager.getStringSync($r('app.string.test').id); 383 } catch (error) { 384 let code = (error as BusinessError).code; 385 let message = (error as BusinessError).message; 386 console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); 387 } 388 ``` 389 390### getStringSync<sup>10+</sup> 391 392getStringSync(resId: number, ...args: Array<string | number>): string 393 394Obtains a string based on the specified resource ID and formats the string based on **args**. This API returns the result synchronously. 395 396**Atomic service API**: This API can be used in atomic services since API version 11. 397 398**System capability**: SystemCapability.Global.ResourceManager 399 400**Parameters** 401 402| Name | Type | Mandatory | Description | 403| ----- | ------ | ---- | ----- | 404| resId | number | Yes | Resource ID.| 405| args | Array<string \| number> | No | Arguments for formatting strings.<br>Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.<br>Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.<br>For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| 406 407**Return value** 408 409| Type | Description | 410| ------ | ---------------------------- | 411| string | Formatted string corresponding to the specified resource ID.| 412 413**Error codes** 414For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 415 416| ID| Error Message| 417| -------- | ---------------------------------------- | 418| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 419| 9001001 | Invalid resource ID. | 420| 9001002 | No matching resource is found based on the resource ID. | 421| 9001006 | The resource is referenced cyclically. | 422| 9001007 | Failed to format the resource obtained based on the resource ID. | 423 424**Example** 425 ```ts 426 import { BusinessError } from '@kit.BasicServicesKit'; 427 428 try { 429 this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); 430 } catch (error) { 431 let code = (error as BusinessError).code; 432 let message = (error as BusinessError).message; 433 console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); 434 } 435 ``` 436 437### getStringSync<sup>9+</sup> 438 439getStringSync(resource: Resource): string 440 441Obtains a string based on the specified resource object. This API returns the result synchronously. 442 443**Atomic service API**: This API can be used in atomic services since API version 11. 444 445**System capability**: SystemCapability.Global.ResourceManager 446 447**Model restriction**: This API can be used only in the stage model. 448 449**Parameters** 450 451| Name | Type | Mandatory | Description | 452| -------- | ---------------------- | ---- | ---- | 453| resource | [Resource](#resource9) | Yes | Resource object.| 454 455**Return value** 456 457| Type | Description | 458| ------ | ---------------- | 459| string | String corresponding to the specified resource object.| 460 461**Error codes** 462 463For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 464 465| ID| Error Message| 466| -------- | ---------------------------------------- | 467| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 468| 9001001 | Invalid resource ID. | 469| 9001002 | No matching resource is found based on the resource ID. | 470| 9001006 | The resource is referenced cyclically. | 471 472**Example** 473 ```ts 474 import { resourceManager } from '@kit.LocalizationKit' 475 import { BusinessError } from '@kit.BasicServicesKit'; 476 477 let resource: resourceManager.Resource = { 478 bundleName: "com.example.myapplication", 479 moduleName: "entry", 480 id: $r('app.string.test').id 481 }; 482 try { 483 this.context.resourceManager.getStringSync(resource); 484 } catch (error) { 485 let code = (error as BusinessError).code; 486 let message = (error as BusinessError).message; 487 console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); 488 } 489 ``` 490 491### getStringSync<sup>10+</sup> 492 493getStringSync(resource: Resource, ...args: Array<string | number>): string 494 495Obtains a string based on the specified resource object and formats the string based on **args**. This API returns the result synchronously. 496 497**Atomic service API**: This API can be used in atomic services since API version 11. 498 499**System capability**: SystemCapability.Global.ResourceManager 500 501**Model restriction**: This API can be used only in the stage model. 502 503**Parameters** 504 505| Name | Type | Mandatory | Description | 506| -------- | ---------------------- | ---- | ---- | 507| resource | [Resource](#resource9) | Yes | Resource object.| 508| args | Array<string \| number> | No | Arguments for formatting strings.<br>Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.<br>Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.<br>For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| 509 510**Return value** 511 512| Type | Description | 513| ------ | ---------------------------- | 514| string | Formatted string corresponding to the specified resource object.| 515 516**Error codes** 517For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 518 519| ID| Error Message| 520| -------- | ---------------------------------------- | 521| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 522| 9001001 | Invalid resource ID. | 523| 9001002 | No matching resource is found based on the resource ID. | 524| 9001006 | The resource is referenced cyclically. | 525| 9001007 | Failed to format the resource obtained based on the resource ID. | 526 527**Example** 528 ```ts 529 import { resourceManager } from '@kit.LocalizationKit' 530 import { BusinessError } from '@kit.BasicServicesKit'; 531 532 let resource: resourceManager.Resource = { 533 bundleName: "com.example.myapplication", 534 moduleName: "entry", 535 id: $r('app.string.test').id 536 }; 537 try { 538 this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); 539 } catch (error) { 540 let code = (error as BusinessError).code; 541 let message = (error as BusinessError).message; 542 console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); 543 } 544 ``` 545 546### getStringByNameSync<sup>9+</sup> 547 548getStringByNameSync(resName: string): string 549 550Obtains a string based on the specified resource name. This API returns the result synchronously. 551 552**Atomic service API**: This API can be used in atomic services since API version 11. 553 554**System capability**: SystemCapability.Global.ResourceManager 555 556**Parameters** 557 558| Name | Type | Mandatory | Description | 559| ------- | ------ | ---- | ---- | 560| resName | string | Yes | Resource name.| 561 562**Return value** 563 564| Type | Description | 565| ------ | ---------- | 566| string | String corresponding to the specified resource name.| 567 568**Error codes** 569 570For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 571 572| ID| Error Message| 573| -------- | ---------------------------------------- | 574| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 575| 9001003 | Invalid resource name. | 576| 9001004 | No matching resource is found based on the resource name. | 577| 9001006 | The resource is referenced cyclically. | 578 579**Example** 580 ```ts 581 import { BusinessError } from '@kit.BasicServicesKit'; 582 583 try { 584 this.context.resourceManager.getStringByNameSync("test"); 585 } catch (error) { 586 let code = (error as BusinessError).code; 587 let message = (error as BusinessError).message; 588 console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`); 589 } 590 ``` 591 592### getStringByNameSync<sup>10+</sup> 593 594getStringByNameSync(resName: string, ...args: Array<string | number>): string 595 596Obtains a string based on the specified resource name and formats the string based on **args**. This API returns the result synchronously. 597 598**Atomic service API**: This API can be used in atomic services since API version 11. 599 600**System capability**: SystemCapability.Global.ResourceManager 601 602**Parameters** 603 604| Name | Type | Mandatory | Description | 605| ------- | ------ | ---- | ---- | 606| resName | string | Yes | Resource name.| 607| args | Array<string \| number> | No | Arguments for formatting strings.<br>Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.<br>Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.<br>For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| 608 609**Return value** 610 611| Type | Description | 612| ------ | ---------------------------- | 613| string | Formatted string corresponding to the specified resource name.| 614 615**Error codes** 616 617For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 618 619| ID| Error Message| 620| -------- | ---------------------------------------- | 621| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 622| 9001003 | Invalid resource name. | 623| 9001004 | No matching resource is found based on the resource name. | 624| 9001006 | The resource is referenced cyclically. | 625| 9001008 | Failed to format the resource obtained based on the resource Name. | 626 627**Example** 628 ```ts 629 import { BusinessError } from '@kit.BasicServicesKit'; 630 631 try { 632 this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); 633 } catch (error) { 634 let code = (error as BusinessError).code; 635 let message = (error as BusinessError).message; 636 console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`); 637 } 638 ``` 639 640### getStringValue<sup>9+</sup> 641 642getStringValue(resId: number, callback: AsyncCallback<string>): void 643 644Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. 645 646**Atomic service API**: This API can be used in atomic services since API version 11. 647 648**System capability**: SystemCapability.Global.ResourceManager 649 650**Parameters** 651 652| Name | Type | Mandatory | Description | 653| -------- | --------------------------- | ---- | --------------- | 654| resId | number | Yes | Resource ID. | 655| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| 656 657**Error codes** 658 659For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 660 661| ID| Error Message| 662| -------- | ---------------------------------------- | 663| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 664| 9001001 | If the module resId invalid. | 665| 9001002 | No matching resource is found based on the resource ID. | 666| 9001006 | The resource is referenced cyclically. | 667 668**Example (stage)** 669 ```ts 670 import { BusinessError } from '@kit.BasicServicesKit'; 671 672 try { 673 this.context.resourceManager.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { 674 if (error != null) { 675 console.error("error is " + error); 676 } else { 677 let str = value; 678 } 679 }); 680 } catch (error) { 681 let code = (error as BusinessError).code; 682 let message = (error as BusinessError).message; 683 console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`); 684 } 685 ``` 686 687### getStringValue<sup>9+</sup> 688 689getStringValue(resId: number): Promise<string> 690 691Obtains a string based on the specified resource ID. This API uses a promise to return the result. 692 693**Atomic service API**: This API can be used in atomic services since API version 11. 694 695**System capability**: SystemCapability.Global.ResourceManager 696 697**Parameters** 698 699| Name | Type | Mandatory | Description | 700| ----- | ------ | ---- | ----- | 701| resId | number | Yes | Resource ID.| 702 703**Return value** 704 705| Type | Description | 706| --------------------- | ----------- | 707| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| 708 709**Error codes** 710 711For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 712 713| ID| Error Message| 714| -------- | ---------------------------------------- | 715| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 716| 9001001 | Invalid resource ID. | 717| 9001002 | No matching resource is found based on the resource ID. | 718| 9001006 | The resource is referenced cyclically. | 719 720**Example** 721 ```ts 722 import { BusinessError } from '@kit.BasicServicesKit'; 723 724 try { 725 this.context.resourceManager.getStringValue($r('app.string.test').id).then((value: string) => { 726 let str = value; 727 }).catch((error: BusinessError) => { 728 console.error("getStringValue promise error is " + error); 729 }); 730 } catch (error) { 731 let code = (error as BusinessError).code; 732 let message = (error as BusinessError).message; 733 console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`); 734 } 735 ``` 736 737### getStringValue<sup>9+</sup> 738 739getStringValue(resource: Resource, callback: AsyncCallback<string>): void 740 741Obtains a string based on the specified resource object. This API uses an asynchronous callback to return the result. 742 743**Atomic service API**: This API can be used in atomic services since API version 11. 744 745**System capability**: SystemCapability.Global.ResourceManager 746 747**Model restriction**: This API can be used only in the stage model. 748 749**Parameters** 750 751| Name | Type | Mandatory | Description | 752| -------- | --------------------------- | ---- | --------------- | 753| resource | [Resource](#resource9) | Yes | Resource object. | 754| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| 755 756**Error codes** 757 758For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 759 760| ID| Error Message| 761| -------- | ---------------------------------------- | 762| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 763| 9001001 | Invalid resource ID. | 764| 9001002 | No matching resource is found based on the resource ID. | 765| 9001006 | The resource is referenced cyclically. | 766 767**Example** 768 ```ts 769 import { resourceManager } from '@kit.LocalizationKit' 770 import { BusinessError } from '@kit.BasicServicesKit'; 771 772 let resource: resourceManager.Resource = { 773 bundleName: "com.example.myapplication", 774 moduleName: "entry", 775 id: $r('app.string.test').id 776 }; 777 try { 778 this.context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => { 779 if (error != null) { 780 console.error("error is " + error); 781 } else { 782 let str = value; 783 } 784 }); 785 } catch (error) { 786 let code = (error as BusinessError).code; 787 let message = (error as BusinessError).message; 788 console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`); 789 } 790 ``` 791 792### getStringValue<sup>9+</sup> 793 794getStringValue(resource: Resource): Promise<string> 795 796Obtains a string based on the specified resource object. This API uses a promise to return the result. 797 798**Atomic service API**: This API can be used in atomic services since API version 11. 799 800**System capability**: SystemCapability.Global.ResourceManager 801 802**Model restriction**: This API can be used only in the stage model. 803 804**Parameters** 805 806| Name | Type | Mandatory | Description | 807| -------- | ---------------------- | ---- | ---- | 808| resource | [Resource](#resource9) | Yes | Resource object.| 809 810**Return value** 811 812| Type | Description | 813| --------------------- | ---------------- | 814| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource object.| 815 816**Error codes** 817 818For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 819 820| ID| Error Message| 821| -------- | ---------------------------------------- | 822| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 823| 9001001 | Invalid resource ID. | 824| 9001002 | No matching resource is found based on the resource ID. | 825| 9001006 | The resource is referenced cyclically. | 826 827**Example** 828 ```ts 829 import { resourceManager } from '@kit.LocalizationKit' 830 import { BusinessError } from '@kit.BasicServicesKit'; 831 832 let resource: resourceManager.Resource = { 833 bundleName: "com.example.myapplication", 834 moduleName: "entry", 835 id: $r('app.string.test').id 836 }; 837 try { 838 this.context.resourceManager.getStringValue(resource).then((value: string) => { 839 let str = value; 840 }).catch((error: BusinessError) => { 841 console.error("getStringValue promise error is " + error); 842 }); 843 } catch (error) { 844 let code = (error as BusinessError).code; 845 let message = (error as BusinessError).message; 846 console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`); 847 } 848 ``` 849 850### getStringByName<sup>9+</sup> 851 852getStringByName(resName: string, callback: AsyncCallback<string>): void 853 854Obtains a string based on the specified resource name. This API uses an asynchronous callback to return the result. 855 856**Atomic service API**: This API can be used in atomic services since API version 11. 857 858**System capability**: SystemCapability.Global.ResourceManager 859 860**Parameters** 861 862| Name | Type | Mandatory | Description | 863| -------- | --------------------------- | ---- | --------------- | 864| resName | string | Yes | Resource name. | 865| callback | AsyncCallback<string> | Yes |Callback used to return the result, which is the string corresponding to the specified resource ID.| 866 867**Error codes** 868For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 869 870| ID| Error Message| 871| -------- | ---------------------------------------- | 872| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 873| 9001003 | Invalid resource name. | 874| 9001004 | No matching resource is found based on the resource name. | 875| 9001006 | The resource is referenced cyclically. | 876 877**Example** 878 ```ts 879 import { BusinessError } from '@kit.BasicServicesKit'; 880 881 try { 882 this.context.resourceManager.getStringByName("test", (error: BusinessError, value: string) => { 883 if (error != null) { 884 console.error("error is " + error); 885 } else { 886 let str = value; 887 } 888 }); 889 } catch (error) { 890 let code = (error as BusinessError).code; 891 let message = (error as BusinessError).message; 892 console.error(`callback getStringByName failed, error code: ${code}, message: ${message}.`); 893 } 894 ``` 895 896### getStringByName<sup>9+</sup> 897 898getStringByName(resName: string): Promise<string> 899 900Obtains a string based on the specified resource name. This API uses a promise to return the result. 901 902**Atomic service API**: This API can be used in atomic services since API version 11. 903 904**System capability**: SystemCapability.Global.ResourceManager 905 906**Parameters** 907 908| Name | Type | Mandatory | Description | 909| ------- | ------ | ---- | ---- | 910| resName | string | Yes | Resource name.| 911 912**Return value** 913 914| Type | Description | 915| --------------------- | ---------- | 916| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource name.| 917 918**Error codes** 919 920For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 921 922| ID| Error Message| 923| -------- | ---------------------------------------- | 924| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 925| 9001003 | Invalid resource name. | 926| 9001004 | No matching resource is found based on the resource name. | 927| 9001006 | The resource is referenced cyclically. | 928 929**Example** 930 ```ts 931 import { BusinessError } from '@kit.BasicServicesKit'; 932 933 try { 934 this.context.resourceManager.getStringByName("test").then((value: string) => { 935 let str = value; 936 }).catch((error: BusinessError) => { 937 console.error("getStringByName promise error is " + error); 938 }); 939 } catch (error) { 940 let code = (error as BusinessError).code; 941 let message = (error as BusinessError).message; 942 console.error(`promise getStringByName failed, error code: ${code}, message: ${message}.`); 943 } 944 ``` 945 946### getStringArrayValueSync<sup>10+</sup> 947 948getStringArrayValueSync(resId: number): Array<string> 949 950Obtains a string array based on the specified resource ID. This API returns the result synchronously. 951 952**Atomic service API**: This API can be used in atomic services since API version 11. 953 954**System capability**: SystemCapability.Global.ResourceManager 955 956**Parameters** 957 958| Name | Type | Mandatory | Description | 959| ----- | ------ | ---- | ----- | 960| resId | number | Yes | Resource ID.| 961 962**Return value** 963 964| Type | Description | 965| --------------------- | ----------- | 966| Array<string> | String array corresponding to the specified resource ID.| 967 968**Error codes** 969 970For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 971 972| ID| Error Message| 973| -------- | ---------------------------------------- | 974| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 975| 9001001 | Invalid resource ID. | 976| 9001002 | No matching resource is found based on the resource ID. | 977| 9001006 | The resource is referenced cyclically. | 978 979**Example** 980 ```ts 981 import { BusinessError } from '@kit.BasicServicesKit'; 982 983 try { 984 this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id); 985 } catch (error) { 986 let code = (error as BusinessError).code; 987 let message = (error as BusinessError).message; 988 console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`); 989 } 990 ``` 991 992### getStringArrayValueSync<sup>10+</sup> 993 994getStringArrayValueSync(resource: Resource): Array<string> 995 996Obtains a string array based on the specified resource object. This API returns the result synchronously. 997 998**Atomic service API**: This API can be used in atomic services since API version 11. 999 1000**System capability**: SystemCapability.Global.ResourceManager 1001 1002**Model restriction**: This API can be used only in the stage model. 1003 1004**Parameters** 1005 1006| Name | Type | Mandatory | Description | 1007| ----- | ------ | ---- | ----- | 1008| resource | [Resource](#resource9) | Yes | Resource object.| 1009 1010**Return value** 1011 1012| Type | Description | 1013| --------------------- | ----------- | 1014| Array<string> | String array corresponding to the specified resource object.| 1015 1016**Error codes** 1017 1018For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1019 1020| ID| Error Message| 1021| -------- | ---------------------------------------- | 1022| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1023| 9001001 | Invalid resource ID. | 1024| 9001002 | No matching resource is found based on the resource ID. | 1025| 9001006 | The resource is referenced cyclically. | 1026 1027**Example** 1028 ```ts 1029 import { resourceManager } from '@kit.LocalizationKit' 1030 import { BusinessError } from '@kit.BasicServicesKit'; 1031 1032 let resource: resourceManager.Resource = { 1033 bundleName: "com.example.myapplication", 1034 moduleName: "entry", 1035 id: $r('app.strarray.test').id 1036 }; 1037 try { 1038 this.context.resourceManager.getStringArrayValueSync(resource); 1039 } catch (error) { 1040 let code = (error as BusinessError).code; 1041 let message = (error as BusinessError).message; 1042 console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`); 1043 } 1044 ``` 1045 1046### getStringArrayByNameSync<sup>10+</sup> 1047 1048getStringArrayByNameSync(resName: string): Array<string> 1049 1050Obtains a string array based on the specified resource name. This API returns the result synchronously. 1051 1052**Atomic service API**: This API can be used in atomic services since API version 11. 1053 1054**System capability**: SystemCapability.Global.ResourceManager 1055 1056**Parameters** 1057 1058| Name | Type | Mandatory | Description | 1059| ----- | ------ | ---- | ----- | 1060| resName | string | Yes | Resource name.| 1061 1062**Return value** 1063 1064| Type | Description | 1065| --------------------- | ----------- | 1066| Array<string> | String array corresponding to the specified resource name.| 1067 1068**Error codes** 1069 1070For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1071 1072| ID| Error Message| 1073| -------- | ---------------------------------------- | 1074| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1075| 9001003 | Invalid resource name. | 1076| 9001004 | No matching resource is found based on the resource name. | 1077| 9001006 | The resource is referenced cyclically. | 1078 1079**Example** 1080 ```ts 1081 try { 1082 this.context.resourceManager.getStringArrayByNameSync("test"); 1083 } catch (error) { 1084 let code = (error as BusinessError).code; 1085 let message = (error as BusinessError).message; 1086 console.error(`getStringArrayByNameSync failed, error code: ${code}, message: ${message}.`); 1087 } 1088 ``` 1089 1090### getStringArrayValue<sup>9+</sup> 1091 1092getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>>): void 1093 1094Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. 1095 1096**Atomic service API**: This API can be used in atomic services since API version 11. 1097 1098**System capability**: SystemCapability.Global.ResourceManager 1099 1100**Parameters** 1101 1102| Name | Type | Mandatory | Description | 1103| -------- | ---------------------------------------- | ---- | ----------------- | 1104| resId | number | Yes | Resource ID. | 1105| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 1106 1107**Error codes** 1108For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1109 1110| ID| Error Message| 1111| -------- | ---------------------------------------- | 1112| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1113| 9001001 | Invalid resource ID. | 1114| 9001002 | No matching resource is found based on the resource ID. | 1115| 9001006 | The resource is referenced cyclically. | 1116 1117**Example** 1118 ```ts 1119 import { BusinessError } from '@kit.BasicServicesKit'; 1120 1121 try { 1122 this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error: BusinessError, value: Array<string>) => { 1123 if (error != null) { 1124 console.error("error is " + error); 1125 } else { 1126 let strArray = value; 1127 } 1128 }); 1129 } catch (error) { 1130 let code = (error as BusinessError).code; 1131 let message = (error as BusinessError).message; 1132 console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`); 1133 } 1134 ``` 1135 1136### getStringArrayValue<sup>9+</sup> 1137 1138getStringArrayValue(resId: number): Promise<Array<string>> 1139 1140Obtains a string array based on the specified resource ID. This API uses a promise to return the result. 1141 1142**Atomic service API**: This API can be used in atomic services since API version 11. 1143 1144**System capability**: SystemCapability.Global.ResourceManager 1145 1146**Parameters** 1147 1148| Name | Type | Mandatory | Description | 1149| ----- | ------ | ---- | ----- | 1150| resId | number | Yes | Resource ID.| 1151 1152**Return value** 1153 1154| Type | Description | 1155| ---------------------------------- | ------------- | 1156| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| 1157 1158**Error codes** 1159For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1160 1161| ID| Error Message| 1162| -------- | ---------------------------------------- | 1163| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1164| 9001001 | Invalid resource ID. | 1165| 9001002 | No matching resource is found based on the resource ID. | 1166| 9001006 | The resource is referenced cyclically. | 1167 1168**Example** 1169 ```ts 1170 import { BusinessError } from '@kit.BasicServicesKit'; 1171 1172 try { 1173 this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then((value: Array<string>) => { 1174 let strArray = value; 1175 }).catch((error: BusinessError) => { 1176 console.error("getStringArrayValue promise error is " + error); 1177 }); 1178 } catch (error) { 1179 let code = (error as BusinessError).code; 1180 let message = (error as BusinessError).message; 1181 console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`); 1182 } 1183 ``` 1184 1185### getStringArrayValue<sup>9+</sup> 1186 1187getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void 1188 1189Obtains a string array based on the specified resource object. This API uses an asynchronous callback to return the result. 1190 1191**Atomic service API**: This API can be used in atomic services since API version 11. 1192 1193**System capability**: SystemCapability.Global.ResourceManager 1194 1195**Model restriction**: This API can be used only in the stage model. 1196 1197**Parameters** 1198 1199| Name | Type | Mandatory | Description | 1200| -------- | ---------------------------------------- | ---- | ----------------- | 1201| resource | [Resource](#resource9) | Yes | Resource object. | 1202| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 1203 1204**Error codes** 1205 1206For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1207 1208| ID| Error Message| 1209| -------- | ---------------------------------------- | 1210| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1211| 9001001 | Invalid resource ID. | 1212| 9001002 | No matching resource is found based on the resource ID. | 1213| 9001006 | The resource is referenced cyclically. | 1214 1215**Example** 1216 ```ts 1217 import { resourceManager } from '@kit.LocalizationKit' 1218 import { BusinessError } from '@kit.BasicServicesKit'; 1219 1220 let resource: resourceManager.Resource = { 1221 bundleName: "com.example.myapplication", 1222 moduleName: "entry", 1223 id: $r('app.strarray.test').id 1224 }; 1225 try { 1226 this.context.resourceManager.getStringArrayValue(resource, (error: BusinessError, value: Array<string>) => { 1227 if (error != null) { 1228 console.error("error is " + error); 1229 } else { 1230 let strArray = value; 1231 } 1232 }); 1233 } catch (error) { 1234 let code = (error as BusinessError).code; 1235 let message = (error as BusinessError).message; 1236 console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`); 1237 } 1238 ``` 1239 1240### getStringArrayValue<sup>9+</sup> 1241 1242getStringArrayValue(resource: Resource): Promise<Array<string>> 1243 1244Obtains a string array based on the specified resource object. This API uses a promise to return the result. 1245 1246**Atomic service API**: This API can be used in atomic services since API version 11. 1247 1248**System capability**: SystemCapability.Global.ResourceManager 1249 1250**Model restriction**: This API can be used only in the stage model. 1251 1252**Parameters** 1253 1254| Name | Type | Mandatory | Description | 1255| -------- | ---------------------- | ---- | ---- | 1256| resource | [Resource](#resource9) | Yes | Resource object.| 1257 1258**Return value** 1259 1260| Type | Description | 1261| ---------------------------------- | ------------------ | 1262| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource object.| 1263 1264**Error codes** 1265 1266For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1267 1268| ID| Error Message| 1269| -------- | ---------------------------------------- | 1270| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1271| 9001001 | Invalid resource ID. | 1272| 9001002 | No matching resource is found based on the resource ID. | 1273| 9001006 | The resource is referenced cyclically. | 1274 1275**Example** 1276 ```ts 1277 import { resourceManager } from '@kit.LocalizationKit' 1278 import { BusinessError } from '@kit.BasicServicesKit'; 1279 1280 let resource: resourceManager.Resource = { 1281 bundleName: "com.example.myapplication", 1282 moduleName: "entry", 1283 id: $r('app.strarray.test').id 1284 }; 1285 try { 1286 this.context.resourceManager.getStringArrayValue(resource).then((value: Array<string>) => { 1287 let strArray = value; 1288 }).catch((error: BusinessError) => { 1289 console.error("getStringArray promise error is " + error); 1290 }); 1291 } catch (error) { 1292 let code = (error as BusinessError).code; 1293 let message = (error as BusinessError).message; 1294 console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`); 1295 } 1296 ``` 1297 1298### getStringArrayByName<sup>9+</sup> 1299 1300getStringArrayByName(resName: string, callback: AsyncCallback<Array<string>>): void 1301 1302Obtains a string array based on the specified resource name. This API uses an asynchronous callback to return the result. 1303 1304**Atomic service API**: This API can be used in atomic services since API version 11. 1305 1306**System capability**: SystemCapability.Global.ResourceManager 1307 1308**Parameters** 1309 1310| Name | Type | Mandatory | Description | 1311| -------- | ---------------------------------------- | ---- | ----------------- | 1312| resName | string | Yes | Resource name. | 1313| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 1314 1315**Error codes** 1316 1317For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1318 1319| ID| Error Message| 1320| -------- | ---------------------------------------- | 1321| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1322| 9001003 | Invalid resource name. | 1323| 9001004 | No matching resource is found based on the resource name. | 1324| 9001006 | The resource is referenced cyclically. | 1325 1326**Example** 1327 ```ts 1328 import { BusinessError } from '@kit.BasicServicesKit'; 1329 1330 try { 1331 this.context.resourceManager.getStringArrayByName("test", (error: BusinessError, value: Array<string>) => { 1332 if (error != null) { 1333 console.error("error is " + error); 1334 } else { 1335 let strArray = value; 1336 } 1337 }); 1338 } catch (error) { 1339 let code = (error as BusinessError).code; 1340 let message = (error as BusinessError).message; 1341 console.error(`callback getStringArrayByName failed, error code: ${code}, message: ${message}.`); 1342 } 1343 ``` 1344 1345### getStringArrayByName<sup>9+</sup> 1346 1347getStringArrayByName(resName: string): Promise<Array<string>> 1348 1349Obtains a string array based on the specified resource name. This API uses a promise to return the result. 1350 1351**Atomic service API**: This API can be used in atomic services since API version 11. 1352 1353**System capability**: SystemCapability.Global.ResourceManager 1354 1355**Parameters** 1356 1357| Name | Type | Mandatory | Description | 1358| ------- | ------ | ---- | ---- | 1359| resName | string | Yes | Resource name.| 1360 1361**Return value** 1362 1363| Type | Description | 1364| ---------------------------------- | ------------ | 1365| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource name.| 1366 1367**Error codes** 1368 1369For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1370 1371| ID| Error Message| 1372| -------- | ---------------------------------------- | 1373| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1374| 9001003 | Invalid resource name. | 1375| 9001004 | No matching resource is found based on the resource name. | 1376| 9001006 | The resource is referenced cyclically. | 1377 1378**Example** 1379 ```ts 1380 import { BusinessError } from '@kit.BasicServicesKit'; 1381 1382 try { 1383 this.context.resourceManager.getStringArrayByName("test").then((value: Array<string>) => { 1384 let strArray = value; 1385 }).catch((error: BusinessError) => { 1386 console.error("getStringArrayByName promise error is " + error); 1387 }); 1388 } catch (error) { 1389 let code = (error as BusinessError).code; 1390 let message = (error as BusinessError).message; 1391 console.error(`promise getStringArrayByName failed, error code: ${code}, message: ${message}.`); 1392 } 1393 ``` 1394 1395### getPluralStringValueSync<sup>10+</sup> 1396 1397getPluralStringValueSync(resId: number, num: number): string 1398 1399Obtains a singular-plural string by the specified number based on the specified resource ID. This API returns the result synchronously. 1400 1401>**NOTE** 1402> 1403> Singular and plural forms are available for English, but not Chinese. 1404 1405**Atomic service API**: This API can be used in atomic services since API version 11. 1406 1407**System capability**: SystemCapability.Global.ResourceManager 1408 1409**Parameters** 1410 1411| Name | Type | Mandatory | Description | 1412| ----- | ------ | ---- | ----- | 1413| resId | number | Yes | Resource ID.| 1414| num | number | Yes | Number. | 1415 1416**Return value** 1417 1418| Type | Description | 1419| -------- | ----------- | 1420| string | Singular-plural string corresponding to the specified resource ID.| 1421 1422**Error codes** 1423 1424For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1425 1426| ID| Error Message| 1427| -------- | ---------------------------------------- | 1428| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1429| 9001001 | Invalid resource ID. | 1430| 9001002 | No matching resource is found based on the resource ID. | 1431| 9001006 | The resource is referenced cyclically. | 1432 1433**Example** 1434 ```ts 1435 import { BusinessError } from '@kit.BasicServicesKit'; 1436 1437 try { 1438 this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1); 1439 } catch (error) { 1440 let code = (error as BusinessError).code; 1441 let message = (error as BusinessError).message; 1442 console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1443 } 1444 ``` 1445 1446### getPluralStringValueSync<sup>10+</sup> 1447 1448getPluralStringValueSync(resource: Resource, num: number): string 1449 1450Obtains a singular-plural string by the specified number based on the specified resource object. This API returns the result synchronously. 1451 1452>**NOTE** 1453> 1454> Singular and plural forms are available for English, but not Chinese. 1455 1456**Atomic service API**: This API can be used in atomic services since API version 11. 1457 1458**System capability**: SystemCapability.Global.ResourceManager 1459 1460**Model restriction**: This API can be used only in the stage model. 1461 1462**Parameters** 1463 1464| Name | Type | Mandatory | Description | 1465| ----- | ------ | ---- | ----- | 1466| resource | [Resource](#resource9) | Yes | Resource object.| 1467| num | number | Yes | Number. | 1468 1469**Return value** 1470 1471| Type | Description | 1472| --------------------- | ----------- | 1473| string | Singular-plural string corresponding to the specified resource object.| 1474 1475**Error codes** 1476 1477For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1478 1479| ID| Error Message| 1480| -------- | ---------------------------------------- | 1481| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1482| 9001001 | Invalid resource ID. | 1483| 9001002 | No matching resource is found based on the resource ID. | 1484| 9001006 | The resource is referenced cyclically. | 1485 1486**Example** 1487 ```ts 1488 import { resourceManager } from '@kit.LocalizationKit' 1489 import { BusinessError } from '@kit.BasicServicesKit'; 1490 1491 let resource: resourceManager.Resource = { 1492 bundleName: "com.example.myapplication", 1493 moduleName: "entry", 1494 id: $r('app.plural.test').id 1495 }; 1496 try { 1497 this.context.resourceManager.getPluralStringValueSync(resource, 1); 1498 } catch (error) { 1499 let code = (error as BusinessError).code; 1500 let message = (error as BusinessError).message; 1501 console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1502 } 1503 ``` 1504 1505### getPluralStringByNameSync<sup>10+</sup> 1506 1507getPluralStringByNameSync(resName: string, num: number): string 1508 1509Obtains a singular-plural string by the specified number based on the specified resource name. This API returns the result synchronously. 1510 1511>**NOTE** 1512> 1513> Singular and plural forms are available for English, but not Chinese. 1514 1515**Atomic service API**: This API can be used in atomic services since API version 11. 1516 1517**System capability**: SystemCapability.Global.ResourceManager 1518 1519**Parameters** 1520 1521| Name | Type | Mandatory | Description | 1522| ----- | ------ | ---- | ----- | 1523| resName | string | Yes | Resource name.| 1524| num | number | Yes | Number. | 1525 1526**Return value** 1527 1528| Type | Description | 1529| --------------------- | ----------- | 1530| string | Singular-plural string corresponding to the specified resource name.| 1531 1532**Error codes** 1533 1534For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1535 1536| ID| Error Message| 1537| -------- | ---------------------------------------- | 1538| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1539| 9001003 | Invalid resource name. | 1540| 9001004 | No matching resource is found based on the resource name. | 1541| 9001006 | The resource is referenced cyclically. | 1542 1543**Example** 1544 ```ts 1545 import { BusinessError } from '@kit.BasicServicesKit'; 1546 1547 try { 1548 this.context.resourceManager.getPluralStringByNameSync("test", 1); 1549 } catch (error) { 1550 let code = (error as BusinessError).code; 1551 let message = (error as BusinessError).message; 1552 console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`); 1553 } 1554 ``` 1555 1556### getPluralStringValue<sup>9+</sup> 1557 1558getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void 1559 1560Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses an asynchronous callback to return the result. 1561 1562>**NOTE** 1563> 1564> Singular and plural forms are available for English, but not Chinese. 1565 1566**Atomic service API**: This API can be used in atomic services since API version 11. 1567 1568**System capability**: SystemCapability.Global.ResourceManager 1569 1570**Parameters** 1571 1572| Name | Type | Mandatory | Description | 1573| -------- | --------------------------- | ---- | ------------------------------- | 1574| resId | number | Yes | Resource ID. | 1575| num | number | Yes | Number. | 1576| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource ID.| 1577 1578**Error codes** 1579 1580For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1581 1582| ID| Error Message| 1583| -------- | ---------------------------------------- | 1584| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1585| 9001001 | Invalid resource ID. | 1586| 9001002 | No matching resource is found based on the resource ID. | 1587| 9001006 | The resource is referenced cyclically. | 1588 1589**Example** 1590 ```ts 1591 import { BusinessError } from '@kit.BasicServicesKit'; 1592 1593 try { 1594 this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error: BusinessError, value: string) => { 1595 if (error != null) { 1596 console.error("error is " + error); 1597 } else { 1598 let str = value; 1599 } 1600 }); 1601 } catch (error) { 1602 let code = (error as BusinessError).code; 1603 let message = (error as BusinessError).message; 1604 console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); 1605 } 1606 ``` 1607 1608### getPluralStringValue<sup>9+</sup> 1609 1610getPluralStringValue(resId: number, num: number): Promise<string> 1611 1612Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses a promise to return the result. 1613 1614>**NOTE** 1615> 1616> Singular and plural forms are available for English, but not Chinese. 1617 1618**Atomic service API**: This API can be used in atomic services since API version 11. 1619 1620**System capability**: SystemCapability.Global.ResourceManager 1621 1622**Parameters** 1623 1624| Name | Type | Mandatory | Description | 1625| ----- | ------ | ---- | ----- | 1626| resId | number | Yes | Resource ID.| 1627| num | number | Yes | Number. | 1628 1629**Return value** 1630 1631| Type | Description | 1632| --------------------- | ------------------------- | 1633| Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource ID.| 1634 1635**Error codes** 1636 1637For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1638 1639| ID| Error Message| 1640| -------- | ---------------------------------------- | 1641| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1642| 9001001 | Invalid resource ID. | 1643| 9001002 | No matching resource is found based on the resource ID. | 1644| 9001006 | The resource is referenced cyclically. | 1645 1646**Example** 1647 ```ts 1648 import { BusinessError } from '@kit.BasicServicesKit'; 1649 1650 try { 1651 this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then((value: string) => { 1652 let str = value; 1653 }).catch((error: BusinessError) => { 1654 console.error("getPluralStringValue promise error is " + error); 1655 }); 1656 } catch (error) { 1657 let code = (error as BusinessError).code; 1658 let message = (error as BusinessError).message; 1659 console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); 1660 } 1661 ``` 1662 1663### getPluralStringValue<sup>9+</sup> 1664 1665getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void 1666 1667Obtains a singular-plural string by the specified number based on the specified resource object. This API uses an asynchronous callback to return the result. 1668 1669>**NOTE** 1670> 1671> Singular and plural forms are available for English, but not Chinese. 1672 1673**Atomic service API**: This API can be used in atomic services since API version 11. 1674 1675**System capability**: SystemCapability.Global.ResourceManager 1676 1677**Model restriction**: This API can be used only in the stage model. 1678 1679**Parameters** 1680 1681| Name | Type | Mandatory | Description | 1682| -------- | --------------------------- | ---- | ------------------------------------ | 1683| resource | [Resource](#resource9) | Yes | Resource object. | 1684| num | number | Yes | Number. | 1685| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource object.| 1686 1687**Error codes** 1688 1689For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1690 1691| ID| Error Message| 1692| -------- | ---------------------------------------- | 1693| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1694| 9001001 | Invalid resource ID. | 1695| 9001002 | No matching resource is found based on the resource ID. | 1696| 9001006 | The resource is referenced cyclically. | 1697 1698**Example** 1699 ```ts 1700 import { resourceManager } from '@kit.LocalizationKit' 1701 import { BusinessError } from '@kit.BasicServicesKit'; 1702 1703 let resource: resourceManager.Resource = { 1704 bundleName: "com.example.myapplication", 1705 moduleName: "entry", 1706 id: $r('app.plural.test').id 1707 }; 1708 try { 1709 this.context.resourceManager.getPluralStringValue(resource, 1, (error: BusinessError, value: string) => { 1710 if (error != null) { 1711 console.error("error is " + error); 1712 } else { 1713 let str = value; 1714 } 1715 }); 1716 } catch (error) { 1717 let code = (error as BusinessError).code; 1718 let message = (error as BusinessError).message; 1719 console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); 1720 } 1721 ``` 1722 1723### getPluralStringValue<sup>9+</sup> 1724 1725getPluralStringValue(resource: Resource, num: number): Promise<string> 1726 1727Obtains a singular-plural string by the specified number based on the specified resource object. This API uses a promise to return the result. 1728 1729>**NOTE** 1730> 1731> Singular and plural forms are available for English, but not Chinese. 1732 1733**Atomic service API**: This API can be used in atomic services since API version 11. 1734 1735**System capability**: SystemCapability.Global.ResourceManager 1736 1737**Model restriction**: This API can be used only in the stage model. 1738 1739**Parameters** 1740 1741| Name | Type | Mandatory | Description | 1742| -------- | ---------------------- | ---- | ---- | 1743| resource | [Resource](#resource9) | Yes | Resource object.| 1744| num | number | Yes | Number. | 1745 1746**Return value** 1747 1748| Type | Description | 1749| --------------------- | ------------------------------ | 1750| Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource object.| 1751 1752**Error codes** 1753 1754For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1755 1756| ID| Error Message| 1757| -------- | ---------------------------------------- | 1758| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1759| 9001001 | Invalid resource ID. | 1760| 9001002 | No matching resource is found based on the resource ID. | 1761| 9001006 | The resource is referenced cyclically. | 1762 1763**Example** 1764 ```ts 1765 import { resourceManager } from '@kit.LocalizationKit' 1766 import { BusinessError } from '@kit.BasicServicesKit'; 1767 1768 let resource: resourceManager.Resource = { 1769 bundleName: "com.example.myapplication", 1770 moduleName: "entry", 1771 id: $r('app.plural.test').id 1772 }; 1773 try { 1774 this.context.resourceManager.getPluralStringValue(resource, 1).then((value: string) => { 1775 let str = value; 1776 }).catch((error: BusinessError) => { 1777 console.error("getPluralStringValue promise error is " + error); 1778 }); 1779 } catch (error) { 1780 let code = (error as BusinessError).code; 1781 let message = (error as BusinessError).message; 1782 console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); 1783 } 1784 ``` 1785 1786### getPluralStringByName<sup>9+</sup> 1787 1788getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void 1789 1790Obtains a singular-plural string by the specified number based on the specified resource name. This API uses an asynchronous callback to return the result. 1791 1792>**NOTE** 1793> 1794> Singular and plural forms are available for English, but not Chinese. 1795 1796**Atomic service API**: This API can be used in atomic services since API version 11. 1797 1798**System capability**: SystemCapability.Global.ResourceManager 1799 1800**Parameters** 1801 1802| Name | Type | Mandatory | Description | 1803| -------- | --------------------------- | ---- | ----------------------------- | 1804| resName | string | Yes | Resource name. | 1805| num | number | Yes | Number. | 1806| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource name.| 1807 1808**Error codes** 1809 1810For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1811 1812| ID| Error Message| 1813| -------- | ---------------------------------------- | 1814| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1815| 9001003 | Invalid resource name. | 1816| 9001004 | No matching resource is found based on the resource name. | 1817| 9001006 | The resource is referenced cyclically. | 1818 1819**Example** 1820 ```ts 1821 import { BusinessError } from '@kit.BasicServicesKit'; 1822 1823 try { 1824 this.context.resourceManager.getPluralStringByName("test", 1, (error: BusinessError, value: string) => { 1825 if (error != null) { 1826 console.error("error is " + error); 1827 } else { 1828 let str = value; 1829 } 1830 }); 1831 } catch (error) { 1832 let code = (error as BusinessError).code; 1833 let message = (error as BusinessError).message; 1834 console.error(`callback getPluralStringByName failed, error code: ${code}, message: ${message}.`); 1835 } 1836 ``` 1837 1838### getPluralStringByName<sup>9+</sup> 1839 1840getPluralStringByName(resName: string, num: number): Promise<string> 1841 1842Obtains a singular-plural string by the specified number based on the specified resource name. This API uses a promise to return the result. 1843 1844>**NOTE** 1845> 1846> Singular and plural forms are available for English, but not Chinese. 1847 1848**Atomic service API**: This API can be used in atomic services since API version 11. 1849 1850**System capability**: SystemCapability.Global.ResourceManager 1851 1852**Parameters** 1853 1854| Name | Type | Mandatory | Description | 1855| ------- | ------ | ---- | ---- | 1856| resName | string | Yes | Resource name.| 1857| num | number | Yes | Number. | 1858 1859**Return value** 1860 1861| Type | Description | 1862| --------------------- | ---------------------- | 1863| Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource name.| 1864 1865**Error codes** 1866 1867For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1868 1869| ID| Error Message| 1870| -------- | ---------------------------------------- | 1871| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1872| 9001003 | Invalid resource name. | 1873| 9001004 | No matching resource is found based on the resource name. | 1874| 9001006 | The resource is referenced cyclically. | 1875 1876**Example** 1877 ```ts 1878 import { BusinessError } from '@kit.BasicServicesKit'; 1879 1880 try { 1881 this.context.resourceManager.getPluralStringByName("test", 1).then((value: string) => { 1882 let str = value; 1883 }).catch((error: BusinessError) => { 1884 console.error("getPluralStringByName promise error is " + error); 1885 }); 1886 } catch (error) { 1887 let code = (error as BusinessError).code; 1888 let message = (error as BusinessError).message; 1889 console.error(`promise getPluralStringByName failed, error code: ${code}, message: ${message}.`); 1890 } 1891 ``` 1892 1893### getMediaContentSync<sup>10+</sup> 1894 1895getMediaContentSync(resId: number, density?: number): Uint8Array 1896 1897Obtains the content of a media file with the default or specified screen density based on the specified resource ID. This API returns the result synchronously. 1898 1899**Atomic service API**: This API can be used in atomic services since API version 11. 1900 1901**System capability**: SystemCapability.Global.ResourceManager 1902 1903**Parameters** 1904 1905| Name | Type | Mandatory | Description | 1906| ----- | ------ | ---- | ----- | 1907| resId | number | Yes | Resource ID.| 1908| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 1909 1910**Return value** 1911 1912| Type | Description | 1913| -------- | ----------- | 1914| Uint8Array | Content of the media file corresponding to the specified resource ID.| 1915 1916**Error codes** 1917 1918For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1919 1920| ID| Error Message| 1921| -------- | ---------------------------------------- | 1922| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1923| 9001001 | Invalid resource ID. | 1924| 9001002 | No matching resource is found based on the resource ID. | 1925 1926**Example** 1927 ```ts 1928 import { BusinessError } from '@kit.BasicServicesKit'; 1929 1930 try { 1931 this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density 1932 } catch (error) { 1933 let code = (error as BusinessError).code; 1934 let message = (error as BusinessError).message; 1935 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1936 } 1937 1938 try { 1939 this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density 1940 } catch (error) { 1941 let code = (error as BusinessError).code; 1942 let message = (error as BusinessError).message; 1943 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1944 } 1945 ``` 1946 1947### getMediaContentSync<sup>10+</sup> 1948 1949getMediaContentSync(resource: Resource, density?: number): Uint8Array 1950 1951Obtains the content of a media file with the default or specified screen density based on the specified resource object. This API returns the result synchronously. 1952 1953**Atomic service API**: This API can be used in atomic services since API version 11. 1954 1955**System capability**: SystemCapability.Global.ResourceManager 1956 1957**Model restriction**: This API can be used only in the stage model. 1958 1959**Parameters** 1960 1961| Name | Type | Mandatory | Description | 1962| ----- | ------ | ---- | ----- | 1963| resource | [Resource](#resource9) | Yes | Resource object.| 1964| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 1965 1966**Return value** 1967 1968| Type | Description | 1969| --------------------- | ----------- | 1970| Uint8Array | Content of the media file corresponding to the specified resource object.| 1971 1972**Error codes** 1973 1974For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1975 1976| ID| Error Message| 1977| -------- | ---------------------------------------- | 1978| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1979| 9001001 | Invalid resource ID. | 1980| 9001002 | No matching resource is found based on the resource ID. | 1981 1982**Example** 1983 ```ts 1984 import { resourceManager } from '@kit.LocalizationKit' 1985 import { BusinessError } from '@kit.BasicServicesKit'; 1986 1987 let resource: resourceManager.Resource = { 1988 bundleName: "com.example.myapplication", 1989 moduleName: "entry", 1990 id: $r('app.media.test').id 1991 }; 1992 try { 1993 this.context.resourceManager.getMediaContentSync(resource); // Default screen density 1994 } catch (error) { 1995 let code = (error as BusinessError).code; 1996 let message = (error as BusinessError).message; 1997 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1998 } 1999 2000 try { 2001 this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density 2002 } catch (error) { 2003 let code = (error as BusinessError).code; 2004 let message = (error as BusinessError).message; 2005 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 2006 } 2007 ``` 2008 2009### getMediaByNameSync<sup>10+</sup> 2010 2011getMediaByNameSync(resName: string, density?: number): Uint8Array 2012 2013Obtains the content of a media file with the default or specified screen density based on the specified resource name. This API returns the result synchronously. 2014 2015**Atomic service API**: This API can be used in atomic services since API version 11. 2016 2017**System capability**: SystemCapability.Global.ResourceManager 2018 2019**Parameters** 2020 2021| Name | Type | Mandatory | Description | 2022| ----- | ------ | ---- | ----- | 2023| resName | string | Yes | Resource name.| 2024| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2025 2026**Return value** 2027 2028| Type | Description | 2029| --------------------- | ----------- | 2030| Uint8Array | Content of the media file corresponding to the specified resource name.| 2031 2032**Error codes** 2033 2034For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2035 2036| ID| Error Message| 2037| -------- | ---------------------------------------- | 2038| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2039| 9001003 | Invalid resource name. | 2040| 9001004 | No matching resource is found based on the resource name. | 2041 2042**Example** 2043 ```ts 2044 import { BusinessError } from '@kit.BasicServicesKit'; 2045 2046 try { 2047 this.context.resourceManager.getMediaByNameSync("test"); // Default screen density 2048 } catch (error) { 2049 let code = (error as BusinessError).code; 2050 let message = (error as BusinessError).message; 2051 console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); 2052 } 2053 2054 try { 2055 this.context.resourceManager.getMediaByNameSync("test", 120); // Specified screen density 2056 } catch (error) { 2057 let code = (error as BusinessError).code; 2058 let message = (error as BusinessError).message; 2059 console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); 2060 } 2061 ``` 2062 2063### getMediaContent<sup>9+</sup> 2064 2065getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void 2066 2067Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. 2068 2069**Atomic service API**: This API can be used in atomic services since API version 11. 2070 2071**System capability**: SystemCapability.Global.ResourceManager 2072 2073**Parameters** 2074 2075| Name | Type | Mandatory | Description | 2076| -------- | ------------------------------- | ---- | ------------------ | 2077| resId | number | Yes | Resource ID. | 2078| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2079 2080**Error codes** 2081 2082For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2083 2084| ID| Error Message| 2085| -------- | ---------------------------------------- | 2086| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2087| 9001001 | Invalid resource ID. | 2088| 9001002 | No matching resource is found based on the resource ID. | 2089 2090**Example** 2091 ```ts 2092 import { BusinessError } from '@kit.BasicServicesKit'; 2093 2094 try { 2095 this.context.resourceManager.getMediaContent($r('app.media.test').id, (error: BusinessError, value: Uint8Array) => { 2096 if (error != null) { 2097 console.error("error is " + error); 2098 } else { 2099 let media = value; 2100 } 2101 }); 2102 } catch (error) { 2103 let code = (error as BusinessError).code; 2104 let message = (error as BusinessError).message; 2105 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2106 } 2107 ``` 2108 2109### getMediaContent<sup>10+</sup> 2110 2111getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8Array>): void 2112 2113Obtains the content of a media file with the specified screen density based on the specified resource ID. This API uses an asynchronous callback to return the result. 2114 2115**Atomic service API**: This API can be used in atomic services since API version 11. 2116 2117**System capability**: SystemCapability.Global.ResourceManager 2118 2119**Parameters** 2120 2121| Name | Type | Mandatory | Description | 2122| -------- | ------------------------------- | ---- | ------------------ | 2123| resId | number | Yes | Resource ID. | 2124| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2125| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2126 2127**Error codes** 2128 2129For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2130 2131| ID| Error Message| 2132| -------- | ---------------------------------------- | 2133| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2134| 9001001 | Invalid resource ID. | 2135| 9001002 | No matching resource is found based on the resource ID. | 2136 2137**Example** 2138 ```ts 2139 import { BusinessError } from '@kit.BasicServicesKit'; 2140 2141 try { 2142 this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error: BusinessError, value: Uint8Array) => { 2143 if (error != null) { 2144 console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2145 } else { 2146 let media = value; 2147 } 2148 }); 2149 } catch (error) { 2150 let code = (error as BusinessError).code; 2151 let message = (error as BusinessError).message; 2152 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2153 } 2154 ``` 2155 2156### getMediaContent<sup>9+</sup> 2157 2158getMediaContent(resId: number): Promise<Uint8Array> 2159 2160Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. 2161 2162**Atomic service API**: This API can be used in atomic services since API version 11. 2163 2164**System capability**: SystemCapability.Global.ResourceManager 2165 2166**Parameters** 2167 2168| Name | Type | Mandatory | Description | 2169| ----- | ------ | ---- | ----- | 2170| resId | number | Yes | Resource ID.| 2171 2172**Return value** 2173 2174| Type | Description | 2175| ------------------------- | -------------- | 2176| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2177 2178**Error codes** 2179 2180For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2181 2182| ID| Error Message| 2183| -------- | ---------------------------------------- | 2184| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2185| 9001001 | Invalid resource ID. | 2186| 9001002 | No matching resource is found based on the resource ID. | 2187 2188**Example** 2189 ```ts 2190 import { BusinessError } from '@kit.BasicServicesKit'; 2191 2192 try { 2193 this.context.resourceManager.getMediaContent($r('app.media.test').id).then((value: Uint8Array) => { 2194 let media = value; 2195 }).catch((error: BusinessError) => { 2196 console.error("getMediaContent promise error is " + error); 2197 }); 2198 } catch (error) { 2199 let code = (error as BusinessError).code; 2200 let message = (error as BusinessError).message; 2201 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2202 } 2203 ``` 2204 2205### getMediaContent<sup>10+</sup> 2206 2207getMediaContent(resId: number, density: number): Promise<Uint8Array> 2208 2209Obtains the content of a media file with the specified screen density based on the specified resource ID. This API uses a promise to return the result. 2210 2211**Atomic service API**: This API can be used in atomic services since API version 11. 2212 2213**System capability**: SystemCapability.Global.ResourceManager 2214 2215**Parameters** 2216 2217| Name | Type | Mandatory | Description | 2218| ----- | ------ | ---- | ----- | 2219| resId | number | Yes | Resource ID.| 2220| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2221 2222**Return value** 2223 2224| Type | Description | 2225| ------------------------- | -------------- | 2226| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2227 2228**Error codes** 2229 2230For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2231 2232| ID| Error Message| 2233| -------- | ---------------------------------------- | 2234| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2235| 9001001 | Invalid resource ID. | 2236| 9001002 | No matching resource is found based on the resource ID. | 2237 2238**Example** 2239 ```ts 2240 import { BusinessError } from '@kit.BasicServicesKit'; 2241 2242 try { 2243 this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then((value: Uint8Array) => { 2244 let media = value; 2245 }).catch((error: BusinessError) => { 2246 console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2247 }); 2248 } catch (error) { 2249 let code = (error as BusinessError).code; 2250 let message = (error as BusinessError).message; 2251 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2252 } 2253 ``` 2254 2255### getMediaContent<sup>9+</sup> 2256 2257getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void 2258 2259Obtains the content of a media file based on the specified resource object. This API uses an asynchronous callback to return the result. 2260 2261**Atomic service API**: This API can be used in atomic services since API version 11. 2262 2263**System capability**: SystemCapability.Global.ResourceManager 2264 2265**Model restriction**: This API can be used only in the stage model. 2266 2267**Parameters** 2268 2269| Name | Type | Mandatory | Description | 2270| -------- | ------------------------------- | ---- | ------------------ | 2271| resource | [Resource](#resource9) | Yes | Resource object. | 2272| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2273 2274**Error codes** 2275 2276For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2277 2278| ID| Error Message| 2279| -------- | ---------------------------------------- | 2280| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2281| 9001001 | Invalid resource ID. | 2282| 9001002 | No matching resource is found based on the resource ID. | 2283 2284**Example** 2285 ```ts 2286 import { resourceManager } from '@kit.LocalizationKit' 2287 import { BusinessError } from '@kit.BasicServicesKit'; 2288 2289 let resource: resourceManager.Resource = { 2290 bundleName: "com.example.myapplication", 2291 moduleName: "entry", 2292 id: $r('app.media.test').id 2293 }; 2294 try { 2295 this.context.resourceManager.getMediaContent(resource, (error: BusinessError, value: Uint8Array) => { 2296 if (error != null) { 2297 console.error("error is " + error); 2298 } else { 2299 let media = value; 2300 } 2301 }); 2302 } catch (error) { 2303 let code = (error as BusinessError).code; 2304 let message = (error as BusinessError).message; 2305 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2306 } 2307 ``` 2308 2309### getMediaContent<sup>10+</sup> 2310 2311getMediaContent(resource: Resource, density: number, callback: AsyncCallback<Uint8Array>): void 2312 2313Obtains the content of a media file with the specified screen density based on the specified resource object. This API uses an asynchronous callback to return the result. 2314 2315**Atomic service API**: This API can be used in atomic services since API version 11. 2316 2317**System capability**: SystemCapability.Global.ResourceManager 2318 2319**Model restriction**: This API can be used only in the stage model. 2320 2321**Parameters** 2322 2323| Name | Type | Mandatory | Description | 2324| -------- | ------------------------------- | ---- | ------------------ | 2325| resource | [Resource](#resource9) | Yes | Resource object. | 2326| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2327| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2328 2329**Error codes** 2330 2331For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2332 2333| ID| Error Message| 2334| -------- | ---------------------------------------- | 2335| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2336| 9001001 | Invalid resource ID. | 2337| 9001002 | No matching resource is found based on the resource ID. | 2338 2339**Example** 2340 ```ts 2341 import { resourceManager } from '@kit.LocalizationKit' 2342 import { BusinessError } from '@kit.BasicServicesKit'; 2343 2344 let resource: resourceManager.Resource = { 2345 bundleName: "com.example.myapplication", 2346 moduleName: "entry", 2347 id: $r('app.media.test').id 2348 }; 2349 try { 2350 this.context.resourceManager.getMediaContent(resource, 120, (error: BusinessError, value: Uint8Array) => { 2351 if (error != null) { 2352 console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2353 } else { 2354 let media = value; 2355 } 2356 }); 2357 } catch (error) { 2358 let code = (error as BusinessError).code; 2359 let message = (error as BusinessError).message; 2360 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2361 } 2362 ``` 2363 2364### getMediaContent<sup>9+</sup> 2365 2366getMediaContent(resource: Resource): Promise<Uint8Array> 2367 2368Obtains the content of a media file based on the specified resource object. This API uses a promise to return the result. 2369 2370**Atomic service API**: This API can be used in atomic services since API version 11. 2371 2372**System capability**: SystemCapability.Global.ResourceManager 2373 2374**Model restriction**: This API can be used only in the stage model. 2375 2376**Parameters** 2377 2378| Name | Type | Mandatory | Description | 2379| -------- | ---------------------- | ---- | ---- | 2380| resource | [Resource](#resource9) | Yes | Resource object.| 2381 2382**Return value** 2383 2384| Type | Description | 2385| ------------------------- | ------------------- | 2386| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| 2387 2388**Error codes** 2389 2390For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2391 2392| ID| Error Message| 2393| -------- | ---------------------------------------- | 2394| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2395| 9001001 | Invalid resource ID. | 2396| 9001002 | No matching resource is found based on the resource ID. | 2397 2398**Example** 2399 ```ts 2400 import { resourceManager } from '@kit.LocalizationKit' 2401 import { BusinessError } from '@kit.BasicServicesKit'; 2402 2403 let resource: resourceManager.Resource = { 2404 bundleName: "com.example.myapplication", 2405 moduleName: "entry", 2406 id: $r('app.media.test').id 2407 }; 2408 try { 2409 this.context.resourceManager.getMediaContent(resource).then((value: Uint8Array) => { 2410 let media = value; 2411 }).catch((error: BusinessError) => { 2412 console.error("getMediaContent promise error is " + error); 2413 }); 2414 } catch (error) { 2415 let code = (error as BusinessError).code; 2416 let message = (error as BusinessError).message; 2417 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2418 } 2419 ``` 2420 2421### getMediaContent<sup>10+</sup> 2422 2423getMediaContent(resource: Resource, density: number): Promise<Uint8Array> 2424 2425Obtains the content of a media file with the specified screen density based on the specified resource object. This API uses a promise to return the result. 2426 2427**Atomic service API**: This API can be used in atomic services since API version 11. 2428 2429**System capability**: SystemCapability.Global.ResourceManager 2430 2431**Model restriction**: This API can be used only in the stage model. 2432 2433**Parameters** 2434 2435| Name | Type | Mandatory | Description | 2436| -------- | ---------------------- | ---- | ---- | 2437| resource | [Resource](#resource9) | Yes | Resource object.| 2438| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2439 2440**Return value** 2441 2442| Type | Description | 2443| ------------------------- | ------------------- | 2444| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| 2445 2446**Error codes** 2447 2448For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2449 2450| ID| Error Message| 2451| -------- | ---------------------------------------- | 2452| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2453| 9001001 | Invalid resource ID. | 2454| 9001002 | No matching resource is found based on the resource ID. | 2455 2456**Example** 2457 ```ts 2458 import { resourceManager } from '@kit.LocalizationKit' 2459 import { BusinessError } from '@kit.BasicServicesKit'; 2460 2461 let resource: resourceManager.Resource = { 2462 bundleName: "com.example.myapplication", 2463 moduleName: "entry", 2464 id: $r('app.media.test').id 2465 }; 2466 try { 2467 this.context.resourceManager.getMediaContent(resource, 120).then((value: Uint8Array) => { 2468 let media = value; 2469 }).catch((error: BusinessError) => { 2470 console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2471 }); 2472 } catch (error) { 2473 let code = (error as BusinessError).code; 2474 let message = (error as BusinessError).message; 2475 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2476 } 2477 ``` 2478 2479### getMediaByName<sup>9+</sup> 2480 2481getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void 2482 2483Obtains the content of a media file based on the specified resource name. This API uses an asynchronous callback to return the result. 2484 2485**Atomic service API**: This API can be used in atomic services since API version 11. 2486 2487**System capability**: SystemCapability.Global.ResourceManager 2488 2489**Parameters** 2490 2491| Name | Type | Mandatory | Description | 2492| -------- | ------------------------------- | ---- | ------------------ | 2493| resName | string | Yes | Resource name. | 2494| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2495 2496**Error codes** 2497For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2498 2499| ID| Error Message| 2500| -------- | ---------------------------------------- | 2501| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2502| 9001003 | Invalid resource name. | 2503| 9001004 | No matching resource is found based on the resource name. | 2504 2505**Example** 2506 ```ts 2507 import { BusinessError } from '@kit.BasicServicesKit'; 2508 2509 try { 2510 this.context.resourceManager.getMediaByName("test", (error: BusinessError, value: Uint8Array) => { 2511 if (error != null) { 2512 console.error("error is " + error); 2513 } else { 2514 let media = value; 2515 } 2516 }); 2517 } catch (error) { 2518 let code = (error as BusinessError).code; 2519 let message = (error as BusinessError).message; 2520 console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); 2521 } 2522 ``` 2523 2524### getMediaByName<sup>10+</sup> 2525 2526getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint8Array>): void 2527 2528Obtains the content of a media file with the specified screen density based on the specified resource name. This API uses an asynchronous callback to return the result. 2529 2530**Atomic service API**: This API can be used in atomic services since API version 11. 2531 2532**System capability**: SystemCapability.Global.ResourceManager 2533 2534**Parameters** 2535 2536| Name | Type | Mandatory | Description | 2537| -------- | ------------------------------- | ---- | ------------------ | 2538| resName | string | Yes | Resource name. | 2539| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2540| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2541 2542**Error codes** 2543 2544For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2545 2546| ID| Error Message| 2547| -------- | ---------------------------------------- | 2548| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2549| 9001003 | Invalid resource name. | 2550| 9001004 | No matching resource is found based on the resource name. | 2551 2552**Example** 2553 ```ts 2554 import { BusinessError } from '@kit.BasicServicesKit'; 2555 2556 try { 2557 this.context.resourceManager.getMediaByName("test", 120, (error: BusinessError, value: Uint8Array) => { 2558 if (error != null) { 2559 console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); 2560 } else { 2561 let media = value; 2562 } 2563 }); 2564 } catch (error) { 2565 let code = (error as BusinessError).code; 2566 let message = (error as BusinessError).message; 2567 console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); 2568 } 2569 ``` 2570 2571### getMediaByName<sup>9+</sup> 2572 2573getMediaByName(resName: string): Promise<Uint8Array> 2574 2575Obtains the content of a media file based on the specified resource name. This API uses a promise to return the result. 2576 2577**Atomic service API**: This API can be used in atomic services since API version 11. 2578 2579**System capability**: SystemCapability.Global.ResourceManager 2580 2581**Parameters** 2582 2583| Name | Type | Mandatory | Description | 2584| ------- | ------ | ---- | ---- | 2585| resName | string | Yes | Resource name.| 2586 2587**Return value** 2588 2589| Type | Description | 2590| ------------------------- | ------------- | 2591| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| 2592 2593**Error codes** 2594 2595For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2596 2597| ID| Error Message| 2598| -------- | ---------------------------------------- | 2599| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2600| 9001003 | Invalid resource name. | 2601| 9001004 | No matching resource is found based on the resource name. | 2602 2603**Example** 2604 ```ts 2605 import { BusinessError } from '@kit.BasicServicesKit'; 2606 2607 try { 2608 this.context.resourceManager.getMediaByName("test").then((value: Uint8Array) => { 2609 let media = value; 2610 }).catch((error: BusinessError) => { 2611 console.error("getMediaByName promise error is " + error); 2612 }); 2613 } catch (error) { 2614 let code = (error as BusinessError).code; 2615 let message = (error as BusinessError).message; 2616 console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); 2617 } 2618 ``` 2619 2620### getMediaByName<sup>10+</sup> 2621 2622getMediaByName(resName: string, density: number): Promise<Uint8Array> 2623 2624Obtains the content of a media file with the specified screen density based on the specified resource name. This API uses a promise to return the result. 2625 2626**Atomic service API**: This API can be used in atomic services since API version 11. 2627 2628**System capability**: SystemCapability.Global.ResourceManager 2629 2630**Parameters** 2631 2632| Name | Type | Mandatory | Description | 2633| ------- | ------ | ---- | ---- | 2634| resName | string | Yes | Resource name.| 2635| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2636 2637**Return value** 2638 2639| Type | Description | 2640| ------------------------- | ------------- | 2641| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| 2642 2643**Error codes** 2644 2645For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2646 2647| ID| Error Message| 2648| -------- | ---------------------------------------- | 2649| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2650| 9001003 | Invalid resource name. | 2651| 9001004 | No matching resource is found based on the resource name. | 2652 2653**Example** 2654 ```ts 2655 import { BusinessError } from '@kit.BasicServicesKit'; 2656 2657 try { 2658 this.context.resourceManager.getMediaByName("test", 120).then((value: Uint8Array) => { 2659 let media = value; 2660 }).catch((error: BusinessError) => { 2661 console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); 2662 }); 2663 } catch (error) { 2664 let code = (error as BusinessError).code; 2665 let message = (error as BusinessError).message; 2666 console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); 2667 } 2668 ``` 2669 2670### getMediaContentBase64Sync<sup>10+</sup> 2671 2672getMediaContentBase64Sync(resId: number, density?: number): string 2673 2674Obtains the Base64 code of an image with the default or specified screen density based on the specified resource ID. This API returns the result synchronously. 2675 2676**Atomic service API**: This API can be used in atomic services since API version 11. 2677 2678**System capability**: SystemCapability.Global.ResourceManager 2679 2680**Parameters** 2681 2682| Name | Type | Mandatory | Description | 2683| ----- | ------ | ---- | ----- | 2684| resId | number | Yes | Resource ID.| 2685| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2686 2687**Return value** 2688 2689| Type | Description | 2690| -------- | ----------- | 2691| string | Base64 code of the image corresponding to the specified resource ID.| 2692 2693**Error codes** 2694 2695For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2696 2697| ID| Error Message| 2698| -------- | ---------------------------------------- | 2699| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2700| 9001001 | Invalid resource ID. | 2701| 9001002 | No matching resource is found based on the resource ID. | 2702 2703**Example** 2704 ```ts 2705 import { BusinessError } from '@kit.BasicServicesKit'; 2706 2707 try { 2708 this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density 2709 } catch (error) { 2710 let code = (error as BusinessError).code; 2711 let message = (error as BusinessError).message; 2712 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2713 } 2714 2715 try { 2716 this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density 2717 } catch (error) { 2718 let code = (error as BusinessError).code; 2719 let message = (error as BusinessError).message; 2720 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2721 } 2722 ``` 2723 2724### getMediaContentBase64Sync<sup>10+</sup> 2725 2726getMediaContentBase64Sync(resource: Resource, density?: number): string 2727 2728Obtains the Base64 code of an image with the default or specified screen density based on the specified resource object. This API returns the result synchronously. 2729 2730**Atomic service API**: This API can be used in atomic services since API version 11. 2731 2732**System capability**: SystemCapability.Global.ResourceManager 2733 2734**Model restriction**: This API can be used only in the stage model. 2735 2736**Parameters** 2737 2738| Name | Type | Mandatory | Description | 2739| ----- | ------ | ---- | ----- | 2740| resource | [Resource](#resource9) | Yes | Resource object.| 2741| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2742 2743**Return value** 2744 2745| Type | Description | 2746| --------------------- | ----------- | 2747| string | Base64 code of the image corresponding to the specified resource object.| 2748 2749**Error codes** 2750 2751For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2752 2753| ID| Error Message| 2754| -------- | ---------------------------------------- | 2755| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2756| 9001001 | Invalid resource ID. | 2757| 9001002 | No matching resource is found based on the resource ID. | 2758 2759**Example** 2760 ```ts 2761 import { resourceManager } from '@kit.LocalizationKit' 2762 import { BusinessError } from '@kit.BasicServicesKit'; 2763 2764 let resource: resourceManager.Resource = { 2765 bundleName: "com.example.myapplication", 2766 moduleName: "entry", 2767 id: $r('app.media.test').id 2768 }; 2769 try { 2770 this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density 2771 } catch (error) { 2772 let code = (error as BusinessError).code; 2773 let message = (error as BusinessError).message; 2774 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2775 } 2776 2777 try { 2778 this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density 2779 } catch (error) { 2780 let code = (error as BusinessError).code; 2781 let message = (error as BusinessError).message; 2782 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2783 } 2784 ``` 2785 2786### getMediaBase64ByNameSync<sup>10+</sup> 2787 2788getMediaBase64ByNameSync(resName: string, density?: number): string 2789 2790Obtains the Base64 code of an image with the default or specified screen density based on the specified resource name. This API returns the result synchronously. 2791 2792**Atomic service API**: This API can be used in atomic services since API version 11. 2793 2794**System capability**: SystemCapability.Global.ResourceManager 2795 2796**Parameters** 2797 2798| Name | Type | Mandatory | Description | 2799| ----- | ------ | ---- | ----- | 2800| resName | string | Yes | Resource name.| 2801| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2802 2803**Return value** 2804 2805| Type | Description | 2806| --------------------- | ----------- | 2807| string | Base64 code of the image corresponding to the specified resource name.| 2808 2809**Error codes** 2810 2811For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2812 2813| ID| Error Message| 2814| -------- | ---------------------------------------- | 2815| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2816| 9001003 | Invalid resource name. | 2817| 9001004 | No matching resource is found based on the resource name. | 2818 2819**Example** 2820 ```ts 2821 import { BusinessError } from '@kit.BasicServicesKit'; 2822 2823 try { 2824 this.context.resourceManager.getMediaBase64ByNameSync("test"); // Default screen density 2825 } catch (error) { 2826 let code = (error as BusinessError).code; 2827 let message = (error as BusinessError).message; 2828 console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); 2829 } 2830 2831 try { 2832 this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // Specified screen density 2833 } catch (error) { 2834 let code = (error as BusinessError).code; 2835 let message = (error as BusinessError).message; 2836 console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); 2837 } 2838 ``` 2839 2840### getMediaContentBase64<sup>9+</sup> 2841 2842getMediaContentBase64(resId: number, callback: AsyncCallback<string>): void 2843 2844Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. 2845 2846**Atomic service API**: This API can be used in atomic services since API version 11. 2847 2848**System capability**: SystemCapability.Global.ResourceManager 2849 2850**Parameters** 2851 2852| Name | Type | Mandatory | Description | 2853| -------- | --------------------------- | ---- | ------------------------ | 2854| resId | number | Yes | Resource ID. | 2855| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2856 2857**Error codes** 2858 2859For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2860 2861| ID| Error Message| 2862| -------- | ---------------------------------------- | 2863| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2864| 9001001 | Invalid resource ID. | 2865| 9001002 | No matching resource is found based on the resource ID. | 2866 2867**Example** 2868 ```ts 2869 import { BusinessError } from '@kit.BasicServicesKit'; 2870 2871 try { 2872 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error: BusinessError, value: string) => { 2873 if (error != null) { 2874 console.error("error is " + error); 2875 } else { 2876 let media = value; 2877 } 2878 }); 2879 } catch (error) { 2880 let code = (error as BusinessError).code; 2881 let message = (error as BusinessError).message; 2882 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2883 } 2884 ``` 2885 2886### getMediaContentBase64<sup>10+</sup> 2887 2888getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<string>): void 2889 2890Obtains the Base64 code of an image with the specified screen density based on the specified resource ID. This API uses an asynchronous callback to return the result. 2891 2892**Atomic service API**: This API can be used in atomic services since API version 11. 2893 2894**System capability**: SystemCapability.Global.ResourceManager 2895 2896**Parameters** 2897 2898| Name | Type | Mandatory | Description | 2899| -------- | --------------------------- | ---- | ------------------------ | 2900| resId | number | Yes | Resource ID. | 2901| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2902| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2903 2904**Error codes** 2905 2906For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2907 2908| ID| Error Message| 2909| -------- | ---------------------------------------- | 2910| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2911| 9001001 | Invalid resource ID. | 2912| 9001002 | No matching resource is found based on the resource ID. | 2913 2914**Example** 2915 ```ts 2916 import { BusinessError } from '@kit.BasicServicesKit'; 2917 2918 try { 2919 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error: BusinessError, value: string) => { 2920 if (error != null) { 2921 console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 2922 } else { 2923 let media = value; 2924 } 2925 }); 2926 } catch (error) { 2927 let code = (error as BusinessError).code; 2928 let message = (error as BusinessError).message; 2929 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2930 } 2931 ``` 2932 2933### getMediaContentBase64<sup>9+</sup> 2934 2935getMediaContentBase64(resId: number): Promise<string> 2936 2937Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. 2938 2939**Atomic service API**: This API can be used in atomic services since API version 11. 2940 2941**System capability**: SystemCapability.Global.ResourceManager 2942 2943**Parameters** 2944 2945| Name | Type | Mandatory | Description | 2946| ----- | ------ | ---- | ----- | 2947| resId | number | Yes | Resource ID.| 2948 2949**Return value** 2950 2951| Type | Description | 2952| --------------------- | -------------------- | 2953| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2954 2955**Error codes** 2956 2957For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2958 2959| ID| Error Message| 2960| -------- | ---------------------------------------- | 2961| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2962| 9001001 | Invalid resource ID. | 2963| 9001002 | No matching resource is found based on the resource ID. | 2964 2965**Example** 2966 ```ts 2967 import { BusinessError } from '@kit.BasicServicesKit'; 2968 2969 try { 2970 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then((value: string) => { 2971 let media = value; 2972 }).catch((error: BusinessError) => { 2973 console.error("getMediaContentBase64 promise error is " + error); 2974 }); 2975 } catch (error) { 2976 let code = (error as BusinessError).code; 2977 let message = (error as BusinessError).message; 2978 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2979 } 2980 ``` 2981 2982### getMediaContentBase64<sup>10+</sup> 2983 2984getMediaContentBase64(resId: number, density: number): Promise<string> 2985 2986Obtains the Base64 code of an image with the specified screen density based on the specified resource ID. This API uses a promise to return the result. 2987 2988**Atomic service API**: This API can be used in atomic services since API version 11. 2989 2990**System capability**: SystemCapability.Global.ResourceManager 2991 2992**Parameters** 2993 2994| Name | Type | Mandatory | Description | 2995| ----- | ------ | ---- | ----- | 2996| resId | number | Yes | Resource ID.| 2997| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2998 2999**Return value** 3000 3001| Type | Description | 3002| --------------------- | -------------------- | 3003| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3004 3005**Error codes** 3006 3007For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3008 3009| ID| Error Message| 3010| -------- | ---------------------------------------- | 3011| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3012| 9001001 | Invalid resource ID. | 3013| 9001002 | No matching resource is found based on the resource ID. | 3014 3015**Example** 3016 ```ts 3017 import { BusinessError } from '@kit.BasicServicesKit'; 3018 3019 try { 3020 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then((value: string) => { 3021 let media = value; 3022 }).catch((error: BusinessError) => { 3023 console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 3024 }); 3025 } catch (error) { 3026 let code = (error as BusinessError).code; 3027 let message = (error as BusinessError).message; 3028 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3029 } 3030 ``` 3031 3032### getMediaContentBase64<sup>9+</sup> 3033 3034getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>): void 3035 3036Obtains the Base64 code of an image based on the specified resource object. This API uses an asynchronous callback to return the result. 3037 3038**Atomic service API**: This API can be used in atomic services since API version 11. 3039 3040**System capability**: SystemCapability.Global.ResourceManager 3041 3042**Model restriction**: This API can be used only in the stage model. 3043 3044**Parameters** 3045 3046| Name | Type | Mandatory | Description | 3047| -------- | --------------------------- | ---- | ------------------------ | 3048| resource | [Resource](#resource9) | Yes | Resource object. | 3049| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3050 3051**Error codes** 3052 3053For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3054 3055| ID| Error Message| 3056| -------- | ---------------------------------------- | 3057| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3058| 9001001 | Invalid resource ID. | 3059| 9001002 | No matching resource is found based on the resource ID. | 3060 3061**Example** 3062 ```ts 3063 import { resourceManager } from '@kit.LocalizationKit' 3064 import { BusinessError } from '@kit.BasicServicesKit'; 3065 3066 let resource: resourceManager.Resource = { 3067 bundleName: "com.example.myapplication", 3068 moduleName: "entry", 3069 id: $r('app.media.test').id 3070 }; 3071 try { 3072 this.context.resourceManager.getMediaContentBase64(resource, (error: BusinessError, value: string) => { 3073 if (error != null) { 3074 console.error("error is " + error); 3075 } else { 3076 let media = value; 3077 } 3078 }); 3079 } catch (error) { 3080 let code = (error as BusinessError).code; 3081 let message = (error as BusinessError).message; 3082 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3083 } 3084 ``` 3085 3086### getMediaContentBase64<sup>10+</sup> 3087 3088getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback<string>): void 3089 3090Obtains the Base64 code of an image with the specified screen density based on the specified resource object. This API uses an asynchronous callback to return the result. 3091 3092**Atomic service API**: This API can be used in atomic services since API version 11. 3093 3094**System capability**: SystemCapability.Global.ResourceManager 3095 3096**Model restriction**: This API can be used only in the stage model. 3097 3098**Parameters** 3099 3100| Name | Type | Mandatory | Description | 3101| -------- | --------------------------- | ---- | ------------------------ | 3102| resource | [Resource](#resource9) | Yes | Resource object. | 3103| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3104| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3105 3106**Error codes** 3107 3108For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3109 3110| ID| Error Message| 3111| -------- | ---------------------------------------- | 3112| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3113| 9001001 | Invalid resource ID. | 3114| 9001002 | No matching resource is found based on the resource ID. | 3115 3116**Example** 3117 ```ts 3118 import { resourceManager } from '@kit.LocalizationKit' 3119 import { BusinessError } from '@kit.BasicServicesKit'; 3120 3121 let resource: resourceManager.Resource = { 3122 bundleName: "com.example.myapplication", 3123 moduleName: "entry", 3124 id: $r('app.media.test').id 3125 }; 3126 try { 3127 this.context.resourceManager.getMediaContentBase64(resource, 120, (error: BusinessError, value: string) => { 3128 if (error != null) { 3129 console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 3130 } else { 3131 let media = value; 3132 } 3133 }); 3134 } catch (error) { 3135 let code = (error as BusinessError).code; 3136 let message = (error as BusinessError).message; 3137 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3138 } 3139 ``` 3140 3141### getMediaContentBase64<sup>9+</sup> 3142 3143getMediaContentBase64(resource: Resource): Promise<string> 3144 3145Obtains the Base64 code of an image based on the specified resource object. This API uses a promise to return the result. 3146 3147**Atomic service API**: This API can be used in atomic services since API version 11. 3148 3149**System capability**: SystemCapability.Global.ResourceManager 3150 3151**Model restriction**: This API can be used only in the stage model. 3152 3153**Parameters** 3154 3155| Name | Type | Mandatory | Description | 3156| -------- | ---------------------- | ---- | ---- | 3157| resource | [Resource](#resource9) | Yes | Resource object.| 3158 3159**Return value** 3160 3161| Type | Description | 3162| --------------------- | ------------------------- | 3163| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| 3164 3165**Error codes** 3166 3167For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3168 3169| ID| Error Message| 3170| -------- | ---------------------------------------- | 3171| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3172| 9001001 | Invalid resource ID. | 3173| 9001002 | No matching resource is found based on the resource ID. | 3174 3175**Example** 3176 ```ts 3177 import { resourceManager } from '@kit.LocalizationKit' 3178 import { BusinessError } from '@kit.BasicServicesKit'; 3179 3180 let resource: resourceManager.Resource = { 3181 bundleName: "com.example.myapplication", 3182 moduleName: "entry", 3183 id: $r('app.media.test').id 3184 }; 3185 try { 3186 this.context.resourceManager.getMediaContentBase64(resource).then((value: string) => { 3187 let media = value; 3188 }).catch((error: BusinessError) => { 3189 console.error("getMediaContentBase64 promise error is " + error); 3190 }); 3191 } catch (error) { 3192 let code = (error as BusinessError).code; 3193 let message = (error as BusinessError).message; 3194 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3195 } 3196 ``` 3197 3198### getMediaContentBase64<sup>10+</sup> 3199 3200getMediaContentBase64(resource: Resource, density: number): Promise<string> 3201 3202Obtains the Base64 code of an image with the specified screen density based on the specified resource object. This API uses a promise to return the result. 3203 3204**Atomic service API**: This API can be used in atomic services since API version 11. 3205 3206**System capability**: SystemCapability.Global.ResourceManager 3207 3208**Model restriction**: This API can be used only in the stage model. 3209 3210**Parameters** 3211 3212| Name | Type | Mandatory | Description | 3213| -------- | ---------------------- | ---- | ---- | 3214| resource | [Resource](#resource9) | Yes | Resource object.| 3215| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3216 3217**Return value** 3218 3219| Type | Description | 3220| --------------------- | ------------------------- | 3221| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| 3222 3223**Error codes** 3224 3225For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3226 3227| ID| Error Message| 3228| -------- | ---------------------------------------- | 3229| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3230| 9001001 | Invalid resource ID. | 3231| 9001002 | No matching resource is found based on the resource ID. | 3232 3233**Example** 3234 ```ts 3235 import { resourceManager } from '@kit.LocalizationKit' 3236 import { BusinessError } from '@kit.BasicServicesKit'; 3237 3238 let resource: resourceManager.Resource = { 3239 bundleName: "com.example.myapplication", 3240 moduleName: "entry", 3241 id: $r('app.media.test').id 3242 }; 3243 try { 3244 this.context.resourceManager.getMediaContentBase64(resource, 120).then((value: string) => { 3245 let media = value; 3246 }).catch((error: BusinessError) => { 3247 console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 3248 }); 3249 } catch (error) { 3250 let code = (error as BusinessError).code; 3251 let message = (error as BusinessError).message; 3252 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3253 } 3254 ``` 3255 3256### getMediaBase64ByName<sup>9+</sup> 3257 3258getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): void 3259 3260Obtains the Base64 code of an image based on the specified resource name. This API uses an asynchronous callback to return the result. 3261 3262**Atomic service API**: This API can be used in atomic services since API version 11. 3263 3264**System capability**: SystemCapability.Global.ResourceManager 3265 3266**Parameters** 3267 3268| Name | Type | Mandatory | Description | 3269| -------- | --------------------------- | ---- | ------------------------ | 3270| resName | string | Yes | Resource name. | 3271| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3272 3273**Error codes** 3274 3275For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3276 3277| ID| Error Message| 3278| -------- | ---------------------------------------- | 3279| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3280| 9001003 | Invalid resource name. | 3281| 9001004 | No matching resource is found based on the resource name. | 3282 3283**Example** 3284 ```ts 3285 import { BusinessError } from '@kit.BasicServicesKit'; 3286 3287 try { 3288 this.context.resourceManager.getMediaBase64ByName("test", (error: BusinessError, value: string) => { 3289 if (error != null) { 3290 console.error("error is " + error); 3291 } else { 3292 let media = value; 3293 } 3294 }); 3295 } catch (error) { 3296 let code = (error as BusinessError).code; 3297 let message = (error as BusinessError).message; 3298 console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3299 } 3300 ``` 3301 3302### getMediaBase64ByName<sup>10+</sup> 3303 3304getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback<string>): void 3305 3306Obtains the Base64 code of an image with the specified screen density based on the specified resource name. This API uses an asynchronous callback to return the result. 3307 3308**Atomic service API**: This API can be used in atomic services since API version 11. 3309 3310**System capability**: SystemCapability.Global.ResourceManager 3311 3312**Parameters** 3313 3314| Name | Type | Mandatory | Description | 3315| -------- | --------------------------- | ---- | ------------------------ | 3316| resName | string | Yes | Resource name. | 3317| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3318| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3319 3320**Error codes** 3321 3322For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3323 3324| ID| Error Message| 3325| -------- | ---------------------------------------- | 3326| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3327| 9001003 | Invalid resource name. | 3328| 9001004 | No matching resource is found based on the resource name. | 3329 3330**Example** 3331 ```ts 3332 import { BusinessError } from '@kit.BasicServicesKit'; 3333 3334 try { 3335 this.context.resourceManager.getMediaBase64ByName("test", 120, (error: BusinessError, value: string) => { 3336 if (error != null) { 3337 console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); 3338 } else { 3339 let media = value; 3340 } 3341 }); 3342 } catch (error) { 3343 let code = (error as BusinessError).code; 3344 let message = (error as BusinessError).message; 3345 console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3346 } 3347 ``` 3348 3349### getMediaBase64ByName<sup>9+</sup> 3350 3351getMediaBase64ByName(resName: string): Promise<string> 3352 3353Obtains the Base64 code of an image based on the specified resource name. This API uses a promise to return the result. 3354 3355**Atomic service API**: This API can be used in atomic services since API version 11. 3356 3357**System capability**: SystemCapability.Global.ResourceManager 3358 3359**Parameters** 3360 3361| Name | Type | Mandatory | Description | 3362| ------- | ------ | ---- | ---- | 3363| resName | string | Yes | Resource name.| 3364 3365**Return value** 3366 3367| Type | Description | 3368| --------------------- | ------------------- | 3369| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| 3370 3371**Error codes** 3372 3373For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3374 3375| ID| Error Message| 3376| -------- | ---------------------------------------- | 3377| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3378| 9001003 | Invalid resource name. | 3379| 9001004 | No matching resource is found based on the resource name. | 3380 3381**Example** 3382 ```ts 3383 import { BusinessError } from '@kit.BasicServicesKit'; 3384 3385 try { 3386 this.context.resourceManager.getMediaBase64ByName("test").then((value: string) => { 3387 let media = value; 3388 }).catch((error: BusinessError) => { 3389 console.error("getMediaBase64ByName promise error is " + error); 3390 }); 3391 } catch (error) { 3392 let code = (error as BusinessError).code; 3393 let message = (error as BusinessError).message; 3394 console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3395 } 3396 ``` 3397 3398### getMediaBase64ByName<sup>10+</sup> 3399 3400getMediaBase64ByName(resName: string, density: number): Promise<string> 3401 3402Obtains the Base64 code of an image with the specified screen density based on the specified resource name. This API uses a promise to return the result. 3403 3404**Atomic service API**: This API can be used in atomic services since API version 11. 3405 3406**System capability**: SystemCapability.Global.ResourceManager 3407 3408**Parameters** 3409 3410| Name | Type | Mandatory | Description | 3411| ------- | ------ | ---- | ---- | 3412| resName | string | Yes | Resource name.| 3413| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3414 3415**Return value** 3416 3417| Type | Description | 3418| --------------------- | ------------------- | 3419| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| 3420 3421**Error codes** 3422 3423For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3424 3425| ID| Error Message| 3426| -------- | ---------------------------------------- | 3427| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3428| 9001003 | Invalid resource name. | 3429| 9001004 | No matching resource is found based on the resource name. | 3430 3431**Example** 3432 ```ts 3433 import { BusinessError } from '@kit.BasicServicesKit'; 3434 3435 try { 3436 this.context.resourceManager.getMediaBase64ByName("test", 120).then((value: string) => { 3437 let media = value; 3438 }).catch((error: BusinessError) => { 3439 console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); 3440 }); 3441 } catch (error) { 3442 let code = (error as BusinessError).code; 3443 let message = (error as BusinessError).message; 3444 console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3445 } 3446 ``` 3447 3448### getDrawableDescriptor<sup>10+</sup> 3449 3450getDrawableDescriptor(resId: number, density?: number, type?: number): DrawableDescriptor 3451 3452Obtains a **DrawableDescriptor** object for icon display based on the specified resource ID. This API returns the result synchronously. 3453 3454**Atomic service API**: This API can be used in atomic services since API version 11. 3455 3456**System capability**: SystemCapability.Global.ResourceManager 3457 3458**Parameters** 3459 3460| Name | Type | Mandatory | Description | 3461| ----- | ------ | ---- | ----- | 3462| resId | number | Yes | Resource ID.| 3463| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3464| type<sup>11+</sup> | number | No | Resource type. The value **1** indicates the layered icon resource of the application in the theme resource package, and the value **0** or the default value indicates the icon resource of the application.| 3465 3466**Return value** 3467 3468| Type | Description | 3469| ------ | ---------- | 3470| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3471 3472**Error codes** 3473 3474For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3475 3476| ID| Error Message| 3477| -------- | ---------------------------------------- | 3478| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3479| 9001001 | Invalid resource ID. | 3480| 9001002 | No matching resource is found based on the resource ID. | 3481 3482**Example** 3483 ```ts 3484 import { BusinessError } from '@kit.BasicServicesKit'; 3485 3486 try { 3487 this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); 3488 } catch (error) { 3489 let code = (error as BusinessError).code; 3490 let message = (error as BusinessError).message; 3491 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3492 } 3493 try { 3494 this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); 3495 } catch (error) { 3496 let code = (error as BusinessError).code; 3497 let message = (error as BusinessError).message; 3498 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3499 } 3500 try { 3501 this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 0, 1); 3502 } catch (error) { 3503 let code = (error as BusinessError).code; 3504 let message = (error as BusinessError).message; 3505 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3506 } 3507 ``` 3508 3509### getDrawableDescriptor<sup>10+</sup> 3510 3511getDrawableDescriptor(resource: Resource, density?: number, type?: number): DrawableDescriptor 3512 3513Obtains a **DrawableDescriptor** object for icon display based on the specified resource object. This API returns the result synchronously. 3514 3515**Atomic service API**: This API can be used in atomic services since API version 11. 3516 3517**System capability**: SystemCapability.Global.ResourceManager 3518 3519**Model restriction**: This API can be used only in the stage model. 3520 3521**Parameters** 3522 3523| Name | Type | Mandatory | Description | 3524| -------- | ---------------------- | ---- | ---- | 3525| resource | [Resource](#resource9) | Yes | Resource object.| 3526| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3527| type<sup>11+</sup> | number | No | Resource type. The value **1** indicates the layered icon resource of the application in the theme resource package, and the value **0** or the default value indicates the icon resource of the application.| 3528 3529**Return value** 3530 3531| Type | Description | 3532| ------- | ----------------- | 3533| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3534 3535**Error codes** 3536 3537For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3538 3539| ID| Error Message| 3540| -------- | ---------------------------------------- | 3541| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3542| 9001001 | Invalid resource ID. | 3543| 9001002 | No matching resource is found based on the resource ID. | 3544 3545**Example** 3546 ```ts 3547 import { resourceManager } from '@kit.LocalizationKit' 3548 import { BusinessError } from '@kit.BasicServicesKit'; 3549 3550 let resource: resourceManager.Resource = { 3551 bundleName: "com.example.myapplication", 3552 moduleName: "entry", 3553 id: $r('app.media.icon').id 3554 }; 3555 try { 3556 this.context.resourceManager.getDrawableDescriptor(resource); 3557 } catch (error) { 3558 let code = (error as BusinessError).code; 3559 let message = (error as BusinessError).message; 3560 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3561 } 3562 try { 3563 this.context.resourceManager.getDrawableDescriptor(resource, 120); 3564 } catch (error) { 3565 let code = (error as BusinessError).code; 3566 let message = (error as BusinessError).message; 3567 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3568 } 3569 try { 3570 this.context.resourceManager.getDrawableDescriptor(resource, 0, 1); 3571 } catch (error) { 3572 let code = (error as BusinessError).code; 3573 let message = (error as BusinessError).message; 3574 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3575 } 3576 ``` 3577 3578### getDrawableDescriptorByName<sup>10+</sup> 3579 3580getDrawableDescriptorByName(resName: string, density?: number, type?: number): DrawableDescriptor 3581 3582Obtains a **DrawableDescriptor** object for icon display based on the specified resource name. This API returns the result synchronously. 3583 3584**Atomic service API**: This API can be used in atomic services since API version 11. 3585 3586**System capability**: SystemCapability.Global.ResourceManager 3587 3588**Parameters** 3589 3590| Name | Type | Mandatory | Description | 3591| ------- | ------ | ---- | ---- | 3592| resName | string | Yes | Resource name.| 3593| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3594| type<sup>11+</sup> | number | No | Resource type. The value **1** indicates the layered icon resource of the application in the theme resource package, and the value **0** or the default value indicates the icon resource of the application.| 3595 3596**Return value** 3597 3598| Type | Description | 3599| ------ | --------- | 3600| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3601 3602**Error codes** 3603 3604For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3605 3606| ID| Error Message| 3607| -------- | ---------------------------------------- | 3608| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3609| 9001003 | Invalid resource name. | 3610| 9001004 | No matching resource is found based on the resource name. | 3611 3612**Example** 3613 ```ts 3614 import { BusinessError } from '@kit.BasicServicesKit'; 3615 3616 try { 3617 this.context.resourceManager.getDrawableDescriptorByName('icon'); 3618 } catch (error) { 3619 let code = (error as BusinessError).code; 3620 let message = (error as BusinessError).message; 3621 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3622 } 3623 try { 3624 this.context.resourceManager.getDrawableDescriptorByName('icon', 120); 3625 } catch (error) { 3626 let code = (error as BusinessError).code; 3627 let message = (error as BusinessError).message; 3628 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3629 } 3630 try { 3631 this.context.resourceManager.getDrawableDescriptorByName('icon', 0, 1); 3632 } catch (error) { 3633 let code = (error as BusinessError).code; 3634 let message = (error as BusinessError).message; 3635 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3636 } 3637 ``` 3638 3639### getBoolean<sup>9+</sup> 3640 3641getBoolean(resId: number): boolean 3642 3643Obtains a Boolean result based on the specified resource ID. This API returns the result synchronously. 3644 3645**Atomic service API**: This API can be used in atomic services since API version 11. 3646 3647**System capability**: SystemCapability.Global.ResourceManager 3648 3649**Parameters** 3650 3651| Name | Type | Mandatory | Description | 3652| ----- | ------ | ---- | ----- | 3653| resId | number | Yes | Resource ID.| 3654 3655**Return value** 3656 3657| Type | Description | 3658| ------- | ------------ | 3659| boolean | Boolean result corresponding to the specified resource ID.| 3660 3661**Error codes** 3662 3663For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3664 3665| ID| Error Message| 3666| -------- | ---------------------------------------- | 3667| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3668| 9001001 | Invalid resource ID. | 3669| 9001002 | No matching resource is found based on the resource ID. | 3670| 9001006 | The resource is referenced cyclically. | 3671 3672**Example** 3673 ```ts 3674 import { BusinessError } from '@kit.BasicServicesKit'; 3675 3676 try { 3677 this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); 3678 } catch (error) { 3679 let code = (error as BusinessError).code; 3680 let message = (error as BusinessError).message; 3681 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3682 } 3683 ``` 3684### getBoolean<sup>9+</sup> 3685 3686getBoolean(resource: Resource): boolean 3687 3688Obtains a Boolean result based on the specified resource object. This API returns the result synchronously. 3689 3690**Atomic service API**: This API can be used in atomic services since API version 11. 3691 3692**System capability**: SystemCapability.Global.ResourceManager 3693 3694**Model restriction**: This API can be used only in the stage model. 3695 3696**Parameters** 3697 3698| Name | Type | Mandatory | Description | 3699| -------- | ---------------------- | ---- | ---- | 3700| resource | [Resource](#resource9) | Yes | Resource object.| 3701 3702**Return value** 3703 3704| Type | Description | 3705| ------- | ----------------- | 3706| boolean | Boolean result corresponding to the specified resource object.| 3707 3708**Error codes** 3709 3710For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3711 3712| ID| Error Message| 3713| -------- | ---------------------------------------- | 3714| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3715| 9001001 | Invalid resource ID. | 3716| 9001002 | No matching resource is found based on the resource ID. | 3717| 9001006 | The resource is referenced cyclically. | 3718 3719**Example** 3720 ```ts 3721 import { resourceManager } from '@kit.LocalizationKit' 3722 import { BusinessError } from '@kit.BasicServicesKit'; 3723 3724 let resource: resourceManager.Resource = { 3725 bundleName: "com.example.myapplication", 3726 moduleName: "entry", 3727 id: $r('app.boolean.boolean_test').id 3728 }; 3729 try { 3730 this.context.resourceManager.getBoolean(resource); 3731 } catch (error) { 3732 let code = (error as BusinessError).code; 3733 let message = (error as BusinessError).message; 3734 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3735 } 3736 ``` 3737 3738### getBooleanByName<sup>9+</sup> 3739 3740getBooleanByName(resName: string): boolean 3741 3742Obtains a Boolean result based on the specified resource name. This API returns the result synchronously. 3743 3744**Atomic service API**: This API can be used in atomic services since API version 11. 3745 3746**System capability**: SystemCapability.Global.ResourceManager 3747 3748**Parameters** 3749 3750| Name | Type | Mandatory | Description | 3751| ------- | ------ | ---- | ---- | 3752| resName | string | Yes | Resource name.| 3753 3754**Return value** 3755 3756| Type | Description | 3757| ------- | ----------- | 3758| boolean | Boolean result corresponding to the specified resource name.| 3759 3760**Error codes** 3761 3762For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3763 3764| ID| Error Message| 3765| -------- | ---------------------------------------- | 3766| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3767| 9001003 | Invalid resource name. | 3768| 9001004 | No matching resource is found based on the resource name. | 3769| 9001006 | The resource is referenced cyclically. | 3770 3771**Example** 3772 ```ts 3773 import { BusinessError } from '@kit.BasicServicesKit'; 3774 3775 try { 3776 this.context.resourceManager.getBooleanByName("boolean_test"); 3777 } catch (error) { 3778 let code = (error as BusinessError).code; 3779 let message = (error as BusinessError).message; 3780 console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`); 3781 } 3782 ``` 3783 3784### getNumber<sup>9+</sup> 3785 3786getNumber(resId: number): number 3787 3788Obtains an integer or float value based on the specified resource ID. This API returns the result synchronously. 3789 3790**Atomic service API**: This API can be used in atomic services since API version 11. 3791 3792**System capability**: SystemCapability.Global.ResourceManager 3793 3794**Parameters** 3795 3796| Name | Type | Mandatory | Description | 3797| ----- | ------ | ---- | ----- | 3798| resId | number | Yes | Resource ID.| 3799 3800**Return value** 3801 3802| Type | Description | 3803| ------ | ---------- | 3804| number | Integer or float value corresponding to the specified resource ID. An integer indicates the original value, and a float number indicates the actual pixel value. For details, see the sample code.| 3805 3806**Error codes** 3807 3808For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3809 3810| ID| Error Message| 3811| -------- | ---------------------------------------- | 3812| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3813| 9001001 | Invalid resource ID. | 3814| 9001002 | No matching resource is found based on the resource ID. | 3815| 9001006 | The resource is referenced cyclically. | 3816 3817**Example** 3818 ```ts 3819 import { BusinessError } from '@kit.BasicServicesKit'; 3820 3821 try { 3822 this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. 3823 } catch (error) { 3824 let code = (error as BusinessError).code; 3825 let message = (error as BusinessError).message; 3826 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3827 } 3828 3829 try { 3830 this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. 3831 } catch (error) { 3832 let code = (error as BusinessError).code; 3833 let message = (error as BusinessError).message; 3834 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3835 } 3836 ``` 3837 3838### getNumber<sup>9+</sup> 3839 3840getNumber(resource: Resource): number 3841 3842Obtains an integer or float value based on the specified resource object. This API returns the result synchronously. 3843 3844> **NOTE** 3845> 3846> If this API is used to obtain the float value whose unit is vp, the value obtained through **resId** is different from that obtained through **resource**. In this case, the value obtained through **resId** is correct. This issue will be rectified in future versions. 3847 3848**Atomic service API**: This API can be used in atomic services since API version 11. 3849 3850**System capability**: SystemCapability.Global.ResourceManager 3851 3852**Model restriction**: This API can be used only in the stage model. 3853 3854**Parameters** 3855 3856| Name | Type | Mandatory | Description | 3857| -------- | ---------------------- | ---- | ---- | 3858| resource | [Resource](#resource9) | Yes | Resource object.| 3859 3860**Return value** 3861 3862| Type | Description | 3863| ------ | --------------- | 3864| number | Integer or float value corresponding to the specified resource name.<br>An integer indicates the original value, and a float number without a unit indicates the original value and a float number with the unit of vp or fp indicates the px value.| 3865 3866**Error codes** 3867 3868For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3869 3870| ID| Error Message| 3871| -------- | ---------------------------------------- | 3872| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3873| 9001001 | Invalid resource ID. | 3874| 9001002 | No matching resource is found based on the resource ID. | 3875| 9001006 | The resource is referenced cyclically. | 3876 3877**Example** 3878 ```ts 3879 import { resourceManager } from '@kit.LocalizationKit' 3880 import { BusinessError } from '@kit.BasicServicesKit'; 3881 3882 let resource: resourceManager.Resource = { 3883 bundleName: "com.example.myapplication", 3884 moduleName: "entry", 3885 id: $r('app.integer.integer_test').id 3886 }; 3887 try { 3888 this.context.resourceManager.getNumber(resource); 3889 } catch (error) { 3890 let code = (error as BusinessError).code; 3891 let message = (error as BusinessError).message; 3892 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3893 } 3894 ``` 3895 3896### getNumberByName<sup>9+</sup> 3897 3898getNumberByName(resName: string): number 3899 3900Obtains an integer or float value based on the specified resource name. This API returns the result synchronously. 3901 3902**Atomic service API**: This API can be used in atomic services since API version 11. 3903 3904**System capability**: SystemCapability.Global.ResourceManager 3905 3906**Parameters** 3907 3908| Name | Type | Mandatory | Description | 3909| ------- | ------ | ---- | ---- | 3910| resName | string | Yes | Resource name.| 3911 3912**Return value** 3913 3914| Type | Description | 3915| ------ | --------- | 3916| number | Integer or float value corresponding to the specified resource name.<br>An integer indicates the original value, and a float number without a unit indicates the original value and a float number with the unit of vp or fp indicates the px value.| 3917 3918**Error codes** 3919 3920For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3921 3922| ID| Error Message| 3923| -------- | ---------------------------------------- | 3924| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3925| 9001003 | Invalid resource name. | 3926| 9001004 | No matching resource is found based on the resource name. | 3927| 9001006 | The resource is referenced cyclically. | 3928 3929**Example** 3930 ```ts 3931 import { BusinessError } from '@kit.BasicServicesKit'; 3932 3933 try { 3934 this.context.resourceManager.getNumberByName("integer_test"); 3935 } catch (error) { 3936 let code = (error as BusinessError).code; 3937 let message = (error as BusinessError).message; 3938 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3939 } 3940 3941 try { 3942 this.context.resourceManager.getNumberByName("float_test"); 3943 } catch (error) { 3944 let code = (error as BusinessError).code; 3945 let message = (error as BusinessError).message; 3946 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3947 } 3948 ``` 3949 3950### getColorSync<sup>10+</sup> 3951 3952getColorSync(resId: number) : number; 3953 3954Obtains a color value based on the specified resource ID. This API returns the result synchronously. 3955 3956**Atomic service API**: This API can be used in atomic services since API version 11. 3957 3958**System capability**: SystemCapability.Global.ResourceManager 3959 3960**Parameters** 3961 3962| Name | Type | Mandatory | Description | 3963| ----- | ------ | ---- | ----- | 3964| resId | number | Yes | Resource ID.| 3965 3966**Return value** 3967 3968| Type | Description | 3969| ------ | ----------- | 3970| number | Color value (decimal) corresponding to the specified resource ID.| 3971 3972**Error codes** 3973 3974For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3975 3976| ID| Error Message| 3977| -------- | ---------------------------------------- | 3978| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3979| 9001001 | Invalid resource ID. | 3980| 9001002 | No matching resource is found based on the resource ID. | 3981| 9001006 | The resource is referenced cyclically. | 3982 3983**Example** 3984 ```ts 3985 import { BusinessError } from '@kit.BasicServicesKit'; 3986 3987 try { 3988 this.context.resourceManager.getColorSync($r('app.color.test').id); 3989 } catch (error) { 3990 let code = (error as BusinessError).code; 3991 let message = (error as BusinessError).message; 3992 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 3993 } 3994 ``` 3995 3996### getColorSync<sup>10+</sup> 3997 3998getColorSync(resource: Resource): number 3999 4000Obtains a color value based on the specified resource object. This API returns the result synchronously. 4001 4002**Atomic service API**: This API can be used in atomic services since API version 11. 4003 4004**System capability**: SystemCapability.Global.ResourceManager 4005 4006**Model restriction**: This API can be used only in the stage model. 4007 4008**Parameters** 4009 4010| Name | Type | Mandatory | Description | 4011| -------- | ---------------------- | ---- | ---- | 4012| resource | [Resource](#resource9) | Yes | Resource object.| 4013 4014**Return value** 4015 4016| Type | Description | 4017| ------ | ---------------- | 4018| number | Color value (decimal) corresponding to the specified resource object.| 4019 4020**Error codes** 4021 4022For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4023 4024| ID| Error Message| 4025| -------- | ---------------------------------------- | 4026| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4027| 9001001 | Invalid resource ID. | 4028| 9001002 | No matching resource is found based on the resource ID. | 4029| 9001006 | The resource is referenced cyclically. | 4030 4031**Example** 4032 ```ts 4033 import { resourceManager } from '@kit.LocalizationKit' 4034 import { BusinessError } from '@kit.BasicServicesKit'; 4035 4036 let resource: resourceManager.Resource = { 4037 bundleName: "com.example.myapplication", 4038 moduleName: "entry", 4039 id: $r('app.color.test').id 4040 }; 4041 try { 4042 this.context.resourceManager.getColorSync(resource); 4043 } catch (error) { 4044 let code = (error as BusinessError).code; 4045 let message = (error as BusinessError).message; 4046 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 4047 } 4048 ``` 4049 4050### getColorByNameSync<sup>10+</sup> 4051 4052getColorByNameSync(resName: string) : number; 4053 4054Obtains a color value based on the specified resource name. This API returns the result synchronously. 4055 4056**Atomic service API**: This API can be used in atomic services since API version 11. 4057 4058**System capability**: SystemCapability.Global.ResourceManager 4059 4060**Parameters** 4061 4062| Name | Type | Mandatory | Description | 4063| ------- | ------ | ---- | ---- | 4064| resName | string | Yes | Resource name.| 4065 4066**Return value** 4067 4068| Type | Description | 4069| ------ | ---------- | 4070| number | Color value (decimal) corresponding to the specified resource name.| 4071 4072**Error codes** 4073 4074For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4075 4076| ID| Error Message| 4077| -------- | ---------------------------------------- | 4078| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4079| 9001003 | Invalid resource name. | 4080| 9001004 | No matching resource is found based on the resource name. | 4081| 9001006 | The resource is referenced cyclically. | 4082 4083**Example** 4084 ```ts 4085 import { BusinessError } from '@kit.BasicServicesKit'; 4086 4087 try { 4088 this.context.resourceManager.getColorByNameSync("test"); 4089 } catch (error) { 4090 let code = (error as BusinessError).code; 4091 let message = (error as BusinessError).message; 4092 console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`); 4093 } 4094 ``` 4095 4096### getColor<sup>10+</sup> 4097 4098getColor(resId: number, callback: AsyncCallback<number>): void; 4099 4100Obtains a color value based on the specified resource ID. This API uses an asynchronous callback to return the result. 4101 4102**Atomic service API**: This API can be used in atomic services since API version 11. 4103 4104**System capability**: SystemCapability.Global.ResourceManager 4105 4106**Parameters** 4107 4108| Name | Type | Mandatory | Description | 4109| -------- | --------------------------- | ---- | --------------- | 4110| resId | number | Yes | Resource ID. | 4111| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4112 4113**Error codes** 4114 4115For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4116 4117| ID| Error Message| 4118| -------- | ---------------------------------------- | 4119| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4120| 9001001 | If the module resId invalid. | 4121| 9001002 | No matching resource is found based on the resource ID. | 4122| 9001006 | The resource is referenced cyclically. | 4123 4124**Example (stage)** 4125 ```ts 4126 import { BusinessError } from '@kit.BasicServicesKit'; 4127 4128 try { 4129 this.context.resourceManager.getColor($r('app.color.test').id, (error: BusinessError, value: number) => { 4130 if (error != null) { 4131 console.error("error is " + error); 4132 } else { 4133 let str = value; 4134 } 4135 }); 4136 } catch (error) { 4137 let code = (error as BusinessError).code; 4138 let message = (error as BusinessError).message; 4139 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 4140 } 4141 ``` 4142 4143### getColor<sup>10+</sup> 4144 4145getColor(resId: number): Promise<number> 4146 4147Obtains a color value based on the specified resource ID. This API uses a promise to return the result. 4148 4149**Atomic service API**: This API can be used in atomic services since API version 11. 4150 4151**System capability**: SystemCapability.Global.ResourceManager 4152 4153**Parameters** 4154 4155| Name | Type | Mandatory | Description | 4156| ----- | ------ | ---- | ----- | 4157| resId | number | Yes | Resource ID.| 4158 4159**Return value** 4160 4161| Type | Description | 4162| --------------------- | ----------- | 4163| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4164 4165**Error codes** 4166 4167For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4168 4169| ID| Error Message| 4170| -------- | ---------------------------------------- | 4171| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4172| 9001001 | Invalid resource ID. | 4173| 9001002 | No matching resource is found based on the resource ID. | 4174| 9001006 | The resource is referenced cyclically. | 4175 4176**Example** 4177 ```ts 4178 import { BusinessError } from '@kit.BasicServicesKit'; 4179 4180 try { 4181 this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => { 4182 let str = value; 4183 }).catch((error: BusinessError) => { 4184 console.error("getColor promise error is " + error); 4185 }); 4186 } catch (error) { 4187 let code = (error as BusinessError).code; 4188 let message = (error as BusinessError).message; 4189 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4190 } 4191 ``` 4192 4193### getColor<sup>10+</sup> 4194 4195getColor(resource: Resource, callback: AsyncCallback<number>): void; 4196 4197Obtains a color value based on the specified resource object. This API uses an asynchronous callback to return the result. 4198 4199**Atomic service API**: This API can be used in atomic services since API version 11. 4200 4201**System capability**: SystemCapability.Global.ResourceManager 4202 4203**Model restriction**: This API can be used only in the stage model. 4204 4205**Parameters** 4206 4207| Name | Type | Mandatory | Description | 4208| -------- | --------------------------- | ---- | --------------- | 4209| resource | [Resource](#resource9) | Yes | Resource object. | 4210| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4211 4212**Error codes** 4213 4214For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4215 4216| ID| Error Message| 4217| -------- | ---------------------------------------- | 4218| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4219| 9001001 | Invalid resource ID. | 4220| 9001002 | No matching resource is found based on the resource ID. | 4221| 9001006 | The resource is referenced cyclically. | 4222 4223**Example** 4224 ```ts 4225 import { resourceManager } from '@kit.LocalizationKit' 4226 import { BusinessError } from '@kit.BasicServicesKit'; 4227 4228 let resource: resourceManager.Resource = { 4229 bundleName: "com.example.myapplication", 4230 moduleName: "entry", 4231 id: $r('app.color.test').id 4232 }; 4233 try { 4234 this.context.resourceManager.getColor(resource, (error: BusinessError, value: number) => { 4235 if (error != null) { 4236 console.error("error is " + error); 4237 } else { 4238 let str = value; 4239 } 4240 }); 4241 } catch (error) { 4242 let code = (error as BusinessError).code; 4243 let message = (error as BusinessError).message; 4244 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 4245 } 4246 ``` 4247 4248### getColor<sup>10+</sup> 4249 4250getColor(resource: Resource): Promise<number>; 4251 4252Obtains a color value based on the specified resource object. This API uses a promise to return the result. 4253 4254**Atomic service API**: This API can be used in atomic services since API version 11. 4255 4256**System capability**: SystemCapability.Global.ResourceManager 4257 4258**Model restriction**: This API can be used only in the stage model. 4259 4260**Parameters** 4261 4262| Name | Type | Mandatory | Description | 4263| -------- | ---------------------- | ---- | ---- | 4264| resource | [Resource](#resource9) | Yes | Resource object.| 4265 4266**Return value** 4267 4268| Type | Description | 4269| --------------------- | ---------------- | 4270| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource object.| 4271 4272**Error codes** 4273 4274For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4275 4276| ID| Error Message| 4277| -------- | ---------------------------------------- | 4278| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4279| 9001001 | Invalid resource ID. | 4280| 9001002 | No matching resource is found based on the resource ID. | 4281| 9001006 | The resource is referenced cyclically. | 4282 4283**Example** 4284 ```ts 4285 import { resourceManager } from '@kit.LocalizationKit' 4286 import { BusinessError } from '@kit.BasicServicesKit'; 4287 4288 let resource: resourceManager.Resource = { 4289 bundleName: "com.example.myapplication", 4290 moduleName: "entry", 4291 id: $r('app.color.test').id 4292 }; 4293 try { 4294 this.context.resourceManager.getColor(resource).then((value: number) => { 4295 let str = value; 4296 }).catch((error: BusinessError) => { 4297 console.error("getColor promise error is " + error); 4298 }); 4299 } catch (error) { 4300 let code = (error as BusinessError).code; 4301 let message = (error as BusinessError).message; 4302 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4303 } 4304 ``` 4305 4306### getColorByName<sup>10+</sup> 4307 4308getColorByName(resName: string, callback: AsyncCallback<number>): void 4309 4310Obtains a color value based on the specified resource name. This API uses an asynchronous callback to return the result. 4311 4312**Atomic service API**: This API can be used in atomic services since API version 11. 4313 4314**System capability**: SystemCapability.Global.ResourceManager 4315 4316**Parameters** 4317 4318| Name | Type | Mandatory | Description | 4319| -------- | --------------------------- | ---- | --------------- | 4320| resName | string | Yes | Resource name. | 4321| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4322 4323**Error codes** 4324 4325For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4326 4327| ID| Error Message| 4328| -------- | ---------------------------------------- | 4329| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4330| 9001003 | Invalid resource name. | 4331| 9001004 | No matching resource is found based on the resource name. | 4332| 9001006 | The resource is referenced cyclically. | 4333 4334**Example** 4335 ```ts 4336 import { BusinessError } from '@kit.BasicServicesKit'; 4337 4338 try { 4339 this.context.resourceManager.getColorByName("test", (error: BusinessError, value: number) => { 4340 if (error != null) { 4341 console.error("error is " + error); 4342 } else { 4343 let string = value; 4344 } 4345 }); 4346 } catch (error) { 4347 let code = (error as BusinessError).code; 4348 let message = (error as BusinessError).message; 4349 console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`); 4350 } 4351 ``` 4352 4353### getColorByName<sup>10+</sup> 4354 4355getColorByName(resName: string): Promise<number> 4356 4357Obtains a color value based on the specified resource name. This API uses a promise to return the result. 4358 4359**Atomic service API**: This API can be used in atomic services since API version 11. 4360 4361**System capability**: SystemCapability.Global.ResourceManager 4362 4363**Parameters** 4364 4365| Name | Type | Mandatory | Description | 4366| ------- | ------ | ---- | ---- | 4367| resName | string | Yes | Resource name.| 4368 4369**Return value** 4370 4371| Type | Description | 4372| --------------------- | ---------- | 4373| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4374 4375**Error codes** 4376 4377For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4378 4379| ID| Error Message| 4380| -------- | ---------------------------------------- | 4381| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4382| 9001003 | Invalid resource name. | 4383| 9001004 | No matching resource is found based on the resource name. | 4384| 9001006 | The resource is referenced cyclically. | 4385 4386**Example** 4387 ```ts 4388 import { BusinessError } from '@kit.BasicServicesKit'; 4389 4390 try { 4391 this.context.resourceManager.getColorByName("test").then((value: number) => { 4392 let string = value; 4393 }).catch((error: BusinessError) => { 4394 console.error("getColorByName promise error is " + error); 4395 }); 4396 } catch (error) { 4397 let code = (error as BusinessError).code; 4398 let message = (error as BusinessError).message; 4399 console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`); 4400 } 4401 ``` 4402 4403### getRawFileContentSync<sup>10+</sup> 4404 4405getRawFileContentSync(path: string): Uint8Array 4406 4407Obtains the content of the raw file in the **resources/rawfile** directory. This API returns the result synchronously. 4408 4409**Atomic service API**: This API can be used in atomic services since API version 11. 4410 4411**System capability**: SystemCapability.Global.ResourceManager 4412 4413**Parameters** 4414 4415| Name | Type | Mandatory | Description | 4416| -------- | ------------------------------- | ---- | ----------------------- | 4417| path | string | Yes | Path of the raw file. | 4418 4419**Return value** 4420 4421| Type | Description | 4422| --------------------- | ---------- | 4423| Uint8Array | Content of the raw file.| 4424 4425**Error codes** 4426 4427For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4428 4429| ID| Error Message| 4430| -------- | ---------------------------------------- | 4431| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4432| 9001005 | Invalid relative path. | 4433 4434**Example** 4435 ```ts 4436 import { BusinessError } from '@kit.BasicServicesKit'; 4437 4438 try { 4439 this.context.resourceManager.getRawFileContentSync("test.txt"); 4440 } catch (error) { 4441 let code = (error as BusinessError).code; 4442 let message = (error as BusinessError).message; 4443 console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`); 4444 } 4445 ``` 4446 4447### getRawFileContent<sup>9+</sup> 4448 4449getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void 4450 4451Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4452 4453**Atomic service API**: This API can be used in atomic services since API version 11. 4454 4455**System capability**: SystemCapability.Global.ResourceManager 4456 4457**Parameters** 4458 4459| Name | Type | Mandatory | Description | 4460| -------- | ------------------------------- | ---- | ----------------------- | 4461| path | string | Yes | Path of the raw file. | 4462| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 4463 4464**Error codes** 4465 4466For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4467 4468| ID| Error Message| 4469| -------- | ---------------------------------------- | 4470| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4471 4472**Example** 4473 ```ts 4474 import { BusinessError } from '@kit.BasicServicesKit'; 4475 4476 try { 4477 this.context.resourceManager.getRawFileContent("test.txt", (error: BusinessError, value: Uint8Array) => { 4478 if (error != null) { 4479 console.error("error is " + error); 4480 } else { 4481 let rawFile = value; 4482 } 4483 }); 4484 } catch (error) { 4485 let code = (error as BusinessError).code; 4486 let message = (error as BusinessError).message; 4487 console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`); 4488 } 4489 ``` 4490 4491### getRawFileContent<sup>9+</sup> 4492 4493getRawFileContent(path: string): Promise<Uint8Array> 4494 4495Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 4496 4497**Atomic service API**: This API can be used in atomic services since API version 11. 4498 4499**System capability**: SystemCapability.Global.ResourceManager 4500 4501**Parameters** 4502 4503| Name | Type | Mandatory | Description | 4504| ---- | ------ | ---- | ----------- | 4505| path | string | Yes | Path of the raw file.| 4506 4507**Return value** 4508 4509| Type | Description | 4510| ------------------------- | ----------- | 4511| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 4512 4513**Error codes** 4514 4515For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4516 4517| ID| Error Message| 4518| -------- | ---------------------------------------- | 4519| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4520| 9001005 | Invalid relative path. | 4521 4522**Example** 4523 ```ts 4524 import { BusinessError } from '@kit.BasicServicesKit'; 4525 4526 try { 4527 this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => { 4528 let rawFile = value; 4529 }).catch((error: BusinessError) => { 4530 console.error("getRawFileContent promise error is " + error); 4531 }); 4532 } catch (error) { 4533 let code = (error as BusinessError).code; 4534 let message = (error as BusinessError).message; 4535 console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`); 4536 } 4537 ``` 4538 4539### getRawFileListSync<sup>10+</sup> 4540 4541getRawFileListSync(path: string): Array\<string> 4542 4543Obtains the list of folders and files in the **resources/rawfile** directory. This API returns the result synchronously. 4544 4545>**NOTE** 4546> 4547> If there is no folder or file in the directory, no information is returned. If there are folders and files in the directory, the list of folders and files is returned. 4548 4549**Atomic service API**: This API can be used in atomic services since API version 11. 4550 4551**System capability**: SystemCapability.Global.ResourceManager 4552 4553**Parameters** 4554 4555| Name | Type | Mandatory | Description | 4556| -------- | ------------------------------- | ---- | ----------------------- | 4557| path | string | Yes | **rawfile** directory. | 4558 4559**Return value** 4560 4561| Type | Description | 4562| ------------------------- | ----------- | 4563| Array\<string> | List of folders and files in the **rawfile** directory.| 4564 4565**Error codes** 4566 4567For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4568 4569| ID| Error Message| 4570| -------- | ---------------------------------------- | 4571| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4572| 9001005 | Invalid relative path. | 4573 4574**Example** 4575 ```ts 4576 import { BusinessError } from '@kit.BasicServicesKit'; 4577 4578 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4579 this.context.resourceManager.getRawFileListSync("") 4580 } catch (error) { 4581 let code = (error as BusinessError).code; 4582 let message = (error as BusinessError).message; 4583 console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`); 4584 } 4585 ``` 4586 4587### getRawFileList<sup>10+</sup> 4588 4589getRawFileList(path: string, callback: AsyncCallback<Array\<string\>>): void; 4590 4591Obtains the list of folders and files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4592 4593>**NOTE** 4594> 4595> If there is no folder or file in the directory, no information is returned. If there are folders and files in the directory, the list of folders and files is returned. 4596 4597**Atomic service API**: This API can be used in atomic services since API version 11. 4598 4599**System capability**: SystemCapability.Global.ResourceManager 4600 4601**Parameters** 4602 4603| Name | Type | Mandatory | Description | 4604| -------- | ------------------------------- | ---- | ----------------------- | 4605| path | string | Yes | **rawfile** directory. | 4606| callback | AsyncCallback<Array\<string\>> | Yes| Callback used to return the result, which is the list of folders and files in the **rawfile** directory.| 4607 4608**Error codes** 4609 4610For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4611 4612| ID| Error Message| 4613| -------- | ---------------------------------------- | 4614| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4615| 9001005 | Invalid relative path. | 4616 4617**Example** 4618 ```ts 4619 import { BusinessError } from '@kit.BasicServicesKit'; 4620 4621 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4622 this.context.resourceManager.getRawFileList("", (error: BusinessError, value: Array<string>) => { 4623 if (error != null) { 4624 console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4625 } else { 4626 let rawFile = value; 4627 } 4628 }); 4629 } catch (error) { 4630 let code = (error as BusinessError).code; 4631 let message = (error as BusinessError).message; 4632 console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`); 4633 } 4634 ``` 4635 4636### getRawFileList<sup>10+</sup> 4637 4638getRawFileList(path: string): Promise<Array\<string\>> 4639 4640Obtains the list of folders and files in the **resources/rawfile** directory. This API uses a promise to return the result. 4641 4642>**NOTE** 4643> 4644> If there is no folder or file in the directory, no information is returned. If there are folders and files in the directory, the list of folders and files is returned. 4645 4646**Atomic service API**: This API can be used in atomic services since API version 11. 4647 4648**System capability**: SystemCapability.Global.ResourceManager 4649 4650**Parameters** 4651 4652| Name | Type | Mandatory | Description | 4653| ---- | ------ | ---- | ----------- | 4654| path | string | Yes | **rawfile** directory.| 4655 4656**Return value** 4657 4658| Type | Description | 4659| ------------------------- | ----------- | 4660| Promise<Array\<string\>> | Promise used to return the result, which is the list of folders and files in the **rawfile** directory.| 4661 4662**Error codes** 4663 4664For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4665 4666| ID| Error Message| 4667| -------- | ---------------------------------------- | 4668| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4669| 9001005 | Invalid relative path. | 4670 4671**Example** 4672 ```ts 4673 import { BusinessError } from '@kit.BasicServicesKit'; 4674 4675 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4676 this.context.resourceManager.getRawFileList("").then((value: Array<string>) => { 4677 let rawFile = value; 4678 }).catch((error: BusinessError) => { 4679 console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4680 }); 4681 } catch (error) { 4682 let code = (error as BusinessError).code; 4683 let message = (error as BusinessError).message; 4684 console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`); 4685 } 4686 ``` 4687 4688### getRawFdSync<sup>10+</sup> 4689 4690getRawFdSync(path: string): RawFileDescriptor 4691 4692Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4693 4694**Atomic service API**: This API can be used in atomic services since API version 11. 4695 4696**System capability**: SystemCapability.Global.ResourceManager 4697 4698**Parameters** 4699 4700| Name | Type | Mandatory | Description | 4701| -------- | ---------------------------------------- | ---- | -------------------------------- | 4702| path | string | Yes | Path of the raw file. | 4703 4704**Return value** 4705 4706| Type | Description | 4707| ------------------------- | ----------- | 4708| [RawFileDescriptor](#rawfiledescriptor8) | Descriptor of the HAP where the raw file is located.| 4709 4710**Error codes** 4711 4712For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4713 4714| ID| Error Message| 4715| -------- | ---------------------------------------- | 4716| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4717| 9001005 | Invalid relative path. | 4718 4719**Example** 4720 ```ts 4721 import { BusinessError } from '@kit.BasicServicesKit'; 4722 4723 try { 4724 this.context.resourceManager.getRawFdSync("test.txt"); 4725 } catch (error) { 4726 let code = (error as BusinessError).code; 4727 let message = (error as BusinessError).message; 4728 console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`); 4729 } 4730 ``` 4731 4732### getRawFd<sup>9+</sup> 4733 4734getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void 4735 4736Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4737 4738**Atomic service API**: This API can be used in atomic services since API version 11. 4739 4740**System capability**: SystemCapability.Global.ResourceManager 4741 4742**Parameters** 4743 4744| Name | Type | Mandatory | Description | 4745| -------- | ---------------------------------------- | ---- | -------------------------------- | 4746| path | string | Yes | Path of the raw file. | 4747| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result, which is the descriptor of the HAP where the raw file is located.| 4748 4749**Error codes** 4750 4751For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4752 4753| ID| Error Message| 4754| -------- | ---------------------------------------- | 4755| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4756| 9001005 | Invalid relative path. | 4757 4758**Example** 4759 ```ts 4760 import { BusinessError } from '@kit.BasicServicesKit'; 4761 import { resourceManager } from '@kit.LocalizationKit' 4762 4763 try { 4764 this.context.resourceManager.getRawFd("test.txt", (error: BusinessError, value: resourceManager.RawFileDescriptor) => { 4765 if (error != null) { 4766 console.error(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); 4767 } else { 4768 let fd = value.fd; 4769 let offset = value.offset; 4770 let length = value.length; 4771 } 4772 }); 4773 } catch (error) { 4774 let code = (error as BusinessError).code; 4775 let message = (error as BusinessError).message; 4776 console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`); 4777 } 4778 ``` 4779 4780### getRawFd<sup>9+</sup> 4781 4782getRawFd(path: string): Promise<RawFileDescriptor> 4783 4784Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. This API uses a promise to return the result. 4785 4786**Atomic service API**: This API can be used in atomic services since API version 11. 4787 4788**System capability**: SystemCapability.Global.ResourceManager 4789 4790**Parameters** 4791 4792| Name | Type | Mandatory | Description | 4793| ---- | ------ | ---- | ----------- | 4794| path | string | Yes | Path of the raw file.| 4795 4796**Return value** 4797 4798| Type | Description | 4799| ---------------------------------------- | ------------------- | 4800| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Descriptor of the HAP where the raw file is located.| 4801 4802**Error codes** 4803 4804For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4805 4806| ID| Error Message| 4807| -------- | ---------------------------------------- | 4808| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4809| 9001005 | Invalid relative path. | 4810 4811**Example** 4812 ```ts 4813 import { BusinessError } from '@kit.BasicServicesKit'; 4814 import { resourceManager } from '@kit.LocalizationKit' 4815 4816 try { 4817 this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => { 4818 let fd = value.fd; 4819 let offset = value.offset; 4820 let length = value.length; 4821 }).catch((error: BusinessError) => { 4822 console.error(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); 4823 }); 4824 } catch (error) { 4825 let code = (error as BusinessError).code; 4826 let message = (error as BusinessError).message; 4827 console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`); 4828 } 4829 ``` 4830 4831### closeRawFdSync<sup>10+</sup> 4832 4833closeRawFdSync(path: string): void 4834 4835Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4836 4837**Atomic service API**: This API can be used in atomic services since API version 11. 4838 4839**System capability**: SystemCapability.Global.ResourceManager 4840 4841**Parameters** 4842 4843| Name | Type | Mandatory | Description | 4844| -------- | ------------------------- | ---- | ----------- | 4845| path | string | Yes | Path of the raw file.| 4846 4847**Error codes** 4848 4849For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4850 4851| ID| Error Message| 4852| -------- | ---------------------------------------- | 4853| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4854| 9001005 | The resource not found by path. | 4855 4856**Example** 4857 ```ts 4858 import { BusinessError } from '@kit.BasicServicesKit'; 4859 4860 try { 4861 this.context.resourceManager.closeRawFdSync("test.txt"); 4862 } catch (error) { 4863 let code = (error as BusinessError).code; 4864 let message = (error as BusinessError).message; 4865 console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`); 4866 } 4867 ``` 4868 4869### closeRawFd<sup>9+</sup> 4870 4871closeRawFd(path: string, callback: AsyncCallback<void>): void 4872 4873Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4874 4875**Atomic service API**: This API can be used in atomic services since API version 11. 4876 4877**System capability**: SystemCapability.Global.ResourceManager 4878 4879**Parameters** 4880 4881| Name | Type | Mandatory | Description | 4882| -------- | ------------------------- | ---- | ----------- | 4883| path | string | Yes | Path of the raw file.| 4884| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4885 4886**Error codes** 4887 4888For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4889 4890| ID| Error Message| 4891| -------- | ---------------------------------------- | 4892| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4893| 9001005 | The resource not found by path. | 4894 4895**Example** 4896 ```ts 4897 import { BusinessError } from '@kit.BasicServicesKit'; 4898 4899 try { 4900 this.context.resourceManager.closeRawFd("test.txt", (error: BusinessError) => { 4901 if (error != null) { 4902 console.error("error is " + error); 4903 } 4904 }); 4905 } catch (error) { 4906 let code = (error as BusinessError).code; 4907 let message = (error as BusinessError).message; 4908 console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`); 4909 } 4910 ``` 4911 4912### closeRawFd<sup>9+</sup> 4913 4914closeRawFd(path: string): Promise<void> 4915 4916Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. This API uses a promise to return the result. 4917 4918**Atomic service API**: This API can be used in atomic services since API version 11. 4919 4920**System capability**: SystemCapability.Global.ResourceManager 4921 4922**Parameters** 4923 4924| Name | Type | Mandatory | Description | 4925| ---- | ------ | ---- | ----------- | 4926| path | string | Yes | Path of the raw file.| 4927 4928**Return value** 4929 4930| Type | Description | 4931| ------------------- | ---- | 4932| Promise<void> | Promise that returns no value.| 4933 4934**Error codes** 4935 4936For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4937 4938| ID| Error Message| 4939| -------- | ---------------------------------------- | 4940| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4941| 9001005 | Invalid relative path. | 4942 4943**Example** 4944 ```ts 4945 import { BusinessError } from '@kit.BasicServicesKit'; 4946 4947 try { 4948 this.context.resourceManager.closeRawFd("test.txt"); 4949 } catch (error) { 4950 let code = (error as BusinessError).code; 4951 let message = (error as BusinessError).message; 4952 console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`); 4953 } 4954 ``` 4955 4956### getConfigurationSync<sup>10+</sup> 4957 4958getConfigurationSync(): Configuration 4959 4960Obtains the device configuration. This API returns the result synchronously. 4961 4962**Atomic service API**: This API can be used in atomic services since API version 11. 4963 4964**System capability**: SystemCapability.Global.ResourceManager 4965 4966**Return value** 4967 4968| Type | Description | 4969| ---------------------------------------- | ---------------- | 4970| [Configuration](#configuration) | Device configuration.| 4971 4972**Example** 4973 ```ts 4974 try { 4975 let value = this.context.resourceManager.getConfigurationSync(); 4976 let direction = value.direction; 4977 let locale = value.locale; 4978 } catch (error) { 4979 console.error("getConfigurationSync error is " + error); 4980 } 4981 ``` 4982 4983### getConfiguration 4984 4985getConfiguration(callback: AsyncCallback<Configuration>): void 4986 4987Obtains the device configuration. This API uses an asynchronous callback to return the result. 4988 4989**Atomic service API**: This API can be used in atomic services since API version 11. 4990 4991**System capability**: SystemCapability.Global.ResourceManager 4992 4993**Parameters** 4994 4995| Name | Type | Mandatory | Description | 4996| -------- | ---------------------------------------- | ---- | ------------------------- | 4997| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result, which is the device configuration.| 4998 4999**Example** 5000 ```ts 5001 import { resourceManager } from '@kit.LocalizationKit' 5002 5003 try { 5004 this.context.resourceManager.getConfiguration((error: BusinessError, value: resourceManager.Configuration) => { 5005 if (error != null) { 5006 console.error("getConfiguration callback error is " + error); 5007 } else { 5008 let direction = value.direction; 5009 let locale = value.locale; 5010 } 5011 }); 5012 } catch (error) { 5013 console.error("getConfiguration callback error is " + error); 5014 } 5015 ``` 5016 5017### getConfiguration 5018 5019getConfiguration(): Promise<Configuration> 5020 5021Obtains the device configuration. This API uses a promise to return the result. 5022 5023**Atomic service API**: This API can be used in atomic services since API version 11. 5024 5025**System capability**: SystemCapability.Global.ResourceManager 5026 5027**Return value** 5028 5029| Type | Description | 5030| ---------------------------------------- | ---------------- | 5031| Promise<[Configuration](#configuration)> | Promise used to return the result, which is the device configuration.| 5032 5033**Example** 5034 ```ts 5035 import { BusinessError } from '@kit.BasicServicesKit'; 5036 import { resourceManager } from '@kit.LocalizationKit' 5037 5038 try { 5039 this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => { 5040 let direction = value.direction; 5041 let locale = value.locale; 5042 }).catch((error: BusinessError) => { 5043 console.error("getConfiguration promise error is " + error); 5044 }); 5045 } catch (error) { 5046 console.error("getConfiguration promise error is " + error); 5047 } 5048 ``` 5049 5050### getDeviceCapabilitySync<sup>10+</sup> 5051 5052getDeviceCapabilitySync(): DeviceCapability 5053 5054Obtains the device capability. This API returns the result synchronously. 5055 5056**Atomic service API**: This API can be used in atomic services since API version 11. 5057 5058**System capability**: SystemCapability.Global.ResourceManager 5059 5060**Return value** 5061 5062| Type | Description | 5063| ---------------------------------------- | ------------------- | 5064| [DeviceCapability](#devicecapability) | Device capability.| 5065 5066**Example** 5067 ```ts 5068 try { 5069 let value = this.context.resourceManager.getDeviceCapabilitySync(); 5070 let screenDensity = value.screenDensity; 5071 let deviceType = value.deviceType; 5072 } catch (error) { 5073 console.error("getDeviceCapabilitySync error is " + error); 5074 } 5075 ``` 5076 5077### getDeviceCapability 5078 5079getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void 5080 5081Obtains the device capability. This API uses an asynchronous callback to return the result. 5082 5083**Atomic service API**: This API can be used in atomic services since API version 11. 5084 5085**System capability**: SystemCapability.Global.ResourceManager 5086 5087**Parameters** 5088 5089| Name | Type | Mandatory | Description | 5090| -------- | ---------------------------------------- | ---- | ---------------------------- | 5091| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result, which is the device capability.| 5092 5093**Example** 5094 ```ts 5095 import { resourceManager } from '@kit.LocalizationKit' 5096 5097 try { 5098 this.context.resourceManager.getDeviceCapability((error: BusinessError, value: resourceManager.DeviceCapability) => { 5099 if (error != null) { 5100 console.error("getDeviceCapability callback error is " + error); 5101 } else { 5102 let screenDensity = value.screenDensity; 5103 let deviceType = value.deviceType; 5104 } 5105 }); 5106 } catch (error) { 5107 console.error("getDeviceCapability callback error is " + error); 5108 } 5109 ``` 5110 5111### getDeviceCapability 5112 5113getDeviceCapability(): Promise<DeviceCapability> 5114 5115Obtains the device capability. This API uses a promise to return the result. 5116 5117**Atomic service API**: This API can be used in atomic services since API version 11. 5118 5119**System capability**: SystemCapability.Global.ResourceManager 5120 5121**Return value** 5122 5123| Type | Description | 5124| ---------------------------------------- | ------------------- | 5125| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result, which is the device capability.| 5126 5127**Example** 5128 ```ts 5129 import { BusinessError } from '@kit.BasicServicesKit'; 5130 import { resourceManager } from '@kit.LocalizationKit' 5131 5132 try { 5133 this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => { 5134 let screenDensity = value.screenDensity; 5135 let deviceType = value.deviceType; 5136 }).catch((error: BusinessError) => { 5137 console.error("getDeviceCapability promise error is " + error); 5138 }); 5139 } catch (error) { 5140 console.error("getDeviceCapability promise error is " + error); 5141 } 5142 ``` 5143 5144### addResource<sup>10+</sup> 5145 5146addResource(path: string) : void 5147 5148Loads resources from the specified path. 5149 5150**Atomic service API**: This API can be used in atomic services since API version 11. 5151 5152**System capability**: SystemCapability.Global.ResourceManager 5153 5154**Parameters** 5155 5156| Name | Type | Mandatory | Description | 5157| -------- | ---------------------- | ---- | ---- | 5158| path | string | Yes | Resource path.| 5159 5160**Error codes** 5161 5162For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5163 5164| ID| Error Message| 5165| -------- | ---------------------------------------- | 5166| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5167| 9001010 | Invalid overlay path. | 5168 5169**Example** 5170 ```ts 5171 import { BusinessError } from '@kit.BasicServicesKit'; 5172 5173 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5174 try { 5175 this.context.resourceManager.addResource(path); 5176 } catch (error) { 5177 let code = (error as BusinessError).code; 5178 let message = (error as BusinessError).message; 5179 console.error(`addResource failed, error code: ${code}, message: ${message}.`); 5180 } 5181 ``` 5182 5183### removeResource<sup>10+</sup> 5184 5185removeResource(path: string) : void 5186 5187Removes the resources loaded from the specified path to restore the original resources. 5188 5189**Atomic service API**: This API can be used in atomic services since API version 11. 5190 5191**System capability**: SystemCapability.Global.ResourceManager 5192 5193**Parameters** 5194 5195| Name | Type | Mandatory | Description | 5196| -------- | ---------------------- | ---- | ---- | 5197| path | string | Yes | Resource path.| 5198 5199**Error codes** 5200 5201For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5202 5203| ID| Error Message| 5204| -------- | ---------------------------------------- | 5205| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5206| 9001010 | Invalid overlay path. | 5207 5208**Example** 5209 ```ts 5210 import { BusinessError } from '@kit.BasicServicesKit'; 5211 5212 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5213 try { 5214 this.context.resourceManager.removeResource(path); 5215 } catch (error) { 5216 let code = (error as BusinessError).code; 5217 let message = (error as BusinessError).message; 5218 console.error(`removeResource failed, error code: ${code}, message: ${message}.`); 5219 } 5220 ``` 5221 5222### getLocales<sup>11+</sup> 5223 5224getLocales(includeSystem?: boolean): Array\<string> 5225 5226Obtains the language list of an application. 5227 5228**Atomic service API**: This API can be used in atomic services since API version 11. 5229 5230**System capability**: SystemCapability.Global.ResourceManager 5231 5232**Parameters** 5233 5234| Name | Type | Mandatory | Description | 5235| -------------- | ------- | ------ | -------------------- | 5236| includeSystem | boolean | No | Whether system resources are included. The default value is **false**.<br> **false**: Only application resources are included.<br>**true**: Both system and application resources are included.<br>If the value of **includeSystem** is invalid, the language list of system resources will be returned.| 5237 5238**Return value** 5239 5240| Type | Description | 5241| ------------------------- | ----------- | 5242| Array\<string> | Language list. The strings in the list are comprised of the language, script (optional), and region (optional), which are connected by a hyphen (-).| 5243 5244**Example** 5245 ```ts 5246 import { resourceManager } from '@kit.LocalizationKit' 5247 import { BusinessError } from '@kit.BasicServicesKit'; 5248 5249 try { 5250 this.context.resourceManager.getLocales(); // Obtain only the language list of application resources. 5251 } catch (error) { 5252 let code = (error as BusinessError).code; 5253 let message = (error as BusinessError).message; 5254 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5255 } 5256 5257 try { 5258 resourceManager.getSystemResourceManager().getLocales(); // Obtain only the language list of system resources. 5259 } catch (error) { 5260 let code = (error as BusinessError).code; 5261 let message = (error as BusinessError).message; 5262 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5263 } 5264 5265 try { 5266 this.context.resourceManager.getLocales(true); // Obtain the language list of application resources and resources. 5267 } catch (error) { 5268 let code = (error as BusinessError).code; 5269 let message = (error as BusinessError).message; 5270 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5271 } 5272 ``` 5273 5274### getSymbol<sup>11+</sup> 5275 5276getSymbol(resId: number):number 5277 5278Obtains a symbol value based on the specified resource ID. This API returns the result synchronously. 5279 5280**Atomic service API**: This API can be used in atomic services since API version 11. 5281 5282**System capability**: SystemCapability.Global.ResourceManager 5283 5284**Parameters** 5285 5286| Name | Type | Mandatory | Description | 5287| ----- | ------ | ---- | ----- | 5288| resId | number | Yes | Resource ID.| 5289 5290**Return value** 5291 5292| Type | Description | 5293| ------ | ----------- | 5294| number | Symbol value (decimal) corresponding to the specified resource ID.| 5295 5296**Error codes** 5297 5298For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5299 5300| ID| Error Message| 5301| -------- | ---------------------------------------- | 5302| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5303| 9001001 | Invalid resource ID. | 5304| 9001002 | No matching resource is found based on the resource ID. | 5305| 9001006 | The resource is referenced cyclically. | 5306 5307**Example** 5308 ```ts 5309 import { BusinessError } from '@kit.BasicServicesKit'; 5310 5311 try { 5312 this.context.resourceManager.getSymbol($r('app.symbol.test').id); 5313 } catch (error) { 5314 let code = (error as BusinessError).code; 5315 let message = (error as BusinessError).message; 5316 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5317 } 5318 ``` 5319 5320### getSymbol<sup>11+</sup> 5321getSymbol(resource: Resource): number 5322 5323Obtains a symbol value based on the specified resource object. This API returns the result synchronously. 5324 5325**Atomic service API**: This API can be used in atomic services since API version 11. 5326 5327**System capability**: SystemCapability.Global.ResourceManager 5328 5329**Model restriction**: This API can be used only in the stage model. 5330 5331**Parameters** 5332 5333| Name | Type | Mandatory | Description | 5334| -------- | ---------------------- | ---- | ---- | 5335| resource | [Resource](#resource9) | Yes | Resource object.| 5336 5337**Return value** 5338 5339| Type | Description | 5340| ------ | ----------- | 5341| number | Symbol value (decimal) corresponding to the specified resource object.| 5342 5343**Error codes** 5344 5345For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5346 5347| ID| Error Message| 5348| -------- | ---------------------------------------- | 5349| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5350| 9001001 | Invalid resource ID. | 5351| 9001002 | No matching resource is found based on the resource ID. | 5352| 9001006 | The resource is referenced cyclically. | 5353 5354**Example** 5355 ```ts 5356 import { resourceManager } from '@kit.LocalizationKit' 5357 import { BusinessError } from '@kit.BasicServicesKit'; 5358 5359 let resource: resourceManager.Resource = { 5360 bundleName: "com.example.myapplication", 5361 moduleName: "entry", 5362 id: $r('app.symbol.test').id 5363 }; 5364 try { 5365 this.context.resourceManager.getSymbol(resource); 5366 } catch (error) { 5367 let code = (error as BusinessError).code; 5368 let message = (error as BusinessError).message; 5369 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5370 } 5371 ``` 5372 5373### getSymbolByName<sup>11+</sup> 5374 5375getSymbolByName(resName: string) : number; 5376 5377Obtains a symbol value based on the specified resource name. This API returns the result synchronously. 5378 5379**Atomic service API**: This API can be used in atomic services since API version 11. 5380 5381**System capability**: SystemCapability.Global.ResourceManager 5382 5383**Parameters** 5384 5385| Name | Type | Mandatory | Description | 5386| ------- | ------ | ---- | ---- | 5387| resName | string | Yes | Resource name.| 5388 5389**Return value** 5390 5391| Type | Description | 5392| ------ | ---------- | 5393| number | Symbol value (decimal) corresponding to the specified resource name.| 5394 5395**Error codes** 5396 5397For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5398 5399| ID| Error Message| 5400| -------- | ---------------------------------------- | 5401| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5402| 9001003 | Invalid resource name. | 5403| 9001004 | No matching resource is found based on the resource name. | 5404| 9001006 | The resource is referenced cyclically. | 5405 5406**Example** 5407 ```ts 5408 import { BusinessError } from '@kit.BasicServicesKit'; 5409 5410 try { 5411 this.context.resourceManager.getSymbolByName("test"); 5412 } catch (error) { 5413 let code = (error as BusinessError).code; 5414 let message = (error as BusinessError).message; 5415 console.error(`getSymbolByName failed, error code: ${code}, message: ${message}.`); 5416 } 5417 ``` 5418 5419### isRawDir<sup>12+</sup> 5420 5421isRawDir(path: string) : bool 5422 5423Checks whether a path is a subdirectory in the **rawfile** directory. This API returns the result synchronously. 5424 5425**Atomic service API**: This API can be used in atomic services since API version 12. 5426 5427**System capability**: SystemCapability.Global.ResourceManager 5428 5429**Parameters** 5430 5431| Name | Type | Mandatory | Description | 5432| ------- | ------ | ---- | ---- | 5433| path | string | Yes | Path of a rawfile.| 5434 5435**Return value** 5436 5437| Type | Description | 5438| ------ | ---------- | 5439| bool |Whether the path is a subdirectory in the **rawfile** directory.<br>**true**: The path is a subdirectory in the **rawfile** directory.<br>**false**: The path is not a subdirectory in the **rawfile** directory.| 5440 5441**Error codes** 5442 5443For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5444 5445| ID| Error Message| 5446| -------- | ---------------------------------------- | 5447| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5448| 9001005 | Invalid relative path. | 5449 5450**Example** 5451 ```ts 5452 import { BusinessError } from '@kit.BasicServicesKit'; 5453 5454 try { 5455 this.context.resourceManager.isRawDir("test.txt"); 5456 } catch (error) { 5457 let code = (error as BusinessError).code; 5458 let message = (error as BusinessError).message; 5459 console.error(`isRawDir failed, error code: ${code}, message: ${message}.`); 5460 } 5461 ``` 5462 5463### getOverrideResourceManager<sup>12+</sup> 5464 5465getOverrideResourceManager(configuration?: Configuration) : ResourceManager 5466 5467Obtains a **ResourceManager** object for loading differentiated resources. This API returns the result synchronously. 5468 5469The style (including the language, color mode, resolution, and orientation) of the resources obtained by a common **ResourceManager** object is determined by the system. With this API, an application can obtain the style of differentiated resources, for example, dark color resources in light color mode. 5470 5471**Atomic service API**: This API can be used in atomic services since API version 12. 5472 5473**System capability**: SystemCapability.Global.ResourceManager 5474 5475**Parameters** 5476 5477| Name | Type | Mandatory| Description | 5478| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5479| configuration | [Configuration](#configuration) | No | Configuration of differentiated resources.<br>After obtaining the configuration of differentiated resources through [getOverrideConfiguration](#getoverrideconfiguration12), modify the configuration items as required, and then pass these items as input parameters to the API.<br>If this parameter is not specified, the system obtains resources that best match the current system.| 5480 5481**Return value** 5482 5483| Type | Description | 5484| --------------- | ---------------------------------- | 5485| ResourceManager | **ResourceManager** object for loading differentiated resources.| 5486 5487**Error codes** 5488 5489For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5490 5491| ID| Error Message | 5492| -------- | ------------------------------------------------------------ | 5493| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5494 5495**Example** 5496 5497 ```ts 5498 import { BusinessError } from '@kit.BasicServicesKit'; 5499 import { resourceManager } from '@kit.LocalizationKit' 5500 5501 try { 5502 let resMgr = this.context.resourceManager 5503 let overrideConfig = resMgr.getOverrideConfiguration() 5504 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5505 let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) 5506 } catch (error) { 5507 let code = (error as BusinessError).code; 5508 let message = (error as BusinessError).message; 5509 console.error(`getOverrideResourceManager failed, error code: ${code}, message: ${message}.`); 5510 } 5511 ``` 5512 5513### getOverrideConfiguration<sup>12+</sup> 5514 5515getOverrideConfiguration() : Configuration 5516 5517Obtains the configuration of differentiated resources. This API returns the result synchronously. This API allows a common **ResourceManager** object and a **ResourceManager** object obtained through [getOverrideResourceManager](#getoverrideresourcemanager12) to obtain the configuration of differentiated resources. 5518 5519**Atomic service API**: This API can be used in atomic services since API version 12. 5520 5521**System capability**: SystemCapability.Global.ResourceManager 5522 5523**Return value** 5524 5525| Type | Description | 5526| ------------------------------- | ---------------- | 5527| [Configuration](#configuration) | Configuration of differentiated resources.| 5528 5529**Example** 5530 5531 ```ts 5532 import { BusinessError } from '@kit.BasicServicesKit'; 5533 import { resourceManager } from '@kit.LocalizationKit' 5534 5535 let overrideConfig = this.context.resourceManager.getOverrideConfiguration() 5536 ``` 5537 5538### updateOverrideConfiguration<sup>12+</sup> 5539 5540updateOverrideConfiguration(configuration: Configuration) : void 5541 5542Updated configuration of differentiated resources. This API allows a common **ResourceManager** object and a **ResourceManager** object obtained through [getOverrideResourceManager](#getoverrideresourcemanager12) to update the configuration of differentiated resources. 5543 5544**Atomic service API**: This API can be used in atomic services since API version 12. 5545 5546**System capability**: SystemCapability.Global.ResourceManager 5547 5548**Parameters** 5549 5550| Name | Type | Mandatory| Description | 5551| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5552| configuration | [Configuration](#configuration) | Yes | Configuration of differentiated resources. After obtaining the configuration of differentiated resources through [getOverrideConfiguration](#getoverrideconfiguration12), modify the configuration items as required, and then pass these items as input parameters to the API.| 5553 5554**Error codes** 5555 5556For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5557 5558| ID| Error Message | 5559| -------- | ------------------------------------------------------------ | 5560| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5561 5562**Example** 5563 5564 ```ts 5565 import { BusinessError } from '@kit.BasicServicesKit'; 5566 import { resourceManager } from '@kit.LocalizationKit' 5567 5568 try { 5569 let resMgr = this.context.resourceManager 5570 let overrideConfig = resMgr.getOverrideConfiguration() 5571 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5572 let overrideResMgr = resMgr.updateOverrideConfiguration(overrideConfig) 5573 } catch (error) { 5574 let code = (error as BusinessError).code; 5575 let message = (error as BusinessError).message; 5576 console.error(`updateOverrideConfiguration failed, error code: ${code}, message: ${message}.`); 5577 } 5578 ``` 5579 5580### release<sup>(deprecated)</sup> 5581 5582release() 5583 5584Releases a **ResourceManager** object. This API is not supported currently. 5585 5586This API is supported since API version 7 and is deprecated since API version 12. 5587 5588**Atomic service API**: This API can be used in atomic services since API version 11. 5589 5590**System capability**: SystemCapability.Global.ResourceManager 5591 5592**Example** 5593 ```ts 5594 try { 5595 this.context.resourceManager.release(); 5596 } catch (error) { 5597 console.error("release error is " + error); 5598 } 5599 ``` 5600 5601### getString<sup>(deprecated)</sup> 5602 5603getString(resId: number, callback: AsyncCallback<string>): void 5604 5605Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. 5606 5607This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9). 5608 5609**System capability**: SystemCapability.Global.ResourceManager 5610 5611**Parameters** 5612 5613| Name | Type | Mandatory | Description | 5614| -------- | --------------------------- | ---- | --------------- | 5615| resId | number | Yes | Resource ID. | 5616| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| 5617 5618**Example** 5619 ```ts 5620 resourceManager.getResourceManager((error, mgr) => { 5621 mgr.getString($r('app.string.test').id, (error: Error, value: string) => { 5622 if (error != null) { 5623 console.error("error is " + error); 5624 } else { 5625 let str = value; 5626 } 5627 }); 5628 }); 5629 ``` 5630 5631 5632### getString<sup>(deprecated)</sup> 5633 5634getString(resId: number): Promise<string> 5635 5636Obtains a string based on the specified resource ID. This API uses a promise to return the result. 5637 5638This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1). 5639 5640**System capability**: SystemCapability.Global.ResourceManager 5641 5642**Parameters** 5643 5644| Name | Type | Mandatory | Description | 5645| ----- | ------ | ---- | ----- | 5646| resId | number | Yes | Resource ID.| 5647 5648**Return value** 5649 5650| Type | Description | 5651| --------------------- | ----------- | 5652| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| 5653 5654**Example** 5655 ```ts 5656 import { BusinessError } from '@kit.BasicServicesKit'; 5657 5658 resourceManager.getResourceManager((error, mgr) => { 5659 mgr.getString($r('app.string.test').id).then((value: string) => { 5660 let str = value; 5661 }).catch((error: BusinessError) => { 5662 console.error("getstring promise error is " + error); 5663 }); 5664 }); 5665 ``` 5666 5667 5668### getStringArray<sup>(deprecated)</sup> 5669 5670getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void 5671 5672Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. 5673 5674This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9). 5675 5676**System capability**: SystemCapability.Global.ResourceManager 5677 5678**Parameters** 5679 5680| Name | Type | Mandatory | Description | 5681| -------- | ---------------------------------------- | ---- | ----------------- | 5682| resId | number | Yes | Resource ID. | 5683| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 5684 5685**Example** 5686 ```ts 5687 resourceManager.getResourceManager((error, mgr) => { 5688 mgr.getStringArray($r('app.strarray.test').id, (error: Error, value: Array<string>) => { 5689 if (error != null) { 5690 console.error("error is " + error); 5691 } else { 5692 let strArray = value; 5693 } 5694 }); 5695 }); 5696 ``` 5697 5698 5699### getStringArray<sup>(deprecated)</sup> 5700 5701getStringArray(resId: number): Promise<Array<string>> 5702 5703Obtains a string array based on the specified resource ID. This API uses a promise to return the result. 5704 5705This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1). 5706 5707**System capability**: SystemCapability.Global.ResourceManager 5708 5709**Parameters** 5710 5711| Name | Type | Mandatory | Description | 5712| ----- | ------ | ---- | ----- | 5713| resId | number | Yes | Resource ID.| 5714 5715**Return value** 5716 5717| Type | Description | 5718| ---------------------------------- | ------------- | 5719| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| 5720 5721**Example** 5722 ```ts 5723 import { BusinessError } from '@kit.BasicServicesKit'; 5724 5725 resourceManager.getResourceManager((error, mgr) => { 5726 mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => { 5727 let strArray = value; 5728 }).catch((error: BusinessError) => { 5729 console.error("getStringArray promise error is " + error); 5730 }); 5731 }); 5732 ``` 5733 5734 5735### getMedia<sup>(deprecated)</sup> 5736 5737getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void 5738 5739Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. 5740 5741This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9). 5742 5743**System capability**: SystemCapability.Global.ResourceManager 5744 5745**Parameters** 5746 5747| Name | Type | Mandatory | Description | 5748| -------- | ------------------------------- | ---- | ------------------ | 5749| resId | number | Yes | Resource ID. | 5750| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5751 5752**Example** 5753 ```ts 5754 resourceManager.getResourceManager((error, mgr) => { 5755 mgr.getMedia($r('app.media.test').id, (error: Error, value: Uint8Array) => { 5756 if (error != null) { 5757 console.error("error is " + error); 5758 } else { 5759 let media = value; 5760 } 5761 }); 5762 }); 5763 ``` 5764 5765### getMedia<sup>(deprecated)</sup> 5766 5767getMedia(resId: number): Promise<Uint8Array> 5768 5769Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. 5770 5771This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1). 5772 5773**System capability**: SystemCapability.Global.ResourceManager 5774 5775**Parameters** 5776 5777| Name | Type | Mandatory | Description | 5778| ----- | ------ | ---- | ----- | 5779| resId | number | Yes | Resource ID.| 5780 5781**Return value** 5782 5783| Type | Description | 5784| ------------------------- | -------------- | 5785| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5786 5787**Example** 5788 ```ts 5789 import { BusinessError } from '@kit.BasicServicesKit'; 5790 5791 resourceManager.getResourceManager((error, mgr) => { 5792 mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => { 5793 let media = value; 5794 }).catch((error: BusinessError) => { 5795 console.error("getMedia promise error is " + error); 5796 }); 5797 }); 5798 ``` 5799 5800 5801### getMediaBase64<sup>(deprecated)</sup> 5802 5803getMediaBase64(resId: number, callback: AsyncCallback<string>): void 5804 5805Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. 5806 5807This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649). 5808 5809**System capability**: SystemCapability.Global.ResourceManager 5810 5811**Parameters** 5812 5813| Name | Type | Mandatory | Description | 5814| -------- | --------------------------- | ---- | ------------------------ | 5815| resId | number | Yes | Resource ID. | 5816| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5817 5818**Example** 5819 ```ts 5820 resourceManager.getResourceManager((error, mgr) => { 5821 mgr.getMediaBase64($r('app.media.test').id, ((error: Error, value: string) => { 5822 if (error != null) { 5823 console.error("error is " + error); 5824 } else { 5825 let media = value; 5826 } 5827 }); 5828 }); 5829 ``` 5830 5831 5832### getMediaBase64<sup>(deprecated)</sup> 5833 5834getMediaBase64(resId: number): Promise<string> 5835 5836Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. 5837 5838This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1). 5839 5840**System capability**: SystemCapability.Global.ResourceManager 5841 5842**Parameters** 5843 5844| Name | Type | Mandatory | Description | 5845| ----- | ------ | ---- | ----- | 5846| resId | number | Yes | Resource ID.| 5847 5848**Return value** 5849 5850| Type | Description | 5851| --------------------- | -------------------- | 5852| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5853 5854**Example** 5855 ```ts 5856 import { BusinessError } from '@kit.BasicServicesKit'; 5857 5858 resourceManager.getResourceManager((error, mgr) => { 5859 mgr.getMediaBase64($r('app.media.test').id).then((value: string) => { 5860 let media = value; 5861 }).catch((error: BusinessError) => { 5862 console.error("getMediaBase64 promise error is " + error); 5863 }); 5864 }); 5865 ``` 5866 5867 5868### getPluralString<sup>(deprecated)</sup> 5869 5870getPluralString(resId: number, num: number): Promise<string> 5871 5872Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses a promise to return the result. 5873 5874>**NOTE** 5875> 5876> Singular and plural forms are available for English, but not Chinese. 5877 5878This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9). 5879 5880**System capability**: SystemCapability.Global.ResourceManager 5881 5882**Parameters** 5883 5884| Name | Type | Mandatory | Description | 5885| ----- | ------ | ---- | ----- | 5886| resId | number | Yes | Resource ID.| 5887| num | number | Yes | Number. | 5888 5889**Return value** 5890 5891| Type | Description | 5892| --------------------- | ------------------------- | 5893| Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource ID.| 5894 5895**Example** 5896 ```ts 5897 import { BusinessError } from '@kit.BasicServicesKit'; 5898 5899 resourceManager.getResourceManager((error, mgr) => { 5900 mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => { 5901 let str = value; 5902 }).catch((error: BusinessError) => { 5903 console.error("getPluralString promise error is " + error); 5904 }); 5905 }); 5906 ``` 5907 5908 5909### getPluralString<sup>(deprecated)</sup> 5910 5911getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void 5912 5913Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses an asynchronous callback to return the result. 5914 5915>**NOTE** 5916> 5917> Singular and plural forms are available for English, but not Chinese. 5918 5919This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1). 5920 5921**System capability**: SystemCapability.Global.ResourceManager 5922 5923**Parameters** 5924 5925| Name | Type | Mandatory | Description | 5926| -------- | --------------------------- | ---- | ------------------------------- | 5927| resId | number | Yes | Resource ID. | 5928| num | number | Yes | Number. | 5929| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource ID.| 5930 5931**Example** 5932 ```ts 5933 resourceManager.getResourceManager((error, mgr) => { 5934 mgr.getPluralString($r("app.plural.test").id, 1, (error: Error, value: string) => { 5935 if (error != null) { 5936 console.error("error is " + error); 5937 } else { 5938 let str = value; 5939 } 5940 }); 5941 }); 5942 ``` 5943 5944 5945### getRawFile<sup>(deprecated)</sup> 5946 5947getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void 5948 5949Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 5950 5951This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9). 5952 5953**System capability**: SystemCapability.Global.ResourceManager 5954 5955**Parameters** 5956 5957| Name | Type | Mandatory | Description | 5958| -------- | ------------------------------- | ---- | ----------------------- | 5959| path | string | Yes | Path of the raw file. | 5960| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 5961 5962**Example** 5963 ```ts 5964 resourceManager.getResourceManager((error, mgr) => { 5965 mgr.getRawFile("test.txt", (error: Error, value: Uint8Array) => { 5966 if (error != null) { 5967 console.error("error is " + error); 5968 } else { 5969 let rawFile = value; 5970 } 5971 }); 5972 }); 5973 ``` 5974 5975 5976### getRawFile<sup>(deprecated)</sup> 5977 5978getRawFile(path: string): Promise<Uint8Array> 5979 5980Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 5981 5982This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1). 5983 5984**System capability**: SystemCapability.Global.ResourceManager 5985 5986**Parameters** 5987 5988| Name | Type | Mandatory | Description | 5989| ---- | ------ | ---- | ----------- | 5990| path | string | Yes | Path of the raw file.| 5991 5992**Return value** 5993 5994| Type | Description | 5995| ------------------------- | ----------- | 5996| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 5997 5998**Example** 5999 ```ts 6000 import { BusinessError } from '@kit.BasicServicesKit'; 6001 6002 resourceManager.getResourceManager((error, mgr) => { 6003 mgr.getRawFile("test.txt").then((value: Uint8Array) => { 6004 let rawFile = value; 6005 }).catch((error: BusinessError) => { 6006 console.error("getRawFile promise error is " + error); 6007 }); 6008 }); 6009 ``` 6010 6011 6012### getRawFileDescriptor<sup>(deprecated)</sup> 6013 6014getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void 6015 6016Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6017 6018This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9). 6019 6020**System capability**: SystemCapability.Global.ResourceManager 6021 6022**Parameters** 6023 6024| Name | Type | Mandatory | Description | 6025| -------- | ---------------------------------------- | ---- | -------------------------------- | 6026| path | string | Yes | Path of the raw file. | 6027| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result, which is the descriptor of the raw file.| 6028 6029**Example** 6030 ```ts 6031 import { resourceManager } from '@kit.LocalizationKit' 6032 6033 resourceManager.getResourceManager((error, mgr) => { 6034 mgr.getRawFileDescriptor("test.txt", (error: Error, value: resourceManager.RawFileDescriptor) => { 6035 if (error != null) { 6036 console.error("error is " + error); 6037 } else { 6038 let fd = value.fd; 6039 let offset = value.offset; 6040 let length = value.length; 6041 } 6042 }); 6043 }); 6044 ``` 6045 6046### getRawFileDescriptor<sup>(deprecated)</sup> 6047 6048getRawFileDescriptor(path: string): Promise<RawFileDescriptor> 6049 6050Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6051 6052This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1). 6053 6054**System capability**: SystemCapability.Global.ResourceManager 6055 6056**Parameters** 6057 6058| Name | Type | Mandatory | Description | 6059| ---- | ------ | ---- | ----------- | 6060| path | string | Yes | Path of the raw file.| 6061 6062**Return value** 6063 6064| Type | Description | 6065| ---------------------------------------- | ------------------- | 6066| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result, which is the descriptor of the raw file.| 6067 6068**Example** 6069 ```ts 6070 import { BusinessError } from '@kit.BasicServicesKit'; 6071 6072 resourceManager.getResourceManager((error, mgr) => { 6073 mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => { 6074 let fd = value.fd; 6075 let offset = value.offset; 6076 let length = value.length; 6077 }).catch((error: BusinessError) => { 6078 console.error("getRawFileDescriptor promise error is " + error); 6079 }); 6080 }); 6081 ``` 6082 6083### closeRawFileDescriptor<sup>(deprecated)</sup> 6084 6085closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void 6086 6087Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6088 6089This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9). 6090 6091**System capability**: SystemCapability.Global.ResourceManager 6092 6093**Parameters** 6094 6095 6096 6097| Name | Type | Mandatory | Description | 6098| -------- | ------------------------- | ---- | ----------- | 6099| path | string | Yes | Path of the raw file.| 6100| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6101 6102**Example** 6103 ```ts 6104 resourceManager.getResourceManager((error, mgr) => { 6105 mgr.closeRawFileDescriptor("test.txt", (error: Error) => { 6106 if (error != null) { 6107 console.error("error is " + error); 6108 } 6109 }); 6110 }); 6111 ``` 6112 6113### closeRawFileDescriptor<sup>(deprecated)</sup> 6114 6115closeRawFileDescriptor(path: string): Promise<void> 6116 6117Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6118 6119This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9-1). 6120 6121**System capability**: SystemCapability.Global.ResourceManager 6122 6123**Parameters** 6124 6125| Name | Type | Mandatory | Description | 6126| ---- | ------ | ---- | ----------- | 6127| path | string | Yes | Path of the raw file.| 6128 6129**Return value** 6130 6131| Type | Description | 6132| ------------------- | ---- | 6133| Promise<void> | Promise that returns no value.| 6134 6135**Example** 6136 ```ts 6137 resourceManager.getResourceManager((error, mgr) => { 6138 mgr.closeRawFileDescriptor("test.txt"); 6139 }); 6140 ``` 6141 6142### Appendix 6143 6144- Content of the **app.string.test** file: 6145 6146 ```json 6147 { 6148 "string": [ 6149 { 6150 "name": "test", 6151 "value": "10" 6152 } 6153 ] 6154 } 6155 ``` 6156 6157 ```json 6158 { 6159 "string": [ 6160 { 6161 "name": "test", 6162 "value": "%s %d %f" 6163 } 6164 ] 6165 } 6166 ``` 6167 6168- Content of the **app.strarray.test** file: 6169 6170 ```json 6171 { 6172 "strarray": [ 6173 { 6174 "name": "test", 6175 "value": [ 6176 ``` 6177 6178- Content of the **app.plural.test** file: 6179 ```json 6180 { 6181 "plural": [ 6182 { 6183 "name": "test", 6184 "value": [ 6185 { 6186 "quantity": "one", 6187 "value": "%d apple" 6188 }, 6189 { 6190 "quantity": "other", 6191 "value": "%d apples" 6192 } 6193 ] 6194 } 6195 ] 6196 } 6197 ``` 6198 6199- Content of the **app.boolean.boolean_test** file: 6200 ```json 6201 { 6202 "boolean": [ 6203 { 6204 "name": "boolean_test", 6205 "value": true 6206 } 6207 6208 } 6209 ``` 6210 6211- Content of the **integer_test** and **float_test** files: 6212 ```json 6213 { 6214 "integer": [ 6215 { 6216 "name": "integer_test", 6217 "value": 100 6218 } 6219 ] 6220 } 6221 ``` 6222 6223 ```json 6224 { 6225 "float": [ 6226 { 6227 "name": "float_test", 6228 "value": "30.6" 6229 } 6230 ] 6231 } 6232 ``` 6233- Content of the **app.color.test** file: 6234 ```json 6235 { 6236 "color": [ 6237 { 6238 "name": "test", 6239 "value": "#FFFFFF" 6240 } 6241 ] 6242 } 6243 ``` 6244