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](#asynccallbackdeprecated)<[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](#asynccallbackdeprecated)<[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 device | 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 modes.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 275| locale | string | Yes | Yes | Language locale.<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 (MCC).<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](../apis-basic-services-kit/js-apis-base.md#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](../apis-basic-services-kit/js-apis-base.md#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](../apis-basic-services-kit/js-apis-base.md#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](../apis-basic-services-kit/js-apis-base.md#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](../apis-basic-services-kit/js-apis-base.md#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](../apis-basic-services-kit/js-apis-base.md#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### getIntPluralStringValueSync<sup>18+</sup> 1390 1391getIntPluralStringValueSync(resId: number, num: number, ...args: Array<string | number>): string; 1392 1393Obtains singular/plural strings based on the specified resource ID. 1394 1395> **NOTE** 1396> 1397> Singular/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 18. 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 | Integer number used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1409| ...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.| 1410 1411**Return value** 1412 1413| Type | Description | 1414| ------ | ---------------------- | 1415| string | Singular or plural string corresponding to the specified resource ID.| 1416 1417**Error codes** 1418 1419For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1420 1421| ID| Error Message | 1422| -------- | ------------------------------------------------------------ | 1423| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1424| 9001001 | Invalid resource ID. | 1425| 9001002 | No matching resource is found based on the resource ID. | 1426| 9001006 | The resource is referenced cyclically. | 1427| 9001007 | Failed to format the resource obtained based on the resource ID. | 1428 1429**Example** 1430 1431 ```ts 1432import { BusinessError } from '@kit.BasicServicesKit'; 1433 1434try { 1435 // If the value of num is 1, the value of quantity is one according to the language plural rules. Therefore, the string whose quantity is one is obtained from the $r ('app.plural.format_test') resource. 1436 this.context.resourceManager.getIntPluralStringValueSync($r('app.plural.format_test').id, 1, 1, "aaa", 1.1); 1437} catch (error) { 1438 let code = (error as BusinessError).code; 1439 let message = (error as BusinessError).message; 1440 console.error(`getIntPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1441} 1442 ``` 1443 1444### getIntPluralStringValueSync<sup>18+</sup> 1445 1446getIntPluralStringValueSync(resource: Resource, num: number, ...args: Array<string | number>): string; 1447 1448Obtains singular/plural strings based on the specified resource object. 1449 1450> **NOTE** 1451> 1452> Singular/plural forms are available for English, but not Chinese. 1453 1454**Atomic service API**: This API can be used in atomic services since API version 18. 1455 1456**System capability**: SystemCapability.Global.ResourceManager 1457 1458**Model restriction**: This API can be used only in the stage model. 1459 1460**Parameters** 1461 1462| Name | Type | Mandatory| Description | 1463| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 1464| resource | [Resource](#resource9) | Yes | Resource object. | 1465| num | number | Yes | Integer number used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1466| ...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.| 1467 1468**Return value** 1469 1470| Type | Description | 1471| ------ | ------------------------------------ | 1472| string | Singular/plural string represented by the resource object.| 1473 1474**Error codes** 1475 1476For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1477 1478| ID| Error Message | 1479| -------- | ------------------------------------------------------------ | 1480| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1481| 9001001 | Invalid resource ID. | 1482| 9001002 | No matching resource is found based on the resource ID. | 1483| 9001006 | The resource is referenced cyclically. | 1484| 9001007 | Failed to format the resource obtained based on the resource ID. | 1485 1486**Example** 1487 1488 ```ts 1489import { resourceManager } from '@kit.LocalizationKit' 1490import { BusinessError } from '@kit.BasicServicesKit'; 1491 1492let resource: resourceManager.Resource = { 1493 bundleName: "com.example.myapplication", 1494 moduleName: "entry", 1495 id: $r('app.plural.format_test').id 1496}; 1497try { 1498 // If the value of num is 1, the value of quantity is one according to the language plural rules. Therefore, the string whose quantity is one is obtained from the $r ('app.plural.format_test') resource. 1499 this.context.resourceManager.getIntPluralStringValueSync(resource, 1, 1, "aaa", 1.1); 1500} catch (error) { 1501 let code = (error as BusinessError).code; 1502 let message = (error as BusinessError).message; 1503 console.error(`getIntPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1504} 1505 ``` 1506 1507### getIntPluralStringByNameSync<sup>18+</sup> 1508 1509getIntPluralStringByNameSync(resName: string, num: number, ...args: Array<string | number>): string; 1510 1511Obtains singular/plural strings based on the specified resource name. 1512 1513> **NOTE** 1514> 1515> Singular/plural forms are available for English, but not Chinese. 1516 1517**Atomic service API**: This API can be used in atomic services since API version 18. 1518 1519**System capability**: SystemCapability.Global.ResourceManager 1520 1521**Parameters** 1522 1523| Name | Type | Mandatory| Description | 1524| ------- | ----------------------- | ---- | ------------------------------------------------------------ | 1525| resName | string | Yes | Resource name. | 1526| num | number | Yes | Integer number used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1527| ...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.| 1528 1529**Return value** 1530 1531| Type | Description | 1532| ------ | ------------------------------------ | 1533| string | Singular/plural string represented by the resource name.| 1534 1535**Error codes** 1536 1537For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1538 1539| ID| Error Message | 1540| -------- | ------------------------------------------------------------ | 1541| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1542| 9001003 | Invalid resource name. | 1543| 9001004 | No matching resource is found based on the resource name. | 1544| 9001006 | The resource is referenced cyclically. | 1545| 9001008 | Failed to format the resource obtained based on the resource name. | 1546 1547**Example** 1548 1549 ```ts 1550import { BusinessError } from '@kit.BasicServicesKit'; 1551 1552try { 1553 // If the value of num is 1, the value of quantity is one according to the language plural rules. Therefore, the string whose quantity is one is obtained from the $r ('app.plural.format_test') resource. 1554 this.context.resourceManager.getIntPluralStringByNameSync("format_test", 1, 1, "aaa", 1.1); 1555} catch (error) { 1556 let code = (error as BusinessError).code; 1557 let message = (error as BusinessError).message; 1558 console.error(`getIntPluralStringByNameSync failed, error code: ${code}, message: ${message}.`); 1559} 1560 ``` 1561 1562### getDoublePluralStringValueSync<sup>18+</sup> 1563 1564getDoublePluralStringValueSync(resId: number, num: number, ...args: Array<string | number>): string; 1565 1566Obtains singular/plural strings based on the specified resource ID. 1567 1568> **NOTE** 1569> 1570> Singular/plural forms are available for English, but not Chinese. 1571 1572**Atomic service API**: This API can be used in atomic services since API version 18. 1573 1574**System capability**: SystemCapability.Global.ResourceManager 1575 1576**Parameters** 1577 1578| Name | Type | Mandatory| Description | 1579| ------- | ----------------------- | ---- | ------------------------------------------------------------ | 1580| resId | number | Yes | Resource ID. | 1581| num | number | Yes | Quantity value (a floating point number), which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1582| ...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.| 1583 1584**Return value** 1585 1586| Type | Description | 1587| ------ | -------------------------------- | 1588| string | Singular/plural string represented by the resource ID.| 1589 1590**Error codes** 1591 1592For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1593 1594| ID| Error Message | 1595| -------- | ------------------------------------------------------------ | 1596| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1597| 9001001 | Invalid resource ID. | 1598| 9001002 | No matching resource is found based on the resource ID. | 1599| 9001006 | The resource is referenced cyclically. | 1600| 9001007 | Failed to format the resource obtained based on the resource ID. | 1601 1602**Example** 1603 1604 ```ts 1605import { BusinessError } from '@kit.BasicServicesKit'; 1606 1607try { 1608 // If the value of num is 2.1, the value of quantity is other according to the language plural rules. Therefore, the string whose quantity is other is obtained from the $r('app.plural.format_test') resource. 1609 this.context.resourceManager.getDoublePluralStringValueSync($r('app.plural.format_test').id, 2.1, 2, "aaa", 1.1); 1610} catch (error) { 1611 let code = (error as BusinessError).code; 1612 let message = (error as BusinessError).message; 1613 console.error(`getDoublePluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1614} 1615 ``` 1616 1617### getDoublePluralStringValueSync<sup>18+</sup> 1618 1619getDoublePluralStringValueSync(resource: Resource, num: number, ...args: Array<string | number>): string; 1620 1621Obtains singular/plural strings based on the specified resource object. 1622 1623> **NOTE** 1624> 1625> Singular/plural forms are available for English, but not Chinese. 1626 1627**Atomic service API**: This API can be used in atomic services since API version 18. 1628 1629**System capability**: SystemCapability.Global.ResourceManager 1630 1631**Model restriction**: This API can be used only in the stage model. 1632 1633**Parameters** 1634 1635| Name | Type | Mandatory| Description | 1636| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 1637| resource | [Resource](#resource9) | Yes | Resource object. | 1638| num | number | Yes | Quantity value (a floating point number), which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1639| ...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.| 1640 1641**Return value** 1642 1643| Type | Description | 1644| ------ | ---------------------------------------- | 1645| string | Singular/plural string represented by the resource object.| 1646 1647**Error codes** 1648 1649For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1650 1651| ID| Error Message | 1652| -------- | ------------------------------------------------------------ | 1653| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1654| 9001001 | Invalid resource ID. | 1655| 9001002 | No matching resource is found based on the resource ID. | 1656| 9001006 | The resource is referenced cyclically. | 1657| 9001007 | Failed to format the resource obtained based on the resource ID. | 1658 1659**Example** 1660 1661 ```ts 1662import { resourceManager } from '@kit.LocalizationKit' 1663import { BusinessError } from '@kit.BasicServicesKit'; 1664 1665let resource: resourceManager.Resource = { 1666 bundleName: "com.example.myapplication", 1667 moduleName: "entry", 1668 id: $r('app.plural.format_test').id 1669}; 1670try { 1671 // If the value of num is 2.1, the value of quantity is other according to the language plural rules. Therefore, the string whose quantity is other is obtained from the $r('app.plural.format_test') resource. 1672 this.context.resourceManager.getDoublePluralStringValueSync(resource, 2.1, 2, "aaa", 1.1); 1673} catch (error) { 1674 let code = (error as BusinessError).code; 1675 let message = (error as BusinessError).message; 1676 console.error(`getDoublePluralStringValueSync failed, error code: ${code}, message: ${message}.`); 1677} 1678 ``` 1679 1680### getDoublePluralStringByNameSync<sup>18+</sup> 1681 1682getDoublePluralStringByNameSync(resName: string, num: number, ...args: Array<string | number>): string; 1683 1684Obtains singular/plural strings based on the specified resource name. 1685 1686> **NOTE** 1687> 1688> Singular/plural forms are available for English, but not Chinese. 1689 1690**Atomic service API**: This API can be used in atomic services since API version 18. 1691 1692**System capability**: SystemCapability.Global.ResourceManager 1693 1694**Parameters** 1695 1696| Name | Type | Mandatory| Description | 1697| ------- | ----------------------- | ---- | ------------------------------------------------------------ | 1698| resName | string | Yes | Resource name. | 1699| num | number | Yes | Quantity value (a floating point number), which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 1700| ...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.| 1701 1702**Return value** 1703 1704| Type | Description | 1705| ------ | -------------------------------- | 1706| string | Singular/plural string represented by the resource name.| 1707 1708**Error codes** 1709 1710For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1711 1712| ID| Error Message | 1713| -------- | ------------------------------------------------------------ | 1714| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1715| 9001003 | Invalid resource name. | 1716| 9001004 | No matching resource is found based on the resource name. | 1717| 9001006 | The resource is referenced cyclically. | 1718| 9001008 | Failed to format the resource obtained based on the resource name. | 1719 1720**Example** 1721 1722 ```ts 1723import { BusinessError } from '@kit.BasicServicesKit'; 1724 1725try { 1726 // If the value of num is 2.1, the value of quantity is other according to the language plural rules. Therefore, the string whose quantity is other is obtained from the $r('app.plural.format_test') resource. 1727 this.context.resourceManager.getDoublePluralStringByNameSync("format_test", 2.1, 2, "aaa", 1.1); 1728} catch (error) { 1729 let code = (error as BusinessError).code; 1730 let message = (error as BusinessError).message; 1731 console.error(`getDoublePluralStringByNameSync failed, error code: ${code}, message: ${message}.`); 1732} 1733 ``` 1734 1735### getMediaContentSync<sup>10+</sup> 1736 1737getMediaContentSync(resId: number, density?: number): Uint8Array 1738 1739Obtains 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. 1740 1741**Atomic service API**: This API can be used in atomic services since API version 11. 1742 1743**System capability**: SystemCapability.Global.ResourceManager 1744 1745**Parameters** 1746 1747| Name | Type | Mandatory | Description | 1748| ----- | ------ | ---- | ----- | 1749| resId | number | Yes | Resource ID.| 1750| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 1751 1752**Return value** 1753 1754| Type | Description | 1755| -------- | ----------- | 1756| Uint8Array | Content of the media file corresponding to the specified resource ID.| 1757 1758**Error codes** 1759 1760For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1761 1762| ID| Error Message| 1763| -------- | ---------------------------------------- | 1764| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1765| 9001001 | Invalid resource ID. | 1766| 9001002 | No matching resource is found based on the resource ID. | 1767 1768**Example** 1769 ```ts 1770 import { BusinessError } from '@kit.BasicServicesKit'; 1771 1772 try { 1773 this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density 1774 } catch (error) { 1775 let code = (error as BusinessError).code; 1776 let message = (error as BusinessError).message; 1777 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1778 } 1779 1780 try { 1781 this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density 1782 } catch (error) { 1783 let code = (error as BusinessError).code; 1784 let message = (error as BusinessError).message; 1785 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1786 } 1787 ``` 1788 1789### getMediaContentSync<sup>10+</sup> 1790 1791getMediaContentSync(resource: Resource, density?: number): Uint8Array 1792 1793Obtains 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. 1794 1795**Atomic service API**: This API can be used in atomic services since API version 11. 1796 1797**System capability**: SystemCapability.Global.ResourceManager 1798 1799**Model restriction**: This API can be used only in the stage model. 1800 1801**Parameters** 1802 1803| Name | Type | Mandatory | Description | 1804| ----- | ------ | ---- | ----- | 1805| resource | [Resource](#resource9) | Yes | Resource object.| 1806| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 1807 1808**Return value** 1809 1810| Type | Description | 1811| --------------------- | ----------- | 1812| Uint8Array | Content of the media file corresponding to the specified resource object.| 1813 1814**Error codes** 1815 1816For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1817 1818| ID| Error Message| 1819| -------- | ---------------------------------------- | 1820| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1821| 9001001 | Invalid resource ID. | 1822| 9001002 | No matching resource is found based on the resource ID. | 1823 1824**Example** 1825 ```ts 1826 import { resourceManager } from '@kit.LocalizationKit' 1827 import { BusinessError } from '@kit.BasicServicesKit'; 1828 1829 let resource: resourceManager.Resource = { 1830 bundleName: "com.example.myapplication", 1831 moduleName: "entry", 1832 id: $r('app.media.test').id 1833 }; 1834 try { 1835 this.context.resourceManager.getMediaContentSync(resource); // Default screen density 1836 } catch (error) { 1837 let code = (error as BusinessError).code; 1838 let message = (error as BusinessError).message; 1839 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1840 } 1841 1842 try { 1843 this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density 1844 } catch (error) { 1845 let code = (error as BusinessError).code; 1846 let message = (error as BusinessError).message; 1847 console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); 1848 } 1849 ``` 1850 1851### getMediaByNameSync<sup>10+</sup> 1852 1853getMediaByNameSync(resName: string, density?: number): Uint8Array 1854 1855Obtains 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. 1856 1857**Atomic service API**: This API can be used in atomic services since API version 11. 1858 1859**System capability**: SystemCapability.Global.ResourceManager 1860 1861**Parameters** 1862 1863| Name | Type | Mandatory | Description | 1864| ----- | ------ | ---- | ----- | 1865| resName | string | Yes | Resource name.| 1866| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 1867 1868**Return value** 1869 1870| Type | Description | 1871| --------------------- | ----------- | 1872| Uint8Array | Content of the media file corresponding to the specified resource name.| 1873 1874**Error codes** 1875 1876For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 1877 1878| ID| Error Message| 1879| -------- | ---------------------------------------- | 1880| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1881| 9001003 | Invalid resource name. | 1882| 9001004 | No matching resource is found based on the resource name. | 1883 1884**Example** 1885 ```ts 1886 import { BusinessError } from '@kit.BasicServicesKit'; 1887 1888 try { 1889 this.context.resourceManager.getMediaByNameSync("test"); // Default screen density 1890 } catch (error) { 1891 let code = (error as BusinessError).code; 1892 let message = (error as BusinessError).message; 1893 console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); 1894 } 1895 1896 try { 1897 this.context.resourceManager.getMediaByNameSync("test", 120); // Specified screen density 1898 } catch (error) { 1899 let code = (error as BusinessError).code; 1900 let message = (error as BusinessError).message; 1901 console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); 1902 } 1903 ``` 1904 1905### getMediaContent<sup>9+</sup> 1906 1907getMediaContent(resId: number, callback: _AsyncCallback<Uint8Array>): void 1908 1909Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. 1910 1911**Atomic service API**: This API can be used in atomic services since API version 11. 1912 1913**System capability**: SystemCapability.Global.ResourceManager 1914 1915**Parameters** 1916 1917| Name | Type | Mandatory | Description | 1918| -------- | ------------------------------- | ---- | ------------------ | 1919| resId | number | Yes | Resource ID. | 1920| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 1921 1922**Error codes** 1923 1924For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1925 1926| ID| Error Message| 1927| -------- | ---------------------------------------- | 1928| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 1929| 9001001 | Invalid resource ID. | 1930| 9001002 | No matching resource is found based on the resource ID. | 1931 1932**Example** 1933 ```ts 1934 import { BusinessError } from '@kit.BasicServicesKit'; 1935 1936 try { 1937 this.context.resourceManager.getMediaContent($r('app.media.test').id, (error: BusinessError, value: Uint8Array) => { 1938 if (error != null) { 1939 console.error("error is " + error); 1940 } else { 1941 let media = value; 1942 } 1943 }); 1944 } catch (error) { 1945 let code = (error as BusinessError).code; 1946 let message = (error as BusinessError).message; 1947 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 1948 } 1949 ``` 1950 1951### getMediaContent<sup>10+</sup> 1952 1953getMediaContent(resId: number, density: number, callback: _AsyncCallback<Uint8Array>): void 1954 1955Obtains 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. 1956 1957**Atomic service API**: This API can be used in atomic services since API version 11. 1958 1959**System capability**: SystemCapability.Global.ResourceManager 1960 1961**Parameters** 1962 1963| Name | Type | Mandatory | Description | 1964| -------- | ------------------------------- | ---- | ------------------ | 1965| resId | number | Yes | Resource ID. | 1966| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 1967| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 1968 1969**Error codes** 1970 1971For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 1972 1973| ID| Error Message| 1974| -------- | ---------------------------------------- | 1975| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 1976| 9001001 | Invalid resource ID. | 1977| 9001002 | No matching resource is found based on the resource ID. | 1978 1979**Example** 1980 ```ts 1981 import { BusinessError } from '@kit.BasicServicesKit'; 1982 1983 try { 1984 this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error: BusinessError, value: Uint8Array) => { 1985 if (error != null) { 1986 console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 1987 } else { 1988 let media = value; 1989 } 1990 }); 1991 } catch (error) { 1992 let code = (error as BusinessError).code; 1993 let message = (error as BusinessError).message; 1994 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 1995 } 1996 ``` 1997 1998### getMediaContent<sup>9+</sup> 1999 2000getMediaContent(resId: number): Promise<Uint8Array> 2001 2002Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. 2003 2004**Atomic service API**: This API can be used in atomic services since API version 11. 2005 2006**System capability**: SystemCapability.Global.ResourceManager 2007 2008**Parameters** 2009 2010| Name | Type | Mandatory | Description | 2011| ----- | ------ | ---- | ----- | 2012| resId | number | Yes | Resource ID.| 2013 2014**Return value** 2015 2016| Type | Description | 2017| ------------------------- | -------------- | 2018| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2019 2020**Error codes** 2021 2022For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2023 2024| ID| Error Message| 2025| -------- | ---------------------------------------- | 2026| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2027| 9001001 | Invalid resource ID. | 2028| 9001002 | No matching resource is found based on the resource ID. | 2029 2030**Example** 2031 ```ts 2032 import { BusinessError } from '@kit.BasicServicesKit'; 2033 2034 try { 2035 this.context.resourceManager.getMediaContent($r('app.media.test').id).then((value: Uint8Array) => { 2036 let media = value; 2037 }).catch((error: BusinessError) => { 2038 console.error("getMediaContent promise error is " + error); 2039 }); 2040 } catch (error) { 2041 let code = (error as BusinessError).code; 2042 let message = (error as BusinessError).message; 2043 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2044 } 2045 ``` 2046 2047### getMediaContent<sup>10+</sup> 2048 2049getMediaContent(resId: number, density: number): Promise<Uint8Array> 2050 2051Obtains 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. 2052 2053**Atomic service API**: This API can be used in atomic services since API version 11. 2054 2055**System capability**: SystemCapability.Global.ResourceManager 2056 2057**Parameters** 2058 2059| Name | Type | Mandatory | Description | 2060| ----- | ------ | ---- | ----- | 2061| resId | number | Yes | Resource ID.| 2062| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2063 2064**Return value** 2065 2066| Type | Description | 2067| ------------------------- | -------------- | 2068| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2069 2070**Error codes** 2071 2072For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2073 2074| ID| Error Message| 2075| -------- | ---------------------------------------- | 2076| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2077| 9001001 | Invalid resource ID. | 2078| 9001002 | No matching resource is found based on the resource ID. | 2079 2080**Example** 2081 ```ts 2082 import { BusinessError } from '@kit.BasicServicesKit'; 2083 2084 try { 2085 this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then((value: Uint8Array) => { 2086 let media = value; 2087 }).catch((error: BusinessError) => { 2088 console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2089 }); 2090 } catch (error) { 2091 let code = (error as BusinessError).code; 2092 let message = (error as BusinessError).message; 2093 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2094 } 2095 ``` 2096 2097### getMediaContent<sup>9+</sup> 2098 2099getMediaContent(resource: Resource, callback: _AsyncCallback<Uint8Array>): void 2100 2101Obtains the content of a media file based on the specified resource object. This API uses an asynchronous callback to return the result. 2102 2103**Atomic service API**: This API can be used in atomic services since API version 11. 2104 2105**System capability**: SystemCapability.Global.ResourceManager 2106 2107**Model restriction**: This API can be used only in the stage model. 2108 2109**Parameters** 2110 2111| Name | Type | Mandatory | Description | 2112| -------- | ------------------------------- | ---- | ------------------ | 2113| resource | [Resource](#resource9) | Yes | Resource object. | 2114| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2115 2116**Error codes** 2117 2118For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2119 2120| ID| Error Message| 2121| -------- | ---------------------------------------- | 2122| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2123| 9001001 | Invalid resource ID. | 2124| 9001002 | No matching resource is found based on the resource ID. | 2125 2126**Example** 2127 ```ts 2128 import { resourceManager } from '@kit.LocalizationKit' 2129 import { BusinessError } from '@kit.BasicServicesKit'; 2130 2131 let resource: resourceManager.Resource = { 2132 bundleName: "com.example.myapplication", 2133 moduleName: "entry", 2134 id: $r('app.media.test').id 2135 }; 2136 try { 2137 this.context.resourceManager.getMediaContent(resource, (error: BusinessError, value: Uint8Array) => { 2138 if (error != null) { 2139 console.error("error is " + error); 2140 } else { 2141 let media = value; 2142 } 2143 }); 2144 } catch (error) { 2145 let code = (error as BusinessError).code; 2146 let message = (error as BusinessError).message; 2147 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2148 } 2149 ``` 2150 2151### getMediaContent<sup>10+</sup> 2152 2153getMediaContent(resource: Resource, density: number, callback: _AsyncCallback<Uint8Array>): void 2154 2155Obtains 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. 2156 2157**Atomic service API**: This API can be used in atomic services since API version 11. 2158 2159**System capability**: SystemCapability.Global.ResourceManager 2160 2161**Model restriction**: This API can be used only in the stage model. 2162 2163**Parameters** 2164 2165| Name | Type | Mandatory | Description | 2166| -------- | ------------------------------- | ---- | ------------------ | 2167| resource | [Resource](#resource9) | Yes | Resource object. | 2168| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2169| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2170 2171**Error codes** 2172 2173For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2174 2175| ID| Error Message| 2176| -------- | ---------------------------------------- | 2177| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2178| 9001001 | Invalid resource ID. | 2179| 9001002 | No matching resource is found based on the resource ID. | 2180 2181**Example** 2182 ```ts 2183 import { resourceManager } from '@kit.LocalizationKit' 2184 import { BusinessError } from '@kit.BasicServicesKit'; 2185 2186 let resource: resourceManager.Resource = { 2187 bundleName: "com.example.myapplication", 2188 moduleName: "entry", 2189 id: $r('app.media.test').id 2190 }; 2191 try { 2192 this.context.resourceManager.getMediaContent(resource, 120, (error: BusinessError, value: Uint8Array) => { 2193 if (error != null) { 2194 console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2195 } else { 2196 let media = value; 2197 } 2198 }); 2199 } catch (error) { 2200 let code = (error as BusinessError).code; 2201 let message = (error as BusinessError).message; 2202 console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); 2203 } 2204 ``` 2205 2206### getMediaContent<sup>9+</sup> 2207 2208getMediaContent(resource: Resource): Promise<Uint8Array> 2209 2210Obtains the content of a media file based on the specified resource object. This API uses a promise to return the result. 2211 2212**Atomic service API**: This API can be used in atomic services since API version 11. 2213 2214**System capability**: SystemCapability.Global.ResourceManager 2215 2216**Model restriction**: This API can be used only in the stage model. 2217 2218**Parameters** 2219 2220| Name | Type | Mandatory | Description | 2221| -------- | ---------------------- | ---- | ---- | 2222| resource | [Resource](#resource9) | Yes | Resource object.| 2223 2224**Return value** 2225 2226| Type | Description | 2227| ------------------------- | ------------------- | 2228| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| 2229 2230**Error codes** 2231 2232For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2233 2234| ID| Error Message| 2235| -------- | ---------------------------------------- | 2236| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2237| 9001001 | Invalid resource ID. | 2238| 9001002 | No matching resource is found based on the resource ID. | 2239 2240**Example** 2241 ```ts 2242 import { resourceManager } from '@kit.LocalizationKit' 2243 import { BusinessError } from '@kit.BasicServicesKit'; 2244 2245 let resource: resourceManager.Resource = { 2246 bundleName: "com.example.myapplication", 2247 moduleName: "entry", 2248 id: $r('app.media.test').id 2249 }; 2250 try { 2251 this.context.resourceManager.getMediaContent(resource).then((value: Uint8Array) => { 2252 let media = value; 2253 }).catch((error: BusinessError) => { 2254 console.error("getMediaContent promise error is " + error); 2255 }); 2256 } catch (error) { 2257 let code = (error as BusinessError).code; 2258 let message = (error as BusinessError).message; 2259 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2260 } 2261 ``` 2262 2263### getMediaContent<sup>10+</sup> 2264 2265getMediaContent(resource: Resource, density: number): Promise<Uint8Array> 2266 2267Obtains 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. 2268 2269**Atomic service API**: This API can be used in atomic services since API version 11. 2270 2271**System capability**: SystemCapability.Global.ResourceManager 2272 2273**Model restriction**: This API can be used only in the stage model. 2274 2275**Parameters** 2276 2277| Name | Type | Mandatory | Description | 2278| -------- | ---------------------- | ---- | ---- | 2279| resource | [Resource](#resource9) | Yes | Resource object.| 2280| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2281 2282**Return value** 2283 2284| Type | Description | 2285| ------------------------- | ------------------- | 2286| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| 2287 2288**Error codes** 2289 2290For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2291 2292| ID| Error Message| 2293| -------- | ---------------------------------------- | 2294| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2295| 9001001 | Invalid resource ID. | 2296| 9001002 | No matching resource is found based on the resource ID. | 2297 2298**Example** 2299 ```ts 2300 import { resourceManager } from '@kit.LocalizationKit' 2301 import { BusinessError } from '@kit.BasicServicesKit'; 2302 2303 let resource: resourceManager.Resource = { 2304 bundleName: "com.example.myapplication", 2305 moduleName: "entry", 2306 id: $r('app.media.test').id 2307 }; 2308 try { 2309 this.context.resourceManager.getMediaContent(resource, 120).then((value: Uint8Array) => { 2310 let media = value; 2311 }).catch((error: BusinessError) => { 2312 console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); 2313 }); 2314 } catch (error) { 2315 let code = (error as BusinessError).code; 2316 let message = (error as BusinessError).message; 2317 console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); 2318 } 2319 ``` 2320 2321### getMediaByName<sup>9+</sup> 2322 2323getMediaByName(resName: string, callback: _AsyncCallback<Uint8Array>): void 2324 2325Obtains the content of a media file based on the specified resource name. This API uses an asynchronous callback to return the result. 2326 2327**Atomic service API**: This API can be used in atomic services since API version 11. 2328 2329**System capability**: SystemCapability.Global.ResourceManager 2330 2331**Parameters** 2332 2333| Name | Type | Mandatory | Description | 2334| -------- | ------------------------------- | ---- | ------------------ | 2335| resName | string | Yes | Resource name. | 2336| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2337 2338**Error codes** 2339For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2340 2341| ID| Error Message| 2342| -------- | ---------------------------------------- | 2343| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2344| 9001003 | Invalid resource name. | 2345| 9001004 | No matching resource is found based on the resource name. | 2346 2347**Example** 2348 ```ts 2349 import { BusinessError } from '@kit.BasicServicesKit'; 2350 2351 try { 2352 this.context.resourceManager.getMediaByName("test", (error: BusinessError, value: Uint8Array) => { 2353 if (error != null) { 2354 console.error("error is " + error); 2355 } else { 2356 let media = value; 2357 } 2358 }); 2359 } catch (error) { 2360 let code = (error as BusinessError).code; 2361 let message = (error as BusinessError).message; 2362 console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); 2363 } 2364 ``` 2365 2366### getMediaByName<sup>10+</sup> 2367 2368getMediaByName(resName: string, density: number, callback: _AsyncCallback<Uint8Array>): void 2369 2370Obtains 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. 2371 2372**Atomic service API**: This API can be used in atomic services since API version 11. 2373 2374**System capability**: SystemCapability.Global.ResourceManager 2375 2376**Parameters** 2377 2378| Name | Type | Mandatory | Description | 2379| -------- | ------------------------------- | ---- | ------------------ | 2380| resName | string | Yes | Resource name. | 2381| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2382| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 2383 2384**Error codes** 2385 2386For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2387 2388| ID| Error Message| 2389| -------- | ---------------------------------------- | 2390| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2391| 9001003 | Invalid resource name. | 2392| 9001004 | No matching resource is found based on the resource name. | 2393 2394**Example** 2395 ```ts 2396 import { BusinessError } from '@kit.BasicServicesKit'; 2397 2398 try { 2399 this.context.resourceManager.getMediaByName("test", 120, (error: BusinessError, value: Uint8Array) => { 2400 if (error != null) { 2401 console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); 2402 } else { 2403 let media = value; 2404 } 2405 }); 2406 } catch (error) { 2407 let code = (error as BusinessError).code; 2408 let message = (error as BusinessError).message; 2409 console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); 2410 } 2411 ``` 2412 2413### getMediaByName<sup>9+</sup> 2414 2415getMediaByName(resName: string): Promise<Uint8Array> 2416 2417Obtains the content of a media file based on the specified resource name. This API uses a promise to return the result. 2418 2419**Atomic service API**: This API can be used in atomic services since API version 11. 2420 2421**System capability**: SystemCapability.Global.ResourceManager 2422 2423**Parameters** 2424 2425| Name | Type | Mandatory | Description | 2426| ------- | ------ | ---- | ---- | 2427| resName | string | Yes | Resource name.| 2428 2429**Return value** 2430 2431| Type | Description | 2432| ------------------------- | ------------- | 2433| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| 2434 2435**Error codes** 2436 2437For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2438 2439| ID| Error Message| 2440| -------- | ---------------------------------------- | 2441| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2442| 9001003 | Invalid resource name. | 2443| 9001004 | No matching resource is found based on the resource name. | 2444 2445**Example** 2446 ```ts 2447 import { BusinessError } from '@kit.BasicServicesKit'; 2448 2449 try { 2450 this.context.resourceManager.getMediaByName("test").then((value: Uint8Array) => { 2451 let media = value; 2452 }).catch((error: BusinessError) => { 2453 console.error("getMediaByName promise error is " + error); 2454 }); 2455 } catch (error) { 2456 let code = (error as BusinessError).code; 2457 let message = (error as BusinessError).message; 2458 console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); 2459 } 2460 ``` 2461 2462### getMediaByName<sup>10+</sup> 2463 2464getMediaByName(resName: string, density: number): Promise<Uint8Array> 2465 2466Obtains 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. 2467 2468**Atomic service API**: This API can be used in atomic services since API version 11. 2469 2470**System capability**: SystemCapability.Global.ResourceManager 2471 2472**Parameters** 2473 2474| Name | Type | Mandatory | Description | 2475| ------- | ------ | ---- | ---- | 2476| resName | string | Yes | Resource name.| 2477| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2478 2479**Return value** 2480 2481| Type | Description | 2482| ------------------------- | ------------- | 2483| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| 2484 2485**Error codes** 2486 2487For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2488 2489| ID| Error Message| 2490| -------- | ---------------------------------------- | 2491| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2492| 9001003 | Invalid resource name. | 2493| 9001004 | No matching resource is found based on the resource name. | 2494 2495**Example** 2496 ```ts 2497 import { BusinessError } from '@kit.BasicServicesKit'; 2498 2499 try { 2500 this.context.resourceManager.getMediaByName("test", 120).then((value: Uint8Array) => { 2501 let media = value; 2502 }).catch((error: BusinessError) => { 2503 console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); 2504 }); 2505 } catch (error) { 2506 let code = (error as BusinessError).code; 2507 let message = (error as BusinessError).message; 2508 console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); 2509 } 2510 ``` 2511 2512### getMediaContentBase64Sync<sup>10+</sup> 2513 2514getMediaContentBase64Sync(resId: number, density?: number): string 2515 2516Obtains 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. 2517 2518**Atomic service API**: This API can be used in atomic services since API version 11. 2519 2520**System capability**: SystemCapability.Global.ResourceManager 2521 2522**Parameters** 2523 2524| Name | Type | Mandatory | Description | 2525| ----- | ------ | ---- | ----- | 2526| resId | number | Yes | Resource ID.| 2527| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2528 2529**Return value** 2530 2531| Type | Description | 2532| -------- | ----------- | 2533| string | Base64 code of the image corresponding to the specified resource ID.| 2534 2535**Error codes** 2536 2537For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2538 2539| ID| Error Message| 2540| -------- | ---------------------------------------- | 2541| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2542| 9001001 | Invalid resource ID. | 2543| 9001002 | No matching resource is found based on the resource ID. | 2544 2545**Example** 2546 ```ts 2547 import { BusinessError } from '@kit.BasicServicesKit'; 2548 2549 try { 2550 this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density 2551 } catch (error) { 2552 let code = (error as BusinessError).code; 2553 let message = (error as BusinessError).message; 2554 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2555 } 2556 2557 try { 2558 this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density 2559 } catch (error) { 2560 let code = (error as BusinessError).code; 2561 let message = (error as BusinessError).message; 2562 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2563 } 2564 ``` 2565 2566### getMediaContentBase64Sync<sup>10+</sup> 2567 2568getMediaContentBase64Sync(resource: Resource, density?: number): string 2569 2570Obtains 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. 2571 2572**Atomic service API**: This API can be used in atomic services since API version 11. 2573 2574**System capability**: SystemCapability.Global.ResourceManager 2575 2576**Model restriction**: This API can be used only in the stage model. 2577 2578**Parameters** 2579 2580| Name | Type | Mandatory | Description | 2581| ----- | ------ | ---- | ----- | 2582| resource | [Resource](#resource9) | Yes | Resource object.| 2583| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2584 2585**Return value** 2586 2587| Type | Description | 2588| --------------------- | ----------- | 2589| string | Base64 code of the image corresponding to the specified resource object.| 2590 2591**Error codes** 2592 2593For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2594 2595| ID| Error Message| 2596| -------- | ---------------------------------------- | 2597| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2598| 9001001 | Invalid resource ID. | 2599| 9001002 | No matching resource is found based on the resource ID. | 2600 2601**Example** 2602 ```ts 2603 import { resourceManager } from '@kit.LocalizationKit' 2604 import { BusinessError } from '@kit.BasicServicesKit'; 2605 2606 let resource: resourceManager.Resource = { 2607 bundleName: "com.example.myapplication", 2608 moduleName: "entry", 2609 id: $r('app.media.test').id 2610 }; 2611 try { 2612 this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density 2613 } catch (error) { 2614 let code = (error as BusinessError).code; 2615 let message = (error as BusinessError).message; 2616 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2617 } 2618 2619 try { 2620 this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density 2621 } catch (error) { 2622 let code = (error as BusinessError).code; 2623 let message = (error as BusinessError).message; 2624 console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); 2625 } 2626 ``` 2627 2628### getMediaBase64ByNameSync<sup>10+</sup> 2629 2630getMediaBase64ByNameSync(resName: string, density?: number): string 2631 2632Obtains 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. 2633 2634**Atomic service API**: This API can be used in atomic services since API version 11. 2635 2636**System capability**: SystemCapability.Global.ResourceManager 2637 2638**Parameters** 2639 2640| Name | Type | Mandatory | Description | 2641| ----- | ------ | ---- | ----- | 2642| resName | string | Yes | Resource name.| 2643| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 2644 2645**Return value** 2646 2647| Type | Description | 2648| --------------------- | ----------- | 2649| string | Base64 code of the image corresponding to the specified resource name.| 2650 2651**Error codes** 2652 2653For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2654 2655| ID| Error Message| 2656| -------- | ---------------------------------------- | 2657| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2658| 9001003 | Invalid resource name. | 2659| 9001004 | No matching resource is found based on the resource name. | 2660 2661**Example** 2662 ```ts 2663 import { BusinessError } from '@kit.BasicServicesKit'; 2664 2665 try { 2666 this.context.resourceManager.getMediaBase64ByNameSync("test"); // Default screen density 2667 } catch (error) { 2668 let code = (error as BusinessError).code; 2669 let message = (error as BusinessError).message; 2670 console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); 2671 } 2672 2673 try { 2674 this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // Specified screen density 2675 } catch (error) { 2676 let code = (error as BusinessError).code; 2677 let message = (error as BusinessError).message; 2678 console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); 2679 } 2680 ``` 2681 2682### getMediaContentBase64<sup>9+</sup> 2683 2684getMediaContentBase64(resId: number, callback: _AsyncCallback<string>): void 2685 2686Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. 2687 2688**Atomic service API**: This API can be used in atomic services since API version 11. 2689 2690**System capability**: SystemCapability.Global.ResourceManager 2691 2692**Parameters** 2693 2694| Name | Type | Mandatory | Description | 2695| -------- | --------------------------- | ---- | ------------------------ | 2696| resId | number | Yes | Resource ID. | 2697| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2698 2699**Error codes** 2700 2701For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2702 2703| ID| Error Message| 2704| -------- | ---------------------------------------- | 2705| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2706| 9001001 | Invalid resource ID. | 2707| 9001002 | No matching resource is found based on the resource ID. | 2708 2709**Example** 2710 ```ts 2711 import { BusinessError } from '@kit.BasicServicesKit'; 2712 2713 try { 2714 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error: BusinessError, value: string) => { 2715 if (error != null) { 2716 console.error("error is " + error); 2717 } else { 2718 let media = value; 2719 } 2720 }); 2721 } catch (error) { 2722 let code = (error as BusinessError).code; 2723 let message = (error as BusinessError).message; 2724 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2725 } 2726 ``` 2727 2728### getMediaContentBase64<sup>10+</sup> 2729 2730getMediaContentBase64(resId: number, density: number, callback: _AsyncCallback<string>): void 2731 2732Obtains 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. 2733 2734**Atomic service API**: This API can be used in atomic services since API version 11. 2735 2736**System capability**: SystemCapability.Global.ResourceManager 2737 2738**Parameters** 2739 2740| Name | Type | Mandatory | Description | 2741| -------- | --------------------------- | ---- | ------------------------ | 2742| resId | number | Yes | Resource ID. | 2743| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2744| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2745 2746**Error codes** 2747 2748For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2749 2750| ID| Error Message| 2751| -------- | ---------------------------------------- | 2752| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2753| 9001001 | Invalid resource ID. | 2754| 9001002 | No matching resource is found based on the resource ID. | 2755 2756**Example** 2757 ```ts 2758 import { BusinessError } from '@kit.BasicServicesKit'; 2759 2760 try { 2761 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error: BusinessError, value: string) => { 2762 if (error != null) { 2763 console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 2764 } else { 2765 let media = value; 2766 } 2767 }); 2768 } catch (error) { 2769 let code = (error as BusinessError).code; 2770 let message = (error as BusinessError).message; 2771 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2772 } 2773 ``` 2774 2775### getMediaContentBase64<sup>9+</sup> 2776 2777getMediaContentBase64(resId: number): Promise<string> 2778 2779Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. 2780 2781**Atomic service API**: This API can be used in atomic services since API version 11. 2782 2783**System capability**: SystemCapability.Global.ResourceManager 2784 2785**Parameters** 2786 2787| Name | Type | Mandatory | Description | 2788| ----- | ------ | ---- | ----- | 2789| resId | number | Yes | Resource ID.| 2790 2791**Return value** 2792 2793| Type | Description | 2794| --------------------- | -------------------- | 2795| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2796 2797**Error codes** 2798 2799For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 2800 2801| ID| Error Message| 2802| -------- | ---------------------------------------- | 2803| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2804| 9001001 | Invalid resource ID. | 2805| 9001002 | No matching resource is found based on the resource ID. | 2806 2807**Example** 2808 ```ts 2809 import { BusinessError } from '@kit.BasicServicesKit'; 2810 2811 try { 2812 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then((value: string) => { 2813 let media = value; 2814 }).catch((error: BusinessError) => { 2815 console.error("getMediaContentBase64 promise error is " + error); 2816 }); 2817 } catch (error) { 2818 let code = (error as BusinessError).code; 2819 let message = (error as BusinessError).message; 2820 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2821 } 2822 ``` 2823 2824### getMediaContentBase64<sup>10+</sup> 2825 2826getMediaContentBase64(resId: number, density: number): Promise<string> 2827 2828Obtains 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. 2829 2830**Atomic service API**: This API can be used in atomic services since API version 11. 2831 2832**System capability**: SystemCapability.Global.ResourceManager 2833 2834**Parameters** 2835 2836| Name | Type | Mandatory | Description | 2837| ----- | ------ | ---- | ----- | 2838| resId | number | Yes | Resource ID.| 2839| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2840 2841**Return value** 2842 2843| Type | Description | 2844| --------------------- | -------------------- | 2845| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2846 2847**Error codes** 2848 2849For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2850 2851| ID| Error Message| 2852| -------- | ---------------------------------------- | 2853| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2854| 9001001 | Invalid resource ID. | 2855| 9001002 | No matching resource is found based on the resource ID. | 2856 2857**Example** 2858 ```ts 2859 import { BusinessError } from '@kit.BasicServicesKit'; 2860 2861 try { 2862 this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then((value: string) => { 2863 let media = value; 2864 }).catch((error: BusinessError) => { 2865 console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 2866 }); 2867 } catch (error) { 2868 let code = (error as BusinessError).code; 2869 let message = (error as BusinessError).message; 2870 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2871 } 2872 ``` 2873 2874### getMediaContentBase64<sup>9+</sup> 2875 2876getMediaContentBase64(resource: Resource, callback: _AsyncCallback<string>): void 2877 2878Obtains the Base64 code of an image based on the specified resource object. This API uses an asynchronous callback to return the result. 2879 2880**Atomic service API**: This API can be used in atomic services since API version 11. 2881 2882**System capability**: SystemCapability.Global.ResourceManager 2883 2884**Model restriction**: This API can be used only in the stage model. 2885 2886**Parameters** 2887 2888| Name | Type | Mandatory | Description | 2889| -------- | --------------------------- | ---- | ------------------------ | 2890| resource | [Resource](#resource9) | Yes | Resource object. | 2891| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2892 2893**Error codes** 2894 2895For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2896 2897| ID| Error Message| 2898| -------- | ---------------------------------------- | 2899| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 2900| 9001001 | Invalid resource ID. | 2901| 9001002 | No matching resource is found based on the resource ID. | 2902 2903**Example** 2904 ```ts 2905 import { resourceManager } from '@kit.LocalizationKit' 2906 import { BusinessError } from '@kit.BasicServicesKit'; 2907 2908 let resource: resourceManager.Resource = { 2909 bundleName: "com.example.myapplication", 2910 moduleName: "entry", 2911 id: $r('app.media.test').id 2912 }; 2913 try { 2914 this.context.resourceManager.getMediaContentBase64(resource, (error: BusinessError, value: string) => { 2915 if (error != null) { 2916 console.error("error is " + error); 2917 } else { 2918 let media = value; 2919 } 2920 }); 2921 } catch (error) { 2922 let code = (error as BusinessError).code; 2923 let message = (error as BusinessError).message; 2924 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2925 } 2926 ``` 2927 2928### getMediaContentBase64<sup>10+</sup> 2929 2930getMediaContentBase64(resource: Resource, density: number, callback: _AsyncCallback<string>): void 2931 2932Obtains 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. 2933 2934**Atomic service API**: This API can be used in atomic services since API version 11. 2935 2936**System capability**: SystemCapability.Global.ResourceManager 2937 2938**Model restriction**: This API can be used only in the stage model. 2939 2940**Parameters** 2941 2942| Name | Type | Mandatory | Description | 2943| -------- | --------------------------- | ---- | ------------------------ | 2944| resource | [Resource](#resource9) | Yes | Resource object. | 2945| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 2946| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 2947 2948**Error codes** 2949 2950For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 2951 2952| ID| Error Message| 2953| -------- | ---------------------------------------- | 2954| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 2955| 9001001 | Invalid resource ID. | 2956| 9001002 | No matching resource is found based on the resource ID. | 2957 2958**Example** 2959 ```ts 2960 import { resourceManager } from '@kit.LocalizationKit' 2961 import { BusinessError } from '@kit.BasicServicesKit'; 2962 2963 let resource: resourceManager.Resource = { 2964 bundleName: "com.example.myapplication", 2965 moduleName: "entry", 2966 id: $r('app.media.test').id 2967 }; 2968 try { 2969 this.context.resourceManager.getMediaContentBase64(resource, 120, (error: BusinessError, value: string) => { 2970 if (error != null) { 2971 console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 2972 } else { 2973 let media = value; 2974 } 2975 }); 2976 } catch (error) { 2977 let code = (error as BusinessError).code; 2978 let message = (error as BusinessError).message; 2979 console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 2980 } 2981 ``` 2982 2983### getMediaContentBase64<sup>9+</sup> 2984 2985getMediaContentBase64(resource: Resource): Promise<string> 2986 2987Obtains the Base64 code of an image based on the specified resource object. This API uses a promise to return the result. 2988 2989**Atomic service API**: This API can be used in atomic services since API version 11. 2990 2991**System capability**: SystemCapability.Global.ResourceManager 2992 2993**Model restriction**: This API can be used only in the stage model. 2994 2995**Parameters** 2996 2997| Name | Type | Mandatory | Description | 2998| -------- | ---------------------- | ---- | ---- | 2999| resource | [Resource](#resource9) | Yes | Resource object.| 3000 3001**Return value** 3002 3003| Type | Description | 3004| --------------------- | ------------------------- | 3005| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| 3006 3007**Error codes** 3008 3009For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3010 3011| ID| Error Message| 3012| -------- | ---------------------------------------- | 3013| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3014| 9001001 | Invalid resource ID. | 3015| 9001002 | No matching resource is found based on the resource ID. | 3016 3017**Example** 3018 ```ts 3019 import { resourceManager } from '@kit.LocalizationKit' 3020 import { BusinessError } from '@kit.BasicServicesKit'; 3021 3022 let resource: resourceManager.Resource = { 3023 bundleName: "com.example.myapplication", 3024 moduleName: "entry", 3025 id: $r('app.media.test').id 3026 }; 3027 try { 3028 this.context.resourceManager.getMediaContentBase64(resource).then((value: string) => { 3029 let media = value; 3030 }).catch((error: BusinessError) => { 3031 console.error("getMediaContentBase64 promise error is " + error); 3032 }); 3033 } catch (error) { 3034 let code = (error as BusinessError).code; 3035 let message = (error as BusinessError).message; 3036 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3037 } 3038 ``` 3039 3040### getMediaContentBase64<sup>10+</sup> 3041 3042getMediaContentBase64(resource: Resource, density: number): Promise<string> 3043 3044Obtains 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. 3045 3046**Atomic service API**: This API can be used in atomic services since API version 11. 3047 3048**System capability**: SystemCapability.Global.ResourceManager 3049 3050**Model restriction**: This API can be used only in the stage model. 3051 3052**Parameters** 3053 3054| Name | Type | Mandatory | Description | 3055| -------- | ---------------------- | ---- | ---- | 3056| resource | [Resource](#resource9) | Yes | Resource object.| 3057| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3058 3059**Return value** 3060 3061| Type | Description | 3062| --------------------- | ------------------------- | 3063| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| 3064 3065**Error codes** 3066 3067For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3068 3069| ID| Error Message| 3070| -------- | ---------------------------------------- | 3071| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3072| 9001001 | Invalid resource ID. | 3073| 9001002 | No matching resource is found based on the resource ID. | 3074 3075**Example** 3076 ```ts 3077 import { resourceManager } from '@kit.LocalizationKit' 3078 import { BusinessError } from '@kit.BasicServicesKit'; 3079 3080 let resource: resourceManager.Resource = { 3081 bundleName: "com.example.myapplication", 3082 moduleName: "entry", 3083 id: $r('app.media.test').id 3084 }; 3085 try { 3086 this.context.resourceManager.getMediaContentBase64(resource, 120).then((value: string) => { 3087 let media = value; 3088 }).catch((error: BusinessError) => { 3089 console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); 3090 }); 3091 } catch (error) { 3092 let code = (error as BusinessError).code; 3093 let message = (error as BusinessError).message; 3094 console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); 3095 } 3096 ``` 3097 3098### getMediaBase64ByName<sup>9+</sup> 3099 3100getMediaBase64ByName(resName: string, callback: _AsyncCallback<string>): void 3101 3102Obtains the Base64 code of an image based on the specified resource name. This API uses an asynchronous callback to return the result. 3103 3104**Atomic service API**: This API can be used in atomic services since API version 11. 3105 3106**System capability**: SystemCapability.Global.ResourceManager 3107 3108**Parameters** 3109 3110| Name | Type | Mandatory | Description | 3111| -------- | --------------------------- | ---- | ------------------------ | 3112| resName | string | Yes | Resource name. | 3113| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3114 3115**Error codes** 3116 3117For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3118 3119| ID| Error Message| 3120| -------- | ---------------------------------------- | 3121| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3122| 9001003 | Invalid resource name. | 3123| 9001004 | No matching resource is found based on the resource name. | 3124 3125**Example** 3126 ```ts 3127 import { BusinessError } from '@kit.BasicServicesKit'; 3128 3129 try { 3130 this.context.resourceManager.getMediaBase64ByName("test", (error: BusinessError, value: string) => { 3131 if (error != null) { 3132 console.error("error is " + error); 3133 } else { 3134 let media = value; 3135 } 3136 }); 3137 } catch (error) { 3138 let code = (error as BusinessError).code; 3139 let message = (error as BusinessError).message; 3140 console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3141 } 3142 ``` 3143 3144### getMediaBase64ByName<sup>10+</sup> 3145 3146getMediaBase64ByName(resName: string, density: number, callback: _AsyncCallback<string>): void 3147 3148Obtains 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. 3149 3150**Atomic service API**: This API can be used in atomic services since API version 11. 3151 3152**System capability**: SystemCapability.Global.ResourceManager 3153 3154**Parameters** 3155 3156| Name | Type | Mandatory | Description | 3157| -------- | --------------------------- | ---- | ------------------------ | 3158| resName | string | Yes | Resource name. | 3159| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3160| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 3161 3162**Error codes** 3163 3164For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3165 3166| ID| Error Message| 3167| -------- | ---------------------------------------- | 3168| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3169| 9001003 | Invalid resource name. | 3170| 9001004 | No matching resource is found based on the resource name. | 3171 3172**Example** 3173 ```ts 3174 import { BusinessError } from '@kit.BasicServicesKit'; 3175 3176 try { 3177 this.context.resourceManager.getMediaBase64ByName("test", 120, (error: BusinessError, value: string) => { 3178 if (error != null) { 3179 console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); 3180 } else { 3181 let media = value; 3182 } 3183 }); 3184 } catch (error) { 3185 let code = (error as BusinessError).code; 3186 let message = (error as BusinessError).message; 3187 console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3188 } 3189 ``` 3190 3191### getMediaBase64ByName<sup>9+</sup> 3192 3193getMediaBase64ByName(resName: string): Promise<string> 3194 3195Obtains the Base64 code of an image based on the specified resource name. This API uses a promise to return the result. 3196 3197**Atomic service API**: This API can be used in atomic services since API version 11. 3198 3199**System capability**: SystemCapability.Global.ResourceManager 3200 3201**Parameters** 3202 3203| Name | Type | Mandatory | Description | 3204| ------- | ------ | ---- | ---- | 3205| resName | string | Yes | Resource name.| 3206 3207**Return value** 3208 3209| Type | Description | 3210| --------------------- | ------------------- | 3211| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| 3212 3213**Error codes** 3214 3215For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3216 3217| ID| Error Message| 3218| -------- | ---------------------------------------- | 3219| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3220| 9001003 | Invalid resource name. | 3221| 9001004 | No matching resource is found based on the resource name. | 3222 3223**Example** 3224 ```ts 3225 import { BusinessError } from '@kit.BasicServicesKit'; 3226 3227 try { 3228 this.context.resourceManager.getMediaBase64ByName("test").then((value: string) => { 3229 let media = value; 3230 }).catch((error: BusinessError) => { 3231 console.error("getMediaBase64ByName promise error is " + error); 3232 }); 3233 } catch (error) { 3234 let code = (error as BusinessError).code; 3235 let message = (error as BusinessError).message; 3236 console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3237 } 3238 ``` 3239 3240### getMediaBase64ByName<sup>10+</sup> 3241 3242getMediaBase64ByName(resName: string, density: number): Promise<string> 3243 3244Obtains 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. 3245 3246**Atomic service API**: This API can be used in atomic services since API version 11. 3247 3248**System capability**: SystemCapability.Global.ResourceManager 3249 3250**Parameters** 3251 3252| Name | Type | Mandatory | Description | 3253| ------- | ------ | ---- | ---- | 3254| resName | string | Yes | Resource name.| 3255| [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | 3256 3257**Return value** 3258 3259| Type | Description | 3260| --------------------- | ------------------- | 3261| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| 3262 3263**Error codes** 3264 3265For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3266 3267| ID| Error Message| 3268| -------- | ---------------------------------------- | 3269| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3270| 9001003 | Invalid resource name. | 3271| 9001004 | No matching resource is found based on the resource name. | 3272 3273**Example** 3274 ```ts 3275 import { BusinessError } from '@kit.BasicServicesKit'; 3276 3277 try { 3278 this.context.resourceManager.getMediaBase64ByName("test", 120).then((value: string) => { 3279 let media = value; 3280 }).catch((error: BusinessError) => { 3281 console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); 3282 }); 3283 } catch (error) { 3284 let code = (error as BusinessError).code; 3285 let message = (error as BusinessError).message; 3286 console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); 3287 } 3288 ``` 3289 3290### getDrawableDescriptor<sup>10+</sup> 3291 3292getDrawableDescriptor(resId: number, density?: number, type?: number): DrawableDescriptor 3293 3294Obtains a **DrawableDescriptor** object for icon display based on the specified resource ID. This API returns the result synchronously. 3295 3296**Atomic service API**: This API can be used in atomic services since API version 11. 3297 3298**System capability**: SystemCapability.Global.ResourceManager 3299 3300**Parameters** 3301 3302| Name | Type | Mandatory | Description | 3303| ----- | ------ | ---- | ----- | 3304| resId | number | Yes | Resource ID.| 3305| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3306| 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.| 3307 3308**Return value** 3309 3310| Type | Description | 3311| ------ | ---------- | 3312| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object 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) and [Universal Error Codes](../errorcode-universal.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| 9001001 | Invalid resource ID. | 3322| 9001002 | No matching resource is found based on the resource ID. | 3323 3324**Example** 3325 ```ts 3326 import { BusinessError } from '@kit.BasicServicesKit'; 3327 import { DrawableDescriptor } from '@kit.ArkUI'; 3328 3329 try { 3330 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); 3331 } catch (error) { 3332 let code = (error as BusinessError).code; 3333 let message = (error as BusinessError).message; 3334 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3335 } 3336 try { 3337 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); 3338 } catch (error) { 3339 let code = (error as BusinessError).code; 3340 let message = (error as BusinessError).message; 3341 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3342 } 3343 try { 3344 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 0, 1); 3345 } catch (error) { 3346 let code = (error as BusinessError).code; 3347 let message = (error as BusinessError).message; 3348 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3349 } 3350 ``` 3351 3352### getDrawableDescriptor<sup>10+</sup> 3353 3354getDrawableDescriptor(resource: Resource, density?: number, type?: number): DrawableDescriptor 3355 3356Obtains a **DrawableDescriptor** object for icon display based on the specified resource object. This API returns the result synchronously. 3357 3358**Atomic service API**: This API can be used in atomic services since API version 11. 3359 3360**System capability**: SystemCapability.Global.ResourceManager 3361 3362**Model restriction**: This API can be used only in the stage model. 3363 3364**Parameters** 3365 3366| Name | Type | Mandatory | Description | 3367| -------- | ---------------------- | ---- | ---- | 3368| resource | [Resource](#resource9) | Yes | Resource object.| 3369| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3370| 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.| 3371 3372**Return value** 3373 3374| Type | Description | 3375| ------- | ----------------- | 3376| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3377 3378**Error codes** 3379 3380For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3381 3382| ID| Error Message| 3383| -------- | ---------------------------------------- | 3384| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3385| 9001001 | Invalid resource ID. | 3386| 9001002 | No matching resource is found based on the resource ID. | 3387 3388**Example** 3389 ```ts 3390 import { resourceManager } from '@kit.LocalizationKit' 3391 import { BusinessError } from '@kit.BasicServicesKit'; 3392 import { DrawableDescriptor } from '@kit.ArkUI'; 3393 3394 let resource: resourceManager.Resource = { 3395 bundleName: "com.example.myapplication", 3396 moduleName: "entry", 3397 id: $r('app.media.icon').id 3398 }; 3399 try { 3400 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource); 3401 } catch (error) { 3402 let code = (error as BusinessError).code; 3403 let message = (error as BusinessError).message; 3404 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3405 } 3406 try { 3407 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource, 120); 3408 } catch (error) { 3409 let code = (error as BusinessError).code; 3410 let message = (error as BusinessError).message; 3411 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3412 } 3413 try { 3414 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptor(resource, 0, 1); 3415 } catch (error) { 3416 let code = (error as BusinessError).code; 3417 let message = (error as BusinessError).message; 3418 console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); 3419 } 3420 ``` 3421 3422### getDrawableDescriptorByName<sup>10+</sup> 3423 3424getDrawableDescriptorByName(resName: string, density?: number, type?: number): DrawableDescriptor 3425 3426Obtains a **DrawableDescriptor** object for icon display based on the specified resource name. This API returns the result synchronously. 3427 3428**Atomic service API**: This API can be used in atomic services since API version 11. 3429 3430**System capability**: SystemCapability.Global.ResourceManager 3431 3432**Parameters** 3433 3434| Name | Type | Mandatory | Description | 3435| ------- | ------ | ---- | ---- | 3436| resName | string | Yes | Resource name.| 3437| [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| 3438| 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.| 3439 3440**Return value** 3441 3442| Type | Description | 3443| ------ | --------- | 3444| [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| 3445 3446**Error codes** 3447 3448For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3449 3450| ID| Error Message| 3451| -------- | ---------------------------------------- | 3452| 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | 3453| 9001003 | Invalid resource name. | 3454| 9001004 | No matching resource is found based on the resource name. | 3455 3456**Example** 3457 ```ts 3458 import { BusinessError } from '@kit.BasicServicesKit'; 3459 import { DrawableDescriptor } from '@kit.ArkUI'; 3460 3461 try { 3462 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon'); 3463 } catch (error) { 3464 let code = (error as BusinessError).code; 3465 let message = (error as BusinessError).message; 3466 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3467 } 3468 try { 3469 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon', 120); 3470 } catch (error) { 3471 let code = (error as BusinessError).code; 3472 let message = (error as BusinessError).message; 3473 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3474 } 3475 try { 3476 let drawableDescriptor:DrawableDescriptor = this.context.resourceManager.getDrawableDescriptorByName('icon', 0, 1); 3477 } catch (error) { 3478 let code = (error as BusinessError).code; 3479 let message = (error as BusinessError).message; 3480 console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); 3481 } 3482 ``` 3483 3484### getBoolean<sup>9+</sup> 3485 3486getBoolean(resId: number): boolean 3487 3488Obtains a Boolean result based on the specified resource ID. This API returns the result synchronously. 3489 3490**Atomic service API**: This API can be used in atomic services since API version 11. 3491 3492**System capability**: SystemCapability.Global.ResourceManager 3493 3494**Parameters** 3495 3496| Name | Type | Mandatory | Description | 3497| ----- | ------ | ---- | ----- | 3498| resId | number | Yes | Resource ID.| 3499 3500**Return value** 3501 3502| Type | Description | 3503| ------- | ------------ | 3504| boolean | Boolean result corresponding to the specified resource ID.| 3505 3506**Error codes** 3507 3508For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3509 3510| ID| Error Message| 3511| -------- | ---------------------------------------- | 3512| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3513| 9001001 | Invalid resource ID. | 3514| 9001002 | No matching resource is found based on the resource ID. | 3515| 9001006 | The resource is referenced cyclically. | 3516 3517**Example** 3518 ```ts 3519 import { BusinessError } from '@kit.BasicServicesKit'; 3520 3521 try { 3522 this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); 3523 } catch (error) { 3524 let code = (error as BusinessError).code; 3525 let message = (error as BusinessError).message; 3526 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3527 } 3528 ``` 3529### getBoolean<sup>9+</sup> 3530 3531getBoolean(resource: Resource): boolean 3532 3533Obtains a Boolean result based on the specified resource object. This API returns the result synchronously. 3534 3535**Atomic service API**: This API can be used in atomic services since API version 11. 3536 3537**System capability**: SystemCapability.Global.ResourceManager 3538 3539**Model restriction**: This API can be used only in the stage model. 3540 3541**Parameters** 3542 3543| Name | Type | Mandatory | Description | 3544| -------- | ---------------------- | ---- | ---- | 3545| resource | [Resource](#resource9) | Yes | Resource object.| 3546 3547**Return value** 3548 3549| Type | Description | 3550| ------- | ----------------- | 3551| boolean | Boolean result corresponding to the specified resource object.| 3552 3553**Error codes** 3554 3555For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3556 3557| ID| Error Message| 3558| -------- | ---------------------------------------- | 3559| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3560| 9001001 | Invalid resource ID. | 3561| 9001002 | No matching resource is found based on the resource ID. | 3562| 9001006 | The resource is referenced cyclically. | 3563 3564**Example** 3565 ```ts 3566 import { resourceManager } from '@kit.LocalizationKit' 3567 import { BusinessError } from '@kit.BasicServicesKit'; 3568 3569 let resource: resourceManager.Resource = { 3570 bundleName: "com.example.myapplication", 3571 moduleName: "entry", 3572 id: $r('app.boolean.boolean_test').id 3573 }; 3574 try { 3575 this.context.resourceManager.getBoolean(resource); 3576 } catch (error) { 3577 let code = (error as BusinessError).code; 3578 let message = (error as BusinessError).message; 3579 console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); 3580 } 3581 ``` 3582 3583### getBooleanByName<sup>9+</sup> 3584 3585getBooleanByName(resName: string): boolean 3586 3587Obtains a Boolean result based on the specified resource name. This API returns the result synchronously. 3588 3589**Atomic service API**: This API can be used in atomic services since API version 11. 3590 3591**System capability**: SystemCapability.Global.ResourceManager 3592 3593**Parameters** 3594 3595| Name | Type | Mandatory | Description | 3596| ------- | ------ | ---- | ---- | 3597| resName | string | Yes | Resource name.| 3598 3599**Return value** 3600 3601| Type | Description | 3602| ------- | ----------- | 3603| boolean | Boolean result corresponding to the specified resource name.| 3604 3605**Error codes** 3606 3607For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3608 3609| ID| Error Message| 3610| -------- | ---------------------------------------- | 3611| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3612| 9001003 | Invalid resource name. | 3613| 9001004 | No matching resource is found based on the resource name. | 3614| 9001006 | The resource is referenced cyclically. | 3615 3616**Example** 3617 ```ts 3618 import { BusinessError } from '@kit.BasicServicesKit'; 3619 3620 try { 3621 this.context.resourceManager.getBooleanByName("boolean_test"); 3622 } catch (error) { 3623 let code = (error as BusinessError).code; 3624 let message = (error as BusinessError).message; 3625 console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`); 3626 } 3627 ``` 3628 3629### getNumber<sup>9+</sup> 3630 3631getNumber(resId: number): number 3632 3633Obtains an integer or float value based on the specified resource ID. This API returns the result synchronously. 3634 3635**Atomic service API**: This API can be used in atomic services since API version 11. 3636 3637**System capability**: SystemCapability.Global.ResourceManager 3638 3639**Parameters** 3640 3641| Name | Type | Mandatory | Description | 3642| ----- | ------ | ---- | ----- | 3643| resId | number | Yes | Resource ID.| 3644 3645**Return value** 3646 3647| Type | Description | 3648| ------ | ---------- | 3649| 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.| 3650 3651**Error codes** 3652 3653For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3654 3655| ID| Error Message| 3656| -------- | ---------------------------------------- | 3657| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3658| 9001001 | Invalid resource ID. | 3659| 9001002 | No matching resource is found based on the resource ID. | 3660| 9001006 | The resource is referenced cyclically. | 3661 3662**Example** 3663 ```ts 3664 import { BusinessError } from '@kit.BasicServicesKit'; 3665 3666 try { 3667 this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. 3668 } catch (error) { 3669 let code = (error as BusinessError).code; 3670 let message = (error as BusinessError).message; 3671 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3672 } 3673 3674 try { 3675 this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. 3676 } catch (error) { 3677 let code = (error as BusinessError).code; 3678 let message = (error as BusinessError).message; 3679 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3680 } 3681 ``` 3682 3683### getNumber<sup>9+</sup> 3684 3685getNumber(resource: Resource): number 3686 3687Obtains an integer or float value based on the specified resource object. This API returns the result synchronously. 3688 3689> **NOTE** 3690> 3691> 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. 3692 3693**Atomic service API**: This API can be used in atomic services since API version 11. 3694 3695**System capability**: SystemCapability.Global.ResourceManager 3696 3697**Model restriction**: This API can be used only in the stage model. 3698 3699**Parameters** 3700 3701| Name | Type | Mandatory | Description | 3702| -------- | ---------------------- | ---- | ---- | 3703| resource | [Resource](#resource9) | Yes | Resource object.| 3704 3705**Return value** 3706 3707| Type | Description | 3708| ------ | --------------- | 3709| 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.| 3710 3711**Error codes** 3712 3713For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3714 3715| ID| Error Message| 3716| -------- | ---------------------------------------- | 3717| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3718| 9001001 | Invalid resource ID. | 3719| 9001002 | No matching resource is found based on the resource ID. | 3720| 9001006 | The resource is referenced cyclically. | 3721 3722**Example** 3723 ```ts 3724 import { resourceManager } from '@kit.LocalizationKit' 3725 import { BusinessError } from '@kit.BasicServicesKit'; 3726 3727 let resource: resourceManager.Resource = { 3728 bundleName: "com.example.myapplication", 3729 moduleName: "entry", 3730 id: $r('app.integer.integer_test').id 3731 }; 3732 try { 3733 this.context.resourceManager.getNumber(resource); 3734 } catch (error) { 3735 let code = (error as BusinessError).code; 3736 let message = (error as BusinessError).message; 3737 console.error(`getNumber failed, error code: ${code}, message: ${message}.`); 3738 } 3739 ``` 3740 3741### getNumberByName<sup>9+</sup> 3742 3743getNumberByName(resName: string): number 3744 3745Obtains an integer or float value based on the specified resource name. This API returns the result synchronously. 3746 3747**Atomic service API**: This API can be used in atomic services since API version 11. 3748 3749**System capability**: SystemCapability.Global.ResourceManager 3750 3751**Parameters** 3752 3753| Name | Type | Mandatory | Description | 3754| ------- | ------ | ---- | ---- | 3755| resName | string | Yes | Resource name.| 3756 3757**Return value** 3758 3759| Type | Description | 3760| ------ | --------- | 3761| 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.| 3762 3763**Error codes** 3764 3765For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 3766 3767| ID| Error Message| 3768| -------- | ---------------------------------------- | 3769| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3770| 9001003 | Invalid resource name. | 3771| 9001004 | No matching resource is found based on the resource name. | 3772| 9001006 | The resource is referenced cyclically. | 3773 3774**Example** 3775 ```ts 3776 import { BusinessError } from '@kit.BasicServicesKit'; 3777 3778 try { 3779 this.context.resourceManager.getNumberByName("integer_test"); 3780 } catch (error) { 3781 let code = (error as BusinessError).code; 3782 let message = (error as BusinessError).message; 3783 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3784 } 3785 3786 try { 3787 this.context.resourceManager.getNumberByName("float_test"); 3788 } catch (error) { 3789 let code = (error as BusinessError).code; 3790 let message = (error as BusinessError).message; 3791 console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); 3792 } 3793 ``` 3794 3795### getColorSync<sup>10+</sup> 3796 3797getColorSync(resId: number) : number; 3798 3799Obtains a color value based on the specified resource ID. This API returns the result synchronously. 3800 3801**Atomic service API**: This API can be used in atomic services since API version 11. 3802 3803**System capability**: SystemCapability.Global.ResourceManager 3804 3805**Parameters** 3806 3807| Name | Type | Mandatory | Description | 3808| ----- | ------ | ---- | ----- | 3809| resId | number | Yes | Resource ID.| 3810 3811**Return value** 3812 3813| Type | Description | 3814| ------ | ----------- | 3815| number | Color value (decimal) corresponding to the specified resource ID.| 3816 3817**Error codes** 3818 3819For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3820 3821| ID| Error Message| 3822| -------- | ---------------------------------------- | 3823| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3824| 9001001 | Invalid resource ID. | 3825| 9001002 | No matching resource is found based on the resource ID. | 3826| 9001006 | The resource is referenced cyclically. | 3827 3828**Example** 3829 ```ts 3830 import { BusinessError } from '@kit.BasicServicesKit'; 3831 3832 try { 3833 this.context.resourceManager.getColorSync($r('app.color.test').id); 3834 } catch (error) { 3835 let code = (error as BusinessError).code; 3836 let message = (error as BusinessError).message; 3837 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 3838 } 3839 ``` 3840 3841### getColorSync<sup>10+</sup> 3842 3843getColorSync(resource: Resource): number 3844 3845Obtains a color value based on the specified resource object. This API returns the result synchronously. 3846 3847**Atomic service API**: This API can be used in atomic services since API version 11. 3848 3849**System capability**: SystemCapability.Global.ResourceManager 3850 3851**Model restriction**: This API can be used only in the stage model. 3852 3853**Parameters** 3854 3855| Name | Type | Mandatory | Description | 3856| -------- | ---------------------- | ---- | ---- | 3857| resource | [Resource](#resource9) | Yes | Resource object.| 3858 3859**Return value** 3860 3861| Type | Description | 3862| ------ | ---------------- | 3863| number | Color value (decimal) corresponding to the specified resource object.| 3864 3865**Error codes** 3866 3867For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3868 3869| ID| Error Message| 3870| -------- | ---------------------------------------- | 3871| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3872| 9001001 | Invalid resource ID. | 3873| 9001002 | No matching resource is found based on the resource ID. | 3874| 9001006 | The resource is referenced cyclically. | 3875 3876**Example** 3877 ```ts 3878 import { resourceManager } from '@kit.LocalizationKit' 3879 import { BusinessError } from '@kit.BasicServicesKit'; 3880 3881 let resource: resourceManager.Resource = { 3882 bundleName: "com.example.myapplication", 3883 moduleName: "entry", 3884 id: $r('app.color.test').id 3885 }; 3886 try { 3887 this.context.resourceManager.getColorSync(resource); 3888 } catch (error) { 3889 let code = (error as BusinessError).code; 3890 let message = (error as BusinessError).message; 3891 console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); 3892 } 3893 ``` 3894 3895### getColorByNameSync<sup>10+</sup> 3896 3897getColorByNameSync(resName: string) : number; 3898 3899Obtains a color value based on the specified resource name. This API returns the result synchronously. 3900 3901**Atomic service API**: This API can be used in atomic services since API version 11. 3902 3903**System capability**: SystemCapability.Global.ResourceManager 3904 3905**Parameters** 3906 3907| Name | Type | Mandatory | Description | 3908| ------- | ------ | ---- | ---- | 3909| resName | string | Yes | Resource name.| 3910 3911**Return value** 3912 3913| Type | Description | 3914| ------ | ---------- | 3915| number | Color value (decimal) corresponding to the specified resource name.| 3916 3917**Error codes** 3918 3919For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3920 3921| ID| Error Message| 3922| -------- | ---------------------------------------- | 3923| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3924| 9001003 | Invalid resource name. | 3925| 9001004 | No matching resource is found based on the resource name. | 3926| 9001006 | The resource is referenced cyclically. | 3927 3928**Example** 3929 ```ts 3930 import { BusinessError } from '@kit.BasicServicesKit'; 3931 3932 try { 3933 this.context.resourceManager.getColorByNameSync("test"); 3934 } catch (error) { 3935 let code = (error as BusinessError).code; 3936 let message = (error as BusinessError).message; 3937 console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`); 3938 } 3939 ``` 3940 3941### getColor<sup>10+</sup> 3942 3943getColor(resId: number, callback: _AsyncCallback<number>): void; 3944 3945Obtains a color value based on the specified resource ID. This API uses an asynchronous callback to return the result. 3946 3947**Atomic service API**: This API can be used in atomic services since API version 11. 3948 3949**System capability**: SystemCapability.Global.ResourceManager 3950 3951**Parameters** 3952 3953| Name | Type | Mandatory | Description | 3954| -------- | --------------------------- | ---- | --------------- | 3955| resId | number | Yes | Resource ID. | 3956| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 3957 3958**Error codes** 3959 3960For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 3961 3962| ID| Error Message| 3963| -------- | ---------------------------------------- | 3964| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 3965| 9001001 | If the module resId invalid. | 3966| 9001002 | No matching resource is found based on the resource ID. | 3967| 9001006 | The resource is referenced cyclically. | 3968 3969**Example (stage)** 3970 ```ts 3971 import { BusinessError } from '@kit.BasicServicesKit'; 3972 3973 try { 3974 this.context.resourceManager.getColor($r('app.color.test').id, (error: BusinessError, value: number) => { 3975 if (error != null) { 3976 console.error("error is " + error); 3977 } else { 3978 let str = value; 3979 } 3980 }); 3981 } catch (error) { 3982 let code = (error as BusinessError).code; 3983 let message = (error as BusinessError).message; 3984 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 3985 } 3986 ``` 3987 3988### getColor<sup>10+</sup> 3989 3990getColor(resId: number): Promise<number> 3991 3992Obtains a color value based on the specified resource ID. This API uses a promise to return the result. 3993 3994**Atomic service API**: This API can be used in atomic services since API version 11. 3995 3996**System capability**: SystemCapability.Global.ResourceManager 3997 3998**Parameters** 3999 4000| Name | Type | Mandatory | Description | 4001| ----- | ------ | ---- | ----- | 4002| resId | number | Yes | Resource ID.| 4003 4004**Return value** 4005 4006| Type | Description | 4007| --------------------- | ----------- | 4008| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4009 4010**Error codes** 4011 4012For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4013 4014| ID| Error Message| 4015| -------- | ---------------------------------------- | 4016| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4017| 9001001 | Invalid resource ID. | 4018| 9001002 | No matching resource is found based on the resource ID. | 4019| 9001006 | The resource is referenced cyclically. | 4020 4021**Example** 4022 ```ts 4023 import { BusinessError } from '@kit.BasicServicesKit'; 4024 4025 try { 4026 this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => { 4027 let str = value; 4028 }).catch((error: BusinessError) => { 4029 console.error("getColor promise error is " + error); 4030 }); 4031 } catch (error) { 4032 let code = (error as BusinessError).code; 4033 let message = (error as BusinessError).message; 4034 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4035 } 4036 ``` 4037 4038### getColor<sup>10+</sup> 4039 4040getColor(resource: Resource, callback: _AsyncCallback<number>): void; 4041 4042Obtains a color value based on the specified resource object. This API uses an asynchronous callback to return the result. 4043 4044**Atomic service API**: This API can be used in atomic services since API version 11. 4045 4046**System capability**: SystemCapability.Global.ResourceManager 4047 4048**Model restriction**: This API can be used only in the stage model. 4049 4050**Parameters** 4051 4052| Name | Type | Mandatory | Description | 4053| -------- | --------------------------- | ---- | --------------- | 4054| resource | [Resource](#resource9) | Yes | Resource object. | 4055| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| 4056 4057**Error codes** 4058 4059For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4060 4061| ID| Error Message| 4062| -------- | ---------------------------------------- | 4063| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4064| 9001001 | Invalid resource ID. | 4065| 9001002 | No matching resource is found based on the resource ID. | 4066| 9001006 | The resource is referenced cyclically. | 4067 4068**Example** 4069 ```ts 4070 import { resourceManager } from '@kit.LocalizationKit' 4071 import { BusinessError } from '@kit.BasicServicesKit'; 4072 4073 let resource: resourceManager.Resource = { 4074 bundleName: "com.example.myapplication", 4075 moduleName: "entry", 4076 id: $r('app.color.test').id 4077 }; 4078 try { 4079 this.context.resourceManager.getColor(resource, (error: BusinessError, value: number) => { 4080 if (error != null) { 4081 console.error("error is " + error); 4082 } else { 4083 let str = value; 4084 } 4085 }); 4086 } catch (error) { 4087 let code = (error as BusinessError).code; 4088 let message = (error as BusinessError).message; 4089 console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); 4090 } 4091 ``` 4092 4093### getColor<sup>10+</sup> 4094 4095getColor(resource: Resource): Promise<number>; 4096 4097Obtains a color value based on the specified resource object. This API uses a promise 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**Model restriction**: This API can be used only in the stage model. 4104 4105**Parameters** 4106 4107| Name | Type | Mandatory | Description | 4108| -------- | ---------------------- | ---- | ---- | 4109| resource | [Resource](#resource9) | Yes | Resource object.| 4110 4111**Return value** 4112 4113| Type | Description | 4114| --------------------- | ---------------- | 4115| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource object.| 4116 4117**Error codes** 4118 4119For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4120 4121| ID| Error Message| 4122| -------- | ---------------------------------------- | 4123| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4124| 9001001 | Invalid resource ID. | 4125| 9001002 | No matching resource is found based on the resource ID. | 4126| 9001006 | The resource is referenced cyclically. | 4127 4128**Example** 4129 ```ts 4130 import { resourceManager } from '@kit.LocalizationKit' 4131 import { BusinessError } from '@kit.BasicServicesKit'; 4132 4133 let resource: resourceManager.Resource = { 4134 bundleName: "com.example.myapplication", 4135 moduleName: "entry", 4136 id: $r('app.color.test').id 4137 }; 4138 try { 4139 this.context.resourceManager.getColor(resource).then((value: number) => { 4140 let str = value; 4141 }).catch((error: BusinessError) => { 4142 console.error("getColor promise error is " + error); 4143 }); 4144 } catch (error) { 4145 let code = (error as BusinessError).code; 4146 let message = (error as BusinessError).message; 4147 console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); 4148 } 4149 ``` 4150 4151### getColorByName<sup>10+</sup> 4152 4153getColorByName(resName: string, callback: _AsyncCallback<number>): void 4154 4155Obtains a color value based on the specified resource name. This API uses an asynchronous callback to return the result. 4156 4157**Atomic service API**: This API can be used in atomic services since API version 11. 4158 4159**System capability**: SystemCapability.Global.ResourceManager 4160 4161**Parameters** 4162 4163| Name | Type | Mandatory | Description | 4164| -------- | --------------------------- | ---- | --------------- | 4165| resName | string | Yes | Resource name. | 4166| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4167 4168**Error codes** 4169 4170For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4171 4172| ID| Error Message| 4173| -------- | ---------------------------------------- | 4174| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4175| 9001003 | Invalid resource name. | 4176| 9001004 | No matching resource is found based on the resource name. | 4177| 9001006 | The resource is referenced cyclically. | 4178 4179**Example** 4180 ```ts 4181 import { BusinessError } from '@kit.BasicServicesKit'; 4182 4183 try { 4184 this.context.resourceManager.getColorByName("test", (error: BusinessError, value: number) => { 4185 if (error != null) { 4186 console.error("error is " + error); 4187 } else { 4188 let string = value; 4189 } 4190 }); 4191 } catch (error) { 4192 let code = (error as BusinessError).code; 4193 let message = (error as BusinessError).message; 4194 console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`); 4195 } 4196 ``` 4197 4198### getColorByName<sup>10+</sup> 4199 4200getColorByName(resName: string): Promise<number> 4201 4202Obtains a color value based on the specified resource name. This API uses a promise to return the result. 4203 4204**Atomic service API**: This API can be used in atomic services since API version 11. 4205 4206**System capability**: SystemCapability.Global.ResourceManager 4207 4208**Parameters** 4209 4210| Name | Type | Mandatory | Description | 4211| ------- | ------ | ---- | ---- | 4212| resName | string | Yes | Resource name.| 4213 4214**Return value** 4215 4216| Type | Description | 4217| --------------------- | ---------- | 4218| Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource name.| 4219 4220**Error codes** 4221 4222For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4223 4224| ID| Error Message| 4225| -------- | ---------------------------------------- | 4226| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4227| 9001003 | Invalid resource name. | 4228| 9001004 | No matching resource is found based on the resource name. | 4229| 9001006 | The resource is referenced cyclically. | 4230 4231**Example** 4232 ```ts 4233 import { BusinessError } from '@kit.BasicServicesKit'; 4234 4235 try { 4236 this.context.resourceManager.getColorByName("test").then((value: number) => { 4237 let string = value; 4238 }).catch((error: BusinessError) => { 4239 console.error("getColorByName promise error is " + error); 4240 }); 4241 } catch (error) { 4242 let code = (error as BusinessError).code; 4243 let message = (error as BusinessError).message; 4244 console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`); 4245 } 4246 ``` 4247 4248### getRawFileContentSync<sup>10+</sup> 4249 4250getRawFileContentSync(path: string): Uint8Array 4251 4252Obtains the content of the raw file in the **resources/rawfile** directory. This API returns the result synchronously. 4253 4254**Atomic service API**: This API can be used in atomic services since API version 11. 4255 4256**System capability**: SystemCapability.Global.ResourceManager 4257 4258**Parameters** 4259 4260| Name | Type | Mandatory | Description | 4261| -------- | ------------------------------- | ---- | ----------------------- | 4262| path | string | Yes | Path of the raw file. | 4263 4264**Return value** 4265 4266| Type | Description | 4267| --------------------- | ---------- | 4268| Uint8Array | Content of the raw file.| 4269 4270**Error codes** 4271 4272For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4273 4274| ID| Error Message| 4275| -------- | ---------------------------------------- | 4276| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4277| 9001005 | Invalid relative path. | 4278 4279**Example** 4280 ```ts 4281 import { BusinessError } from '@kit.BasicServicesKit'; 4282 4283 try { 4284 this.context.resourceManager.getRawFileContentSync("test.txt"); 4285 } catch (error) { 4286 let code = (error as BusinessError).code; 4287 let message = (error as BusinessError).message; 4288 console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`); 4289 } 4290 ``` 4291 4292### getRawFileContent<sup>9+</sup> 4293 4294getRawFileContent(path: string, callback: _AsyncCallback<Uint8Array>): void 4295 4296Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4297 4298**Atomic service API**: This API can be used in atomic services since API version 11. 4299 4300**System capability**: SystemCapability.Global.ResourceManager 4301 4302**Parameters** 4303 4304| Name | Type | Mandatory | Description | 4305| -------- | ------------------------------- | ---- | ----------------------- | 4306| path | string | Yes | Path of the raw file. | 4307| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 4308 4309**Error codes** 4310 4311For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4312 4313| ID| Error Message| 4314| -------- | ---------------------------------------- | 4315| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4316 4317**Example** 4318 ```ts 4319 import { BusinessError } from '@kit.BasicServicesKit'; 4320 4321 try { 4322 this.context.resourceManager.getRawFileContent("test.txt", (error: BusinessError, value: Uint8Array) => { 4323 if (error != null) { 4324 console.error("error is " + error); 4325 } else { 4326 let rawFile = value; 4327 } 4328 }); 4329 } catch (error) { 4330 let code = (error as BusinessError).code; 4331 let message = (error as BusinessError).message; 4332 console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`); 4333 } 4334 ``` 4335 4336### getRawFileContent<sup>9+</sup> 4337 4338getRawFileContent(path: string): Promise<Uint8Array> 4339 4340Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 4341 4342**Atomic service API**: This API can be used in atomic services since API version 11. 4343 4344**System capability**: SystemCapability.Global.ResourceManager 4345 4346**Parameters** 4347 4348| Name | Type | Mandatory | Description | 4349| ---- | ------ | ---- | ----------- | 4350| path | string | Yes | Path of the raw file.| 4351 4352**Return value** 4353 4354| Type | Description | 4355| ------------------------- | ----------- | 4356| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 4357 4358**Error codes** 4359 4360For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4361 4362| ID| Error Message| 4363| -------- | ---------------------------------------- | 4364| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4365| 9001005 | Invalid relative path. | 4366 4367**Example** 4368 ```ts 4369 import { BusinessError } from '@kit.BasicServicesKit'; 4370 4371 try { 4372 this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => { 4373 let rawFile = value; 4374 }).catch((error: BusinessError) => { 4375 console.error("getRawFileContent promise error is " + error); 4376 }); 4377 } catch (error) { 4378 let code = (error as BusinessError).code; 4379 let message = (error as BusinessError).message; 4380 console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`); 4381 } 4382 ``` 4383 4384### getRawFileListSync<sup>10+</sup> 4385 4386getRawFileListSync(path: string): Array\<string> 4387 4388Obtains the list of folders and files in the **resources/rawfile** directory. This API returns the result synchronously. 4389 4390>**NOTE** 4391> 4392> 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. 4393 4394**Atomic service API**: This API can be used in atomic services since API version 11. 4395 4396**System capability**: SystemCapability.Global.ResourceManager 4397 4398**Parameters** 4399 4400| Name | Type | Mandatory | Description | 4401| -------- | ------------------------------- | ---- | ----------------------- | 4402| path | string | Yes | **rawfile** directory. | 4403 4404**Return value** 4405 4406| Type | Description | 4407| ------------------------- | ----------- | 4408| Array\<string> | List of folders and files in the **rawfile** directory.| 4409 4410**Error codes** 4411 4412For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4413 4414| ID| Error Message| 4415| -------- | ---------------------------------------- | 4416| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4417| 9001005 | Invalid relative path. | 4418 4419**Example** 4420 ```ts 4421 import { BusinessError } from '@kit.BasicServicesKit'; 4422 4423 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4424 this.context.resourceManager.getRawFileListSync("") 4425 } catch (error) { 4426 let code = (error as BusinessError).code; 4427 let message = (error as BusinessError).message; 4428 console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`); 4429 } 4430 ``` 4431 4432### getRawFileList<sup>10+</sup> 4433 4434getRawFileList(path: string, callback: _AsyncCallback<Array\<string\>>): void; 4435 4436Obtains the list of folders and files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 4437 4438>**NOTE** 4439> 4440> 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. 4441 4442**Atomic service API**: This API can be used in atomic services since API version 11. 4443 4444**System capability**: SystemCapability.Global.ResourceManager 4445 4446**Parameters** 4447 4448| Name | Type | Mandatory | Description | 4449| -------- | ------------------------------- | ---- | ----------------------- | 4450| path | string | Yes | **rawfile** directory. | 4451| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<Array\<string\>> | Yes| Callback used to return the result, which is the list of folders and files in the **rawfile** directory.| 4452 4453**Error codes** 4454 4455For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4456 4457| ID| Error Message| 4458| -------- | ---------------------------------------- | 4459| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4460| 9001005 | Invalid relative path. | 4461 4462**Example** 4463 ```ts 4464 import { BusinessError } from '@kit.BasicServicesKit'; 4465 4466 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4467 this.context.resourceManager.getRawFileList("", (error: BusinessError, value: Array<string>) => { 4468 if (error != null) { 4469 console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4470 } else { 4471 let rawFile = value; 4472 } 4473 }); 4474 } catch (error) { 4475 let code = (error as BusinessError).code; 4476 let message = (error as BusinessError).message; 4477 console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`); 4478 } 4479 ``` 4480 4481### getRawFileList<sup>10+</sup> 4482 4483getRawFileList(path: string): Promise<Array\<string\>> 4484 4485Obtains the list of folders and files in the **resources/rawfile** directory. This API uses a promise to return the result. 4486 4487>**NOTE** 4488> 4489> 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. 4490 4491**Atomic service API**: This API can be used in atomic services since API version 11. 4492 4493**System capability**: SystemCapability.Global.ResourceManager 4494 4495**Parameters** 4496 4497| Name | Type | Mandatory | Description | 4498| ---- | ------ | ---- | ----------- | 4499| path | string | Yes | **rawfile** directory.| 4500 4501**Return value** 4502 4503| Type | Description | 4504| ------------------------- | ----------- | 4505| Promise<Array\<string\>> | Promise used to return the result, which is the list of folders and files in the **rawfile** directory.| 4506 4507**Error codes** 4508 4509For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4510 4511| ID| Error Message| 4512| -------- | ---------------------------------------- | 4513| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4514| 9001005 | Invalid relative path. | 4515 4516**Example** 4517 ```ts 4518 import { BusinessError } from '@kit.BasicServicesKit'; 4519 4520 try { // Passing "" means to obtain the list of files in the root directory of the raw file. 4521 this.context.resourceManager.getRawFileList("").then((value: Array<string>) => { 4522 let rawFile = value; 4523 }).catch((error: BusinessError) => { 4524 console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); 4525 }); 4526 } catch (error) { 4527 let code = (error as BusinessError).code; 4528 let message = (error as BusinessError).message; 4529 console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`); 4530 } 4531 ``` 4532 4533### getRawFdSync<sup>10+</sup> 4534 4535getRawFdSync(path: string): RawFileDescriptor 4536 4537Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4538 4539**Atomic service API**: This API can be used in atomic services since API version 11. 4540 4541**System capability**: SystemCapability.Global.ResourceManager 4542 4543**Parameters** 4544 4545| Name | Type | Mandatory | Description | 4546| -------- | ---------------------------------------- | ---- | -------------------------------- | 4547| path | string | Yes | Path of the raw file. | 4548 4549**Return value** 4550 4551| Type | Description | 4552| ------------------------- | ----------- | 4553| [RawFileDescriptor](#rawfiledescriptor9) | Descriptor of the HAP where the raw file is located.| 4554 4555**Error codes** 4556 4557For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4558 4559| ID| Error Message| 4560| -------- | ---------------------------------------- | 4561| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4562| 9001005 | Invalid relative path. | 4563 4564**Example** 4565 ```ts 4566 import { BusinessError } from '@kit.BasicServicesKit'; 4567 4568 try { 4569 this.context.resourceManager.getRawFdSync("test.txt"); 4570 } catch (error) { 4571 let code = (error as BusinessError).code; 4572 let message = (error as BusinessError).message; 4573 console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`); 4574 } 4575 ``` 4576 4577### getRawFd<sup>9+</sup> 4578 4579getRawFd(path: string, callback: _AsyncCallback<RawFileDescriptor>): void 4580 4581Obtains 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. 4582 4583**Atomic service API**: This API can be used in atomic services since API version 11. 4584 4585**System capability**: SystemCapability.Global.ResourceManager 4586 4587**Parameters** 4588 4589| Name | Type | Mandatory | Description | 4590| -------- | ---------------------------------------- | ---- | -------------------------------- | 4591| path | string | Yes | Path of the raw file. | 4592| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<[RawFileDescriptor](#rawfiledescriptor9)> | Yes | Callback used to return the result, which is the descriptor of the HAP where the raw file is located.| 4593 4594**Error codes** 4595 4596For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4597 4598| ID| Error Message| 4599| -------- | ---------------------------------------- | 4600| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4601| 9001005 | Invalid relative path. | 4602 4603**Example** 4604 ```ts 4605 import { BusinessError } from '@kit.BasicServicesKit'; 4606 import { resourceManager } from '@kit.LocalizationKit' 4607 4608 try { 4609 this.context.resourceManager.getRawFd("test.txt", (error: BusinessError, value: resourceManager.RawFileDescriptor) => { 4610 if (error != null) { 4611 console.error(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); 4612 } else { 4613 let fd = value.fd; 4614 let offset = value.offset; 4615 let length = value.length; 4616 } 4617 }); 4618 } catch (error) { 4619 let code = (error as BusinessError).code; 4620 let message = (error as BusinessError).message; 4621 console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`); 4622 } 4623 ``` 4624 4625### getRawFd<sup>9+</sup> 4626 4627getRawFd(path: string): Promise<RawFileDescriptor> 4628 4629Obtains 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. 4630 4631**Atomic service API**: This API can be used in atomic services since API version 11. 4632 4633**System capability**: SystemCapability.Global.ResourceManager 4634 4635**Parameters** 4636 4637| Name | Type | Mandatory | Description | 4638| ---- | ------ | ---- | ----------- | 4639| path | string | Yes | Path of the raw file.| 4640 4641**Return value** 4642 4643| Type | Description | 4644| ---------------------------------------- | ------------------- | 4645| Promise<[RawFileDescriptor](#rawfiledescriptor9)> | Descriptor of the HAP where the raw file is located.| 4646 4647**Error codes** 4648 4649For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4650 4651| ID| Error Message| 4652| -------- | ---------------------------------------- | 4653| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4654| 9001005 | Invalid relative path. | 4655 4656**Example** 4657 ```ts 4658 import { BusinessError } from '@kit.BasicServicesKit'; 4659 import { resourceManager } from '@kit.LocalizationKit' 4660 4661 try { 4662 this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => { 4663 let fd = value.fd; 4664 let offset = value.offset; 4665 let length = value.length; 4666 }).catch((error: BusinessError) => { 4667 console.error(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); 4668 }); 4669 } catch (error) { 4670 let code = (error as BusinessError).code; 4671 let message = (error as BusinessError).message; 4672 console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`); 4673 } 4674 ``` 4675 4676### closeRawFdSync<sup>10+</sup> 4677 4678closeRawFdSync(path: string): void 4679 4680Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. 4681 4682**Atomic service API**: This API can be used in atomic services since API version 11. 4683 4684**System capability**: SystemCapability.Global.ResourceManager 4685 4686**Parameters** 4687 4688| Name | Type | Mandatory | Description | 4689| -------- | ------------------------- | ---- | ----------- | 4690| path | string | Yes | Path of the raw file.| 4691 4692**Error codes** 4693 4694For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 4695 4696| ID| Error Message| 4697| -------- | ---------------------------------------- | 4698| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4699| 9001005 | The resource not found by path. | 4700 4701**Example** 4702 ```ts 4703 import { BusinessError } from '@kit.BasicServicesKit'; 4704 4705 try { 4706 this.context.resourceManager.closeRawFdSync("test.txt"); 4707 } catch (error) { 4708 let code = (error as BusinessError).code; 4709 let message = (error as BusinessError).message; 4710 console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`); 4711 } 4712 ``` 4713 4714### closeRawFd<sup>9+</sup> 4715 4716closeRawFd(path: string, callback: _AsyncCallback<void>): void 4717 4718Closes 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. 4719 4720**Atomic service API**: This API can be used in atomic services since API version 11. 4721 4722**System capability**: SystemCapability.Global.ResourceManager 4723 4724**Parameters** 4725 4726| Name | Type | Mandatory | Description | 4727| -------- | ------------------------- | ---- | ----------- | 4728| path | string | Yes | Path of the raw file.| 4729| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<void> | Yes | Callback used to return the result. | 4730 4731**Error codes** 4732 4733For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4734 4735| ID| Error Message| 4736| -------- | ---------------------------------------- | 4737| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4738| 9001005 | The resource not found by path. | 4739 4740**Example** 4741 ```ts 4742 import { BusinessError } from '@kit.BasicServicesKit'; 4743 4744 try { 4745 this.context.resourceManager.closeRawFd("test.txt", (error: BusinessError) => { 4746 if (error != null) { 4747 console.error("error is " + error); 4748 } 4749 }); 4750 } catch (error) { 4751 let code = (error as BusinessError).code; 4752 let message = (error as BusinessError).message; 4753 console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`); 4754 } 4755 ``` 4756 4757### closeRawFd<sup>9+</sup> 4758 4759closeRawFd(path: string): Promise<void> 4760 4761Closes 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. 4762 4763**Atomic service API**: This API can be used in atomic services since API version 11. 4764 4765**System capability**: SystemCapability.Global.ResourceManager 4766 4767**Parameters** 4768 4769| Name | Type | Mandatory | Description | 4770| ---- | ------ | ---- | ----------- | 4771| path | string | Yes | Path of the raw file.| 4772 4773**Return value** 4774 4775| Type | Description | 4776| ------------------- | ---- | 4777| Promise<void> | Promise that returns no value.| 4778 4779**Error codes** 4780 4781For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 4782 4783| ID| Error Message| 4784| -------- | ---------------------------------------- | 4785| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 4786| 9001005 | Invalid relative path. | 4787 4788**Example** 4789 ```ts 4790 import { BusinessError } from '@kit.BasicServicesKit'; 4791 4792 try { 4793 this.context.resourceManager.closeRawFd("test.txt"); 4794 } catch (error) { 4795 let code = (error as BusinessError).code; 4796 let message = (error as BusinessError).message; 4797 console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`); 4798 } 4799 ``` 4800 4801### getConfigurationSync<sup>10+</sup> 4802 4803getConfigurationSync(): Configuration 4804 4805Obtains the device configuration. This API returns the result synchronously. 4806 4807**Atomic service API**: This API can be used in atomic services since API version 11. 4808 4809**System capability**: SystemCapability.Global.ResourceManager 4810 4811**Return value** 4812 4813| Type | Description | 4814| ---------------------------------------- | ---------------- | 4815| [Configuration](#configuration) | Device configuration.| 4816 4817**Example** 4818 ```ts 4819 try { 4820 let value = this.context.resourceManager.getConfigurationSync(); 4821 let direction = value.direction; 4822 let locale = value.locale; 4823 } catch (error) { 4824 console.error("getConfigurationSync error is " + error); 4825 } 4826 ``` 4827 4828### getConfiguration 4829 4830getConfiguration(callback: _AsyncCallback<Configuration>): void 4831 4832Obtains the device configuration. This API uses an asynchronous callback to return the result. 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| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<[Configuration](#configuration)> | Yes | Callback used to return the result, which is the device configuration.| 4843 4844**Example** 4845 ```ts 4846 import { resourceManager } from '@kit.LocalizationKit' 4847 4848 try { 4849 this.context.resourceManager.getConfiguration((error: BusinessError, value: resourceManager.Configuration) => { 4850 if (error != null) { 4851 console.error("getConfiguration callback error is " + error); 4852 } else { 4853 let direction = value.direction; 4854 let locale = value.locale; 4855 } 4856 }); 4857 } catch (error) { 4858 console.error("getConfiguration callback error is " + error); 4859 } 4860 ``` 4861 4862### getConfiguration 4863 4864getConfiguration(): Promise<Configuration> 4865 4866Obtains the device configuration. This API uses a promise to return the result. 4867 4868**Atomic service API**: This API can be used in atomic services since API version 11. 4869 4870**System capability**: SystemCapability.Global.ResourceManager 4871 4872**Return value** 4873 4874| Type | Description | 4875| ---------------------------------------- | ---------------- | 4876| Promise<[Configuration](#configuration)> | Promise used to return the result, which is the device configuration.| 4877 4878**Example** 4879 ```ts 4880 import { BusinessError } from '@kit.BasicServicesKit'; 4881 import { resourceManager } from '@kit.LocalizationKit' 4882 4883 try { 4884 this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => { 4885 let direction = value.direction; 4886 let locale = value.locale; 4887 }).catch((error: BusinessError) => { 4888 console.error("getConfiguration promise error is " + error); 4889 }); 4890 } catch (error) { 4891 console.error("getConfiguration promise error is " + error); 4892 } 4893 ``` 4894 4895### getDeviceCapabilitySync<sup>10+</sup> 4896 4897getDeviceCapabilitySync(): DeviceCapability 4898 4899Obtains the device capability. This API returns the result synchronously. 4900 4901**Atomic service API**: This API can be used in atomic services since API version 11. 4902 4903**System capability**: SystemCapability.Global.ResourceManager 4904 4905**Return value** 4906 4907| Type | Description | 4908| ---------------------------------------- | ------------------- | 4909| [DeviceCapability](#devicecapability) | Device capability.| 4910 4911**Example** 4912 ```ts 4913 try { 4914 let value = this.context.resourceManager.getDeviceCapabilitySync(); 4915 let screenDensity = value.screenDensity; 4916 let deviceType = value.deviceType; 4917 } catch (error) { 4918 console.error("getDeviceCapabilitySync error is " + error); 4919 } 4920 ``` 4921 4922### getDeviceCapability 4923 4924getDeviceCapability(callback: _AsyncCallback<DeviceCapability>): void 4925 4926Obtains the device capability. This API uses an asynchronous callback to return the result. 4927 4928**Atomic service API**: This API can be used in atomic services since API version 11. 4929 4930**System capability**: SystemCapability.Global.ResourceManager 4931 4932**Parameters** 4933 4934| Name | Type | Mandatory | Description | 4935| -------- | ---------------------------------------- | ---- | ---------------------------- | 4936| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result, which is the device capability.| 4937 4938**Example** 4939 ```ts 4940 import { resourceManager } from '@kit.LocalizationKit' 4941 4942 try { 4943 this.context.resourceManager.getDeviceCapability((error: BusinessError, value: resourceManager.DeviceCapability) => { 4944 if (error != null) { 4945 console.error("getDeviceCapability callback error is " + error); 4946 } else { 4947 let screenDensity = value.screenDensity; 4948 let deviceType = value.deviceType; 4949 } 4950 }); 4951 } catch (error) { 4952 console.error("getDeviceCapability callback error is " + error); 4953 } 4954 ``` 4955 4956### getDeviceCapability 4957 4958getDeviceCapability(): Promise<DeviceCapability> 4959 4960Obtains the device capability. This API uses a promise to return the result. 4961 4962**Atomic service API**: This API can be used in atomic services since API version 11. 4963 4964**System capability**: SystemCapability.Global.ResourceManager 4965 4966**Return value** 4967 4968| Type | Description | 4969| ---------------------------------------- | ------------------- | 4970| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result, which is the device capability.| 4971 4972**Example** 4973 ```ts 4974 import { BusinessError } from '@kit.BasicServicesKit'; 4975 import { resourceManager } from '@kit.LocalizationKit' 4976 4977 try { 4978 this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => { 4979 let screenDensity = value.screenDensity; 4980 let deviceType = value.deviceType; 4981 }).catch((error: BusinessError) => { 4982 console.error("getDeviceCapability promise error is " + error); 4983 }); 4984 } catch (error) { 4985 console.error("getDeviceCapability promise error is " + error); 4986 } 4987 ``` 4988 4989### addResource<sup>10+</sup> 4990 4991addResource(path: string) : void 4992 4993Loads resources from the specified path. 4994 4995**Atomic service API**: This API can be used in atomic services since API version 11. 4996 4997**System capability**: SystemCapability.Global.ResourceManager 4998 4999**Parameters** 5000 5001| Name | Type | Mandatory | Description | 5002| -------- | ---------------------- | ---- | ---- | 5003| path | string | Yes | Resource path.| 5004 5005**Error codes** 5006 5007For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5008 5009| ID| Error Message| 5010| -------- | ---------------------------------------- | 5011| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5012| 9001010 | Invalid overlay path. | 5013 5014**Example** 5015 ```ts 5016 import { BusinessError } from '@kit.BasicServicesKit'; 5017 5018 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5019 try { 5020 this.context.resourceManager.addResource(path); 5021 } catch (error) { 5022 let code = (error as BusinessError).code; 5023 let message = (error as BusinessError).message; 5024 console.error(`addResource failed, error code: ${code}, message: ${message}.`); 5025 } 5026 ``` 5027 5028### removeResource<sup>10+</sup> 5029 5030removeResource(path: string) : void 5031 5032Removes the resources loaded from the specified path to restore the original resources. 5033 5034**Atomic service API**: This API can be used in atomic services since API version 11. 5035 5036**System capability**: SystemCapability.Global.ResourceManager 5037 5038**Parameters** 5039 5040| Name | Type | Mandatory | Description | 5041| -------- | ---------------------- | ---- | ---- | 5042| path | string | Yes | Resource path.| 5043 5044**Error codes** 5045 5046For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5047 5048| ID| Error Message| 5049| -------- | ---------------------------------------- | 5050| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5051| 9001010 | Invalid overlay path. | 5052 5053**Example** 5054 ```ts 5055 import { BusinessError } from '@kit.BasicServicesKit'; 5056 5057 let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; 5058 try { 5059 this.context.resourceManager.removeResource(path); 5060 } catch (error) { 5061 let code = (error as BusinessError).code; 5062 let message = (error as BusinessError).message; 5063 console.error(`removeResource failed, error code: ${code}, message: ${message}.`); 5064 } 5065 ``` 5066 5067### getLocales<sup>11+</sup> 5068 5069getLocales(includeSystem?: boolean): Array\<string> 5070 5071Obtains the language list of an application. 5072 5073**Atomic service API**: This API can be used in atomic services since API version 11. 5074 5075**System capability**: SystemCapability.Global.ResourceManager 5076 5077**Parameters** 5078 5079| Name | Type | Mandatory | Description | 5080| -------------- | ------- | ------ | -------------------- | 5081| 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.| 5082 5083**Return value** 5084 5085| Type | Description | 5086| ------------------------- | ----------- | 5087| 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 (-).| 5088 5089**Example** 5090 ```ts 5091 import { resourceManager } from '@kit.LocalizationKit' 5092 import { BusinessError } from '@kit.BasicServicesKit'; 5093 5094 try { 5095 this.context.resourceManager.getLocales(); // Obtain only the language list of application resources. 5096 } catch (error) { 5097 let code = (error as BusinessError).code; 5098 let message = (error as BusinessError).message; 5099 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5100 } 5101 5102 try { 5103 resourceManager.getSystemResourceManager().getLocales(); // Obtain only the language list of system resources. 5104 } catch (error) { 5105 let code = (error as BusinessError).code; 5106 let message = (error as BusinessError).message; 5107 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5108 } 5109 5110 try { 5111 this.context.resourceManager.getLocales(true); // Obtain the language list of application resources and resources. 5112 } catch (error) { 5113 let code = (error as BusinessError).code; 5114 let message = (error as BusinessError).message; 5115 console.error(`getLocales failed, error code: ${code}, message: ${message}.`); 5116 } 5117 ``` 5118 5119### getSymbol<sup>11+</sup> 5120 5121getSymbol(resId: number):number 5122 5123Obtains a symbol value based on the specified resource ID. This API returns the result synchronously. 5124 5125**Atomic service API**: This API can be used in atomic services since API version 11. 5126 5127**System capability**: SystemCapability.Global.ResourceManager 5128 5129**Parameters** 5130 5131| Name | Type | Mandatory | Description | 5132| ----- | ------ | ---- | ----- | 5133| resId | number | Yes | Resource ID.| 5134 5135**Return value** 5136 5137| Type | Description | 5138| ------ | ----------- | 5139| number | Symbol value (decimal) corresponding to the specified resource ID.| 5140 5141**Error codes** 5142 5143For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5144 5145| ID| Error Message| 5146| -------- | ---------------------------------------- | 5147| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5148| 9001001 | Invalid resource ID. | 5149| 9001002 | No matching resource is found based on the resource ID. | 5150| 9001006 | The resource is referenced cyclically. | 5151 5152**Example** 5153 ```ts 5154 import { BusinessError } from '@kit.BasicServicesKit'; 5155 5156 try { 5157 this.context.resourceManager.getSymbol($r('app.symbol.test').id); 5158 } catch (error) { 5159 let code = (error as BusinessError).code; 5160 let message = (error as BusinessError).message; 5161 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5162 } 5163 ``` 5164 5165### getSymbol<sup>11+</sup> 5166getSymbol(resource: Resource): number 5167 5168Obtains a symbol value based on the specified resource object. This API returns the result synchronously. 5169 5170**Atomic service API**: This API can be used in atomic services since API version 11. 5171 5172**System capability**: SystemCapability.Global.ResourceManager 5173 5174**Model restriction**: This API can be used only in the stage model. 5175 5176**Parameters** 5177 5178| Name | Type | Mandatory | Description | 5179| -------- | ---------------------- | ---- | ---- | 5180| resource | [Resource](#resource9) | Yes | Resource object.| 5181 5182**Return value** 5183 5184| Type | Description | 5185| ------ | ----------- | 5186| number | Symbol value (decimal) corresponding to the specified resource object.| 5187 5188**Error codes** 5189 5190For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5191 5192| ID| Error Message| 5193| -------- | ---------------------------------------- | 5194| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5195| 9001001 | Invalid resource ID. | 5196| 9001002 | No matching resource is found based on the resource ID. | 5197| 9001006 | The resource is referenced cyclically. | 5198 5199**Example** 5200 ```ts 5201 import { resourceManager } from '@kit.LocalizationKit' 5202 import { BusinessError } from '@kit.BasicServicesKit'; 5203 5204 let resource: resourceManager.Resource = { 5205 bundleName: "com.example.myapplication", 5206 moduleName: "entry", 5207 id: $r('app.symbol.test').id 5208 }; 5209 try { 5210 this.context.resourceManager.getSymbol(resource); 5211 } catch (error) { 5212 let code = (error as BusinessError).code; 5213 let message = (error as BusinessError).message; 5214 console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); 5215 } 5216 ``` 5217 5218### getSymbolByName<sup>11+</sup> 5219 5220getSymbolByName(resName: string) : number; 5221 5222Obtains a symbol value based on the specified resource name. This API returns the result synchronously. 5223 5224**Atomic service API**: This API can be used in atomic services since API version 11. 5225 5226**System capability**: SystemCapability.Global.ResourceManager 5227 5228**Parameters** 5229 5230| Name | Type | Mandatory | Description | 5231| ------- | ------ | ---- | ---- | 5232| resName | string | Yes | Resource name.| 5233 5234**Return value** 5235 5236| Type | Description | 5237| ------ | ---------- | 5238| number | Symbol value (decimal) corresponding to the specified resource name.| 5239 5240**Error codes** 5241 5242For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5243 5244| ID| Error Message| 5245| -------- | ---------------------------------------- | 5246| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5247| 9001003 | Invalid resource name. | 5248| 9001004 | No matching resource is found based on the resource name. | 5249| 9001006 | The resource is referenced cyclically. | 5250 5251**Example** 5252 ```ts 5253 import { BusinessError } from '@kit.BasicServicesKit'; 5254 5255 try { 5256 this.context.resourceManager.getSymbolByName("test"); 5257 } catch (error) { 5258 let code = (error as BusinessError).code; 5259 let message = (error as BusinessError).message; 5260 console.error(`getSymbolByName failed, error code: ${code}, message: ${message}.`); 5261 } 5262 ``` 5263 5264### isRawDir<sup>12+</sup> 5265 5266isRawDir(path: string) : bool 5267 5268Checks whether a path is a subdirectory in the **rawfile** directory. This API returns the result synchronously. 5269 5270**Atomic service API**: This API can be used in atomic services since API version 12. 5271 5272**System capability**: SystemCapability.Global.ResourceManager 5273 5274**Parameters** 5275 5276| Name | Type | Mandatory | Description | 5277| ------- | ------ | ---- | ---- | 5278| path | string | Yes | Path of a raw file.| 5279 5280**Return value** 5281 5282| Type | Description | 5283| ------ | ---------- | 5284| 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.| 5285 5286**Error codes** 5287 5288For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5289 5290| ID| Error Message| 5291| -------- | ---------------------------------------- | 5292| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5293| 9001005 | Invalid relative path. | 5294 5295**Example** 5296 ```ts 5297 import { BusinessError } from '@kit.BasicServicesKit'; 5298 5299 try { 5300 this.context.resourceManager.isRawDir("test.txt"); 5301 } catch (error) { 5302 let code = (error as BusinessError).code; 5303 let message = (error as BusinessError).message; 5304 console.error(`isRawDir failed, error code: ${code}, message: ${message}.`); 5305 } 5306 ``` 5307 5308### getOverrideResourceManager<sup>12+</sup> 5309 5310getOverrideResourceManager(configuration?: Configuration) : ResourceManager 5311 5312Obtains a **ResourceManager** object for loading differentiated resources. This API returns the result synchronously. 5313 5314The 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. 5315 5316**Atomic service API**: This API can be used in atomic services since API version 12. 5317 5318**System capability**: SystemCapability.Global.ResourceManager 5319 5320**Parameters** 5321 5322| Name | Type | Mandatory| Description | 5323| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5324| 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.| 5325 5326**Return value** 5327 5328| Type | Description | 5329| --------------- | ---------------------------------- | 5330| ResourceManager | **ResourceManager** object for loading differentiated resources.| 5331 5332**Error codes** 5333 5334For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5335 5336| ID| Error Message | 5337| -------- | ------------------------------------------------------------ | 5338| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5339 5340**Example** 5341 5342 ```ts 5343 import { BusinessError } from '@kit.BasicServicesKit'; 5344 import { resourceManager } from '@kit.LocalizationKit' 5345 5346 try { 5347 let resMgr = this.context.resourceManager 5348 let overrideConfig = resMgr.getOverrideConfiguration() 5349 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5350 let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) 5351 } catch (error) { 5352 let code = (error as BusinessError).code; 5353 let message = (error as BusinessError).message; 5354 console.error(`getOverrideResourceManager failed, error code: ${code}, message: ${message}.`); 5355 } 5356 ``` 5357 5358### getOverrideConfiguration<sup>12+</sup> 5359 5360getOverrideConfiguration() : Configuration 5361 5362Obtains 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. 5363 5364**Atomic service API**: This API can be used in atomic services since API version 12. 5365 5366**System capability**: SystemCapability.Global.ResourceManager 5367 5368**Return value** 5369 5370| Type | Description | 5371| ------------------------------- | ---------------- | 5372| [Configuration](#configuration) | Configuration of differentiated resources.| 5373 5374**Example** 5375 5376 ```ts 5377 import { BusinessError } from '@kit.BasicServicesKit'; 5378 import { resourceManager } from '@kit.LocalizationKit' 5379 5380 let overrideConfig = this.context.resourceManager.getOverrideConfiguration() 5381 ``` 5382 5383### updateOverrideConfiguration<sup>12+</sup> 5384 5385updateOverrideConfiguration(configuration: Configuration) : void 5386 5387Updated 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. 5388 5389**Atomic service API**: This API can be used in atomic services since API version 12. 5390 5391**System capability**: SystemCapability.Global.ResourceManager 5392 5393**Parameters** 5394 5395| Name | Type | Mandatory| Description | 5396| ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | 5397| 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.| 5398 5399**Error codes** 5400 5401For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 5402 5403| ID| Error Message | 5404| -------- | ------------------------------------------------------------ | 5405| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | 5406 5407**Example** 5408 5409 ```ts 5410 import { BusinessError } from '@kit.BasicServicesKit'; 5411 import { resourceManager } from '@kit.LocalizationKit' 5412 5413 try { 5414 let resMgr = this.context.resourceManager 5415 let overrideConfig = resMgr.getOverrideConfiguration() 5416 overrideConfig.colorMode = resourceManager.ColorMode.DARK 5417 let overrideResMgr = resMgr.updateOverrideConfiguration(overrideConfig) 5418 } catch (error) { 5419 let code = (error as BusinessError).code; 5420 let message = (error as BusinessError).message; 5421 console.error(`updateOverrideConfiguration failed, error code: ${code}, message: ${message}.`); 5422 } 5423 ``` 5424 5425### release<sup>(deprecated)</sup> 5426 5427release() 5428 5429Releases a **ResourceManager** object. This API is not supported currently. 5430 5431This API is supported since API version 7 and is deprecated since API version 12. 5432 5433**Atomic service API**: This API can be used in atomic services since API version 11. 5434 5435**System capability**: SystemCapability.Global.ResourceManager 5436 5437**Example** 5438 ```ts 5439 try { 5440 this.context.resourceManager.release(); 5441 } catch (error) { 5442 console.error("release error is " + error); 5443 } 5444 ``` 5445 5446### getString<sup>(deprecated)</sup> 5447 5448getString(resId: number, callback: AsyncCallback<string>): void 5449 5450Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. 5451 5452This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9). 5453 5454**System capability**: SystemCapability.Global.ResourceManager 5455 5456**Parameters** 5457 5458| Name | Type | Mandatory | Description | 5459| -------- | --------------------------- | ---- | --------------- | 5460| resId | number | Yes | Resource ID. | 5461| callback | [AsyncCallback](#asynccallbackdeprecated)<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| 5462 5463**Example** 5464 ```ts 5465 resourceManager.getResourceManager((error, mgr) => { 5466 mgr.getString($r('app.string.test').id, (error: Error, value: string) => { 5467 if (error != null) { 5468 console.error("error is " + error); 5469 } else { 5470 let str = value; 5471 } 5472 }); 5473 }); 5474 ``` 5475 5476 5477### getString<sup>(deprecated)</sup> 5478 5479getString(resId: number): Promise<string> 5480 5481Obtains a string based on the specified resource ID. This API uses a promise to return the result. 5482 5483This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1). 5484 5485**System capability**: SystemCapability.Global.ResourceManager 5486 5487**Parameters** 5488 5489| Name | Type | Mandatory | Description | 5490| ----- | ------ | ---- | ----- | 5491| resId | number | Yes | Resource ID.| 5492 5493**Return value** 5494 5495| Type | Description | 5496| --------------------- | ----------- | 5497| Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| 5498 5499**Example** 5500 ```ts 5501 import { BusinessError } from '@kit.BasicServicesKit'; 5502 5503 resourceManager.getResourceManager((error, mgr) => { 5504 mgr.getString($r('app.string.test').id).then((value: string) => { 5505 let str = value; 5506 }).catch((error: BusinessError) => { 5507 console.error("getstring promise error is " + error); 5508 }); 5509 }); 5510 ``` 5511 5512 5513### getStringArray<sup>(deprecated)</sup> 5514 5515getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void 5516 5517Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. 5518 5519This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9). 5520 5521**System capability**: SystemCapability.Global.ResourceManager 5522 5523**Parameters** 5524 5525| Name | Type | Mandatory | Description | 5526| -------- | ---------------------------------------- | ---- | ----------------- | 5527| resId | number | Yes | Resource ID. | 5528| callback | [AsyncCallback](#asynccallbackdeprecated)<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| 5529 5530**Example** 5531 ```ts 5532 resourceManager.getResourceManager((error, mgr) => { 5533 mgr.getStringArray($r('app.strarray.test').id, (error: Error, value: Array<string>) => { 5534 if (error != null) { 5535 console.error("error is " + error); 5536 } else { 5537 let strArray = value; 5538 } 5539 }); 5540 }); 5541 ``` 5542 5543 5544### getStringArray<sup>(deprecated)</sup> 5545 5546getStringArray(resId: number): Promise<Array<string>> 5547 5548Obtains a string array based on the specified resource ID. This API uses a promise to return the result. 5549 5550This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1). 5551 5552**System capability**: SystemCapability.Global.ResourceManager 5553 5554**Parameters** 5555 5556| Name | Type | Mandatory | Description | 5557| ----- | ------ | ---- | ----- | 5558| resId | number | Yes | Resource ID.| 5559 5560**Return value** 5561 5562| Type | Description | 5563| ---------------------------------- | ------------- | 5564| Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| 5565 5566**Example** 5567 ```ts 5568 import { BusinessError } from '@kit.BasicServicesKit'; 5569 5570 resourceManager.getResourceManager((error, mgr) => { 5571 mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => { 5572 let strArray = value; 5573 }).catch((error: BusinessError) => { 5574 console.error("getStringArray promise error is " + error); 5575 }); 5576 }); 5577 ``` 5578 5579 5580### getMedia<sup>(deprecated)</sup> 5581 5582getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void 5583 5584Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. 5585 5586This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9). 5587 5588**System capability**: SystemCapability.Global.ResourceManager 5589 5590**Parameters** 5591 5592| Name | Type | Mandatory | Description | 5593| -------- | ------------------------------- | ---- | ------------------ | 5594| resId | number | Yes | Resource ID. | 5595| callback | [AsyncCallback](#asynccallbackdeprecated)<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5596 5597**Example** 5598 ```ts 5599 resourceManager.getResourceManager((error, mgr) => { 5600 mgr.getMedia($r('app.media.test').id, (error: Error, value: Uint8Array) => { 5601 if (error != null) { 5602 console.error("error is " + error); 5603 } else { 5604 let media = value; 5605 } 5606 }); 5607 }); 5608 ``` 5609 5610### getMedia<sup>(deprecated)</sup> 5611 5612getMedia(resId: number): Promise<Uint8Array> 5613 5614Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. 5615 5616This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1). 5617 5618**System capability**: SystemCapability.Global.ResourceManager 5619 5620**Parameters** 5621 5622| Name | Type | Mandatory | Description | 5623| ----- | ------ | ---- | ----- | 5624| resId | number | Yes | Resource ID.| 5625 5626**Return value** 5627 5628| Type | Description | 5629| ------------------------- | -------------- | 5630| Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| 5631 5632**Example** 5633 ```ts 5634 import { BusinessError } from '@kit.BasicServicesKit'; 5635 5636 resourceManager.getResourceManager((error, mgr) => { 5637 mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => { 5638 let media = value; 5639 }).catch((error: BusinessError) => { 5640 console.error("getMedia promise error is " + error); 5641 }); 5642 }); 5643 ``` 5644 5645 5646### getMediaBase64<sup>(deprecated)</sup> 5647 5648getMediaBase64(resId: number, callback: AsyncCallback<string>): void 5649 5650Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. 5651 5652This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649). 5653 5654**System capability**: SystemCapability.Global.ResourceManager 5655 5656**Parameters** 5657 5658| Name | Type | Mandatory | Description | 5659| -------- | --------------------------- | ---- | ------------------------ | 5660| resId | number | Yes | Resource ID. | 5661| callback | [AsyncCallback](#asynccallbackdeprecated)<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5662 5663**Example** 5664 ```ts 5665 resourceManager.getResourceManager((error, mgr) => { 5666 mgr.getMediaBase64($r('app.media.test').id, ((error: Error, value: string) => { 5667 if (error != null) { 5668 console.error("error is " + error); 5669 } else { 5670 let media = value; 5671 } 5672 }); 5673 }); 5674 ``` 5675 5676 5677### getMediaBase64<sup>(deprecated)</sup> 5678 5679getMediaBase64(resId: number): Promise<string> 5680 5681Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. 5682 5683This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1). 5684 5685**System capability**: SystemCapability.Global.ResourceManager 5686 5687**Parameters** 5688 5689| Name | Type | Mandatory | Description | 5690| ----- | ------ | ---- | ----- | 5691| resId | number | Yes | Resource ID.| 5692 5693**Return value** 5694 5695| Type | Description | 5696| --------------------- | -------------------- | 5697| Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| 5698 5699**Example** 5700 ```ts 5701 import { BusinessError } from '@kit.BasicServicesKit'; 5702 5703 resourceManager.getResourceManager((error, mgr) => { 5704 mgr.getMediaBase64($r('app.media.test').id).then((value: string) => { 5705 let media = value; 5706 }).catch((error: BusinessError) => { 5707 console.error("getMediaBase64 promise error is " + error); 5708 }); 5709 }); 5710 ``` 5711 5712### getPluralStringValueSync<sup>(deprecated)</sup> 5713 5714getPluralStringValueSync(resId: number, num: number): string 5715 5716Obtains singular/plural strings based on the specified resource ID and quantity. This API returns the result synchronously. 5717 5718> **NOTE** 5719> 5720> Singular/plural forms are available for English, but not Chinese. 5721> 5722> This API is supported since API version 10 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18). 5723 5724**Atomic service API**: This API can be used in atomic services since API version 11. 5725 5726**System capability**: SystemCapability.Global.ResourceManager 5727 5728**Parameters** 5729 5730| Name| Type | Mandatory| Description | 5731| ------ | ------ | ---- | ------------------------------------------------------------ | 5732| resId | number | Yes | Resource ID. | 5733| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 5734 5735**Return value** 5736 5737| Type | Description | 5738| ------ | ------------------------------------------------ | 5739| string | Singular/plural string corresponding to the specified quantity and resource ID.| 5740 5741**Error codes** 5742 5743For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5744 5745| ID| Error Message | 5746| -------- | ------------------------------------------------------------ | 5747| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5748| 9001001 | Invalid resource ID. | 5749| 9001002 | No matching resource is found based on the resource ID. | 5750| 9001006 | The resource is referenced cyclically. | 5751 5752**Example** 5753 5754 ```ts 5755 import { BusinessError } from '@kit.BasicServicesKit'; 5756 5757 try { 5758 this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1); 5759 } catch (error) { 5760 let code = (error as BusinessError).code; 5761 let message = (error as BusinessError).message; 5762 console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 5763 } 5764 ``` 5765 5766### getPluralStringValueSync<sup>(deprecated)</sup> 5767 5768getPluralStringValueSync(resource: Resource, num: number): string 5769 5770Obtains singular/plural strings based on the specified quantity and resource object. This API returns the result synchronously. 5771 5772> **NOTE** 5773> 5774> Singular/plural forms are available for English, but not Chinese. 5775> 5776> This API is supported since API version 10 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18-1). 5777 5778**Atomic service API**: This API can be used in atomic services since API version 11. 5779 5780**System capability**: SystemCapability.Global.ResourceManager 5781 5782**Model restriction**: This API can be used only in the stage model. 5783 5784**Parameters** 5785 5786| Name | Type | Mandatory| Description | 5787| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 5788| resource | [Resource](#resource9) | Yes | Resource object. | 5789| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 5790 5791**Return value** 5792 5793| Type | Description | 5794| ------ | ---------------------------------------------------- | 5795| string | Singular/plural string corresponding to the specified quantity and resource object.| 5796 5797**Error codes** 5798 5799For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5800 5801| ID| Error Message | 5802| -------- | ------------------------------------------------------------ | 5803| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5804| 9001001 | Invalid resource ID. | 5805| 9001002 | No matching resource is found based on the resource ID. | 5806| 9001006 | The resource is referenced cyclically. | 5807 5808**Example** 5809 5810 ```ts 5811 import { resourceManager } from '@kit.LocalizationKit' 5812 import { BusinessError } from '@kit.BasicServicesKit'; 5813 5814 let resource: resourceManager.Resource = { 5815 bundleName: "com.example.myapplication", 5816 moduleName: "entry", 5817 id: $r('app.plural.test').id 5818 }; 5819 try { 5820 this.context.resourceManager.getPluralStringValueSync(resource, 1); 5821 } catch (error) { 5822 let code = (error as BusinessError).code; 5823 let message = (error as BusinessError).message; 5824 console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); 5825 } 5826 ``` 5827 5828### getPluralStringByNameSync<sup>(deprecated)</sup> 5829 5830getPluralStringByNameSync(resName: string, num: number): string 5831 5832Obtains singular/plural strings based on the specified quantity and resource name. This API returns the result synchronously. 5833 5834> **NOTE** 5835> 5836> Singular/plural forms are available for English, but not Chinese. 5837> 5838> This API is supported since API version 10 and deprecated since API version 18. You are advised to use [getIntPluralStringByNameSync](#getintpluralstringbynamesync18). 5839 5840**Atomic service API**: This API can be used in atomic services since API version 11. 5841 5842**System capability**: SystemCapability.Global.ResourceManager 5843 5844**Parameters** 5845 5846| Name | Type | Mandatory| Description | 5847| ------- | ------ | ---- | ------------------------------------------------------------ | 5848| resName | string | Yes | Resource name. | 5849| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 5850 5851**Return value** 5852 5853| Type | Description | 5854| ------ | ------------------------------------------------ | 5855| string | Singular/plural string corresponding to the specified quantity and resource name.| 5856 5857**Error codes** 5858 5859For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 5860 5861| ID| Error Message | 5862| -------- | ------------------------------------------------------------ | 5863| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5864| 9001003 | Invalid resource name. | 5865| 9001004 | No matching resource is found based on the resource name. | 5866| 9001006 | The resource is referenced cyclically. | 5867 5868**Example** 5869 5870 ```ts 5871 import { BusinessError } from '@kit.BasicServicesKit'; 5872 5873 try { 5874 this.context.resourceManager.getPluralStringByNameSync("test", 1); 5875 } catch (error) { 5876 let code = (error as BusinessError).code; 5877 let message = (error as BusinessError).message; 5878 console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`); 5879 } 5880 ``` 5881 5882### getPluralStringValue<sup>(deprecated)</sup> 5883 5884getPluralStringValue(resId: number, num: number, callback: _AsyncCallback<string>): void 5885 5886Obtains singular/plural strings based on the specified quantity and resource ID. This API uses an asynchronous callback to return the result. 5887 5888> **NOTE** 5889> 5890> Singular/plural forms are available for English, but not Chinese. 5891> 5892> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18). 5893 5894**Atomic service API**: This API can be used in atomic services since API version 11. 5895 5896**System capability**: SystemCapability.Global.ResourceManager 5897 5898**Parameters** 5899 5900| Name | Type | Mandatory| Description | 5901| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 5902| resId | number | Yes | Resource ID. | 5903| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)| 5904| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the singular/plural string corresponding to the specified resource ID. | 5905 5906**Error codes** 5907 5908For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 5909 5910| ID| Error Message | 5911| -------- | ------------------------------------------------------------ | 5912| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5913| 9001001 | Invalid resource ID. | 5914| 9001002 | No matching resource is found based on the resource ID. | 5915| 9001006 | The resource is referenced cyclically. | 5916 5917**Example** 5918 5919 ```ts 5920 import { BusinessError } from '@kit.BasicServicesKit'; 5921 5922 try { 5923 this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error: BusinessError, value: string) => { 5924 if (error != null) { 5925 console.error("error is " + error); 5926 } else { 5927 let str = value; 5928 } 5929 }); 5930 } catch (error) { 5931 let code = (error as BusinessError).code; 5932 let message = (error as BusinessError).message; 5933 console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); 5934 } 5935 ``` 5936 5937### getPluralStringValue<sup>(deprecated)</sup> 5938 5939getPluralStringValue(resId: number, num: number): Promise<string> 5940 5941Obtains singular/plural strings based on the specified quantity and resource ID. This API uses a promise to return the result. 5942 5943> **NOTE** 5944> 5945> Singular/plural forms are available for English, but not Chinese. 5946> 5947> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18). 5948 5949**Atomic service API**: This API can be used in atomic services since API version 11. 5950 5951**System capability**: SystemCapability.Global.ResourceManager 5952 5953**Parameters** 5954 5955| Name| Type | Mandatory| Description | 5956| ------ | ------ | ---- | ------------------------------------------------------------ | 5957| resId | number | Yes | Resource ID. | 5958| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 5959 5960**Return value** 5961 5962| Type | Description | 5963| --------------------- | ---------------------------------------------------- | 5964| Promise<string> | Promise used to return the result, which is the singular/plural string corresponding to the specified resource ID.| 5965 5966**Error codes** 5967 5968For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 5969 5970| ID| Error Message | 5971| -------- | ------------------------------------------------------------ | 5972| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 5973| 9001001 | Invalid resource ID. | 5974| 9001002 | No matching resource is found based on the resource ID. | 5975| 9001006 | The resource is referenced cyclically. | 5976 5977**Example** 5978 5979 ```ts 5980 import { BusinessError } from '@kit.BasicServicesKit'; 5981 5982 try { 5983 this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then((value: string) => { 5984 let str = value; 5985 }).catch((error: BusinessError) => { 5986 console.error("getPluralStringValue promise error is " + error); 5987 }); 5988 } catch (error) { 5989 let code = (error as BusinessError).code; 5990 let message = (error as BusinessError).message; 5991 console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); 5992 } 5993 ``` 5994 5995### getPluralStringValue<sup>(deprecated)</sup> 5996 5997getPluralStringValue(resource: Resource, num: number, callback: _AsyncCallback<string>): void 5998 5999Obtains singular/plural strings based on the specified quantity and resource object. This API uses an asynchronous callback to return the result. 6000 6001> **NOTE** 6002> 6003> Singular/plural forms are available for English, but not Chinese. 6004> 6005> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18-1). 6006 6007**Atomic service API**: This API can be used in atomic services since API version 11. 6008 6009**System capability**: SystemCapability.Global.ResourceManager 6010 6011**Model restriction**: This API can be used only in the stage model. 6012 6013**Parameters** 6014 6015| Name | Type | Mandatory| Description | 6016| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 6017| resource | [Resource](#resource9) | Yes | Resource object. | 6018| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)| 6019| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the singular/plural string corresponding to the specified resource object. | 6020 6021**Error codes** 6022 6023For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). 6024 6025| ID| Error Message | 6026| -------- | ------------------------------------------------------------ | 6027| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 6028| 9001001 | Invalid resource ID. | 6029| 9001002 | No matching resource is found based on the resource ID. | 6030| 9001006 | The resource is referenced cyclically. | 6031 6032**Example** 6033 6034 ```ts 6035 import { resourceManager } from '@kit.LocalizationKit' 6036 import { BusinessError } from '@kit.BasicServicesKit'; 6037 6038 let resource: resourceManager.Resource = { 6039 bundleName: "com.example.myapplication", 6040 moduleName: "entry", 6041 id: $r('app.plural.test').id 6042 }; 6043 try { 6044 this.context.resourceManager.getPluralStringValue(resource, 1, (error: BusinessError, value: string) => { 6045 if (error != null) { 6046 console.error("error is " + error); 6047 } else { 6048 let str = value; 6049 } 6050 }); 6051 } catch (error) { 6052 let code = (error as BusinessError).code; 6053 let message = (error as BusinessError).message; 6054 console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); 6055 } 6056 ``` 6057 6058### getPluralStringValue<sup>(deprecated)</sup> 6059 6060getPluralStringValue(resource: Resource, num: number): Promise<string> 6061 6062Obtains singular/plural strings based on the specified quantity and resource object. This API uses a promise to return the result. 6063 6064> **NOTE** 6065> 6066> Singular/plural forms are available for English, but not Chinese. 6067> 6068> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18-1). 6069 6070**Atomic service API**: This API can be used in atomic services since API version 11. 6071 6072**System capability**: SystemCapability.Global.ResourceManager 6073 6074**Model restriction**: This API can be used only in the stage model. 6075 6076**Parameters** 6077 6078| Name | Type | Mandatory| Description | 6079| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 6080| resource | [Resource](#resource9) | Yes | Resource object. | 6081| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 6082 6083**Return value** 6084 6085| Type | Description | 6086| --------------------- | -------------------------------------------------------- | 6087| Promise<string> | Promise used to return the result, which is the singular/plural string corresponding to the specified resource object.| 6088 6089**Error codes** 6090 6091For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 6092 6093| ID| Error Message | 6094| -------- | ------------------------------------------------------------ | 6095| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 6096| 9001001 | Invalid resource ID. | 6097| 9001002 | No matching resource is found based on the resource ID. | 6098| 9001006 | The resource is referenced cyclically. | 6099 6100**Example** 6101 6102 ```ts 6103 import { resourceManager } from '@kit.LocalizationKit' 6104 import { BusinessError } from '@kit.BasicServicesKit'; 6105 6106 let resource: resourceManager.Resource = { 6107 bundleName: "com.example.myapplication", 6108 moduleName: "entry", 6109 id: $r('app.plural.test').id 6110 }; 6111 try { 6112 this.context.resourceManager.getPluralStringValue(resource, 1).then((value: string) => { 6113 let str = value; 6114 }).catch((error: BusinessError) => { 6115 console.error("getPluralStringValue promise error is " + error); 6116 }); 6117 } catch (error) { 6118 let code = (error as BusinessError).code; 6119 let message = (error as BusinessError).message; 6120 console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); 6121 } 6122 ``` 6123 6124### getPluralStringByName<sup>(deprecated)</sup> 6125 6126getPluralStringByName(resName: string, num: number, callback: _AsyncCallback<string>): void 6127 6128Obtains singular/plural strings based on the specified quantity and resource name. This API uses an asynchronous callback to return the result. 6129 6130> **NOTE** 6131> 6132> Singular/plural forms are available for English, but not Chinese. 6133> 6134> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringByNameSync](#getintpluralstringbynamesync18). 6135 6136**Atomic service API**: This API can be used in atomic services since API version 11. 6137 6138**System capability**: SystemCapability.Global.ResourceManager 6139 6140**Parameters** 6141 6142| Name | Type | Mandatory| Description | 6143| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 6144| resName | string | Yes | Resource name. | 6145| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)| 6146| callback | [_AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<string> | Yes | Callback used to return the result, which is the singular/plural string corresponding to the specified resource name. | 6147 6148**Error codes** 6149 6150For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 6151 6152| ID| Error Message | 6153| -------- | ------------------------------------------------------------ | 6154| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 6155| 9001003 | Invalid resource name. | 6156| 9001004 | No matching resource is found based on the resource name. | 6157| 9001006 | The resource is referenced cyclically. | 6158 6159**Example** 6160 6161 ```ts 6162 import { BusinessError } from '@kit.BasicServicesKit'; 6163 6164 try { 6165 this.context.resourceManager.getPluralStringByName("test", 1, (error: BusinessError, value: string) => { 6166 if (error != null) { 6167 console.error("error is " + error); 6168 } else { 6169 let str = value; 6170 } 6171 }); 6172 } catch (error) { 6173 let code = (error as BusinessError).code; 6174 let message = (error as BusinessError).message; 6175 console.error(`callback getPluralStringByName failed, error code: ${code}, message: ${message}.`); 6176 } 6177 ``` 6178 6179### getPluralStringByName<sup>(deprecated)</sup> 6180 6181getPluralStringByName(resName: string, num: number): Promise<string> 6182 6183Obtains singular/plural strings based on the specified quantity and resource name. This API uses a promise to return the result. 6184 6185> **NOTE** 6186> 6187> Singular/plural forms are available for English, but not Chinese. 6188> 6189> This API is supported since API version 9 and deprecated since API version 18. You are advised to use [getIntPluralStringByNameSync](#getintpluralstringbynamesync18). 6190 6191**Atomic service API**: This API can be used in atomic services since API version 11. 6192 6193**System capability**: SystemCapability.Global.ResourceManager 6194 6195**Parameters** 6196 6197| Name | Type | Mandatory| Description | 6198| ------- | ------ | ---- | ------------------------------------------------------------ | 6199| resName | string | Yes | Resource name. | 6200| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 6201 6202**Return value** 6203 6204| Type | Description | 6205| --------------------- | ------------------------------------------------ | 6206| Promise<string> | Promise used to return the result, which is the singular/plural string corresponding to the specified resource name.| 6207 6208**Error codes** 6209 6210For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). 6211 6212| ID| Error Message | 6213| -------- | ------------------------------------------------------------ | 6214| 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | 6215| 9001003 | Invalid resource name. | 6216| 9001004 | No matching resource is found based on the resource name. | 6217| 9001006 | The resource is referenced cyclically. | 6218 6219**Example** 6220 6221 ```ts 6222 import { BusinessError } from '@kit.BasicServicesKit'; 6223 6224 try { 6225 this.context.resourceManager.getPluralStringByName("test", 1).then((value: string) => { 6226 let str = value; 6227 }).catch((error: BusinessError) => { 6228 console.error("getPluralStringByName promise error is " + error); 6229 }); 6230 } catch (error) { 6231 let code = (error as BusinessError).code; 6232 let message = (error as BusinessError).message; 6233 console.error(`promise getPluralStringByName failed, error code: ${code}, message: ${message}.`); 6234 } 6235 ``` 6236 6237### getPluralString<sup>(deprecated)</sup> 6238 6239getPluralString(resId: number, num: number): Promise<string> 6240 6241Obtains singular/plural strings based on the specified quantity and resource ID. This API uses a promise to return the result. 6242 6243> **NOTE** 6244> 6245> Singular/plural forms are available for English, but not Chinese. 6246> 6247> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18). 6248 6249**System capability**: SystemCapability.Global.ResourceManager 6250 6251**Parameters** 6252 6253| Name | Type | Mandatory | Description | 6254| ----- | ------ | ---- | ----- | 6255| resId | number | Yes | Resource ID.| 6256| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).| 6257 6258**Return value** 6259 6260| Type | Description | 6261| --------------------- | ------------------------- | 6262| Promise<string> | Promise used to return the result, which is the singular/plural string corresponding to the specified resource ID.| 6263 6264**Example** 6265 6266 ```ts 6267 import { BusinessError } from '@kit.BasicServicesKit'; 6268 6269 resourceManager.getResourceManager((error, mgr) => { 6270 mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => { 6271 let str = value; 6272 }).catch((error: BusinessError) => { 6273 console.error("getPluralString promise error is " + error); 6274 }); 6275 }); 6276 ``` 6277 6278 6279### getPluralString<sup>(deprecated)</sup> 6280 6281getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void 6282 6283Obtains singular/plural strings based on the specified quantity and resource ID. This API uses an asynchronous callback to return the result. 6284 6285> **NOTE** 6286> 6287> Singular/plural forms are available for English, but not Chinese. 6288> 6289> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getIntPluralStringValueSync](#getintpluralstringvaluesync18). 6290 6291**System capability**: SystemCapability.Global.ResourceManager 6292 6293**Parameters** 6294 6295| Name | Type | Mandatory | Description | 6296| -------- | --------------------------- | ---- | ------------------------------- | 6297| resId | number | Yes | Resource ID. | 6298| num | number | Yes | Quantity value, which is used to obtain the corresponding string representation based on the current language's plural rules. For details about the plural rules of a language, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)| 6299| callback | [AsyncCallback](#asynccallbackdeprecated)<string> | Yes | Callback used to return the result, which is the singular/plural string corresponding to the specified resource ID.| 6300 6301**Example** 6302 6303 ```ts 6304 resourceManager.getResourceManager((error, mgr) => { 6305 mgr.getPluralString($r("app.plural.test").id, 1, (error: Error, value: string) => { 6306 if (error != null) { 6307 console.error("error is " + error); 6308 } else { 6309 let str = value; 6310 } 6311 }); 6312 }); 6313 ``` 6314 6315 6316### getRawFile<sup>(deprecated)</sup> 6317 6318getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void 6319 6320Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6321 6322> **NOTE** 6323> 6324> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9) instead. 6325 6326**System capability**: SystemCapability.Global.ResourceManager 6327 6328**Parameters** 6329 6330| Name | Type | Mandatory | Description | 6331| -------- | ------------------------------- | ---- | ----------------------- | 6332| path | string | Yes | Path of the raw file. | 6333| callback | [AsyncCallback](#asynccallbackdeprecated)<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| 6334 6335**Example** 6336 ```ts 6337 resourceManager.getResourceManager((error, mgr) => { 6338 mgr.getRawFile("test.txt", (error: Error, value: Uint8Array) => { 6339 if (error != null) { 6340 console.error("error is " + error); 6341 } else { 6342 let rawFile = value; 6343 } 6344 }); 6345 }); 6346 ``` 6347 6348 6349### getRawFile<sup>(deprecated)</sup> 6350 6351getRawFile(path: string): Promise<Uint8Array> 6352 6353Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6354 6355> **NOTE** 6356> 6357> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1) instead. 6358 6359**System capability**: SystemCapability.Global.ResourceManager 6360 6361**Parameters** 6362 6363| Name | Type | Mandatory | Description | 6364| ---- | ------ | ---- | ----------- | 6365| path | string | Yes | Path of the raw file.| 6366 6367**Return value** 6368 6369| Type | Description | 6370| ------------------------- | ----------- | 6371| Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| 6372 6373**Example** 6374 ```ts 6375 import { BusinessError } from '@kit.BasicServicesKit'; 6376 6377 resourceManager.getResourceManager((error, mgr) => { 6378 mgr.getRawFile("test.txt").then((value: Uint8Array) => { 6379 let rawFile = value; 6380 }).catch((error: BusinessError) => { 6381 console.error("getRawFile promise error is " + error); 6382 }); 6383 }); 6384 ``` 6385 6386 6387### getRawFileDescriptor<sup>(deprecated)</sup> 6388 6389getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void 6390 6391Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6392 6393> **NOTE** 6394> 6395> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9) instead. 6396 6397**System capability**: SystemCapability.Global.ResourceManager 6398 6399**Parameters** 6400 6401| Name | Type | Mandatory | Description | 6402| -------- | ---------------------------------------- | ---- | -------------------------------- | 6403| path | string | Yes | Path of the raw file. | 6404| callback | [AsyncCallback](#asynccallbackdeprecated)<[RawFileDescriptor](#rawfiledescriptor9)> | Yes | Callback used to return the result, which is the descriptor of the raw file.| 6405 6406**Example** 6407 ```ts 6408 import { resourceManager } from '@kit.LocalizationKit' 6409 6410 resourceManager.getResourceManager((error, mgr) => { 6411 mgr.getRawFileDescriptor("test.txt", (error: Error, value: resourceManager.RawFileDescriptor) => { 6412 if (error != null) { 6413 console.error("error is " + error); 6414 } else { 6415 let fd = value.fd; 6416 let offset = value.offset; 6417 let length = value.length; 6418 } 6419 }); 6420 }); 6421 ``` 6422 6423### getRawFileDescriptor<sup>(deprecated)</sup> 6424 6425getRawFileDescriptor(path: string): Promise<RawFileDescriptor> 6426 6427Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6428 6429> **NOTE** 6430> 6431> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1) instead. 6432 6433**System capability**: SystemCapability.Global.ResourceManager 6434 6435**Parameters** 6436 6437| Name | Type | Mandatory | Description | 6438| ---- | ------ | ---- | ----------- | 6439| path | string | Yes | Path of the raw file.| 6440 6441**Return value** 6442 6443| Type | Description | 6444| ---------------------------------------- | ------------------- | 6445| Promise<[RawFileDescriptor](#rawfiledescriptor9)> | Promise used to return the result, which is the descriptor of the raw file.| 6446 6447**Example** 6448 ```ts 6449 import { BusinessError } from '@kit.BasicServicesKit'; 6450 6451 resourceManager.getResourceManager((error, mgr) => { 6452 mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => { 6453 let fd = value.fd; 6454 let offset = value.offset; 6455 let length = value.length; 6456 }).catch((error: BusinessError) => { 6457 console.error("getRawFileDescriptor promise error is " + error); 6458 }); 6459 }); 6460 ``` 6461 6462### closeRawFileDescriptor<sup>(deprecated)</sup> 6463 6464closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void 6465 6466Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. 6467 6468> **NOTE** 6469> 6470> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9) instead. 6471 6472**System capability**: SystemCapability.Global.ResourceManager 6473 6474**Parameters** 6475 6476 6477 6478| Name | Type | Mandatory | Description | 6479| -------- | ------------------------- | ---- | ----------- | 6480| path | string | Yes | Path of the raw file.| 6481| callback | [AsyncCallback](#asynccallbackdeprecated)<void> | Yes | Callback used to return the result. | 6482 6483**Example** 6484 ```ts 6485 resourceManager.getResourceManager((error, mgr) => { 6486 mgr.closeRawFileDescriptor("test.txt", (error: Error) => { 6487 if (error != null) { 6488 console.error("error is " + error); 6489 } 6490 }); 6491 }); 6492 ``` 6493 6494### closeRawFileDescriptor<sup>(deprecated)</sup> 6495 6496closeRawFileDescriptor(path: string): Promise<void> 6497 6498Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. 6499 6500> **NOTE** 6501> 6502> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9-1) instead. 6503 6504**System capability**: SystemCapability.Global.ResourceManager 6505 6506**Parameters** 6507 6508| Name | Type | Mandatory | Description | 6509| ---- | ------ | ---- | ----------- | 6510| path | string | Yes | Path of the raw file.| 6511 6512**Return value** 6513 6514| Type | Description | 6515| ------------------- | ---- | 6516| Promise<void> | Promise that returns no value.| 6517 6518**Example** 6519 ```ts 6520 resourceManager.getResourceManager((error, mgr) => { 6521 mgr.closeRawFileDescriptor("test.txt"); 6522 }); 6523 ``` 6524 6525## AsyncCallback<sup>(deprecated)</sup> 6526 6527``` 6528AsyncCallback<T> { 6529 (err: Error, data: T): void; 6530} 6531``` 6532 6533Defines an asynchronous callback that carries an error parameter and asynchronous return value. 6534 6535> **NOTE** 6536> 6537> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback) instead. 6538 6539**System capability**: SystemCapability.Global.ResourceManager 6540 6541| Name| Type | Mandatory| Description | 6542| ---- | ------------------------------------------------------------ | ---- | ---------------------------- | 6543| err | Error | Yes | Error message when the API fails to be called.| 6544| data | T | Yes | Callback information when the API is called.| 6545 6546## Appendix 6547 6548- Content of the **app.string.test** file: 6549 6550 ```json 6551 { 6552 "string": [ 6553 { 6554 "name": "test", 6555 "value": "10" 6556 } 6557 ] 6558 } 6559 ``` 6560 6561 ```json 6562 { 6563 "string": [ 6564 { 6565 "name": "test", 6566 "value": "%s %d %f" 6567 } 6568 ] 6569 } 6570 ``` 6571 6572- Content of the **app.strarray.test** file: 6573 6574 ```json 6575 { 6576 "strarray": [ 6577 { 6578 "name": "test", 6579 "value": [ 6580 { 6581 "value": "strarray_test" 6582 } 6583 ] 6584 } 6585 ] 6586 } 6587 ``` 6588 6589- Content of the **app.plural.test** file: 6590 ```json 6591 { 6592 "plural": [ 6593 { 6594 "name": "test", 6595 "value": [ 6596 { 6597 "quantity": "one", 6598 "value": "%d apple" 6599 }, 6600 { 6601 "quantity": "other", 6602 "value": "%d apples" 6603 } 6604 ] 6605 } 6606 ] 6607 } 6608 ``` 6609 6610- Content of the **app.plural.format_test** file: 6611 6612 ``` 6613 { 6614 "plural": [ 6615 { 6616 "name": "format_test", 6617 "value": [ 6618 { 6619 "quantity": "one", 6620 "value": "%d apple, %s, %f" 6621 }, 6622 { 6623 "quantity": "other", 6624 "value": "%d apples, %s, %f" 6625 } 6626 ] 6627 } 6628 ] 6629 } 6630 ``` 6631 6632- Content of the **app.boolean.boolean_test** file: 6633 ```json 6634 { 6635 "boolean": [ 6636 { 6637 "name": "boolean_test", 6638 "value": true 6639 } 6640 ] 6641 } 6642 ``` 6643 6644- Content of the **integer_test** and **float_test** files: 6645 ```json 6646 { 6647 "integer": [ 6648 { 6649 "name": "integer_test", 6650 "value": 100 6651 } 6652 ] 6653 } 6654 ``` 6655 6656 ```json 6657 { 6658 "float": [ 6659 { 6660 "name": "float_test", 6661 "value": "30.6" 6662 } 6663 ] 6664 } 6665 ``` 6666- Content of the **app.color.test** file: 6667 ```json 6668 { 6669 "color": [ 6670 { 6671 "name": "test", 6672 "value": "#FFFFFF" 6673 } 6674 ] 6675 } 6676 ``` 6677