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>9+</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](js-apis-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](js-apis-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 import { DrawableDescriptor } from '@kit.ArkUI'; 3480 3481 try { 3482 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); 3483 } catch (error) { 3484 let code = (error as BusinessError).code; 3485 let message = (error as BusinessError).message; 3486 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3487 } 3488 try { 3489 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); 3490 } catch (error) { 3491 let code = (error as BusinessError).code; 3492 let message = (error as BusinessError).message; 3493 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3494 } 3495 try { 3496 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 0, 1); 3497 } catch (error) { 3498 let code = (error as BusinessError).code; 3499 let message = (error as BusinessError).message; 3500 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3501 } 3502 ``` 3503 3504### getDrawableDescriptor<sup>10+</sup> 3505 3506getDrawableDescriptor(resource: Resource, density?: number, type?: number): DrawableDescriptor 3507 3508Obtains a **DrawableDescriptor** object for icon display based on the specified resource object. This API returns the result synchronously. 3509 3510**Atomic service API**: This API can be used in atomic services since API version 11. 3511 3512**System capability**: SystemCapability.Global.ResourceManager 3513 3514**Model restriction**: This API can be used only in the stage model. 3515 3516**Parameters** 3517 3518| Name | Type | Mandatory | Description | 3519| -------- | ---------------------- | ---- | ---- | 3520| resource | [Resource](#resource9) | Yes | Resource object.| 3521| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3522| 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.| 3523 3524**Return value** 3525 3526| Type | Description | 3527| ------- | ----------------- | 3528| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3529 3530**Error codes** 3531 3532For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3533 3534| ID| Error Message| 3535| -------- | ---------------------------------------- | 3536| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3537| 9001001 | Invalid resource ID. | 3538| 9001002 | No matching resource is found based on the resource ID. | 3539 3540**Example** 3541 ```ts 3542 import { resourceManager } from '@kit.LocalizationKit' 3543 import { BusinessError } from '@kit.BasicServicesKit'; 3544 import { DrawableDescriptor } from '@kit.ArkUI'; 3545 3546 let resource: resourceManager.Resource = { 3547 bundleName: "com.example.myapplication", 3548 moduleName: "entry", 3549 id: $r('app.media.icon').id 3550 }; 3551 try { 3552 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource); 3553 } catch (error) { 3554 let code = (error as BusinessError).code; 3555 let message = (error as BusinessError).message; 3556 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3557 } 3558 try { 3559 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource, 120); 3560 } catch (error) { 3561 let code = (error as BusinessError).code; 3562 let message = (error as BusinessError).message; 3563 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3564 } 3565 try { 3566 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource, 0, 1); 3567 } catch (error) { 3568 let code = (error as BusinessError).code; 3569 let message = (error as BusinessError).message; 3570 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3571 } 3572 ``` 3573 3574### getDrawableDescriptorByName<sup>10+</sup> 3575 3576getDrawableDescriptorByName(resName: string, density?: number, type?: number): DrawableDescriptor 3577 3578Obtains a **DrawableDescriptor** object for icon display based on the specified resource name. This API returns the result synchronously. 3579 3580**Atomic service API**: This API can be used in atomic services since API version 11. 3581 3582**System capability**: SystemCapability.Global.ResourceManager 3583 3584**Parameters** 3585 3586| Name | Type | Mandatory | Description | 3587| ------- | ------ | ---- | ---- | 3588| resName | string | Yes | Resource name.| 3589| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3590| 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.| 3591 3592**Return value** 3593 3594| Type | Description | 3595| ------ | --------- | 3596| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3597 3598**Error codes** 3599 3600For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3601 3602| ID| Error Message| 3603| -------- | ---------------------------------------- | 3604| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3605| 9001003 | Invalid resource name. | 3606| 9001004 | No matching resource is found based on the resource name. | 3607 3608**Example** 3609 ```ts 3610 import { BusinessError } from '@kit.BasicServicesKit'; 3611 import { DrawableDescriptor } from '@kit.ArkUI'; 3612 3613 try { 3614 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon'); 3615 } catch (error) { 3616 let code = (error as BusinessError).code; 3617 let message = (error as BusinessError).message; 3618 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3619 } 3620 try { 3621 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon', 120); 3622 } catch (error) { 3623 let code = (error as BusinessError).code; 3624 let message = (error as BusinessError).message; 3625 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3626 } 3627 try { 3628 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon', 0, 1); 3629 } catch (error) { 3630 let code = (error as BusinessError).code; 3631 let message = (error as BusinessError).message; 3632 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3633 } 3634 ``` 3635 3636### getBoolean<sup>9+</sup> 3637 3638getBoolean(resId: number): boolean 3639 3640Obtains a Boolean result based on the specified resource ID. This API returns the result synchronously. 3641 3642**Atomic service API**: This API can be used in atomic services since API version 11. 3643 3644**System capability**: SystemCapability.Global.ResourceManager 3645 3646**Parameters** 3647 3648| Name | Type | Mandatory | Description | 3649| ----- | ------ | ---- | ----- | 3650| resId | number | Yes | Resource ID.| 3651 3652**Return value** 3653 3654| Type | Description | 3655| ------- | ------------ | 3656| boolean | Boolean result corresponding to the specified resource ID.| 3657 3658**Error codes** 3659 3660For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3661 3662| ID| Error Message| 3663| -------- | ---------------------------------------- | 3664| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3665| 9001001 | Invalid resource ID. | 3666| 9001002 | No matching resource is found based on the resource ID. | 3667| 9001006 | The resource is referenced cyclically. | 3668 3669**Example** 3670 ```ts 3671 import { BusinessError } from '@kit.BasicServicesKit'; 3672 3673 try { 3674 this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); 3675 } catch (error) { 3676 let code = (error as BusinessError).code; 3677 let message = (error as BusinessError).message; 3678 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3679 } 3680 ``` 3681### getBoolean<sup>9+</sup> 3682 3683getBoolean(resource: Resource): boolean 3684 3685Obtains a Boolean result based on the specified resource object. This API returns the result synchronously. 3686 3687**Atomic service API**: This API can be used in atomic services since API version 11. 3688 3689**System capability**: SystemCapability.Global.ResourceManager 3690 3691**Model restriction**: This API can be used only in the stage model. 3692 3693**Parameters** 3694 3695| Name | Type | Mandatory | Description | 3696| -------- | ---------------------- | ---- | ---- | 3697| resource | [Resource](#resource9) | Yes | Resource object.| 3698 3699**Return value** 3700 3701| Type | Description | 3702| ------- | ----------------- | 3703| boolean | Boolean result corresponding to the specified resource object.| 3704 3705**Error codes** 3706 3707For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3708 3709| ID| Error Message| 3710| -------- | ---------------------------------------- | 3711| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3712| 9001001 | Invalid resource ID. | 3713| 9001002 | No matching resource is found based on the resource ID. | 3714| 9001006 | The resource is referenced cyclically. | 3715 3716**Example** 3717 ```ts 3718 import { resourceManager } from '@kit.LocalizationKit' 3719 import { BusinessError } from '@kit.BasicServicesKit'; 3720 3721 let resource: resourceManager.Resource = { 3722 bundleName: "com.example.myapplication", 3723 moduleName: "entry", 3724 id: $r('app.boolean.boolean_test').id 3725 }; 3726 try { 3727 this.context.resourceManager.getBoolean(resource); 3728 } catch (error) { 3729 let code = (error as BusinessError).code; 3730 let message = (error as BusinessError).message; 3731 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3732 } 3733 ``` 3734 3735### getBooleanByName<sup>9+</sup> 3736 3737getBooleanByName(resName: string): boolean 3738 3739Obtains a Boolean result based on the specified resource name. This API returns the result synchronously. 3740 3741**Atomic service API**: This API can be used in atomic services since API version 11. 3742 3743**System capability**: SystemCapability.Global.ResourceManager 3744 3745**Parameters** 3746 3747| Name | Type | Mandatory | Description | 3748| ------- | ------ | ---- | ---- | 3749| resName | string | Yes | Resource name.| 3750 3751**Return value** 3752 3753| Type | Description | 3754| ------- | ----------- | 3755| boolean | Boolean result corresponding to the specified resource name.| 3756 3757**Error codes** 3758 3759For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3760 3761| ID| Error Message| 3762| -------- | ---------------------------------------- | 3763| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3764| 9001003 | Invalid resource name. | 3765| 9001004 | No matching resource is found based on the resource name. | 3766| 9001006 | The resource is referenced cyclically. | 3767 3768**Example** 3769 ```ts 3770 import { BusinessError } from '@kit.BasicServicesKit'; 3771 3772 try { 3773 this.context.resourceManager.getBooleanByName("boolean_test"); 3774 } catch (error) { 3775 let code = (error as BusinessError).code; 3776 let message = (error as BusinessError).message; 3777 console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`); 3778 } 3779 ``` 3780 3781### getNumber<sup>9+</sup> 3782 3783getNumber(resId: number): number 3784 3785Obtains an integer or float value based on the specified resource ID. This API returns the result synchronously. 3786 3787**Atomic service API**: This API can be used in atomic services since API version 11. 3788 3789**System capability**: SystemCapability.Global.ResourceManager 3790 3791**Parameters** 3792 3793| Name | Type | Mandatory | Description | 3794| ----- | ------ | ---- | ----- | 3795| resId | number | Yes | Resource ID.| 3796 3797**Return value** 3798 3799| Type | Description | 3800| ------ | ---------- | 3801| 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.| 3802 3803**Error codes** 3804 3805For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3806 3807| ID| Error Message| 3808| -------- | ---------------------------------------- | 3809| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3810| 9001001 | Invalid resource ID. | 3811| 9001002 | No matching resource is found based on the resource ID. | 3812| 9001006 | The resource is referenced cyclically. | 3813 3814**Example** 3815 ```ts 3816 import { BusinessError } from '@kit.BasicServicesKit'; 3817 3818 try { 3819 this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. 3820 } catch (error) { 3821 let code = (error as BusinessError).code; 3822 let message = (error as BusinessError).message; 3823 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3824 } 3825 3826 try { 3827 this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. 3828 } catch (error) { 3829 let code = (error as BusinessError).code; 3830 let message = (error as BusinessError).message; 3831 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3832 } 3833 ``` 3834 3835### getNumber<sup>9+</sup> 3836 3837getNumber(resource: Resource): number 3838 3839Obtains an integer or float value based on the specified resource object. This API returns the result synchronously. 3840 3841> **NOTE** 3842> 3843> 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. 3844 3845**Atomic service API**: This API can be used in atomic services since API version 11. 3846 3847**System capability**: SystemCapability.Global.ResourceManager 3848 3849**Model restriction**: This API can be used only in the stage model. 3850 3851**Parameters** 3852 3853| Name | Type | Mandatory | Description | 3854| -------- | ---------------------- | ---- | ---- | 3855| resource | [Resource](#resource9) | Yes | Resource object.| 3856 3857**Return value** 3858 3859| Type | Description | 3860| ------ | --------------- | 3861| 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.| 3862 3863**Error codes** 3864 3865For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3866 3867| ID| Error Message| 3868| -------- | ---------------------------------------- | 3869| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3870| 9001001 | Invalid resource ID. | 3871| 9001002 | No matching resource is found based on the resource ID. | 3872| 9001006 | The resource is referenced cyclically. | 3873 3874**Example** 3875 ```ts 3876 import { resourceManager } from '@kit.LocalizationKit' 3877 import { BusinessError } from '@kit.BasicServicesKit'; 3878 3879 let resource: resourceManager.Resource = { 3880 bundleName: "com.example.myapplication", 3881 moduleName: "entry", 3882 id: $r('app.integer.integer_test').id 3883 }; 3884 try { 3885 this.context.resourceManager.getNumber(resource); 3886 } catch (error) { 3887 let code = (error as BusinessError).code; 3888 let message = (error as BusinessError).message; 3889 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3890 } 3891 ``` 3892 3893### getNumberByName<sup>9+</sup> 3894 3895getNumberByName(resName: string): number 3896 3897Obtains an integer or float value based on the specified resource name. This API returns the result synchronously. 3898 3899**Atomic service API**: This API can be used in atomic services since API version 11. 3900 3901**System capability**: SystemCapability.Global.ResourceManager 3902 3903**Parameters** 3904 3905| Name | Type | Mandatory | Description | 3906| ------- | ------ | ---- | ---- | 3907| resName | string | Yes | Resource name.| 3908 3909**Return value** 3910 3911| Type | Description | 3912| ------ | --------- | 3913| 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.| 3914 3915**Error codes** 3916 3917For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3918 3919| ID| Error Message| 3920| -------- | ---------------------------------------- | 3921| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3922| 9001003 | Invalid resource name. | 3923| 9001004 | No matching resource is found based on the resource name. | 3924| 9001006 | The resource is referenced cyclically. | 3925 3926**Example** 3927 ```ts 3928 import { BusinessError } from '@kit.BasicServicesKit'; 3929 3930 try { 3931 this.context.resourceManager.getNumberByName("integer_test"); 3932 } catch (error) { 3933 let code = (error as BusinessError).code; 3934 let message = (error as BusinessError).message; 3935 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3936 } 3937 3938 try { 3939 this.context.resourceManager.getNumberByName("float_test"); 3940 } catch (error) { 3941 let code = (error as BusinessError).code; 3942 let message = (error as BusinessError).message; 3943 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3944 } 3945 ``` 3946 3947### getColorSync<sup>10+</sup> 3948 3949getColorSync(resId: number) : number; 3950 3951Obtains a color value based on the specified resource ID. This API returns the result synchronously. 3952 3953**Atomic service API**: This API can be used in atomic services since API version 11. 3954 3955**System capability**: SystemCapability.Global.ResourceManager 3956 3957**Parameters** 3958 3959| Name | Type | Mandatory | Description | 3960| ----- | ------ | ---- | ----- | 3961| resId | number | Yes | Resource ID.| 3962 3963**Return value** 3964 3965| Type | Description | 3966| ------ | ----------- | 3967| number | Color value (decimal) corresponding to the specified resource ID.| 3968 3969**Error codes** 3970 3971For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3972 3973| ID| Error Message| 3974| -------- | ---------------------------------------- | 3975| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3976| 9001001 | Invalid resource ID. | 3977| 9001002 | No matching resource is found based on the resource ID. | 3978| 9001006 | The resource is referenced cyclically. | 3979 3980**Example** 3981 ```ts 3982 import { BusinessError } from '@kit.BasicServicesKit'; 3983 3984 try { 3985 this.context.resourceManager.getColorSync($r('app.color.test').id); 3986 } catch (error) { 3987 let code = (error as BusinessError).code; 3988 let message = (error as BusinessError).message; 3989 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 3990 } 3991 ``` 3992 3993### getColorSync<sup>10+</sup> 3994 3995getColorSync(resource: Resource): number 3996 3997Obtains a color value based on the specified resource object. This API returns the result synchronously. 3998 3999**Atomic service API**: This API can be used in atomic services since API version 11. 4000 4001**System capability**: SystemCapability.Global.ResourceManager 4002 4003**Model restriction**: This API can be used only in the stage model. 4004 4005**Parameters** 4006 4007| Name | Type | Mandatory | Description | 4008| -------- | ---------------------- | ---- | ---- | 4009| resource | [Resource](#resource9) | Yes | Resource object.| 4010 4011**Return value** 4012 4013| Type | Description | 4014| ------ | ---------------- | 4015| number | Color value (decimal) corresponding to the specified resource object.| 4016 4017**Error codes** 4018 4019For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4020 4021| ID| Error Message| 4022| -------- | ---------------------------------------- | 4023| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4024| 9001001 | Invalid resource ID. | 4025| 9001002 | No matching resource is found based on the resource ID. | 4026| 9001006 | The resource is referenced cyclically. | 4027 4028**Example** 4029 ```ts 4030 import { resourceManager } from '@kit.LocalizationKit' 4031 import { BusinessError } from '@kit.BasicServicesKit'; 4032 4033 let resource: resourceManager.Resource = { 4034 bundleName: "com.example.myapplication", 4035 moduleName: "entry", 4036 id: $r('app.color.test').id 4037 }; 4038 try { 4039 this.context.resourceManager.getColorSync(resource); 4040 } catch (error) { 4041 let code = (error as BusinessError).code; 4042 let message = (error as BusinessError).message; 4043 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 4044 } 4045 ``` 4046 4047### getColorByNameSync<sup>10+</sup> 4048 4049getColorByNameSync(resName: string) : number; 4050 4051Obtains a color value based on the specified resource name. This API returns the result synchronously. 4052 4053**Atomic service API**: This API can be used in atomic services since API version 11. 4054 4055**System capability**: SystemCapability.Global.ResourceManager 4056 4057**Parameters** 4058 4059| Name | Type | Mandatory | Description | 4060| ------- | ------ | ---- | ---- | 4061| resName | string | Yes | Resource name.| 4062 4063**Return value** 4064 4065| Type | Description | 4066| ------ | ---------- | 4067| number | Color value (decimal) corresponding to the specified resource name.| 4068 4069**Error codes** 4070 4071For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4072 4073| ID| Error Message| 4074| -------- | ---------------------------------------- | 4075| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4076| 9001003 | Invalid resource name. | 4077| 9001004 | No matching resource is found based on the resource name. | 4078| 9001006 | The resource is referenced cyclically. | 4079 4080**Example** 4081 ```ts 4082 import { BusinessError } from '@kit.BasicServicesKit'; 4083 4084 try { 4085 this.context.resourceManager.getColorByNameSync("test"); 4086 } catch (error) { 4087 let code = (error as BusinessError).code; 4088 let message = (error as BusinessError).message; 4089 console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`); 4090 } 4091 ``` 4092 4093### getColor<sup>10+</sup> 4094 4095getColor(resId: number, callback: AsyncCallback<number>): void; 4096 4097Obtains a color value based on the specified resource ID. This API uses an asynchronous callback to return the result. 4098 4099**Atomic service API**: This API can be used in atomic services since API version 11. 4100 4101**System capability**: SystemCapability.Global.ResourceManager 4102 4103**Parameters** 4104 4105| Name | Type | Mandatory | Description | 4106| -------- | --------------------------- | ---- | --------------- | 4107| resId | number | Yes | Resource ID. | 4108| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4109 4110**Error codes** 4111 4112For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4113 4114| ID| Error Message| 4115| -------- | ---------------------------------------- | 4116| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4117| 9001001 | If the module resId invalid. | 4118| 9001002 | No matching resource is found based on the resource ID. | 4119| 9001006 | The resource is referenced cyclically. | 4120 4121**Example (stage)** 4122 ```ts 4123 import { BusinessError } from '@kit.BasicServicesKit'; 4124 4125 try { 4126 this.context.resourceManager.getColor($r('app.color.test').id, (error: BusinessError, value: number) => { 4127 if (error != null) { 4128 console.error("error is " + error); 4129 } else { 4130 let str = value; 4131 } 4132 }); 4133 } catch (error) { 4134 let code = (error as BusinessError).code; 4135 let message = (error as BusinessError).message; 4136 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 4137 } 4138 ``` 4139 4140### getColor<sup>10+</sup> 4141 4142getColor(resId: number): Promise<number> 4143 4144Obtains a color value based on the specified resource ID. This API uses a promise to return the result. 4145 4146**Atomic service API**: This API can be used in atomic services since API version 11. 4147 4148**System capability**: SystemCapability.Global.ResourceManager 4149 4150**Parameters** 4151 4152| Name | Type | Mandatory | Description | 4153| ----- | ------ | ---- | ----- | 4154| resId | number | Yes | Resource ID.| 4155 4156**Return value** 4157 4158| Type | Description | 4159| --------------------- | ----------- | 4160| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4161 4162**Error codes** 4163 4164For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4165 4166| ID| Error Message| 4167| -------- | ---------------------------------------- | 4168| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4169| 9001001 | Invalid resource ID. | 4170| 9001002 | No matching resource is found based on the resource ID. | 4171| 9001006 | The resource is referenced cyclically. | 4172 4173**Example** 4174 ```ts 4175 import { BusinessError } from '@kit.BasicServicesKit'; 4176 4177 try { 4178 this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => { 4179 let str = value; 4180 }).catch((error: BusinessError) => { 4181 console.error("getColor promise error is " + error); 4182 }); 4183 } catch (error) { 4184 let code = (error as BusinessError).code; 4185 let message = (error as BusinessError).message; 4186 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4187 } 4188 ``` 4189 4190### getColor<sup>10+</sup> 4191 4192getColor(resource: Resource, callback: AsyncCallback<number>): void; 4193 4194Obtains a color value based on the specified resource object. This API uses an asynchronous callback to return the result. 4195 4196**Atomic service API**: This API can be used in atomic services since API version 11. 4197 4198**System capability**: SystemCapability.Global.ResourceManager 4199 4200**Model restriction**: This API can be used only in the stage model. 4201 4202**Parameters** 4203 4204| Name | Type | Mandatory | Description | 4205| -------- | --------------------------- | ---- | --------------- | 4206| resource | [Resource](#resource9) | Yes | Resource object. | 4207| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4208 4209**Error codes** 4210 4211For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4212 4213| ID| Error Message| 4214| -------- | ---------------------------------------- | 4215| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4216| 9001001 | Invalid resource ID. | 4217| 9001002 | No matching resource is found based on the resource ID. | 4218| 9001006 | The resource is referenced cyclically. | 4219 4220**Example** 4221 ```ts 4222 import { resourceManager } from '@kit.LocalizationKit' 4223 import { BusinessError } from '@kit.BasicServicesKit'; 4224 4225 let resource: resourceManager.Resource = { 4226 bundleName: "com.example.myapplication", 4227 moduleName: "entry", 4228 id: $r('app.color.test').id 4229 }; 4230 try { 4231 this.context.resourceManager.getColor(resource, (error: BusinessError, value: number) => { 4232 if (error != null) { 4233 console.error("error is " + error); 4234 } else { 4235 let str = value; 4236 } 4237 }); 4238 } catch (error) { 4239 let code = (error as BusinessError).code; 4240 let message = (error as BusinessError).message; 4241 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 4242 } 4243 ``` 4244 4245### getColor<sup>10+</sup> 4246 4247getColor(resource: Resource): Promise<number>; 4248 4249Obtains a color value based on the specified resource object. This API uses a promise to return the result. 4250 4251**Atomic service API**: This API can be used in atomic services since API version 11. 4252 4253**System capability**: SystemCapability.Global.ResourceManager 4254 4255**Model restriction**: This API can be used only in the stage model. 4256 4257**Parameters** 4258 4259| Name | Type | Mandatory | Description | 4260| -------- | ---------------------- | ---- | ---- | 4261| resource | [Resource](#resource9) | Yes | Resource object.| 4262 4263**Return value** 4264 4265| Type | Description | 4266| --------------------- | ---------------- | 4267| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource object.| 4268 4269**Error codes** 4270 4271For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4272 4273| ID| Error Message| 4274| -------- | ---------------------------------------- | 4275| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4276| 9001001 | Invalid resource ID. | 4277| 9001002 | No matching resource is found based on the resource ID. | 4278| 9001006 | The resource is referenced cyclically. | 4279 4280**Example** 4281 ```ts 4282 import { resourceManager } from '@kit.LocalizationKit' 4283 import { BusinessError } from '@kit.BasicServicesKit'; 4284 4285 let resource: resourceManager.Resource = { 4286 bundleName: "com.example.myapplication", 4287 moduleName: "entry", 4288 id: $r('app.color.test').id 4289 }; 4290 try { 4291 this.context.resourceManager.getColor(resource).then((value: number) => { 4292 let str = value; 4293 }).catch((error: BusinessError) => { 4294 console.error("getColor promise error is " + error); 4295 }); 4296 } catch (error) { 4297 let code = (error as BusinessError).code; 4298 let message = (error as BusinessError).message; 4299 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4300 } 4301 ``` 4302 4303### getColorByName<sup>10+</sup> 4304 4305getColorByName(resName: string, callback: AsyncCallback<number>): void 4306 4307Obtains a color value based on the specified resource name. This API uses an asynchronous callback to return the result. 4308 4309**Atomic service API**: This API can be used in atomic services since API version 11. 4310 4311**System capability**: SystemCapability.Global.ResourceManager 4312 4313**Parameters** 4314 4315| Name | Type | Mandatory | Description | 4316| -------- | --------------------------- | ---- | --------------- | 4317| resName | string | Yes | Resource name. | 4318| callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4319 4320**Error codes** 4321 4322For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4323 4324| ID| Error Message| 4325| -------- | ---------------------------------------- | 4326| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4327| 9001003 | Invalid resource name. | 4328| 9001004 | No matching resource is found based on the resource name. | 4329| 9001006 | The resource is referenced cyclically. | 4330 4331**Example** 4332 ```ts 4333 import { BusinessError } from '@kit.BasicServicesKit'; 4334 4335 try { 4336 this.context.resourceManager.getColorByName("test", (error: BusinessError, value: number) => { 4337 if (error != null) { 4338 console.error("error is " + error); 4339 } else { 4340 let string = value; 4341 } 4342 }); 4343 } catch (error) { 4344 let code = (error as BusinessError).code; 4345 let message = (error as BusinessError).message; 4346 console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`); 4347 } 4348 ``` 4349 4350### getColorByName<sup>10+</sup> 4351 4352getColorByName(resName: string): Promise<number> 4353 4354Obtains a color value based on the specified resource name. This API uses a promise to return the result. 4355 4356**Atomic service API**: This API can be used in atomic services since API version 11. 4357 4358**System capability**: SystemCapability.Global.ResourceManager 4359 4360**Parameters** 4361 4362| Name | Type | Mandatory | Description | 4363| ------- | ------ | ---- | ---- | 4364| resName | string | Yes | Resource name.| 4365 4366**Return value** 4367 4368| Type | Description | 4369| --------------------- | ---------- | 4370| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4371 4372**Error codes** 4373 4374For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4375 4376| ID| Error Message| 4377| -------- | ---------------------------------------- | 4378| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4379| 9001003 | Invalid resource name. | 4380| 9001004 | No matching resource is found based on the resource name. | 4381| 9001006 | The resource is referenced cyclically. | 4382 4383**Example** 4384 ```ts 4385 import { BusinessError } from '@kit.BasicServicesKit'; 4386 4387 try { 4388 this.context.resourceManager.getColorByName("test").then((value: number) => { 4389 let string = value; 4390 }).catch((error: BusinessError) => { 4391 console.error("getColorByName promise error is " + error); 4392 }); 4393 } catch (error) { 4394 let code = (error as BusinessError).code; 4395 let message = (error as BusinessError).message; 4396 console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`); 4397 } 4398 ``` 4399 4400### getRawFileContentSync<sup>10+</sup> 4401 4402getRawFileContentSync(path: string): Uint8Array 4403 4404Obtains the content of the raw file in the **resources/rawfile** directory. This API returns the result synchronously. 4405 4406**Atomic service API**: This API can be used in atomic services since API version 11. 4407 4408**System capability**: SystemCapability.Global.ResourceManager 4409 4410**Parameters** 4411 4412| Name | Type | Mandatory | Description | 4413| -------- | ------------------------------- | ---- | ----------------------- | 4414| path | string | Yes | Path of the raw file. | 4415 4416**Return value** 4417 4418| Type | Description | 4419| --------------------- | ---------- | 4420| Uint8Array | Content of the raw file.| 4421 4422**Error codes** 4423 4424For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4425 4426| ID| Error Message| 4427| -------- | ---------------------------------------- | 4428| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4429| 9001005 | Invalid relative path. | 4430 4431**Example** 4432 ```ts 4433 import { BusinessError } from '@kit.BasicServicesKit'; 4434 4435 try { 4436 this.context.resourceManager.getRawFileContentSync("test.txt"); 4437 } catch (error) { 4438 let code = (error as BusinessError).code; 4439 let message = (error as BusinessError).message; 4440 console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`); 4441 } 4442 ``` 4443 4444### getRawFileContent<sup>9+</sup> 4445 4446getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void 4447 4448Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4449 4450**Atomic service API**: This API can be used in atomic services since API version 11. 4451 4452**System capability**: SystemCapability.Global.ResourceManager 4453 4454**Parameters** 4455 4456| Name | Type | Mandatory | Description | 4457| -------- | ------------------------------- | ---- | ----------------------- | 4458| path | string | Yes | Path of the raw file. | 4459| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 4460 4461**Error codes** 4462 4463For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4464 4465| ID| Error Message| 4466| -------- | ---------------------------------------- | 4467| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4468 4469**Example** 4470 ```ts 4471 import { BusinessError } from '@kit.BasicServicesKit'; 4472 4473 try { 4474 this.context.resourceManager.getRawFileContent("test.txt", (error: BusinessError, value: Uint8Array) => { 4475 if (error != null) { 4476 console.error("error is " + error); 4477 } else { 4478 let rawFile = value; 4479 } 4480 }); 4481 } catch (error) { 4482 let code = (error as BusinessError).code; 4483 let message = (error as BusinessError).message; 4484 console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`); 4485 } 4486 ``` 4487 4488### getRawFileContent<sup>9+</sup> 4489 4490getRawFileContent(path: string): Promise<Uint8Array> 4491 4492Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 4493 4494**Atomic service API**: This API can be used in atomic services since API version 11. 4495 4496**System capability**: SystemCapability.Global.ResourceManager 4497 4498**Parameters** 4499 4500| Name | Type | Mandatory | Description | 4501| ---- | ------ | ---- | ----------- | 4502| path | string | Yes | Path of the raw file.| 4503 4504**Return value** 4505 4506| Type | Description | 4507| ------------------------- | ----------- | 4508| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 4509 4510**Error codes** 4511 4512For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4513 4514| ID| Error Message| 4515| -------- | ---------------------------------------- | 4516| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4517| 9001005 | Invalid relative path. | 4518 4519**Example** 4520 ```ts 4521 import { BusinessError } from '@kit.BasicServicesKit'; 4522 4523 try { 4524 this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => { 4525 let rawFile = value; 4526 }).catch((error: BusinessError) => { 4527 console.error("getRawFileContent promise error is " + error); 4528 }); 4529 } catch (error) { 4530 let code = (error as BusinessError).code; 4531 let message = (error as BusinessError).message; 4532 console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`); 4533 } 4534 ``` 4535 4536### getRawFileListSync<sup>10+</sup> 4537 4538getRawFileListSync(path: string): Array\<string> 4539 4540Obtains the list of folders and files in the **resources/rawfile** directory. This API returns the result synchronously. 4541 4542>**NOTE** 4543> 4544> 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. 4545 4546**Atomic service API**: This API can be used in atomic services since API version 11. 4547 4548**System capability**: SystemCapability.Global.ResourceManager 4549 4550**Parameters** 4551 4552| Name | Type | Mandatory | Description | 4553| -------- | ------------------------------- | ---- | ----------------------- | 4554| path | string | Yes | **rawfile** directory. | 4555 4556**Return value** 4557 4558| Type | Description | 4559| ------------------------- | ----------- | 4560| Array\<string> | List of folders and files in the **rawfile** directory.| 4561 4562**Error codes** 4563 4564For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4565 4566| ID| Error Message| 4567| -------- | ---------------------------------------- | 4568| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4569| 9001005 | Invalid relative path. | 4570 4571**Example** 4572 ```ts 4573 import { BusinessError } from '@kit.BasicServicesKit'; 4574 4575 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4576 this.context.resourceManager.getRawFileListSync("") 4577 } catch (error) { 4578 let code = (error as BusinessError).code; 4579 let message = (error as BusinessError).message; 4580 console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`); 4581 } 4582 ``` 4583 4584### getRawFileList<sup>10+</sup> 4585 4586getRawFileList(path: string, callback: AsyncCallback<Array\<string\>>): void; 4587 4588Obtains the list of folders and files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4589 4590>**NOTE** 4591> 4592> 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. 4593 4594**Atomic service API**: This API can be used in atomic services since API version 11. 4595 4596**System capability**: SystemCapability.Global.ResourceManager 4597 4598**Parameters** 4599 4600| Name | Type | Mandatory | Description | 4601| -------- | ------------------------------- | ---- | ----------------------- | 4602| path | string | Yes | **rawfile** directory. | 4603| callback | AsyncCallback<Array\<string\>> | Yes| Callback used to return the result, which is the list of folders and files in the **rawfile** directory.| 4604 4605**Error codes** 4606 4607For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4608 4609| ID| Error Message| 4610| -------- | ---------------------------------------- | 4611| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4612| 9001005 | Invalid relative path. | 4613 4614**Example** 4615 ```ts 4616 import { BusinessError } from '@kit.BasicServicesKit'; 4617 4618 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4619 this.context.resourceManager.getRawFileList("", (error: BusinessError, value: Array<string>) => { 4620 if (error != null) { 4621 console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4622 } else { 4623 let rawFile = value; 4624 } 4625 }); 4626 } catch (error) { 4627 let code = (error as BusinessError).code; 4628 let message = (error as BusinessError).message; 4629 console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`); 4630 } 4631 ``` 4632 4633### getRawFileList<sup>10+</sup> 4634 4635getRawFileList(path: string): Promise<Array\<string\>> 4636 4637Obtains the list of folders and files in the **resources/rawfile** directory. This API uses a promise to return the result. 4638 4639>**NOTE** 4640> 4641> 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. 4642 4643**Atomic service API**: This API can be used in atomic services since API version 11. 4644 4645**System capability**: SystemCapability.Global.ResourceManager 4646 4647**Parameters** 4648 4649| Name | Type | Mandatory | Description | 4650| ---- | ------ | ---- | ----------- | 4651| path | string | Yes | **rawfile** directory.| 4652 4653**Return value** 4654 4655| Type | Description | 4656| ------------------------- | ----------- | 4657| Promise<Array\<string\>> | Promise used to return the result, which is the list of folders and files in the **rawfile** directory.| 4658 4659**Error codes** 4660 4661For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4662 4663| ID| Error Message| 4664| -------- | ---------------------------------------- | 4665| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4666| 9001005 | Invalid relative path. | 4667 4668**Example** 4669 ```ts 4670 import { BusinessError } from '@kit.BasicServicesKit'; 4671 4672 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4673 this.context.resourceManager.getRawFileList("").then((value: Array<string>) => { 4674 let rawFile = value; 4675 }).catch((error: BusinessError) => { 4676 console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4677 }); 4678 } catch (error) { 4679 let code = (error as BusinessError).code; 4680 let message = (error as BusinessError).message; 4681 console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`); 4682 } 4683 ``` 4684 4685### getRawFdSync<sup>10+</sup> 4686 4687getRawFdSync(path: string): RawFileDescriptor 4688 4689Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4690 4691**Atomic service API**: This API can be used in atomic services since API version 11. 4692 4693**System capability**: SystemCapability.Global.ResourceManager 4694 4695**Parameters** 4696 4697| Name | Type | Mandatory | Description | 4698| -------- | ---------------------------------------- | ---- | -------------------------------- | 4699| path | string | Yes | Path of the raw file. | 4700 4701**Return value** 4702 4703| Type | Description | 4704| ------------------------- | ----------- | 4705| [RawFileDescriptor](#rawfiledescriptor9) | Descriptor of the HAP where the raw file is located.| 4706 4707**Error codes** 4708 4709For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4710 4711| ID| Error Message| 4712| -------- | ---------------------------------------- | 4713| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4714| 9001005 | Invalid relative path. | 4715 4716**Example** 4717 ```ts 4718 import { BusinessError } from '@kit.BasicServicesKit'; 4719 4720 try { 4721 this.context.resourceManager.getRawFdSync("test.txt"); 4722 } catch (error) { 4723 let code = (error as BusinessError).code; 4724 let message = (error as BusinessError).message; 4725 console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`); 4726 } 4727 ``` 4728 4729### getRawFd<sup>9+</sup> 4730 4731getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void 4732 4733Obtains 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. 4734 4735**Atomic service API**: This API can be used in atomic services since API version 11. 4736 4737**System capability**: SystemCapability.Global.ResourceManager 4738 4739**Parameters** 4740 4741| Name | Type | Mandatory | Description | 4742| -------- | ---------------------------------------- | ---- | -------------------------------- | 4743| path | string | Yes | Path of the raw file. | 4744| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor9)> | Yes | Callback used to return the result, which is the descriptor of the HAP where the raw file is located.| 4745 4746**Error codes** 4747 4748For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4749 4750| ID| Error Message| 4751| -------- | ---------------------------------------- | 4752| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4753| 9001005 | Invalid relative path. | 4754 4755**Example** 4756 ```ts 4757 import { BusinessError } from '@kit.BasicServicesKit'; 4758 import { resourceManager } from '@kit.LocalizationKit' 4759 4760 try { 4761 this.context.resourceManager.getRawFd("test.txt", (error: BusinessError, value: resourceManager.RawFileDescriptor) => { 4762 if (error != null) { 4763 console.error(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); 4764 } else { 4765 let fd = value.fd; 4766 let offset = value.offset; 4767 let length = value.length; 4768 } 4769 }); 4770 } catch (error) { 4771 let code = (error as BusinessError).code; 4772 let message = (error as BusinessError).message; 4773 console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`); 4774 } 4775 ``` 4776 4777### getRawFd<sup>9+</sup> 4778 4779getRawFd(path: string): Promise<RawFileDescriptor> 4780 4781Obtains 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. 4782 4783**Atomic service API**: This API can be used in atomic services since API version 11. 4784 4785**System capability**: SystemCapability.Global.ResourceManager 4786 4787**Parameters** 4788 4789| Name | Type | Mandatory | Description | 4790| ---- | ------ | ---- | ----------- | 4791| path | string | Yes | Path of the raw file.| 4792 4793**Return value** 4794 4795| Type | Description | 4796| ---------------------------------------- | ------------------- | 4797| Promise<[RawFileDescriptor](#rawfiledescriptor9)> | Descriptor of the HAP where the raw file is located.| 4798 4799**Error codes** 4800 4801For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4802 4803| ID| Error Message| 4804| -------- | ---------------------------------------- | 4805| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4806| 9001005 | Invalid relative path. | 4807 4808**Example** 4809 ```ts 4810 import { BusinessError } from '@kit.BasicServicesKit'; 4811 import { resourceManager } from '@kit.LocalizationKit' 4812 4813 try { 4814 this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => { 4815 let fd = value.fd; 4816 let offset = value.offset; 4817 let length = value.length; 4818 }).catch((error: BusinessError) => { 4819 console.error(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); 4820 }); 4821 } catch (error) { 4822 let code = (error as BusinessError).code; 4823 let message = (error as BusinessError).message; 4824 console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`); 4825 } 4826 ``` 4827 4828### closeRawFdSync<sup>10+</sup> 4829 4830closeRawFdSync(path: string): void 4831 4832Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4833 4834**Atomic service API**: This API can be used in atomic services since API version 11. 4835 4836**System capability**: SystemCapability.Global.ResourceManager 4837 4838**Parameters** 4839 4840| Name | Type | Mandatory | Description | 4841| -------- | ------------------------- | ---- | ----------- | 4842| path | string | Yes | Path of the raw file.| 4843 4844**Error codes** 4845 4846For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4847 4848| ID| Error Message| 4849| -------- | ---------------------------------------- | 4850| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4851| 9001005 | The resource not found by path. | 4852 4853**Example** 4854 ```ts 4855 import { BusinessError } from '@kit.BasicServicesKit'; 4856 4857 try { 4858 this.context.resourceManager.closeRawFdSync("test.txt"); 4859 } catch (error) { 4860 let code = (error as BusinessError).code; 4861 let message = (error as BusinessError).message; 4862 console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`); 4863 } 4864 ``` 4865 4866### closeRawFd<sup>9+</sup> 4867 4868closeRawFd(path: string, callback: AsyncCallback<void>): void 4869 4870Closes 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. 4871 4872**Atomic service API**: This API can be used in atomic services since API version 11. 4873 4874**System capability**: SystemCapability.Global.ResourceManager 4875 4876**Parameters** 4877 4878| Name | Type | Mandatory | Description | 4879| -------- | ------------------------- | ---- | ----------- | 4880| path | string | Yes | Path of the raw file.| 4881| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 4882 4883**Error codes** 4884 4885For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4886 4887| ID| Error Message| 4888| -------- | ---------------------------------------- | 4889| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4890| 9001005 | The resource not found by path. | 4891 4892**Example** 4893 ```ts 4894 import { BusinessError } from '@kit.BasicServicesKit'; 4895 4896 try { 4897 this.context.resourceManager.closeRawFd("test.txt", (error: BusinessError) => { 4898 if (error != null) { 4899 console.error("error is " + error); 4900 } 4901 }); 4902 } catch (error) { 4903 let code = (error as BusinessError).code; 4904 let message = (error as BusinessError).message; 4905 console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`); 4906 } 4907 ``` 4908 4909### closeRawFd<sup>9+</sup> 4910 4911closeRawFd(path: string): Promise<void> 4912 4913Closes 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. 4914 4915**Atomic service API**: This API can be used in atomic services since API version 11. 4916 4917**System capability**: SystemCapability.Global.ResourceManager 4918 4919**Parameters** 4920 4921| Name | Type | Mandatory | Description | 4922| ---- | ------ | ---- | ----------- | 4923| path | string | Yes | Path of the raw file.| 4924 4925**Return value** 4926 4927| Type | Description | 4928| ------------------- | ---- | 4929| Promise<void> | Promise that returns no value.| 4930 4931**Error codes** 4932 4933For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4934 4935| ID| Error Message| 4936| -------- | ---------------------------------------- | 4937| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4938| 9001005 | Invalid relative path. | 4939 4940**Example** 4941 ```ts 4942 import { BusinessError } from '@kit.BasicServicesKit'; 4943 4944 try { 4945 this.context.resourceManager.closeRawFd("test.txt"); 4946 } catch (error) { 4947 let code = (error as BusinessError).code; 4948 let message = (error as BusinessError).message; 4949 console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`); 4950 } 4951 ``` 4952 4953### getConfigurationSync<sup>10+</sup> 4954 4955getConfigurationSync(): Configuration 4956 4957Obtains the device configuration. This API returns the result synchronously. 4958 4959**Atomic service API**: This API can be used in atomic services since API version 11. 4960 4961**System capability**: SystemCapability.Global.ResourceManager 4962 4963**Return value** 4964 4965| Type | Description | 4966| ---------------------------------------- | ---------------- | 4967| [Configuration](#configuration) | Device configuration.| 4968 4969**Example** 4970 ```ts 4971 try { 4972 let value = this.context.resourceManager.getConfigurationSync(); 4973 let direction = value.direction; 4974 let locale = value.locale; 4975 } catch (error) { 4976 console.error("getConfigurationSync error is " + error); 4977 } 4978 ``` 4979 4980### getConfiguration 4981 4982getConfiguration(callback: AsyncCallback<Configuration>): void 4983 4984Obtains the device configuration. This API uses an asynchronous callback to return the result. 4985 4986**Atomic service API**: This API can be used in atomic services since API version 11. 4987 4988**System capability**: SystemCapability.Global.ResourceManager 4989 4990**Parameters** 4991 4992| Name | Type | Mandatory | Description | 4993| -------- | ---------------------------------------- | ---- | ------------------------- | 4994| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result, which is the device configuration.| 4995 4996**Example** 4997 ```ts 4998 import { resourceManager } from '@kit.LocalizationKit' 4999 5000 try { 5001 this.context.resourceManager.getConfiguration((error: BusinessError, value: resourceManager.Configuration) => { 5002 if (error != null) { 5003 console.error("getConfiguration callback error is " + error); 5004 } else { 5005 let direction = value.direction; 5006 let locale = value.locale; 5007 } 5008 }); 5009 } catch (error) { 5010 console.error("getConfiguration callback error is " + error); 5011 } 5012 ``` 5013 5014### getConfiguration 5015 5016getConfiguration(): Promise<Configuration> 5017 5018Obtains the device configuration. This API uses a promise to return the result. 5019 5020**Atomic service API**: This API can be used in atomic services since API version 11. 5021 5022**System capability**: SystemCapability.Global.ResourceManager 5023 5024**Return value** 5025 5026| Type | Description | 5027| ---------------------------------------- | ---------------- | 5028| Promise<[Configuration](#configuration)> | Promise used to return the result, which is the device configuration.| 5029 5030**Example** 5031 ```ts 5032 import { BusinessError } from '@kit.BasicServicesKit'; 5033 import { resourceManager } from '@kit.LocalizationKit' 5034 5035 try { 5036 this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => { 5037 let direction = value.direction; 5038 let locale = value.locale; 5039 }).catch((error: BusinessError) => { 5040 console.error("getConfiguration promise error is " + error); 5041 }); 5042 } catch (error) { 5043 console.error("getConfiguration promise error is " + error); 5044 } 5045 ``` 5046 5047### getDeviceCapabilitySync<sup>10+</sup> 5048 5049getDeviceCapabilitySync(): DeviceCapability 5050 5051Obtains the device capability. This API returns the result synchronously. 5052 5053**Atomic service API**: This API can be used in atomic services since API version 11. 5054 5055**System capability**: SystemCapability.Global.ResourceManager 5056 5057**Return value** 5058 5059| Type | Description | 5060| ---------------------------------------- | ------------------- | 5061| [DeviceCapability](#devicecapability) | Device capability.| 5062 5063**Example** 5064 ```ts 5065 try { 5066 let value = this.context.resourceManager.getDeviceCapabilitySync(); 5067 let screenDensity = value.screenDensity; 5068 let deviceType = value.deviceType; 5069 } catch (error) { 5070 console.error("getDeviceCapabilitySync error is " + error); 5071 } 5072 ``` 5073 5074### getDeviceCapability 5075 5076getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void 5077 5078Obtains the device capability. This API uses an asynchronous callback to return the result. 5079 5080**Atomic service API**: This API can be used in atomic services since API version 11. 5081 5082**System capability**: SystemCapability.Global.ResourceManager 5083 5084**Parameters** 5085 5086| Name | Type | Mandatory | Description | 5087| -------- | ---------------------------------------- | ---- | ---------------------------- | 5088| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result, which is the device capability.| 5089 5090**Example** 5091 ```ts 5092 import { resourceManager } from '@kit.LocalizationKit' 5093 5094 try { 5095 this.context.resourceManager.getDeviceCapability((error: BusinessError, value: resourceManager.DeviceCapability) => { 5096 if (error != null) { 5097 console.error("getDeviceCapability callback error is " + error); 5098 } else { 5099 let screenDensity = value.screenDensity; 5100 let deviceType = value.deviceType; 5101 } 5102 }); 5103 } catch (error) { 5104 console.error("getDeviceCapability callback error is " + error); 5105 } 5106 ``` 5107 5108### getDeviceCapability 5109 5110getDeviceCapability(): Promise<DeviceCapability> 5111 5112Obtains the device capability. This API uses a promise to return the result. 5113 5114**Atomic service API**: This API can be used in atomic services since API version 11. 5115 5116**System capability**: SystemCapability.Global.ResourceManager 5117 5118**Return value** 5119 5120| Type | Description | 5121| ---------------------------------------- | ------------------- | 5122| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result, which is the device capability.| 5123 5124**Example** 5125 ```ts 5126 import { BusinessError } from '@kit.BasicServicesKit'; 5127 import { resourceManager } from '@kit.LocalizationKit' 5128 5129 try { 5130 this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => { 5131 let screenDensity = value.screenDensity; 5132 let deviceType = value.deviceType; 5133 }).catch((error: BusinessError) => { 5134 console.error("getDeviceCapability promise error is " + error); 5135 }); 5136 } catch (error) { 5137 console.error("getDeviceCapability promise error is " + error); 5138 } 5139 ``` 5140 5141### addResource<sup>10+</sup> 5142 5143addResource(path: string) : void 5144 5145Loads resources from the specified path. 5146 5147**Atomic service API**: This API can be used in atomic services since API version 11. 5148 5149**System capability**: SystemCapability.Global.ResourceManager 5150 5151**Parameters** 5152 5153| Name | Type | Mandatory | Description | 5154| -------- | ---------------------- | ---- | ---- | 5155| path | string | Yes | Resource path.| 5156 5157**Error codes** 5158 5159For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5160 5161| ID| Error Message| 5162| -------- | ---------------------------------------- | 5163| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5164| 9001010 | Invalid overlay path. | 5165 5166**Example** 5167 ```ts 5168 import { BusinessError } from '@kit.BasicServicesKit'; 5169 5170 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5171 try { 5172 this.context.resourceManager.addResource(path); 5173 } catch (error) { 5174 let code = (error as BusinessError).code; 5175 let message = (error as BusinessError).message; 5176 console.error(`addResource failed, error code: ${code}, message: ${message}.`); 5177 } 5178 ``` 5179 5180### removeResource<sup>10+</sup> 5181 5182removeResource(path: string) : void 5183 5184Removes the resources loaded from the specified path to restore the original resources. 5185 5186**Atomic service API**: This API can be used in atomic services since API version 11. 5187 5188**System capability**: SystemCapability.Global.ResourceManager 5189 5190**Parameters** 5191 5192| Name | Type | Mandatory | Description | 5193| -------- | ---------------------- | ---- | ---- | 5194| path | string | Yes | Resource path.| 5195 5196**Error codes** 5197 5198For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5199 5200| ID| Error Message| 5201| -------- | ---------------------------------------- | 5202| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5203| 9001010 | Invalid overlay path. | 5204 5205**Example** 5206 ```ts 5207 import { BusinessError } from '@kit.BasicServicesKit'; 5208 5209 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5210 try { 5211 this.context.resourceManager.removeResource(path); 5212 } catch (error) { 5213 let code = (error as BusinessError).code; 5214 let message = (error as BusinessError).message; 5215 console.error(`removeResource failed, error code: ${code}, message: ${message}.`); 5216 } 5217 ``` 5218 5219### getLocales<sup>11+</sup> 5220 5221getLocales(includeSystem?: boolean): Array\<string> 5222 5223Obtains the language list of an application. 5224 5225**Atomic service API**: This API can be used in atomic services since API version 11. 5226 5227**System capability**: SystemCapability.Global.ResourceManager 5228 5229**Parameters** 5230 5231| Name | Type | Mandatory | Description | 5232| -------------- | ------- | ------ | -------------------- | 5233| 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.| 5234 5235**Return value** 5236 5237| Type | Description | 5238| ------------------------- | ----------- | 5239| 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 (-).| 5240 5241**Example** 5242 ```ts 5243 import { resourceManager } from '@kit.LocalizationKit' 5244 import { BusinessError } from '@kit.BasicServicesKit'; 5245 5246 try { 5247 this.context.resourceManager.getLocales(); // Obtain only the language list of application resources. 5248 } catch (error) { 5249 let code = (error as BusinessError).code; 5250 let message = (error as BusinessError).message; 5251 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5252 } 5253 5254 try { 5255 resourceManager.getSystemResourceManager().getLocales(); // Obtain only the language list of system resources. 5256 } catch (error) { 5257 let code = (error as BusinessError).code; 5258 let message = (error as BusinessError).message; 5259 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5260 } 5261 5262 try { 5263 this.context.resourceManager.getLocales(true); // Obtain the language list of application resources and resources. 5264 } catch (error) { 5265 let code = (error as BusinessError).code; 5266 let message = (error as BusinessError).message; 5267 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5268 } 5269 ``` 5270 5271### getSymbol<sup>11+</sup> 5272 5273getSymbol(resId: number):number 5274 5275Obtains a symbol value based on the specified resource ID. This API returns the result synchronously. 5276 5277**Atomic service API**: This API can be used in atomic services since API version 11. 5278 5279**System capability**: SystemCapability.Global.ResourceManager 5280 5281**Parameters** 5282 5283| Name | Type | Mandatory | Description | 5284| ----- | ------ | ---- | ----- | 5285| resId | number | Yes | Resource ID.| 5286 5287**Return value** 5288 5289| Type | Description | 5290| ------ | ----------- | 5291| number | Symbol value (decimal) corresponding to the specified resource ID.| 5292 5293**Error codes** 5294 5295For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5296 5297| ID| Error Message| 5298| -------- | ---------------------------------------- | 5299| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5300| 9001001 | Invalid resource ID. | 5301| 9001002 | No matching resource is found based on the resource ID. | 5302| 9001006 | The resource is referenced cyclically. | 5303 5304**Example** 5305 ```ts 5306 import { BusinessError } from '@kit.BasicServicesKit'; 5307 5308 try { 5309 this.context.resourceManager.getSymbol($r('app.symbol.test').id); 5310 } catch (error) { 5311 let code = (error as BusinessError).code; 5312 let message = (error as BusinessError).message; 5313 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5314 } 5315 ``` 5316 5317### getSymbol<sup>11+</sup> 5318getSymbol(resource: Resource): number 5319 5320Obtains a symbol value based on the specified resource object. This API returns the result synchronously. 5321 5322**Atomic service API**: This API can be used in atomic services since API version 11. 5323 5324**System capability**: SystemCapability.Global.ResourceManager 5325 5326**Model restriction**: This API can be used only in the stage model. 5327 5328**Parameters** 5329 5330| Name | Type | Mandatory | Description | 5331| -------- | ---------------------- | ---- | ---- | 5332| resource | [Resource](#resource9) | Yes | Resource object.| 5333 5334**Return value** 5335 5336| Type | Description | 5337| ------ | ----------- | 5338| number | Symbol value (decimal) corresponding to the specified resource object.| 5339 5340**Error codes** 5341 5342For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5343 5344| ID| Error Message| 5345| -------- | ---------------------------------------- | 5346| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5347| 9001001 | Invalid resource ID. | 5348| 9001002 | No matching resource is found based on the resource ID. | 5349| 9001006 | The resource is referenced cyclically. | 5350 5351**Example** 5352 ```ts 5353 import { resourceManager } from '@kit.LocalizationKit' 5354 import { BusinessError } from '@kit.BasicServicesKit'; 5355 5356 let resource: resourceManager.Resource = { 5357 bundleName: "com.example.myapplication", 5358 moduleName: "entry", 5359 id: $r('app.symbol.test').id 5360 }; 5361 try { 5362 this.context.resourceManager.getSymbol(resource); 5363 } catch (error) { 5364 let code = (error as BusinessError).code; 5365 let message = (error as BusinessError).message; 5366 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5367 } 5368 ``` 5369 5370### getSymbolByName<sup>11+</sup> 5371 5372getSymbolByName(resName: string) : number; 5373 5374Obtains a symbol value based on the specified resource name. This API returns the result synchronously. 5375 5376**Atomic service API**: This API can be used in atomic services since API version 11. 5377 5378**System capability**: SystemCapability.Global.ResourceManager 5379 5380**Parameters** 5381 5382| Name | Type | Mandatory | Description | 5383| ------- | ------ | ---- | ---- | 5384| resName | string | Yes | Resource name.| 5385 5386**Return value** 5387 5388| Type | Description | 5389| ------ | ---------- | 5390| number | Symbol value (decimal) corresponding to the specified resource name.| 5391 5392**Error codes** 5393 5394For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5395 5396| ID| Error Message| 5397| -------- | ---------------------------------------- | 5398| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5399| 9001003 | Invalid resource name. | 5400| 9001004 | No matching resource is found based on the resource name. | 5401| 9001006 | The resource is referenced cyclically. | 5402 5403**Example** 5404 ```ts 5405 import { BusinessError } from '@kit.BasicServicesKit'; 5406 5407 try { 5408 this.context.resourceManager.getSymbolByName("test"); 5409 } catch (error) { 5410 let code = (error as BusinessError).code; 5411 let message = (error as BusinessError).message; 5412 console.error(`getSymbolByName failed, error code: ${code}, message: ${message}.`); 5413 } 5414 ``` 5415 5416### isRawDir<sup>12+</sup> 5417 5418isRawDir(path: string) : bool 5419 5420Checks whether a path is a subdirectory in the **rawfile** directory. This API returns the result synchronously. 5421 5422**Atomic service API**: This API can be used in atomic services since API version 12. 5423 5424**System capability**: SystemCapability.Global.ResourceManager 5425 5426**Parameters** 5427 5428| Name | Type | Mandatory | Description | 5429| ------- | ------ | ---- | ---- | 5430| path | string | Yes | Path of a rawfile.| 5431 5432**Return value** 5433 5434| Type | Description | 5435| ------ | ---------- | 5436| 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.| 5437 5438**Error codes** 5439 5440For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5441 5442| ID| Error Message| 5443| -------- | ---------------------------------------- | 5444| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5445| 9001005 | Invalid relative path. | 5446 5447**Example** 5448 ```ts 5449 import { BusinessError } from '@kit.BasicServicesKit'; 5450 5451 try { 5452 this.context.resourceManager.isRawDir("test.txt"); 5453 } catch (error) { 5454 let code = (error as BusinessError).code; 5455 let message = (error as BusinessError).message; 5456 console.error(`isRawDir failed, error code: ${code}, message: ${message}.`); 5457 } 5458 ``` 5459 5460### getOverrideResourceManager<sup>12+</sup> 5461 5462getOverrideResourceManager(configuration?: Configuration) : ResourceManager 5463 5464Obtains a **ResourceManager** object for loading differentiated resources. This API returns the result synchronously. 5465 5466The 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. 5467 5468**Atomic service API**: This API can be used in atomic services since API version 12. 5469 5470**System capability**: SystemCapability.Global.ResourceManager 5471 5472**Parameters** 5473 5474| Name | Type | Mandatory| Description | 5475| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5476| 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.| 5477 5478**Return value** 5479 5480| Type | Description | 5481| --------------- | ---------------------------------- | 5482| ResourceManager | **ResourceManager** object for loading differentiated resources.| 5483 5484**Error codes** 5485 5486For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5487 5488| ID| Error Message | 5489| -------- | ------------------------------------------------------------ | 5490| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5491 5492**Example** 5493 5494 ```ts 5495 import { BusinessError } from '@kit.BasicServicesKit'; 5496 import { resourceManager } from '@kit.LocalizationKit' 5497 5498 try { 5499 let resMgr = this.context.resourceManager 5500 let overrideConfig = resMgr.getOverrideConfiguration() 5501 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5502 let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) 5503 } catch (error) { 5504 let code = (error as BusinessError).code; 5505 let message = (error as BusinessError).message; 5506 console.error(`getOverrideResourceManager failed, error code: ${code}, message: ${message}.`); 5507 } 5508 ``` 5509 5510### getOverrideConfiguration<sup>12+</sup> 5511 5512getOverrideConfiguration() : Configuration 5513 5514Obtains 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. 5515 5516**Atomic service API**: This API can be used in atomic services since API version 12. 5517 5518**System capability**: SystemCapability.Global.ResourceManager 5519 5520**Return value** 5521 5522| Type | Description | 5523| ------------------------------- | ---------------- | 5524| [Configuration](#configuration) | Configuration of differentiated resources.| 5525 5526**Example** 5527 5528 ```ts 5529 import { BusinessError } from '@kit.BasicServicesKit'; 5530 import { resourceManager } from '@kit.LocalizationKit' 5531 5532 let overrideConfig = this.context.resourceManager.getOverrideConfiguration() 5533 ``` 5534 5535### updateOverrideConfiguration<sup>12+</sup> 5536 5537updateOverrideConfiguration(configuration: Configuration) : void 5538 5539Updated 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. 5540 5541**Atomic service API**: This API can be used in atomic services since API version 12. 5542 5543**System capability**: SystemCapability.Global.ResourceManager 5544 5545**Parameters** 5546 5547| Name | Type | Mandatory| Description | 5548| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5549| 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.| 5550 5551**Error codes** 5552 5553For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5554 5555| ID| Error Message | 5556| -------- | ------------------------------------------------------------ | 5557| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5558 5559**Example** 5560 5561 ```ts 5562 import { BusinessError } from '@kit.BasicServicesKit'; 5563 import { resourceManager } from '@kit.LocalizationKit' 5564 5565 try { 5566 let resMgr = this.context.resourceManager 5567 let overrideConfig = resMgr.getOverrideConfiguration() 5568 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5569 let overrideResMgr = resMgr.updateOverrideConfiguration(overrideConfig) 5570 } catch (error) { 5571 let code = (error as BusinessError).code; 5572 let message = (error as BusinessError).message; 5573 console.error(`updateOverrideConfiguration failed, error code: ${code}, message: ${message}.`); 5574 } 5575 ``` 5576 5577### release<sup>(deprecated)</sup> 5578 5579release() 5580 5581Releases a **ResourceManager** object. This API is not supported currently. 5582 5583This API is supported since API version 7 and is deprecated since API version 12. 5584 5585**Atomic service API**: This API can be used in atomic services since API version 11. 5586 5587**System capability**: SystemCapability.Global.ResourceManager 5588 5589**Example** 5590 ```ts 5591 try { 5592 this.context.resourceManager.release(); 5593 } catch (error) { 5594 console.error("release error is " + error); 5595 } 5596 ``` 5597 5598### getString<sup>(deprecated)</sup> 5599 5600getString(resId: number, callback: AsyncCallback<string>): void 5601 5602Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. 5603 5604This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9). 5605 5606**System capability**: SystemCapability.Global.ResourceManager 5607 5608**Parameters** 5609 5610| Name | Type | Mandatory | Description | 5611| -------- | --------------------------- | ---- | --------------- | 5612| resId | number | Yes | Resource ID. | 5613| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| 5614 5615**Example** 5616 ```ts 5617 resourceManager.getResourceManager((error, mgr) => { 5618 mgr.getString($r('app.string.test').id, (error: Error, value: string) => { 5619 if (error != null) { 5620 console.error("error is " + error); 5621 } else { 5622 let str = value; 5623 } 5624 }); 5625 }); 5626 ``` 5627 5628 5629### getString<sup>(deprecated)</sup> 5630 5631getString(resId: number): Promise<string> 5632 5633Obtains a string based on the specified resource ID. This API uses a promise to return the result. 5634 5635This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1). 5636 5637**System capability**: SystemCapability.Global.ResourceManager 5638 5639**Parameters** 5640 5641| Name | Type | Mandatory | Description | 5642| ----- | ------ | ---- | ----- | 5643| resId | number | Yes | Resource ID.| 5644 5645**Return value** 5646 5647| Type | Description | 5648| --------------------- | ----------- | 5649| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| 5650 5651**Example** 5652 ```ts 5653 import { BusinessError } from '@kit.BasicServicesKit'; 5654 5655 resourceManager.getResourceManager((error, mgr) => { 5656 mgr.getString($r('app.string.test').id).then((value: string) => { 5657 let str = value; 5658 }).catch((error: BusinessError) => { 5659 console.error("getstring promise error is " + error); 5660 }); 5661 }); 5662 ``` 5663 5664 5665### getStringArray<sup>(deprecated)</sup> 5666 5667getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void 5668 5669Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. 5670 5671This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9). 5672 5673**System capability**: SystemCapability.Global.ResourceManager 5674 5675**Parameters** 5676 5677| Name | Type | Mandatory | Description | 5678| -------- | ---------------------------------------- | ---- | ----------------- | 5679| resId | number | Yes | Resource ID. | 5680| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 5681 5682**Example** 5683 ```ts 5684 resourceManager.getResourceManager((error, mgr) => { 5685 mgr.getStringArray($r('app.strarray.test').id, (error: Error, value: Array<string>) => { 5686 if (error != null) { 5687 console.error("error is " + error); 5688 } else { 5689 let strArray = value; 5690 } 5691 }); 5692 }); 5693 ``` 5694 5695 5696### getStringArray<sup>(deprecated)</sup> 5697 5698getStringArray(resId: number): Promise<Array<string>> 5699 5700Obtains a string array based on the specified resource ID. This API uses a promise to return the result. 5701 5702This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1). 5703 5704**System capability**: SystemCapability.Global.ResourceManager 5705 5706**Parameters** 5707 5708| Name | Type | Mandatory | Description | 5709| ----- | ------ | ---- | ----- | 5710| resId | number | Yes | Resource ID.| 5711 5712**Return value** 5713 5714| Type | Description | 5715| ---------------------------------- | ------------- | 5716| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| 5717 5718**Example** 5719 ```ts 5720 import { BusinessError } from '@kit.BasicServicesKit'; 5721 5722 resourceManager.getResourceManager((error, mgr) => { 5723 mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => { 5724 let strArray = value; 5725 }).catch((error: BusinessError) => { 5726 console.error("getStringArray promise error is " + error); 5727 }); 5728 }); 5729 ``` 5730 5731 5732### getMedia<sup>(deprecated)</sup> 5733 5734getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void 5735 5736Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. 5737 5738This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9). 5739 5740**System capability**: SystemCapability.Global.ResourceManager 5741 5742**Parameters** 5743 5744| Name | Type | Mandatory | Description | 5745| -------- | ------------------------------- | ---- | ------------------ | 5746| resId | number | Yes | Resource ID. | 5747| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5748 5749**Example** 5750 ```ts 5751 resourceManager.getResourceManager((error, mgr) => { 5752 mgr.getMedia($r('app.media.test').id, (error: Error, value: Uint8Array) => { 5753 if (error != null) { 5754 console.error("error is " + error); 5755 } else { 5756 let media = value; 5757 } 5758 }); 5759 }); 5760 ``` 5761 5762### getMedia<sup>(deprecated)</sup> 5763 5764getMedia(resId: number): Promise<Uint8Array> 5765 5766Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. 5767 5768This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1). 5769 5770**System capability**: SystemCapability.Global.ResourceManager 5771 5772**Parameters** 5773 5774| Name | Type | Mandatory | Description | 5775| ----- | ------ | ---- | ----- | 5776| resId | number | Yes | Resource ID.| 5777 5778**Return value** 5779 5780| Type | Description | 5781| ------------------------- | -------------- | 5782| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5783 5784**Example** 5785 ```ts 5786 import { BusinessError } from '@kit.BasicServicesKit'; 5787 5788 resourceManager.getResourceManager((error, mgr) => { 5789 mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => { 5790 let media = value; 5791 }).catch((error: BusinessError) => { 5792 console.error("getMedia promise error is " + error); 5793 }); 5794 }); 5795 ``` 5796 5797 5798### getMediaBase64<sup>(deprecated)</sup> 5799 5800getMediaBase64(resId: number, callback: AsyncCallback<string>): void 5801 5802Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. 5803 5804This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649). 5805 5806**System capability**: SystemCapability.Global.ResourceManager 5807 5808**Parameters** 5809 5810| Name | Type | Mandatory | Description | 5811| -------- | --------------------------- | ---- | ------------------------ | 5812| resId | number | Yes | Resource ID. | 5813| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5814 5815**Example** 5816 ```ts 5817 resourceManager.getResourceManager((error, mgr) => { 5818 mgr.getMediaBase64($r('app.media.test').id, ((error: Error, value: string) => { 5819 if (error != null) { 5820 console.error("error is " + error); 5821 } else { 5822 let media = value; 5823 } 5824 }); 5825 }); 5826 ``` 5827 5828 5829### getMediaBase64<sup>(deprecated)</sup> 5830 5831getMediaBase64(resId: number): Promise<string> 5832 5833Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. 5834 5835This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1). 5836 5837**System capability**: SystemCapability.Global.ResourceManager 5838 5839**Parameters** 5840 5841| Name | Type | Mandatory | Description | 5842| ----- | ------ | ---- | ----- | 5843| resId | number | Yes | Resource ID.| 5844 5845**Return value** 5846 5847| Type | Description | 5848| --------------------- | -------------------- | 5849| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5850 5851**Example** 5852 ```ts 5853 import { BusinessError } from '@kit.BasicServicesKit'; 5854 5855 resourceManager.getResourceManager((error, mgr) => { 5856 mgr.getMediaBase64($r('app.media.test').id).then((value: string) => { 5857 let media = value; 5858 }).catch((error: BusinessError) => { 5859 console.error("getMediaBase64 promise error is " + error); 5860 }); 5861 }); 5862 ``` 5863 5864 5865### getPluralString<sup>(deprecated)</sup> 5866 5867getPluralString(resId: number, num: number): Promise<string> 5868 5869Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses a promise to return the result. 5870 5871>**NOTE** 5872> 5873> Singular and plural forms are available for English, but not Chinese. 5874 5875This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9). 5876 5877**System capability**: SystemCapability.Global.ResourceManager 5878 5879**Parameters** 5880 5881| Name | Type | Mandatory | Description | 5882| ----- | ------ | ---- | ----- | 5883| resId | number | Yes | Resource ID.| 5884| num | number | Yes | Number. | 5885 5886**Return value** 5887 5888| Type | Description | 5889| --------------------- | ------------------------- | 5890| Promise<string> | Promise used to return the result, which is the singular/plural string corresponding to the specified resource ID.| 5891 5892**Example** 5893 ```ts 5894 import { BusinessError } from '@kit.BasicServicesKit'; 5895 5896 resourceManager.getResourceManager((error, mgr) => { 5897 mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => { 5898 let str = value; 5899 }).catch((error: BusinessError) => { 5900 console.error("getPluralString promise error is " + error); 5901 }); 5902 }); 5903 ``` 5904 5905 5906### getPluralString<sup>(deprecated)</sup> 5907 5908getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void 5909 5910Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses an asynchronous callback to return the result. 5911 5912>**NOTE** 5913> 5914> Singular and plural forms are available for English, but not Chinese. 5915 5916This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1). 5917 5918**System capability**: SystemCapability.Global.ResourceManager 5919 5920**Parameters** 5921 5922| Name | Type | Mandatory | Description | 5923| -------- | --------------------------- | ---- | ------------------------------- | 5924| resId | number | Yes | Resource ID. | 5925| num | number | Yes | Number. | 5926| callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular/plural string corresponding to the specified resource ID.| 5927 5928**Example** 5929 ```ts 5930 resourceManager.getResourceManager((error, mgr) => { 5931 mgr.getPluralString($r("app.plural.test").id, 1, (error: Error, value: string) => { 5932 if (error != null) { 5933 console.error("error is " + error); 5934 } else { 5935 let str = value; 5936 } 5937 }); 5938 }); 5939 ``` 5940 5941 5942### getRawFile<sup>(deprecated)</sup> 5943 5944getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void 5945 5946Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 5947 5948This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9). 5949 5950**System capability**: SystemCapability.Global.ResourceManager 5951 5952**Parameters** 5953 5954| Name | Type | Mandatory | Description | 5955| -------- | ------------------------------- | ---- | ----------------------- | 5956| path | string | Yes | Path of the raw file. | 5957| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 5958 5959**Example** 5960 ```ts 5961 resourceManager.getResourceManager((error, mgr) => { 5962 mgr.getRawFile("test.txt", (error: Error, value: Uint8Array) => { 5963 if (error != null) { 5964 console.error("error is " + error); 5965 } else { 5966 let rawFile = value; 5967 } 5968 }); 5969 }); 5970 ``` 5971 5972 5973### getRawFile<sup>(deprecated)</sup> 5974 5975getRawFile(path: string): Promise<Uint8Array> 5976 5977Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 5978 5979This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1). 5980 5981**System capability**: SystemCapability.Global.ResourceManager 5982 5983**Parameters** 5984 5985| Name | Type | Mandatory | Description | 5986| ---- | ------ | ---- | ----------- | 5987| path | string | Yes | Path of the raw file.| 5988 5989**Return value** 5990 5991| Type | Description | 5992| ------------------------- | ----------- | 5993| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 5994 5995**Example** 5996 ```ts 5997 import { BusinessError } from '@kit.BasicServicesKit'; 5998 5999 resourceManager.getResourceManager((error, mgr) => { 6000 mgr.getRawFile("test.txt").then((value: Uint8Array) => { 6001 let rawFile = value; 6002 }).catch((error: BusinessError) => { 6003 console.error("getRawFile promise error is " + error); 6004 }); 6005 }); 6006 ``` 6007 6008 6009### getRawFileDescriptor<sup>(deprecated)</sup> 6010 6011getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void 6012 6013Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6014 6015This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9). 6016 6017**System capability**: SystemCapability.Global.ResourceManager 6018 6019**Parameters** 6020 6021| Name | Type | Mandatory | Description | 6022| -------- | ---------------------------------------- | ---- | -------------------------------- | 6023| path | string | Yes | Path of the raw file. | 6024| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor9)> | Yes | Callback used to return the result, which is the descriptor of the raw file.| 6025 6026**Example** 6027 ```ts 6028 import { resourceManager } from '@kit.LocalizationKit' 6029 6030 resourceManager.getResourceManager((error, mgr) => { 6031 mgr.getRawFileDescriptor("test.txt", (error: Error, value: resourceManager.RawFileDescriptor) => { 6032 if (error != null) { 6033 console.error("error is " + error); 6034 } else { 6035 let fd = value.fd; 6036 let offset = value.offset; 6037 let length = value.length; 6038 } 6039 }); 6040 }); 6041 ``` 6042 6043### getRawFileDescriptor<sup>(deprecated)</sup> 6044 6045getRawFileDescriptor(path: string): Promise<RawFileDescriptor> 6046 6047Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6048 6049This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1). 6050 6051**System capability**: SystemCapability.Global.ResourceManager 6052 6053**Parameters** 6054 6055| Name | Type | Mandatory | Description | 6056| ---- | ------ | ---- | ----------- | 6057| path | string | Yes | Path of the raw file.| 6058 6059**Return value** 6060 6061| Type | Description | 6062| ---------------------------------------- | ------------------- | 6063| Promise<[RawFileDescriptor](#rawfiledescriptor9)> | Promise used to return the result, which is the descriptor of the raw file.| 6064 6065**Example** 6066 ```ts 6067 import { BusinessError } from '@kit.BasicServicesKit'; 6068 6069 resourceManager.getResourceManager((error, mgr) => { 6070 mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => { 6071 let fd = value.fd; 6072 let offset = value.offset; 6073 let length = value.length; 6074 }).catch((error: BusinessError) => { 6075 console.error("getRawFileDescriptor promise error is " + error); 6076 }); 6077 }); 6078 ``` 6079 6080### closeRawFileDescriptor<sup>(deprecated)</sup> 6081 6082closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void 6083 6084Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6085 6086This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9). 6087 6088**System capability**: SystemCapability.Global.ResourceManager 6089 6090**Parameters** 6091 6092 6093 6094| Name | Type | Mandatory | Description | 6095| -------- | ------------------------- | ---- | ----------- | 6096| path | string | Yes | Path of the raw file.| 6097| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 6098 6099**Example** 6100 ```ts 6101 resourceManager.getResourceManager((error, mgr) => { 6102 mgr.closeRawFileDescriptor("test.txt", (error: Error) => { 6103 if (error != null) { 6104 console.error("error is " + error); 6105 } 6106 }); 6107 }); 6108 ``` 6109 6110### closeRawFileDescriptor<sup>(deprecated)</sup> 6111 6112closeRawFileDescriptor(path: string): Promise<void> 6113 6114Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6115 6116This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9-1). 6117 6118**System capability**: SystemCapability.Global.ResourceManager 6119 6120**Parameters** 6121 6122| Name | Type | Mandatory | Description | 6123| ---- | ------ | ---- | ----------- | 6124| path | string | Yes | Path of the raw file.| 6125 6126**Return value** 6127 6128| Type | Description | 6129| ------------------- | ---- | 6130| Promise<void> | Promise that returns no value.| 6131 6132**Example** 6133 ```ts 6134 resourceManager.getResourceManager((error, mgr) => { 6135 mgr.closeRawFileDescriptor("test.txt"); 6136 }); 6137 ``` 6138 6139### Appendix 6140 6141- Content of the **app.string.test** file: 6142 6143 ```json 6144 { 6145 "string": [ 6146 { 6147 "name": "test", 6148 "value": "10" 6149 } 6150 ] 6151 } 6152 ``` 6153 6154 ```json 6155 { 6156 "string": [ 6157 { 6158 "name": "test", 6159 "value": "%s %d %f" 6160 } 6161 ] 6162 } 6163 ``` 6164 6165- Content of the **app.strarray.test** file: 6166 6167 ```json 6168 { 6169 "strarray": [ 6170 { 6171 "name": "test", 6172 "value": [ 6173 { 6174 "value": "strarray_test" 6175 } 6176 ] 6177 } 6178 ] 6179 } 6180 ``` 6181 6182- Content of the **app.plural.test** file: 6183 ```json 6184 { 6185 "plural": [ 6186 { 6187 "name": "test", 6188 "value": [ 6189 { 6190 "quantity": "one", 6191 "value": "%d apple" 6192 }, 6193 { 6194 "quantity": "other", 6195 "value": "%d apples" 6196 } 6197 ] 6198 } 6199 ] 6200 } 6201 ``` 6202 6203- Content of the **app.boolean.boolean_test** file: 6204 ```json 6205 { 6206 "boolean": [ 6207 { 6208 "name": "boolean_test", 6209 "value": true 6210 } 6211 6212 } 6213 ``` 6214 6215- Content of the **integer_test** and **float_test** files: 6216 ```json 6217 { 6218 "integer": [ 6219 { 6220 "name": "integer_test", 6221 "value": 100 6222 } 6223 ] 6224 } 6225 ``` 6226 6227 ```json 6228 { 6229 "float": [ 6230 { 6231 "name": "float_test", 6232 "value": "30.6" 6233 } 6234 ] 6235 } 6236 ``` 6237- Content of the **app.color.test** file: 6238 ```json 6239 { 6240 "color": [ 6241 { 6242 "name": "test", 6243 "value": "#FFFFFF" 6244 } 6245 ] 6246 } 6247 ``` 6248