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