# @ohos.resourceManager (Resource Management) The **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. > **NOTE** > > 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. ## Modules to Import ```js import { resourceManager } from '@kit.LocalizationKit' ``` ## How to Use Since 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. For the FA model, you need to import the required bundle and then call the [getResourceManager](#resourcemanagergetresourcemanager) API to obtain a **ResourceManager** object. For details about how to reference context in the stage model, see [Context in the Stage Model](../../application-models/application-context-stage.md). ```ts import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage) { let context = this.context; let resourceManager = context.resourceManager; } } ``` ## resourceManager.getResourceManager getResourceManager(callback: AsyncCallback<ResourceManager>): void Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the FA model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------------------- | | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes |Callback used to return the result, which is a **ResourceManager** object.| **Example** ```js resourceManager.getResourceManager((error, mgr) => { if (error != null) { console.error("error is " + error); return; } mgr.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); }); ``` ## resourceManager.getResourceManager getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void Obtains the **ResourceManager** object of the specified application. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the FA model. **Parameters** | Name | Type | Mandatory | Description | | ---------- | ---------------------------------------- | ---- | ----------------------------- | | bundleName | string | Yes | Bundle name of an application. | | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result, which is a **ResourceManager** object.| **Example** ```js resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => { }); ``` ## resourceManager.getResourceManager getResourceManager(): Promise<ResourceManager> Obtains the **ResourceManager** object of this application. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the FA model. **Return value** | Type | Description | | ---------------------------------------- | ----------------- | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result, which is a **ResourceManager** object.| **Example** ```js import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager().then((mgr: resourceManager.ResourceManager) => { mgr.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); }).catch((error: BusinessError) => { console.error("error is " + error); }); ``` ## resourceManager.getResourceManager getResourceManager(bundleName: string): Promise<ResourceManager> Obtains the **ResourceManager** object of the specified application. This API uses a promise to return the result. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the FA model. **Parameters** | Name | Type | Mandatory | Description | | ---------- | ------ | ---- | ------------- | | bundleName | string | Yes | Bundle name of an application.| **Return value** | Type | Description | | ---------------------------------------- | ------------------ | | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result, which is a **ResourceManager** object.| **Example** ```js import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager("com.example.myapplication").then((mgr: resourceManager.ResourceManager) => { }).catch((error: BusinessError) => { }); ``` ## resourceManager.getSystemResourceManager10+ getSystemResourceManager(): ResourceManager Obtains a **ResourceManager** object. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ------------------ | | [Resourcemanager](#resourcemanager) | **ResourceManager** object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 9001009 | Failed to access the system resource.which is not mapped to application sandbox, This error code will be thrown. | **Example** ```js import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; try { let systemResourceManager = resourceManager.getSystemResourceManager(); systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("systemResourceManager getStringValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`systemResourceManager getStringValue failed, error code: ${code}, message: ${message}.`); } ``` ## Direction Enumerates the screen directions. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Name | Value | Description | | -------------------- | ---- | ---- | | DIRECTION_VERTICAL | 0 | Portrait | | DIRECTION_HORIZONTAL | 1 | Landscape | ## DeviceType Enumerates the device types. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Name | Value | Description | | -------------------- | ---- | ---- | | DEVICE_TYPE_PHONE | 0x00 | Phone | | DEVICE_TYPE_TABLET | 0x01 | Tablet | | DEVICE_TYPE_CAR | 0x02 | Automobile | | DEVICE_TYPE_TV | 0x04 | TV | | DEVICE_TYPE_WEARABLE | 0x06 | Wearable | | DEVICE_TYPE_2IN111+ | 0x07 | 2-in-1 | ## ScreenDensity Enumerates the screen density types. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Name | Value | Description | | -------------- | ---- | ---------- | | SCREEN_SDPI | 120 | Screen density with small-scale dots per inch (SDPI). | | SCREEN_MDPI | 160 | Screen density with medium-scale dots per inch (MDPI). | | SCREEN_LDPI | 240 | Screen density with large-scale dots per inch (LDPI). | | SCREEN_XLDPI | 320 | Screen density with extra-large-scale dots per inch (XLDPI). | | SCREEN_XXLDPI | 480 | Screen density with extra-extra-large-scale dots per inch (XXLDPI). | | SCREEN_XXXLDPI | 640 | Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).| ## ColorMode12+ Defines the color mode of the current device. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.Global.ResourceManager | Name | Value | Description | | ----- | ---- | ---------- | | DARK | 0 | Dark mode.| | LIGHT | 1 | Light mode.| ## Configuration Defines the device configuration. **System capability**: SystemCapability.Global.ResourceManager | Name | Type | Readable| Writable| Description | | --------------------------- | ------------------------------- | ---- | ---- | ------------------ | | direction | [Direction](#direction) | Yes | Yes | Screen orientation.
**Atomic service API**: This API can be used in atomic services since API version 11. | | locale | string | Yes | Yes | Country or region.
**Atomic service API**: This API can be used in atomic services since API version 11.| | deviceType12+ | [DeviceType](#devicetype) | Yes | Yes | Device type.
**Atomic service API**: This API can be used in atomic services since API version 12. | | screenDensity12+ | [ScreenDensity](#screendensity) | Yes | Yes | Screen density.
**Atomic service API**: This API can be used in atomic services since API version 12. | | colorMode12+ | [ColorMode](#colormode12) | Yes | Yes | Color mode.
**Atomic service API**: This API can be used in atomic services since API version 12. | | mcc12+ | number | Yes | Yes | Mobile country code.
**Atomic service API**: This API can be used in atomic services since API version 12. | | mnc12+ | number | Yes | Yes | Mobile network code (MNC).
**Atomic service API**: This API can be used in atomic services since API version 12. | ## DeviceCapability Defines the device capability. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Name | Type | Readable | Writable | Description | | ------------- | ------------------------------- | ---- | ---- | -------- | | screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density of the device.| | deviceType | [DeviceType](#devicetype) | Yes | No | Device type. | ## RawFileDescriptor8+ type RawFileDescriptor = _RawFileDescriptor **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Type | Description | | ------ | ---- | |[_RawFileDescriptor](rawFileDescriptor.md#rawfiledescriptor-1)|Descriptor of the HAP where the raw file is located.| ## Resource9+ type Resource = _Resource **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager | Type | Description | | ------ | ---- | |[_Resource](resource.md#resource-1)|Resource information of an application.| ## ResourceManager Defines the capability of accessing application resources. > **NOTE** > > - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. > > - 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. > > - 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. > > - For details about intra-HAP and cross-HAP/HSP resource access modes, see [Resource Access](../../quick-start/resource-categories-and-access.md#resource-access). > > - For details about the content of the test files used in the sample code, see [Appendix](#appendix). ### getStringSync9+ getStringSync(resId: number): string Obtains a string based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------ | ----------- | | string | String corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringSync($r('app.string.test').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringSync10+ getStringSync(resId: number, ...args: Array): string Obtains a string based on the specified resource ID and formats the string based on **args**. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | args | Array | No | Arguments for formatting strings.
Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.
Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.
For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| **Return value** | Type | Description | | ------ | ---------------------------- | | string | Formatted string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | | 9001007 | Failed to format the resource obtained based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringSync9+ getStringSync(resource: Resource): string Obtains a string based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------ | ---------------- | | string | String corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.string.test').id }; try { this.context.resourceManager.getStringSync(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringSync10+ getStringSync(resource: Resource, ...args: Array): string Obtains a string based on the specified resource object and formats the string based on **args**. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| | args | Array | No | Arguments for formatting strings.
Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.
Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.
For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| **Return value** | Type | Description | | ------ | ---------------------------- | | string | Formatted string corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | | 9001007 | Failed to format the resource obtained based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.string.test').id }; try { this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringByNameSync9+ getStringByNameSync(resName: string): string Obtains a string based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------ | ---------- | | string | String corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringByNameSync("test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringByNameSync10+ getStringByNameSync(resName: string, ...args: Array): string Obtains a string based on the specified resource name and formats the string based on **args**. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| | args | Array | No | Arguments for formatting strings.
Supported value types include %d, %f, %s, %%, %number\\$d, %number\\$f, and %number\\$s.
Note: %% is escaped to %. % number\\$d indicates the sequence number of the parameter to be used.
For example, %%d is converted to a %d string after formatting, and %1\\$d indicates that the first parameter is used.| **Return value** | Type | Description | | ------ | ---------------------------- | | string | Formatted string corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | | 9001008 | Failed to format the resource obtained based on the resource Name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringValue9+ getStringValue(resId: number, callback: AsyncCallback<string>): void Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | If the module resId invalid. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example (stage)** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringValue9+ getStringValue(resId: number): Promise<string> Obtains a string based on the specified resource ID. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringValue($r('app.string.test').id).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getStringValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringValue9+ getStringValue(resource: Resource, callback: AsyncCallback<string>): void Obtains a string based on the specified resource object. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.string.test').id }; try { this.context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringValue9+ getStringValue(resource: Resource): Promise<string> Obtains a string based on the specified resource object. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | --------------------- | ---------------- | | Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.string.test').id }; try { this.context.resourceManager.getStringValue(resource).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getStringValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringByName9+ getStringByName(resName: string, callback: AsyncCallback<string>): void Obtains a string based on the specified resource name. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resName | string | Yes | Resource name. | | callback | AsyncCallback<string> | Yes |Callback used to return the result, which is the string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringByName("test", (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringByName failed, error code: ${code}, message: ${message}.`); } ``` ### getStringByName9+ getStringByName(resName: string): Promise<string> Obtains a string based on the specified resource name. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | --------------------- | ---------- | | Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringByName("test").then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getStringByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringByName failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValueSync10+ getStringArrayValueSync(resId: number): Array<string> Obtains a string array based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | ----------- | | Array<string> | String array corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValueSync10+ getStringArrayValueSync(resource: Resource): Array<string> Obtains a string array based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | --------------------- | ----------- | | Array<string> | String array corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.strarray.test').id }; try { this.context.resourceManager.getStringArrayValueSync(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayByNameSync10+ getStringArrayByNameSync(resName: string): Array<string> Obtains a string array based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | --------------------- | ----------- | | Array<string> | String array corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts try { this.context.resourceManager.getStringArrayByNameSync("test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getStringArrayByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValue9+ getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>>): void Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error: BusinessError, value: Array) => { if (error != null) { console.error("error is " + error); } else { let strArray = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValue9+ getStringArrayValue(resId: number): Promise<Array<string>> Obtains a string array based on the specified resource ID. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then((value: Array) => { let strArray = value; }).catch((error: BusinessError) => { console.error("getStringArrayValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValue9+ getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void Obtains a string array based on the specified resource object. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.strarray.test').id }; try { this.context.resourceManager.getStringArrayValue(resource, (error: BusinessError, value: Array) => { if (error != null) { console.error("error is " + error); } else { let strArray = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringArrayValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayValue9+ getStringArrayValue(resource: Resource): Promise<Array<string>> Obtains a string array based on the specified resource object. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ---------------------------------- | ------------------ | | Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.strarray.test').id }; try { this.context.resourceManager.getStringArrayValue(resource).then((value: Array) => { let strArray = value; }).catch((error: BusinessError) => { console.error("getStringArray promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringArrayValue failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayByName9+ getStringArrayByName(resName: string, callback: AsyncCallback<Array<string>>): void Obtains a string array based on the specified resource name. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | resName | string | Yes | Resource name. | | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringArrayByName("test", (error: BusinessError, value: Array) => { if (error != null) { console.error("error is " + error); } else { let strArray = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getStringArrayByName failed, error code: ${code}, message: ${message}.`); } ``` ### getStringArrayByName9+ getStringArrayByName(resName: string): Promise<Array<string>> Obtains a string array based on the specified resource name. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ---------------------------------- | ------------ | | Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getStringArrayByName("test").then((value: Array) => { let strArray = value; }).catch((error: BusinessError) => { console.error("getStringArrayByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getStringArrayByName failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValueSync10+ getPluralStringValueSync(resId: number, num: number): string Obtains a singular-plural string by the specified number based on the specified resource ID. This API returns the result synchronously. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | num | number | Yes | Number. | **Return value** | Type | Description | | -------- | ----------- | | string | Singular-plural string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValueSync10+ getPluralStringValueSync(resource: Resource, num: number): string Obtains a singular-plural string by the specified number based on the specified resource object. This API returns the result synchronously. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resource | [Resource](#resource9) | Yes | Resource object.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ----------- | | string | Singular-plural string corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.plural.test').id }; try { this.context.resourceManager.getPluralStringValueSync(resource, 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringByNameSync10+ getPluralStringByNameSync(resName: string, num: number): string Obtains a singular-plural string by the specified number based on the specified resource name. This API returns the result synchronously. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resName | string | Yes | Resource name.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ----------- | | string | Singular-plural string corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringByNameSync("test", 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValue9+ getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses an asynchronous callback to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------------- | | resId | number | Yes | Resource ID. | | num | number | Yes | Number. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValue9+ getPluralStringValue(resId: number, num: number): Promise<string> Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses a promise to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getPluralStringValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValue9+ getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void Obtains a singular-plural string by the specified number based on the specified resource object. This API uses an asynchronous callback to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------------------ | | resource | [Resource](#resource9) | Yes | Resource object. | | num | number | Yes | Number. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.plural.test').id }; try { this.context.resourceManager.getPluralStringValue(resource, 1, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getPluralStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringValue9+ getPluralStringValue(resource: Resource, num: number): Promise<string> Obtains a singular-plural string by the specified number based on the specified resource object. This API uses a promise to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ------------------------------ | | Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.plural.test').id }; try { this.context.resourceManager.getPluralStringValue(resource, 1).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getPluralStringValue promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getPluralStringValue failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringByName9+ getPluralStringByName(resName: string, num: number, callback: AsyncCallback<string>): void Obtains a singular-plural string by the specified number based on the specified resource name. This API uses an asynchronous callback to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ----------------------------- | | resName | string | Yes | Resource name. | | num | number | Yes | Number. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringByName("test", 1, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getPluralStringByName failed, error code: ${code}, message: ${message}.`); } ``` ### getPluralStringByName9+ getPluralStringByName(resName: string, num: number): Promise<string> Obtains a singular-plural string by the specified number based on the specified resource name. This API uses a promise to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ---------------------- | | Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getPluralStringByName("test", 1).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getPluralStringByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getPluralStringByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentSync10+ getMediaContentSync(resId: number, density?: number): Uint8Array Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | -------- | ----------- | | Uint8Array | Content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentSync10+ getMediaContentSync(resource: Resource, density?: number): Uint8Array Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | --------------------- | ----------- | | Uint8Array | Content of the media file corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentSync(resource); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaContentSync(resource, 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaByNameSync10+ getMediaByNameSync(resName: string, density?: number): Uint8Array Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resName | string | Yes | Resource name.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | --------------------- | ----------- | | Uint8Array | Content of the media file corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaByNameSync("test"); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaByNameSync("test", 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent9+ getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContent($r('app.media.test').id, (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent10+ getMediaContent(resId: number, density: number, callback: AsyncCallback<Uint8Array>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resId | number | Yes | Resource ID. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContent($r('app.media.test').id, 120, (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent9+ getMediaContent(resId: number): Promise<Uint8Array> Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContent($r('app.media.test').id).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaContent promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent10+ getMediaContent(resId: number, density: number): Promise<Uint8Array> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContent($r('app.media.test').id, 120).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent9+ getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void Obtains the content of a media file based on the specified resource object. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContent(resource, (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent10+ getMediaContent(resource: Resource, density: number, callback: AsyncCallback<Uint8Array>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resource | [Resource](#resource9) | Yes | Resource object. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContent(resource, 120, (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent9+ getMediaContent(resource: Resource): Promise<Uint8Array> Obtains the content of a media file based on the specified resource object. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------------------------- | ------------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContent(resource).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaContent promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContent10+ getMediaContent(resource: Resource, density: number): Promise<Uint8Array> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | ------------------------- | ------------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContent(resource, 120).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContent failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaByName9+ getMediaByName(resName: string, callback: AsyncCallback<Uint8Array>): void Obtains the content of a media file based on the specified resource name. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resName | string | Yes | Resource name. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaByName("test", (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaByName10+ getMediaByName(resName: string, density: number, callback: AsyncCallback<Uint8Array>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resName | string | Yes | Resource name. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaByName("test", 120, (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaByName9+ getMediaByName(resName: string): Promise<Uint8Array> Obtains the content of a media file based on the specified resource name. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------------------------- | ------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaByName("test").then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaByName10+ getMediaByName(resName: string, density: number): Promise<Uint8Array> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | ------------------------- | ------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaByName("test", 120).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase64Sync10+ getMediaContentBase64Sync(resId: number, density?: number): string Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | -------- | ----------- | | string | Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase64Sync10+ getMediaContentBase64Sync(resource: Resource, density?: number): string Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | --------------------- | ----------- | | string | Base64 code of the image corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentBase64Sync(resource); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaContentBase64Sync(resource, 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaBase64ByNameSync10+ getMediaBase64ByNameSync(resName: string, density?: number): string Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resName | string | Yes | Resource name.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| **Return value** | Type | Description | | --------------------- | ----------- | | string | Base64 code of the image corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaBase64ByNameSync("test"); // Default screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // Specified screen density } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase649+ getMediaContentBase64(resId: number, callback: AsyncCallback<string>): void Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase6410+ getMediaContentBase64(resId: number, density: number, callback: AsyncCallback<string>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resId | number | Yes | Resource ID. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120, (error: BusinessError, value: string) => { if (error != null) { console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase649+ getMediaContentBase64(resId: number): Promise<string> Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaContentBase64 promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase6410+ getMediaContentBase64(resId: number, density: number): Promise<string> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, 120).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase649+ getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>): void Obtains the Base64 code of an image based on the specified resource object. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentBase64(resource, (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase6410+ getMediaContentBase64(resource: Resource, density: number, callback: AsyncCallback<string>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resource | [Resource](#resource9) | Yes | Resource object. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentBase64(resource, 120, (error: BusinessError, value: string) => { if (error != null) { console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase649+ getMediaContentBase64(resource: Resource): Promise<string> Obtains the Base64 code of an image based on the specified resource object. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentBase64(resource).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaContentBase64 promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaContentBase6410+ getMediaContentBase64(resource: Resource, density: number): Promise<string> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContentBase64(resource, 120).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaContentBase64 failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaBase64ByName9+ getMediaBase64ByName(resName: string, callback: AsyncCallback<string>): void Obtains the Base64 code of an image based on the specified resource name. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resName | string | Yes | Resource name. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaBase64ByName("test", (error: BusinessError, value: string) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaBase64ByName10+ getMediaBase64ByName(resName: string, density: number, callback: AsyncCallback<string>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resName | string | Yes | Resource name. | | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaBase64ByName("test", 120, (error: BusinessError, value: string) => { if (error != null) { console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); } else { let media = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaBase64ByName9+ getMediaBase64ByName(resName: string): Promise<string> Obtains the Base64 code of an image based on the specified resource name. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | --------------------- | ------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaBase64ByName("test").then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaBase64ByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); } ``` ### getMediaBase64ByName10+ getMediaBase64ByName(resName: string, density: number): Promise<string> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| | [density](#screendensity) | number | Yes | Screen density. The value **0** indicates the default screen density. | **Return value** | Type | Description | | --------------------- | ------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getMediaBase64ByName("test", 120).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getMediaBase64ByName failed, error code: ${code}, message: ${message}.`); } ``` ### getDrawableDescriptor10+ getDrawableDescriptor(resId: number, density?: number, type?: number): DrawableDescriptor Obtains a **DrawableDescriptor** object for icon display based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| | type11+ | 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.| **Return value** | Type | Description | | ------ | ---------- | | [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 0, 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } ``` ### getDrawableDescriptor10+ getDrawableDescriptor(resource: Resource, density?: number, type?: number): DrawableDescriptor Obtains a **DrawableDescriptor** object for icon display based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| | type11+ | 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.| **Return value** | Type | Description | | ------- | ----------------- | | [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.icon').id }; try { this.context.resourceManager.getDrawableDescriptor(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptor(resource, 120); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptor(resource, 0, 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptor failed, error code: ${code}, message: ${message}.`); } ``` ### getDrawableDescriptorByName10+ getDrawableDescriptorByName(resName: string, density?: number, type?: number): DrawableDescriptor Obtains a **DrawableDescriptor** object for icon display based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| | [density](#screendensity) | number | No | Screen density. The default value or value **0** indicates the default screen density.| | type11+ | 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.| **Return value** | Type | Description | | ------ | --------- | | [DrawableDescriptor](../apis-arkui/js-apis-arkui-drawableDescriptor.md#drawabledescriptor) | **DrawableDescriptor** object corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getDrawableDescriptorByName('icon'); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptorByName('icon', 120); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getDrawableDescriptorByName('icon', 0, 1); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getDrawableDescriptorByName failed, error code: ${code}, message: ${message}.`); } ``` ### getBoolean9+ getBoolean(resId: number): boolean Obtains a Boolean result based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------- | ------------ | | boolean | Boolean result corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); } ``` ### getBoolean9+ getBoolean(resource: Resource): boolean Obtains a Boolean result based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------- | ----------------- | | boolean | Boolean result corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.boolean.boolean_test').id }; try { this.context.resourceManager.getBoolean(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getBoolean failed, error code: ${code}, message: ${message}.`); } ``` ### getBooleanByName9+ getBooleanByName(resName: string): boolean Obtains a Boolean result based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------- | ----------- | | boolean | Boolean result corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getBooleanByName("boolean_test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`); } ``` ### getNumber9+ getNumber(resId: number): number Obtains an integer or float value based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------ | ---------- | | 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.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getNumber failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getNumber failed, error code: ${code}, message: ${message}.`); } ``` ### getNumber9+ getNumber(resource: Resource): number Obtains an integer or float value based on the specified resource object. This API returns the result synchronously. > **NOTE** > > 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------ | --------------- | | number | Integer or float value corresponding to the specified resource name.
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.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.integer.integer_test').id }; try { this.context.resourceManager.getNumber(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getNumber failed, error code: ${code}, message: ${message}.`); } ``` ### getNumberByName9+ getNumberByName(resName: string): number Obtains an integer or float value based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------ | --------- | | number | Integer or float value corresponding to the specified resource name.
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.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getNumberByName("integer_test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getNumberByName("float_test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`); } ``` ### getColorSync10+ getColorSync(resId: number) : number; Obtains a color value based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------ | ----------- | | number | Color value (decimal) corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColorSync($r('app.color.test').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); } ``` ### getColorSync10+ getColorSync(resource: Resource): number Obtains a color value based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------ | ---------------- | | number | Color value (decimal) corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.color.test').id }; try { this.context.resourceManager.getColorSync(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getColorSync failed, error code: ${code}, message: ${message}.`); } ``` ### getColorByNameSync10+ getColorByNameSync(resName: string) : number; Obtains a color value based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------ | ---------- | | number | Color value (decimal) corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColorByNameSync("test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`); } ``` ### getColor10+ getColor(resId: number, callback: AsyncCallback<number>): void; Obtains a color value based on the specified resource ID. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | If the module resId invalid. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example (stage)** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColor($r('app.color.test').id, (error: BusinessError, value: number) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); } ``` ### getColor10+ getColor(resId: number): Promise<number> Obtains a color value based on the specified resource ID. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | ----------- | | Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColor($r('app.color.test').id).then((value: number) => { let str = value; }).catch((error: BusinessError) => { console.error("getColor promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); } ``` ### getColor10+ getColor(resource: Resource, callback: AsyncCallback<number>): void; Obtains a color value based on the specified resource object. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resource | [Resource](#resource9) | Yes | Resource object. | | callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.color.test').id }; try { this.context.resourceManager.getColor(resource, (error: BusinessError, value: number) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getColor failed, error code: ${code}, message: ${message}.`); } ``` ### getColor10+ getColor(resource: Resource): Promise<number>; Obtains a color value based on the specified resource object. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | --------------------- | ---------------- | | Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.color.test').id }; try { this.context.resourceManager.getColor(resource).then((value: number) => { let str = value; }).catch((error: BusinessError) => { console.error("getColor promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getColor failed, error code: ${code}, message: ${message}.`); } ``` ### getColorByName10+ getColorByName(resName: string, callback: AsyncCallback<number>): void Obtains a color value based on the specified resource name. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resName | string | Yes | Resource name. | | callback | AsyncCallback<number> | Yes | Callback used to return the result, which is the color value (decimal) corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColorByName("test", (error: BusinessError, value: number) => { if (error != null) { console.error("error is " + error); } else { let string = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getColorByName failed, error code: ${code}, message: ${message}.`); } ``` ### getColorByName10+ getColorByName(resName: string): Promise<number> Obtains a color value based on the specified resource name. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | --------------------- | ---------- | | Promise<number> | Promise used to return the result, which is the color value (decimal) corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getColorByName("test").then((value: number) => { let string = value; }).catch((error: BusinessError) => { console.error("getColorByName promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getColorByName failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileContentSync10+ getRawFileContentSync(path: string): Uint8Array Obtains the content of the raw file in the **resources/rawfile** directory. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | Path of the raw file. | **Return value** | Type | Description | | --------------------- | ---------- | | Uint8Array | Content of the raw file.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getRawFileContentSync("test.txt"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getRawFileContentSync failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileContent9+ getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | Path of the raw file. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getRawFileContent("test.txt", (error: BusinessError, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let rawFile = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getRawFileContent failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileContent9+ getRawFileContent(path: string): Promise<Uint8Array> Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getRawFileContent("test.txt").then((value: Uint8Array) => { let rawFile = value; }).catch((error: BusinessError) => { console.error("getRawFileContent promise error is " + error); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getRawFileContent failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileListSync10+ getRawFileListSync(path: string): Array\ Obtains the list of folders and files in the **resources/rawfile** directory. This API returns the result synchronously. >**NOTE** > > 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | **rawfile** directory. | **Return value** | Type | Description | | ------------------------- | ----------- | | Array\ | List of folders and files in the **rawfile** directory.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { // Passing "" means to obtain the list of files in the root directory of the raw file. this.context.resourceManager.getRawFileListSync("") } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileList10+ getRawFileList(path: string, callback: AsyncCallback<Array\>): void; Obtains the list of folders and files in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. >**NOTE** > > 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | **rawfile** directory. | | callback | AsyncCallback<Array\> | Yes| Callback used to return the result, which is the list of folders and files in the **rawfile** directory.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { // Passing "" means to obtain the list of files in the root directory of the raw file. this.context.resourceManager.getRawFileList("", (error: BusinessError, value: Array) => { if (error != null) { console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); } else { let rawFile = value; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFileList10+ getRawFileList(path: string): Promise<Array\> Obtains the list of folders and files in the **resources/rawfile** directory. This API uses a promise to return the result. >**NOTE** > > 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | **rawfile** directory.| **Return value** | Type | Description | | ------------------------- | ----------- | | Promise<Array\> | Promise used to return the result, which is the list of folders and files in the **rawfile** directory.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { // Passing "" means to obtain the list of files in the root directory of the raw file. this.context.resourceManager.getRawFileList("").then((value: Array) => { let rawFile = value; }).catch((error: BusinessError) => { console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getRawFileList failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFdSync10+ getRawFdSync(path: string): RawFileDescriptor Obtains the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------------- | | path | string | Yes | Path of the raw file. | **Return value** | Type | Description | | ------------------------- | ----------- | | [RawFileDescriptor](#rawfiledescriptor8) | Descriptor of the HAP where the raw file is located.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getRawFdSync("test.txt"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getRawFdSync failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFd9+ getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------------- | | path | string | Yes | Path of the raw file. | | callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result, which is the descriptor of the HAP where the raw file is located.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getRawFd("test.txt", (error: BusinessError, value: resourceManager.RawFileDescriptor) => { if (error != null) { console.error(`callback getRawFd failed error code: ${error.code}, message: ${error.message}.`); } else { let fd = value.fd; let offset = value.offset; let length = value.length; } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback getRawFd failed, error code: ${code}, message: ${message}.`); } ``` ### getRawFd9+ getRawFd(path: string): Promise<RawFileDescriptor> Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Descriptor of the HAP where the raw file is located.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getRawFd("test.txt").then((value: resourceManager.RawFileDescriptor) => { let fd = value.fd; let offset = value.offset; let length = value.length; }).catch((error: BusinessError) => { console.error(`promise getRawFd error error code: ${error.code}, message: ${error.message}.`); }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise getRawFd failed, error code: ${code}, message: ${message}.`); } ``` ### closeRawFdSync10+ closeRawFdSync(path: string): void Closes the descriptor of the HAP where the raw file is located in the **resources/rawfile** directory. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | The resource not found by path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.closeRawFdSync("test.txt"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`closeRawFd failed, error code: ${code}, message: ${message}.`); } ``` ### closeRawFd9+ closeRawFd(path: string, callback: AsyncCallback<void>): void Closes 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----------- | | path | string | Yes | Path of the raw file.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | The resource not found by path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.closeRawFd("test.txt", (error: BusinessError) => { if (error != null) { console.error("error is " + error); } }); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`); } ``` ### closeRawFd9+ closeRawFd(path: string): Promise<void> Closes 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. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.closeRawFd("test.txt"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`); } ``` ### getConfigurationSync10+ getConfigurationSync(): Configuration Obtains the device configuration. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ---------------- | | [Configuration](#configuration) | Device configuration.| **Example** ```ts try { let value = this.context.resourceManager.getConfigurationSync(); let direction = value.direction; let locale = value.locale; } catch (error) { console.error("getConfigurationSync error is " + error); } ``` ### getConfiguration getConfiguration(callback: AsyncCallback<Configuration>): void Obtains the device configuration. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------------- | | callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result, which is the device configuration.| **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getConfiguration((error: BusinessError, value: resourceManager.Configuration) => { if (error != null) { console.error("getConfiguration callback error is " + error); } else { let direction = value.direction; let locale = value.locale; } }); } catch (error) { console.error("getConfiguration callback error is " + error); } ``` ### getConfiguration getConfiguration(): Promise<Configuration> Obtains the device configuration. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ---------------- | | Promise<[Configuration](#configuration)> | Promise used to return the result, which is the device configuration.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getConfiguration().then((value: resourceManager.Configuration) => { let direction = value.direction; let locale = value.locale; }).catch((error: BusinessError) => { console.error("getConfiguration promise error is " + error); }); } catch (error) { console.error("getConfiguration promise error is " + error); } ``` ### getDeviceCapabilitySync10+ getDeviceCapabilitySync(): DeviceCapability Obtains the device capability. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ------------------- | | [DeviceCapability](#devicecapability) | Device capability.| **Example** ```ts try { let value = this.context.resourceManager.getDeviceCapabilitySync(); let screenDensity = value.screenDensity; let deviceType = value.deviceType; } catch (error) { console.error("getDeviceCapabilitySync error is " + error); } ``` ### getDeviceCapability getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void Obtains the device capability. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------- | | callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result, which is the device capability.| **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getDeviceCapability((error: BusinessError, value: resourceManager.DeviceCapability) => { if (error != null) { console.error("getDeviceCapability callback error is " + error); } else { let screenDensity = value.screenDensity; let deviceType = value.deviceType; } }); } catch (error) { console.error("getDeviceCapability callback error is " + error); } ``` ### getDeviceCapability getDeviceCapability(): Promise<DeviceCapability> Obtains the device capability. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result, which is the device capability.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { this.context.resourceManager.getDeviceCapability().then((value: resourceManager.DeviceCapability) => { let screenDensity = value.screenDensity; let deviceType = value.deviceType; }).catch((error: BusinessError) => { console.error("getDeviceCapability promise error is " + error); }); } catch (error) { console.error("getDeviceCapability promise error is " + error); } ``` ### addResource10+ addResource(path: string) : void Loads resources from the specified path. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | path | string | Yes | Resource path.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001010 | Invalid overlay path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; try { this.context.resourceManager.addResource(path); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`addResource failed, error code: ${code}, message: ${message}.`); } ``` ### removeResource10+ removeResource(path: string) : void Removes the resources loaded from the specified path to restore the original resources. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | path | string | Yes | Resource path.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001010 | Invalid overlay path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; try { this.context.resourceManager.removeResource(path); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`removeResource failed, error code: ${code}, message: ${message}.`); } ``` ### getLocales11+ getLocales(includeSystem?: boolean): Array\ Obtains the language list of an application. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------------- | ------- | ------ | -------------------- | | includeSystem | boolean | No | Whether system resources are included. The default value is **false**.
**false**: Only application resources are included.
**true**: Both system and application resources are included.
If the value of **includeSystem** is invalid, the language list of system resources will be returned.| **Return value** | Type | Description | | ------------------------- | ----------- | | Array\ | Language list. The strings in the list are comprised of the language, script (optional), and region (optional), which are connected by a hyphen (-).| **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getLocales(); // Obtain only the language list of application resources. } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getLocales failed, error code: ${code}, message: ${message}.`); } try { resourceManager.getSystemResourceManager().getLocales(); // Obtain only the language list of system resources. } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getLocales failed, error code: ${code}, message: ${message}.`); } try { this.context.resourceManager.getLocales(true); // Obtain the language list of application resources and resources. } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getLocales failed, error code: ${code}, message: ${message}.`); } ``` ### getSymbol11+ getSymbol(resId: number):number Obtains a symbol value based on the specified resource ID. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------ | ----------- | | number | Symbol value (decimal) corresponding to the specified resource ID.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getSymbol($r('app.symbol.test').id); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); } ``` ### getSymbol11+ getSymbol(resource: Resource): number Obtains a symbol value based on the specified resource object. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Model restriction**: This API can be used only in the stage model. **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------- | ---- | ---- | | resource | [Resource](#resource9) | Yes | Resource object.| **Return value** | Type | Description | | ------ | ----------- | | number | Symbol value (decimal) corresponding to the specified resource object.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001001 | Invalid resource ID. | | 9001002 | No matching resource is found based on the resource ID. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' import { BusinessError } from '@kit.BasicServicesKit'; let resource: resourceManager.Resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.symbol.test').id }; try { this.context.resourceManager.getSymbol(resource); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getSymbol failed, error code: ${code}, message: ${message}.`); } ``` ### getSymbolByName11+ getSymbolByName(resName: string) : number; Obtains a symbol value based on the specified resource name. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | resName | string | Yes | Resource name.| **Return value** | Type | Description | | ------ | ---------- | | number | Symbol value (decimal) corresponding to the specified resource name.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001003 | Invalid resource name. | | 9001004 | No matching resource is found based on the resource name. | | 9001006 | The resource is referenced cyclically. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.getSymbolByName("test"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getSymbolByName failed, error code: ${code}, message: ${message}.`); } ``` ### isRawDir12+ isRawDir(path: string) : bool Checks whether a path is a subdirectory in the **rawfile** directory. This API returns the result synchronously. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---- | | path | string | Yes | Path of a rawfile.| **Return value** | Type | Description | | ------ | ---------- | | bool |Whether the path is a subdirectory in the **rawfile** directory.
**true**: The path is a subdirectory in the **rawfile** directory.
**false**: The path is not a subdirectory in the **rawfile** directory.| **Error codes** For details about the error codes, see [Resource Manager Error Codes](errorcode-resource-manager.md). | ID| Error Message| | -------- | ---------------------------------------- | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types. | | 9001005 | Invalid relative path. | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; try { this.context.resourceManager.isRawDir("test.txt"); } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`isRawDir failed, error code: ${code}, message: ${message}.`); } ``` ### getOverrideResourceManager12+ getOverrideResourceManager(configuration?: Configuration) : ResourceManager Obtains a **ResourceManager** object for loading differentiated resources. This API returns the result synchronously. The 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. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | | configuration | [Configuration](#configuration) | No | 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.
If this parameter is not specified, the system obtains resources that best match the current system.| **Return value** | Type | Description | | --------------- | ---------------------------------- | | ResourceManager | **ResourceManager** object for loading differentiated resources.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { let resMgr = this.context.resourceManager let overrideConfig = resMgr.getOverrideConfiguration() overrideConfig.colorMode = resourceManager.ColorMode.DARK let overrideResMgr = resMgr.getOverrideResourceManager(overrideConfig) } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`getOverrideResourceManager failed, error code: ${code}, message: ${message}.`); } ``` ### getOverrideConfiguration12+ getOverrideConfiguration() : Configuration Obtains 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. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.Global.ResourceManager **Return value** | Type | Description | | ------------------------------- | ---------------- | | [Configuration](#configuration) | Configuration of differentiated resources.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' let overrideConfig = this.context.resourceManager.getOverrideConfiguration() ``` ### updateOverrideConfiguration12+ updateOverrideConfiguration(configuration: Configuration) : void Updated 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. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------- | ---- | ------------------------------------------------------------ | | 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.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | If the input parameter invalid. Possible causes: Incorrect parameter types | **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; import { resourceManager } from '@kit.LocalizationKit' try { let resMgr = this.context.resourceManager let overrideConfig = resMgr.getOverrideConfiguration() overrideConfig.colorMode = resourceManager.ColorMode.DARK let overrideResMgr = resMgr.updateOverrideConfiguration(overrideConfig) } catch (error) { let code = (error as BusinessError).code; let message = (error as BusinessError).message; console.error(`updateOverrideConfiguration failed, error code: ${code}, message: ${message}.`); } ``` ### release(deprecated) release() Releases a **ResourceManager** object. This API is not supported currently. This API is supported since API version 7 and is deprecated since API version 12. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.Global.ResourceManager **Example** ```ts try { this.context.resourceManager.release(); } catch (error) { console.error("release error is " + error); } ``` ### getString(deprecated) getString(resId: number, callback: AsyncCallback<string>): void Obtains a string based on the specified resource ID. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------- | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the string corresponding to the specified resource ID.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getString($r('app.string.test').id, (error: Error, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); }); ``` ### getString(deprecated) getString(resId: number): Promise<string> Obtains a string based on the specified resource ID. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | ----------- | | Promise<string> | Promise used to return the result, which is the string corresponding to the specified resource ID.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getString($r('app.string.test').id).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getstring promise error is " + error); }); }); ``` ### getStringArray(deprecated) getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void Obtains a string array based on the specified resource ID. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ----------------- | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result, which is the string array corresponding to the specified resource ID.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getStringArray($r('app.strarray.test').id, (error: Error, value: Array) => { if (error != null) { console.error("error is " + error); } else { let strArray = value; } }); }); ``` ### getStringArray(deprecated) getStringArray(resId: number): Promise<Array<string>> Obtains a string array based on the specified resource ID. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ---------------------------------- | ------------- | | Promise<Array<string>> | Promise used to return the result, which is the string array corresponding to the specified resource ID.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getStringArray($r('app.strarray.test').id).then((value: Array) => { let strArray = value; }).catch((error: BusinessError) => { console.error("getStringArray promise error is " + error); }); }); ``` ### getMedia(deprecated) getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void Obtains the content of a media file based on the specified resource ID. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ------------------ | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getMedia($r('app.media.test').id, (error: Error, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); }); ``` ### getMedia(deprecated) getMedia(resId: number): Promise<Uint8Array> Obtains the content of a media file based on the specified resource ID. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | ------------------------- | -------------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the media file corresponding to the specified resource ID.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getMedia($r('app.media.test').id).then((value: Uint8Array) => { let media = value; }).catch((error: BusinessError) => { console.error("getMedia promise error is " + error); }); }); ``` ### getMediaBase64(deprecated) getMediaBase64(resId: number, callback: AsyncCallback<string>): void Obtains the Base64 code of an image based on the specified resource ID. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------ | | resId | number | Yes | Resource ID. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getMediaBase64($r('app.media.test').id, ((error: Error, value: string) => { if (error != null) { console.error("error is " + error); } else { let media = value; } }); }); ``` ### getMediaBase64(deprecated) getMediaBase64(resId: number): Promise<string> Obtains the Base64 code of an image based on the specified resource ID. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase649-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| **Return value** | Type | Description | | --------------------- | -------------------- | | Promise<string> | Promise used to return the result, which is the Base64 code of the image corresponding to the specified resource ID.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getMediaBase64($r('app.media.test').id).then((value: string) => { let media = value; }).catch((error: BusinessError) => { console.error("getMediaBase64 promise error is " + error); }); }); ``` ### getPluralString(deprecated) getPluralString(resId: number, num: number): Promise<string> Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses a promise to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----- | | resId | number | Yes | Resource ID.| | num | number | Yes | Number. | **Return value** | Type | Description | | --------------------- | ------------------------- | | Promise<string> | Promise used to return the result, which is the singular-plural string corresponding to the specified resource ID.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getPluralString($r("app.plural.test").id, 1).then((value: string) => { let str = value; }).catch((error: BusinessError) => { console.error("getPluralString promise error is " + error); }); }); ``` ### getPluralString(deprecated) getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void Obtains a singular-plural string by the specified number based on the specified resource ID. This API uses an asynchronous callback to return the result. >**NOTE** > > Singular and plural forms are available for English, but not Chinese. This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ------------------------------- | | resId | number | Yes | Resource ID. | | num | number | Yes | Number. | | callback | AsyncCallback<string> | Yes | Callback used to return the result, which is the singular-plural string corresponding to the specified resource ID.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getPluralString($r("app.plural.test").id, 1, (error: Error, value: string) => { if (error != null) { console.error("error is " + error); } else { let str = value; } }); }); ``` ### getRawFile(deprecated) getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------------- | | path | string | Yes | Path of the raw file. | | callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result, which is the content of the raw file.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.getRawFile("test.txt", (error: Error, value: Uint8Array) => { if (error != null) { console.error("error is " + error); } else { let rawFile = value; } }); }); ``` ### getRawFile(deprecated) getRawFile(path: string): Promise<Uint8Array> Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ------------------------- | ----------- | | Promise<Uint8Array> | Promise used to return the result, which is the content of the raw file.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getRawFile("test.txt").then((value: Uint8Array) => { let rawFile = value; }).catch((error: BusinessError) => { console.error("getRawFile promise error is " + error); }); }); ``` ### getRawFileDescriptor(deprecated) getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | -------------------------------- | | path | string | Yes | Path of the raw file. | | callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result, which is the descriptor of the raw file.| **Example** ```ts import { resourceManager } from '@kit.LocalizationKit' resourceManager.getResourceManager((error, mgr) => { mgr.getRawFileDescriptor("test.txt", (error: Error, value: resourceManager.RawFileDescriptor) => { if (error != null) { console.error("error is " + error); } else { let fd = value.fd; let offset = value.offset; let length = value.length; } }); }); ``` ### getRawFileDescriptor(deprecated) getRawFileDescriptor(path: string): Promise<RawFileDescriptor> Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ---------------------------------------- | ------------------- | | Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result, which is the descriptor of the raw file.| **Example** ```ts import { BusinessError } from '@kit.BasicServicesKit'; resourceManager.getResourceManager((error, mgr) => { mgr.getRawFileDescriptor("test.txt").then((value: resourceManager.RawFileDescriptor) => { let fd = value.fd; let offset = value.offset; let length = value.length; }).catch((error: BusinessError) => { console.error("getRawFileDescriptor promise error is " + error); }); }); ``` ### closeRawFileDescriptor(deprecated) closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result. This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ----------- | | path | string | Yes | Path of the raw file.| | callback | AsyncCallback<void> | Yes | Callback used to return the result. | **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.closeRawFileDescriptor("test.txt", (error: Error) => { if (error != null) { console.error("error is " + error); } }); }); ``` ### closeRawFileDescriptor(deprecated) closeRawFileDescriptor(path: string): Promise<void> Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result. This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9-1). **System capability**: SystemCapability.Global.ResourceManager **Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | | path | string | Yes | Path of the raw file.| **Return value** | Type | Description | | ------------------- | ---- | | Promise<void> | Promise that returns no value.| **Example** ```ts resourceManager.getResourceManager((error, mgr) => { mgr.closeRawFileDescriptor("test.txt"); }); ``` ### Appendix - Content of the **app.string.test** file: ```json { "string": [ { "name": "test", "value": "10" } ] } ``` ```json { "string": [ { "name": "test", "value": "%s %d %f" } ] } ``` - Content of the **app.strarray.test** file: ```json { "strarray": [ { "name": "test", "value": [ ``` - Content of the **app.plural.test** file: ```json { "plural": [ { "name": "test", "value": [ { "quantity": "one", "value": "%d apple" }, { "quantity": "other", "value": "%d apples" } ] } ] } ``` - Content of the **app.boolean.boolean_test** file: ```json { "boolean": [ { "name": "boolean_test", "value": true } } ``` - Content of the **integer_test** and **float_test** files: ```json { "integer": [ { "name": "integer_test", "value": 100 } ] } ``` ```json { "float": [ { "name": "float_test", "value": "30.6" } ] } ``` - Content of the **app.color.test** file: ```json { "color": [ { "name": "test", "value": "#FFFFFF" } ] } ```