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