# @ohos.resourceManager (资源管理)

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

本模块提供应用资源和系统资源的访问能力，允许应用根据当前的[Configuration](#configuration)配置，获取最匹配的应用资源或系统资源，支持国际化资源匹配和多设备适配。具体匹配规则参考[资源匹配](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/resource-categories-and-access#资源匹配)。

Configuration配置包括语言-文字-国家地区、横竖屏、颜色模式、Mcc（移动国家码）和Mnc（移动网络码）、设备类型、屏幕密度。

**使用场景**：

* 应用国际化：根据用户语言和地区自动获取匹配的字符串资源。
* 多设备适配：根据设备类型、屏幕密度获取合适的媒体资源。
* 动态资源配置：根据设备状态（横竖屏、颜色模式等）获取对应配置的资源。

> 说明
>
> 本模块首批接口从API version 6开始支持。后续版本的新增接口，采用上角标单独标记接口的起始版本。

## 导入模块

> phone | 2in1 | tablet | tv | wearable

```js
import { resourceManager } from '@kit.LocalizationKit';
```

## 使用说明

> phone | 2in1 | tablet | tv | wearable

* FA模型需要先导入模块，再调用[getResourceManager](#resourcemanagergetresourcemanager)接口获取资源管理对象。

* 从API version 9开始，Stage模型无需导入模块，支持通过Context获取资源管理resourceManager对象。Context的更多介绍请参考[应用上下文Context](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/application-context-stage)。

  ```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

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getResourceManager(callback: AsyncCallback<ResourceManager>): void

获取当前应用的资源管理对象。使用callback异步回调。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在FA模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:-----------------------------------------------------------------------------|:-|:-------------|
|callback|[AsyncCallback](#asynccallbackdeprecated)<[ResourceManager](#resourcemanager)>|是|回调函数，返回资源管理对象。|

**示例：**

```js
import resourceManager from '@ohos.resourceManager';
// FA模型请使用上述方式导入模块

export default {
    onCreate() {
        resourceManager.getResourceManager((error, mgr) => {
            if (error != null) {
                console.error("error is " + error);
                return;
            }
            // 'test'仅作示例，请替换为实际使用的资源名称
            mgr.getStringByName('test', (error, value) => {
                if (error) {
                    console.error("error is " + JSON.stringify(error));
                } else {
                    console.info("success is " + value);
                }

            });
        });
    }
};
```

## resourceManager.getResourceManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void

获取指定应用的资源管理对象。使用callback异步回调。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在FA模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----------------------------------------------------------------------------|:-|:--------------------|
|bundleName|string|是|应用包名。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<[ResourceManager](#resourcemanager)>|是|回调函数，返回应用包名对应的资源管理对象。|

**示例：**

```js
import resourceManager from '@ohos.resourceManager';
// FA模型请使用上述方式导入模块

// 'com.example.testapp'仅作示例，请替换为实际应用包名
const BUNDLE_NAME = 'com.example.testapp';

export default {
    onCreate() {
        resourceManager.getResourceManager(BUNDLE_NAME, (error, mgr) => {
            if (error != null) {
                console.error("getResourceManager error is " + error);
                return;
            }
            // 'test'仅作示例，请替换为实际使用的资源名称
            mgr.getStringByName('test', (error, value) => {
                if (error) {
                    console.error("getResourceManager error is " + JSON.stringify(error));
                } else {
                    console.info("getResourceManager success is " + value);
                }
            });
        });
    }
};
```

## resourceManager.getResourceManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getResourceManager(): Promise<ResourceManager>

获取当前应用的资源管理对象。使用Promise异步回调。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在FA模型下使用。

**返回值：**

|类型|说明|
|:-------------------------------------------|:------------------|
|Promise<[ResourceManager](#resourcemanager)>|Promise对象，返回资源管理对象。|

**示例：**

```js
import resourceManager from '@ohos.resourceManager';
// FA模型请使用上述方式导入模块

export default {
    onCreate() {
        resourceManager.getResourceManager().then(resMgr => {
            try {
                // 'test'仅作示例，请替换为实际使用的资源名称
                let testStr = resMgr.getStringByNameSync('test')
                console.info("getResourceManager success is " + testStr);
            } catch (error) {
                console.error("getResourceManager error is " + JSON.stringify(error));
            }
        }).catch(error => {
            console.error("getResourceManager error is " + error);
        });
    }
};
```

## resourceManager.getResourceManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getResourceManager(bundleName: string): Promise<ResourceManager>

获取指定应用的资源管理对象。使用Promise异步回调。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在FA模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:---------|:-----|:-|:----|
|bundleName|string|是|应用包名。|

**返回值：**

|类型|说明|
|:-------------------------------------------|:-------------------------|
|Promise<[ResourceManager](#resourcemanager)>|Promise对象，返回应用包名对应的资源管理对象。|

**示例：**

```js
import resourceManager from '@ohos.resourceManager';
// FA模型请使用上述方式导入模块

// 'com.example.testapp'仅作示例，请替换为实际应用包名
const BUNDLE_NAME = 'com.example.testapp';

export default {
    onCreate() {
        resourceManager.getResourceManager(BUNDLE_NAME).then(resMgr => {
            try {
                // 'test'仅作示例，请替换为实际使用的资源名称
                let testStr = resMgr.getStringByNameSync('test')
                console.info("getResourceManager success is " + testStr);
            } catch (error) {
                console.error("getResourceManager error is " + JSON.stringify(error));
            }
        }).catch(error => {
            console.error("getResourceManager error is " + error);
        });
    }
};
```

## resourceManager.getSysResourceManager^20+^

> phone 20+ | 2in1 20+ | tablet 20+ | tv 20+ | wearable 20+

getSysResourceManager(): ResourceManager

获取系统资源管理对象，用于访问系统预置的资源。

**元服务API：** 从API version 20开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:----------------------------------|:--------|
|[ResourceManager](#resourcemanager)|系统资源管理对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------------------------|
|9001009|Failed to access the system resource. which is not mapped to application sandbox, This error code will be thrown.|

**示例：**

```js
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  let systemResourceManager = resourceManager.getSysResourceManager();
  // 'sys.string.ohos_lab_vibrate'仅作示例，请替换为实际使用的资源
  systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then((value: string) => {
    let str = value;
  }).catch((error: BusinessError) => {
    console.error(`systemResourceManager getStringValue promise error: ${error}`);
  });
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getSysResourceManager failed, error code: ${code}, message: ${message}.`);
}
```

## Direction

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

用于表示设备屏幕方向。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|值|说明|
|:-------------------|:-|:--|
|DIRECTION_VERTICAL|0|竖屏。|
|DIRECTION_HORIZONTAL|1|横屏。|

## DeviceType

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

用于表示当前设备类型。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|值|说明|
|:--------------------|:---|:----|
|DEVICE_TYPE_PHONE|0x00|手机。|
|DEVICE_TYPE_TABLET|0x01|平板。|
|DEVICE_TYPE_CAR|0x02|汽车。|
|DEVICE_TYPE_PC|0x03|电脑。|
|DEVICE_TYPE_TV|0x04|电视。|
|DEVICE_TYPE_WEARABLE|0x06|穿戴。|
|DEVICE_TYPE_2IN1^11+^|0x07|2IN1。|

## ScreenDensity

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

用于表示当前设备屏幕密度。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|值|说明|
|:-------------|:--|:-------|
|SCREEN_SDPI|120|低屏幕密度。|
|SCREEN_MDPI|160|中屏幕密度。|
|SCREEN_LDPI|240|高屏幕密度。|
|SCREEN_XLDPI|320|特高屏幕密度。|
|SCREEN_XXLDPI|480|超高屏幕密度。|
|SCREEN_XXXLDPI|640|超特高屏幕密度。|

## ColorMode^12+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

用于表示当前设备颜色模式。

**元服务API：** 从API version 12开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|值|说明|
|:----|:-|:----|
|DARK|0|深色模式。|
|LIGHT|1|浅色模式。|

## Configuration

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示当前设备的状态。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|类型|只读|可选|说明|
|:-----------------|:------------------------------|:-|:-|:----------------------------------------------------|
|direction|[Direction](#direction)|否|否|屏幕方向。 **元服务API：** 从API version 11开始，该接口支持在元服务中使用。|
|locale|string|否|否|语言文字国家地区。 **元服务API：** 从API version 11开始，该接口支持在元服务中使用。|
|deviceType^12+^|[DeviceType](#devicetype)|否|否|设备类型。 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|
|screenDensity^12+^|[ScreenDensity](#screendensity)|否|否|屏幕密度。 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|
|colorMode^12+^|[ColorMode](#colormode12)|否|否|颜色模式。 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|
|mcc^12+^|number|否|否|移动国家码。 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|
|mnc^12+^|number|否|否|移动网络码。 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|

## DeviceCapability

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

表示设备支持的能力。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|名称|类型|只读|可选|说明|
|:------------|:------------------------------|:-|:-|:--------|
|screenDensity|[ScreenDensity](#screendensity)|否|否|当前设备屏幕密度。|
|deviceType|[DeviceType](#devicetype)|否|否|当前设备类型。|

## RawFileDescriptor^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

type RawFileDescriptor = _RawFileDescriptor

表示rawfile文件所在HAP的文件描述符信息。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|类型|说明|
|:------------------------------------------------------------------------------------------------------------------------------------|:--------------------------|
|[_RawFileDescriptor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-rawfiledescriptor#rawfiledescriptor-1)|表示rawfile文件所在HAP的文件描述符（fd）。|

## Resource^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

type Resource = _Resource

表示资源相关信息，包括应用包名、应用模块名、资源ID、资源类型和格式化参数等。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

|类型|说明|
|:---------------------------------------------------------------------------------------------------------|:---------------------------------------|
|[_Resource](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-resource#resource-1)|表示资源信息，包含资源ID值、应用包名、模块名称等信息，一般可使用$r方式获取。|

## ResourceManager

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

提供访问应用资源和系统资源的能力，可访问的资源范围为当前Context对应的HAP/HSP模块中的资源以及所有的系统资源。
> 说明
>
> * ResourceManager涉及到的方法，仅限基于TS扩展的声明式开发范式使用。
>
> * 资源文件在工程的resources目录中定义，通过resName、resId、Resource对象等可以获取对应的字符串、字符串数组、颜色等资源值，resName为资源名称，resId可通过$r(资源地址).id的方式获取，例如$r('app.string.test').id。
>
> * 单HAP包获取自身资源、跨HAP/HSP包获取资源，由于入参为Resource的接口相比于入参为resName、resId的接口耗时更长，因此更推荐使用参数为resName或resId的接口。跨HAP/HSP包获取资源，**需要先使用[createModuleContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-application#applicationcreatemodulecontext)创建对应module的context** ，再调用参数为resName或resId的接口。更多请参考[资源访问](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/resource-categories-and-access#资源访问)。
>
> * 在API version 22及之前版本，中间码HAR、字节码HAR通过资源ID相关接口访问资源时，因ID无效会抛出异常；从API version 23开始，中间码HAR、字节码HAR通过资源ID相关接口可以正常访问资源，更多请参考[资源访问](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/resource-categories-and-access#资源访问)。
>
> * 示例代码中test文件的具体内容请参考[附录](#附录)。

### getStringSync^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringSync(resId: number): string

获取指定资源ID对应的字符串，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:-----|:-----------|
|string|资源ID值对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.string.test'仅作示例，请替换为实际使用的资源
            let testStr = this.context.resourceManager.getStringSync($r('app.string.test').id);
            console.info(`getStringSync, result: ${testStr}`);
            // 打印输出结果: getStringSync, result: I'm a test string resource.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getStringSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringSync(resId: number, ...args: Array<string | number>): string

获取指定资源ID对应的字符串，并使用args参数依次替换字符串中的格式化占位符。使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:--------------|
|string|资源ID值对应的格式化字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a %1$s, format int: %2$d, format float: %3$f."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.string.test'仅作示例，请替换为实际使用的资源
            let testStr = this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
            console.info(`getStringSync, result: ${testStr}`);
            // 打印输出结果: getStringSync, result: I'm a format string, format int: 10, format float: 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}.`);
        }
    }
}
```

### getStringByNameSync^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringByNameSync(resName: string): string

获取指定资源名称对应的字符串，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:-----|:----------|
|string|资源名称对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            let testStr = this.context.resourceManager.getStringByNameSync("test");
            console.info(`getStringByNameSync, result: ${testStr}`);
            // 打印输出结果: getStringByNameSync, result: I'm a test string resource.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getStringByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getStringByNameSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringByNameSync(resName: string, ...args: Array<string | number>): string

获取指定资源名称对应的字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:-------------|
|string|资源名称对应的格式化字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a %1$s, format int: %2$d, format float: %3$f."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            let testStr = this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
            console.info(`getStringByNameSync, result: ${testStr}`);
            // 打印输出结果: getStringByNameSync, result: I'm a format string, format int: 10, format float: 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}.`);
        }
    }
}
```

### getStringValue^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringValue(resId: number, callback: _AsyncCallback<string>): void

获取指定资源ID对应的字符串。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:-------------|
|resId|number|是|资源ID值。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回获取的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例Stage：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.string.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringValue($r('app.string.test').id, (error: BusinessError, value: string) => {
            if (error != null) {
                console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                console.info(`getStringValue, result: ${value}`);
                // 打印输出结果: getStringValue, result: I'm a test string resource.
            }
        });
    }
}
```

### getStringValue^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringValue(resId: number): Promise<string>

获取指定资源ID对应的字符串。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:--------------|:-----------------------|
|Promise<string>|Promise对象，返回资源ID值对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.string.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringValue($r('app.string.test').id).then((value: string) => {
            console.info(`getStringValue, result: ${value}`);
            // 打印输出结果: getStringValue, result: I'm a test string resource.
        }).catch((error: BusinessError) => {
            console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
        });
    }
}
```

### getStringByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringByName(resName: string, callback: _AsyncCallback<string>): void

获取指定资源名称对应的字符串。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:-------------|
|resName|string|是|资源名称。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回获取的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringByName("test", (error: BusinessError, value: string) => {
            if (error != null) {
                console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                console.info(`getStringByName, result: ${value}`);
                // 打印输出结果: getStringByName, result: I'm a test string resource.
            }
        });
    }
}
```

### getStringByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringByName(resName: string): Promise<string>

获取指定资源名称对应的字符串。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:--------------|:----------------------|
|Promise<string>|Promise对象，返回资源名称对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringByName("test").then((value: string) => {
            console.info(`getStringByName, result: ${value}`);
            // 打印输出结果: getStringByName, result: I'm a test string resource.
        }).catch((error: BusinessError) => {
            console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
        });
    }
}
```

### getStringArrayValueSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValueSync(resId: number): Array<string>

获取指定资源ID对应的字符串数组，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:------------|:-------------|
|Array<string>|资源ID值对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.strarray.test'仅作示例，请替换为实际使用的资源
            let strArray: Array<string> = this.context.resourceManager.getStringArrayValueSync($r('app.strarray.test').id);
            console.info(`getStringArrayValueSync, result: ${strArray[0]}`);
            // 打印输出结果: getStringArrayValueSync, result: I'm one of the array's values.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getStringArrayByNameSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayByNameSync(resName: string): Array<string>

获取指定资源名称对应的字符串数组，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:------------|:------------|
|Array<string>|对应资源名称的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            let strArray: Array<string> = this.context.resourceManager.getStringArrayByNameSync("test");
            console.info(`getStringArrayByNameSync, result: ${strArray[0]}`);
            // 打印输出结果: getStringArrayByNameSync, result: I'm one of the array's values.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getStringArrayByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getStringArrayValue^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValue(resId: number, callback: _AsyncCallback<Array<string>>): void

获取指定资源ID对应的字符串数组。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------|:-|:--------------------|
|resId|number|是|资源ID值。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Array<string>>|是|回调函数，返回资源ID值对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.strarray.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id,
            (error: BusinessError, value: Array<string>) => {
                if (error != null) {
                    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
                } else {
                    console.info(`getStringArrayValue, result: ${value[0]}`);
                    // 打印输出结果: getStringArrayValue, result: I'm one of the array's values.
                }
            });
    }
}
```

### getStringArrayValue^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValue(resId: number): Promise<Array<string>>

获取指定资源ID对应的字符串数组。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:---------------------|:-------------------------|
|Promise<Array<string>>|Promise对象，返回资源ID值对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.strarray.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id)
            .then((value: Array<string>) => {
                console.info(`getStringArrayValue, result: ${value[0]}`);
                // 打印输出结果: getStringArrayValue, result: I'm one of the array's values.
            })
            .catch((error: BusinessError) => {
                console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
            });
    }
}
```

### getStringArrayByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayByName(resName: string, callback: _AsyncCallback<Array<string>>): void

获取指定资源名称对应的字符串数组。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------|:-|:-------------------|
|resName|string|是|资源名称。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Array<string>>|是|回调函数，返回资源名称对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringArrayByName("test", (error: BusinessError, value: Array<string>) => {
            if (error != null) {
                console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                let strArray = value;
                console.info(`getStringArrayByName, result: ${value[0]}`);
                // 打印输出结果: getStringArrayByName, result: I'm one of the array's values.
            }
        });
    }
}
```

### getStringArrayByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayByName(resName: string): Promise<Array<string>>

获取指定资源名称对应的字符串数组。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:---------------------|:------------------------|
|Promise<Array<string>>|Promise对象，返回资源名称对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getStringArrayByName("test")
            .then((value: Array<string>) => {
                console.info(`getStringArrayByName, result: ${value[0]}`);
                // 打印输出结果: getStringArrayByName, result: I'm one of the array's values.
            })
            .catch((error: BusinessError) => {
                console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
            });
    }
}
```

### getIntPluralStringValueSync^18+^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getIntPluralStringValueSync(resId: number, num: number, ...args: Array<string | number>): string

获取指定资源ID对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> * 在英语、德语等语言中，单复数类型包括基数词（如1、2、3）和序数词（如1st、2nd、3rd），本接口仅支持在基数词类型下使用。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值（整数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:-----------------|
|string|资源ID值对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
            // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
            // 'app.plural.format_test'仅作示例，请替换为实际使用的资源
            let pluralStr = this.context.resourceManager.getIntPluralStringValueSync($r('app.plural.format_test').id, 1, 1, "basket", 0.3);
            console.info(`getIntPluralStringValueSync, result: ${pluralStr}`);
            // 打印输出结果: getIntPluralStringValueSync, result: There is 1 apple in the basket, the total amount is 0.3 kg.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getIntPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getIntPluralStringByNameSync^18+^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getIntPluralStringByNameSync(resName: string, num: number, ...args: Array<string | number>): string

获取指定资源名称对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> * 在英语、德语等语言中，单复数类型包括基数词（如1、2、3）和序数词（如1st、2nd、3rd），本接口仅支持在基数词类型下使用。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|num|number|是|数量值（整数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:----------------|
|string|资源名称对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
            // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
            // "format_test"仅作示例，请替换为实际使用的资源
            let pluralStr = this.context.resourceManager.getIntPluralStringByNameSync("format_test", 1, 1, "basket", 0.3);
            console.info(`getIntPluralStringByNameSync, result: ${pluralStr}`);
            // 打印输出结果: getIntPluralStringByNameSync, result: There is 1 apple in the basket, the total amount is 0.3 kg.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getIntPluralStringByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getDoublePluralStringValueSync^18+^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getDoublePluralStringValueSync(resId: number, num: number, ...args: Array<string | number>): string

获取指定资源ID对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> * 在英语、德语等语言中，单复数类型包括基数词（如1、2、3）和序数词（如1st、2nd、3rd），本接口仅支持在基数词类型下使用。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值（浮点数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:-----------------|
|string|资源ID值对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 根据语言单复数规则，参数num取值为2.1，英文环境下对应单复数类别为other
            // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为other的字符串
            // 'app.plural.format_test'仅作示例，请替换为实际使用的资源
            let pluralStr = this.context.resourceManager.getDoublePluralStringValueSync($r('app.plural.format_test').id, 2.1, 2, "basket", 0.6);
            console.info(`getDoublePluralStringValueSync, result: ${pluralStr}`);
            // 打印输出结果: getDoublePluralStringValueSync, result: There are 2 apples in the basket, the total amount is 0.6 kg.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getDoublePluralStringValueSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getDoublePluralStringByNameSync^18+^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getDoublePluralStringByNameSync(resName: string, num: number, ...args: Array<string | number>): string

获取指定资源名称对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> * 在英语、德语等语言中，单复数类型包括基数词（如1、2、3）和序数词（如1st、2nd、3rd），本接口仅支持在基数词类型下使用。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|num|number|是|数量值（浮点数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:----------------|
|string|资源名称对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 根据语言单复数规则，参数num取值为2.1，英文环境下对应单复数类别为other
            // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为other的字符串
            // "format_test"仅作示例，请替换为实际使用的资源
            let pluralStr = this.context.resourceManager.getDoublePluralStringByNameSync("format_test", 2.1, 2, "basket", 0.6);
            console.info(`getDoublePluralStringByNameSync, result: ${pluralStr}`);
            // 打印输出结果: getDoublePluralStringByNameSync, result: There are 2 apples in the basket, the total amount is 0.6 kg.
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getDoublePluralStringByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getMediaContentSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentSync(resId: number, density?: number): Uint8Array

获取指定资源ID对应的默认或指定的屏幕密度媒体文件内容，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:-----------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:---------|:-------------|
|Uint8Array|资源ID对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaContentSync($r('app.media.test').id); // 默认屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaContentSync($r('app.media.test').id, 120); // 指定屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getMediaByNameSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaByNameSync(resName: string, density?: number): Uint8Array

获取指定资源名称对应的默认或指定的屏幕密度媒体文件内容，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:-----------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:---------|:-------------|
|Uint8Array|资源名称对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaByNameSync("test"); // 默认屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // "test"仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaByNameSync("test", 120); // 指定屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getMediaContent^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resId: number, callback: _AsyncCallback<Uint8Array>): void

获取指定资源ID对应的媒体文件内容。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------|
|resId|number|是|资源ID值。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回资源ID对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContent^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resId: number, density: number, callback: _AsyncCallback<Uint8Array>): void

获取指定资源ID对应的指定屏幕密度媒体文件内容。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回资源ID对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContent^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resId: number): Promise<Uint8Array>

获取指定资源ID对应的媒体文件内容。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:------------------|:--------------------------|
|Promise<Uint8Array>|Promise对象，返回资源ID值对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContent^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resId: number, density: number): Promise<Uint8Array>

获取指定资源ID对应的指定屏幕密度媒体文件内容。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:------------------|:--------------------------|
|Promise<Uint8Array>|Promise对象，返回资源ID值对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaByName(resName: string, callback: _AsyncCallback<Uint8Array>): void

获取指定资源名称对应的媒体文件内容。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------|
|resName|string|是|资源名称。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回资源名称对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001003|Invalid resource name.|
|9001004|No matching resource is found based on the resource name.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaByName(resName: string, density: number, callback: _AsyncCallback<Uint8Array>): void

获取指定资源名称对应的指定屏幕密度媒体文件内容。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回资源名称对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaByName(resName: string): Promise<Uint8Array>

获取指定资源名称对应的媒体文件内容。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:------------------|:-------------------------|
|Promise<Uint8Array>|Promise对象，返回资源名称对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001003|Invalid resource name.|
|9001004|No matching resource is found based on the resource name.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaByName(resName: string, density: number): Promise<Uint8Array>

获取指定资源名称对应的指定屏幕密度媒体文件内容。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:------------------|:-------------------------|
|Promise<Uint8Array>|Promise对象，返回资源名称对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContentBase64Sync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64Sync(resId: number, density?: number): string

获取指定资源ID对应的默认或指定的屏幕密度图片资源Base64编码，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:-----------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:-----|:-------------------|
|string|资源ID对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id); // 默认屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaContentBase64Sync($r('app.media.test').id, 120); // 指定屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getMediaBase64ByNameSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64ByNameSync(resName: string, density?: number): string

获取指定资源名称对应的默认或指定的屏幕密度图片资源Base64编码，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:-----------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:-----|:-------------------|
|string|资源名称对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaBase64ByNameSync("test"); // 默认屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // "test"仅作示例，请替换为实际使用的资源
            this.context.resourceManager.getMediaBase64ByNameSync("test", 120); // 指定屏幕密度
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getMediaBase64ByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getMediaContentBase64^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resId: number, callback: _AsyncCallback<string>): void

获取指定资源ID对应的图片资源Base64编码。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:---------------------------|
|resId|number|是|资源ID值。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源ID值对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContentBase64^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resId: number, density: number, callback: _AsyncCallback<string>): void

获取指定资源ID对应的指定屏幕密度图片资源Base64编码。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源ID值对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContentBase64^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resId: number): Promise<string>

获取指定资源ID对应的图片资源Base64编码。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:--------------|:--------------------------------|
|Promise<string>|Promise对象，返回资源ID值对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaContentBase64^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resId: number, density: number): Promise<string>

获取指定资源ID对应的指定屏幕密度图片资源Base64编码。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:--------------|:--------------------------------|
|Promise<string>|Promise对象，返回资源ID值对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.test'仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaBase64ByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64ByName(resName: string, callback: _AsyncCallback<string>): void

获取指定资源名称对应的图片资源Base64编码。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:------------------------|
|resName|string|是|资源名称。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源名称的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001003|Invalid resource name.|
|9001004|No matching resource is found based on the resource name.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaBase64ByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64ByName(resName: string, density: number, callback: _AsyncCallback<string>): void

获取指定资源名称对应的指定屏幕密度图片资源Base64编码。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源名称的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaBase64ByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64ByName(resName: string): Promise<string>

获取指定资源名称对应的图片资源Base64编码。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------|
|Promise<string>|Promise对象，返回资源名称对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001003|Invalid resource name.|
|9001004|No matching resource is found based on the resource name.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getMediaBase64ByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64ByName(resName: string, density: number): Promise<string>

获取指定资源名称对应的指定屏幕密度图片资源Base64编码。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------|
|Promise<string>|Promise对象，返回资源名称对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getDrawableDescriptor^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDrawableDescriptor(resId: number, density?: number, type?: number): DrawableDescriptor

获取指定资源ID对应的DrawableDescriptor对象，用于图标的显示，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:-----------------------------------------------------------------|
|resId|number|是|资源ID值。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|type^11+^|number|否|图标类型。默认值为0。 0：表示获取应用自身图标资源。 1：表示获取主题资源包中应用的分层图标资源。|

**返回值：**

|类型|说明|
|:------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------|
|[DrawableDescriptor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-arkui-drawabledescriptor#drawabledescriptor)|资源ID值对应的DrawableDescriptor对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { DrawableDescriptor } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.media.icon'仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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 {
            // 'app.media.icon'仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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 {
            // 'app.media.icon'仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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}.`);
        }
    }
}
```

### getDrawableDescriptorByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDrawableDescriptorByName(resName: string, density?: number, type?: number): DrawableDescriptor

获取指定资源名称对应的DrawableDescriptor对象，用于图标的显示，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:--------|:-----|:-|:-----------------------------------------------------------------|
|resName|string|是|资源名称。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|type^11+^|number|否|图标类型。默认值为0。 0：表示获取应用自身图标资源。 1：表示获取主题资源包中应用的分层图标资源。|

**返回值：**

|类型|说明|
|:------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------|
|[DrawableDescriptor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-arkui-drawabledescriptor#drawabledescriptor)|资源名称对应的DrawableDescriptor对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { DrawableDescriptor } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "icon"仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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 {
            // "icon"仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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 {
            // "icon"仅作示例，请替换为实际使用的资源
            let drawableDescriptor:DrawableDescriptor = 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}.`);
        }
    }
}
```

### getBoolean^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getBoolean(resId: number): boolean

获取指定资源ID值对应的布尔值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:------|:-----------|
|boolean|资源ID值对应的布尔值。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/boolean.json
{
  "boolean": [
    {
      "name": "boolean_test",
      "value": true
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.boolean.boolean_test'仅作示例，请替换为实际使用的资源
            let boolTest = this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
            console.info(`getBoolean, result: ${boolTest}`);
            // 打印输出结果: getBoolean, result: true
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getBooleanByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getBooleanByName(resName: string): boolean

获取指定资源名称对应的布尔值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:------|:----------|
|boolean|资源名称对应的布尔值。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/boolean.json
{
  "boolean": [
    {
      "name": "boolean_test",
      "value": true
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "boolean_test"仅作示例，请替换为实际使用的资源
            let boolTest = this.context.resourceManager.getBooleanByName("boolean_test");
            console.info(`getBooleanByName, result: ${boolTest}`);
            // 打印输出结果: getBooleanByName, result: true
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getBooleanByName failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getNumber^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getNumber(resId: number): number

获取指定资源ID对应的integer数值或者float数值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:-----|:------------------------------------------------------------------------------------------------------------------------------|
|number|资源ID值对应的数值。 integer类型资源返回资源文件中定义的原始数值。 float类型资源不带单位时返回资源文件中定义的原始数值，带"vp"或"fp"单位时返回转换后的像素(px)值。转换公式：像素值 = 原始数值 × densityPixels。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/integer.json
{
  "integer": [
    {
      "name": "integer_test",
      "value": 100
    }
  ]
}
```

```json5
// 资源文件路径: src/main/resources/base/element/float.json
{
  "float": [
    {
      "name": "float_test",
      "value": "30.6vp"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // integer对应返回的是原数值
            // 'app.integer.integer_test'仅作示例，请替换为实际使用的资源
            let intValue = this.context.resourceManager.getNumber($r('app.integer.integer_test').id);
            console.info(`getNumber, int value: ${intValue}`);
            // 打印输出结果: getNumber, int value: 100
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // float对应返回的是真实像素点值，带"vp","fp"单位的像素值 = 原数值 * densityPixels
            // 'app.float.float_test'仅作示例，请替换为实际使用的资源
            let floatValue = this.context.resourceManager.getNumber($r('app.float.float_test').id);
            console.info(`getNumber, densityPixels: ${display.getDefaultDisplaySync().densityPixels}, float value: ${floatValue}`);
            // 打印输出结果: getNumber, densityPixels: 3.25, float value: 99.45000457763672
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getNumberByName^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getNumberByName(resName: string): number

获取指定资源名称对应的integer数值或者float数值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:-----|:-----------------------------------------------------------------------------------------------------------------------------|
|number|资源名称对应的数值。 integer类型资源返回资源文件中定义的原始数值。 float类型资源不带单位时返回资源文件中定义的原始数值，带"vp"或"fp"单位时返回转换后的像素(px)值。转换公式：像素值 = 原始数值 × densityPixels。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/integer.json
{
  "integer": [
    {
      "name": "integer_test",
      "value": 100
    }
  ]
}
```

```json5
// 资源文件路径: src/main/resources/base/element/float.json
{
  "float": [
    {
      "name": "float_test",
      "value": "30.6vp"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { display } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // integer对应返回的是原数值
            // "integer_test"仅作示例，请替换为实际使用的资源
            let intValue = this.context.resourceManager.getNumberByName("integer_test");
            console.info(`getNumberByName, int value: ${intValue}`);
            // 打印输出结果: getNumberByName, int value: 100
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
        }

        try {
            // float对应返回的是真实像素点值，带"vp","fp"单位的像素值 = 原数值 * densityPixels
            // "float_test"仅作示例，请替换为实际使用的资源
            let floatValue = this.context.resourceManager.getNumberByName("float_test");
            console.info(`getNumberByName, densityPixels: ${display.getDefaultDisplaySync().densityPixels}, float value: ${floatValue}`);
            // 打印输出结果: getNumberByName, densityPixels: 3.25, float value: 99.45000457763672
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getNumberByName failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getColorSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColorSync(resId: number) : number

获取指定资源ID对应的颜色值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:-----|:----------------|
|number|资源ID值对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.color.test'仅作示例，请替换为实际使用的资源
            let colorValue = this.context.resourceManager.getColorSync($r('app.color.test').id);
            console.info(`getColorSync, result: ${colorValue}`);
            // 打印输出结果: getColorSync, result: 4294967295
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getColorByNameSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColorByNameSync(resName: string) : number

获取指定资源名称对应的颜色值，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:-----|:---------------|
|number|资源名称对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test"仅作示例，请替换为实际使用的资源
            let colorValue = this.context.resourceManager.getColorByNameSync("test");
            console.info(`getColorByNameSync, result: ${colorValue}`);
            // 打印输出结果: getColorByNameSync, result: 4294967295
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getColorByNameSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getColor^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColor(resId: number, callback: _AsyncCallback<number>): void

获取指定资源ID对应的颜色值。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:-----------------------|
|resId|number|是|资源ID值。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<number>|是|回调函数，返回资源ID值对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例Stage：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.color.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getColor($r('app.color.test').id, (error: BusinessError, value: number) => {
            if (error != null) {
                console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                console.info(`getColor, result: ${value}`);
                // 打印输出结果: getColor, result: 4294967295
            }
        });
    }
}
```

### getColor^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColor(resId: number): Promise<number>

获取指定资源ID对应的颜色值。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:--------------|:----------------------------|
|Promise<number>|Promise对象，返回资源ID值对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 'app.color.test'仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getColor($r('app.color.test').id)
            .then((value: number) => {
                console.info(`getColor, result: ${value}`);
                // 打印输出结果: getColor, result: 4294967295
            })
            .catch((error: BusinessError) => {
                console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
            });
    }
}
```

### getColorByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColorByName(resName: string, callback: _AsyncCallback<number>): void

获取指定资源名称对应的颜色值。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:----------------------|
|resName|string|是|资源名称。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<number>|是|回调函数，返回资源名称对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getColorByName("test", (error: BusinessError, value: number) => {
            if (error != null) {
                console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                console.info(`getColorByName, result: ${value}`);
                // 打印输出结果: getColorByName, result: 4294967295
            }
        });
    }
}
```

### getColorByName^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColorByName(resName: string): Promise<number>

获取指定资源名称对应的颜色值。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:--------------|:---------------------------|
|Promise<number>|Promise对象，返回资源名称对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "test"仅作示例，请替换为实际使用的资源
        this.context.resourceManager.getColorByName("test")
            .then((value: number) => {
                console.info(`getColorByName, result: ${value}`);
                // 打印输出结果: getColorByName, result: 4294967295
            })
            .catch((error: BusinessError) => {
                console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
            });
    }
}
```

### getRawFileContentSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileContentSync(path: string): Uint8Array

获取resources/rawfile目录下对应的rawfile文件内容，使用同步形式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:---------|:----------------|
|Uint8Array|返回获取的rawfile文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getRawFileContent^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileContent(path: string, callback: _AsyncCallback<Uint8Array>): void

获取resources/rawfile目录下对应的rawfile文件内容。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回获取的rawfile文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getRawFileContent^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileContent(path: string): Promise<Uint8Array>

获取resources/rawfile目录下对应的rawfile文件内容。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------------|:--------------------------|
|Promise<Uint8Array>|Promise对象，返回获取的rawfile文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getRawFileListSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileListSync(path: string): Array<string>

获取resources/rawfile下指定子目录中的文件夹及文件列表，使用同步形式返回。
> 说明
>
> 若文件夹中无文件，则抛出异常；若文件夹中有文件，则返回文件夹及文件列表。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:------------------------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile子目录路径，如"subdir"，不以"/"开头。 空字符串""表示获取rawfile根目录下的文件夹及文件列表。|

**返回值：**

|类型|说明|
|:------------|:--------------------|
|Array<string>|rawfile子目录下的文件夹及文件列表。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 传入""表示获取rawfile根目录下的文件列表，假设rawfile根目录下存在test.txt文件
            // 传入""仅作示例，请替换为rawfile目录下实际的文件路径
            let fileList: Array<string> = this.context.resourceManager.getRawFileListSync("");
            console.info(`getRawFileListSync, result: ${JSON.stringify(fileList)}`);
            // 打印输出结果: getRawFileListSync, result: ["test.txt"]
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getRawFileListSync failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getRawFileList^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileList(path: string, callback: _AsyncCallback<Array<string>>): void

获取resources/rawfile下指定子目录中的文件夹及文件列表。使用callback异步回调。
> 说明
>
> 若文件夹中无文件，则抛出异常；若文件夹中有文件，则返回文件夹及文件列表。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------|:-|:------------------------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile子目录路径，如"subdir"，不以"/"开头。 空字符串""表示获取rawfile根目录下的文件夹及文件列表。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Array<string>>|是|回调函数，返回rawfile子目录下的文件夹及文件列表。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 传入""表示获取rawfile根目录下的文件列表，假设rawfile根目录下存在test.txt文件
        // 传入""仅作示例，请替换为rawfile目录下实际的文件路径
        this.context.resourceManager.getRawFileList("", (error: BusinessError, value: Array<string>) => {
            if (error != null) {
                console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
            } else {
                console.info(`getRawFileList, result: ${JSON.stringify(value)}`);
                // 打印输出结果: getRawFileList, result: ["test.txt"]
            }
        });
    }
}
```

### getRawFileList^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileList(path: string): Promise<Array<string>>

获取resources/rawfile下指定子目录中的文件夹及文件列表。使用Promise异步回调。
> 说明
>
> 若文件夹中无文件，则抛出异常；若文件夹中有文件，则返回文件夹及文件列表。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:------------------------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile子目录路径，如"subdir"，不以"/"开头。 空字符串""表示获取rawfile根目录下的文件夹及文件列表。|

**返回值：**

|类型|说明|
|:---------------------|:--------------------------------|
|Promise<Array<string>>|Promise对象，返回rawfile子目录下的文件夹及文件列表。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // 传入""表示获取rawfile根目录下的文件列表，假设rawfile根目录下存在test.txt文件
        // 传入""仅作示例，请替换为rawfile目录下实际的文件路径
        this.context.resourceManager.getRawFileList("")
            .then((value: Array<string>) => {
                console.info(`getRawFileList, result: ${JSON.stringify(value)}`);
                // 打印输出结果: getRawFileList, result: ["test.txt"]
            })
            .catch((error: BusinessError) => {
                console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
            });
    }
}
```

### getRawFdSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFdSync(path: string): RawFileDescriptor

获取resources/rawfile目录下rawfile文件所在HAP的文件描述符（fd），使用同步方式返回。
> 说明
>
> 文件描述符（fd）使用完毕后需调用[closeRawFdSync](#closerawfdsync10)或[closeRawFd](#closerawfd9)关闭fd，避免资源泄漏。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:---------------------------------------|:------------------------|
|[RawFileDescriptor](#rawfiledescriptor9)|rawfile文件所在HAP的文件描述符（fd）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getRawFd^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFd(path: string, callback: _AsyncCallback<RawFileDescriptor>): void

获取resources/rawfile目录下对应rawfile文件所在HAP的文件描述符（fd）。使用callback异步回调。
> 说明
>
> 文件描述符（fd）使用完毕后需调用[closeRawFdSync](#closerawfdsync10)或[closeRawFd](#closerawfd9)关闭fd，避免资源泄漏。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<[RawFileDescriptor](#rawfiledescriptor9)>|是|回调函数，返回的rawfile文件所在HAP的文件描述符（fd）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### getRawFd^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFd(path: string): Promise<RawFileDescriptor>

获取resources/rawfile目录下rawfile文件所在HAP的文件描述符（fd）。使用Promise异步回调。
> 说明
>
> 文件描述符（fd）使用完毕后需调用[closeRawFdSync](#closerawfdsync10)或[closeRawFd](#closerawfd9)关闭fd，避免资源泄漏。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:------------------------------------|
|Promise<[RawFileDescriptor](#rawfiledescriptor9)>|Promise对象，返回rawfile文件所在HAP的文件描述符（fd）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "test.txt"仅作示例，请替换为实际使用的资源
            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}.`);
        }
    }
}
```

### closeRawFdSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

closeRawFdSync(path: string): void

关闭resources/rawfile目录下rawfile文件所在HAP的文件描述符（fd），使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    try {
      // "test.txt"仅作示例，请替换为实际使用的资源
      let rawfile = this.context.resourceManager.getRawFdSync("test.txt");
      // 根据实际业务场景，使用rawfile资源

      this.context.resourceManager.closeRawFdSync("test.txt");
      console.info(`closeRawFdSync test success.`);
    } catch (error) {
      let code = (error as BusinessError).code;
      let message = (error as BusinessError).message;
      console.error(`closeRawFdSync test failed, error code: ${code}, message: ${message}.`);
    }
  }
}
```

### closeRawFd^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

closeRawFd(path: string, callback: _AsyncCallback<void>): void

关闭resources/rawfile目录下rawfile文件所在HAP的文件描述符（fd）。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<void>|是|回调函数。当关闭rawfile所在HAP的文件描述符（fd）成功，err为undefined，否则为错误对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    try {
      // "test.txt"仅作示例，请替换为实际使用的资源
      let rawfile = this.context.resourceManager.getRawFdSync("test.txt");
      // 根据实际业务场景，使用rawfile资源
      this.context.resourceManager.closeRawFd("test.txt", (error: BusinessError) => {
        if (error != null) {
          console.error("error is " + error);
          return;
        }
        console.info('closeRawFd success.');
      });
    } catch (error) {
      let code = (error as BusinessError).code;
      let message = (error as BusinessError).message;
      console.error(`callback closeRawFd failed, error code: ${code}, message: ${message}.`);
    }
  }
}
```

### closeRawFd^9+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

closeRawFd(path: string): Promise<void>

关闭resources/rawfile目录下rawfile文件所在HAP的文件描述符（fd）。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------|:-------------------------|
|Promise<void>|Promise对象。无返回结果的Promise对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    try {
      // "test.txt"仅作示例，请替换为实际使用的资源
      let rawfile = this.context.resourceManager.getRawFdSync("test.txt");
      // 根据实际业务场景，使用rawfile资源
      this.context.resourceManager.closeRawFd("test.txt");
      console.info(`closeRawFd test success.`);
    } catch (error) {
      let code = (error as BusinessError).code;
      let message = (error as BusinessError).message;
      console.error(`promise closeRawFd failed, error code: ${code}, message: ${message}.`);
    }
  }
}
```

### getConfigurationSync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getConfigurationSync(): Configuration

获取设备的Configuration，使用同步形式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:------------------------------|:----------------|
|[Configuration](#configuration)|设备的Configuration。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            let value = this.context.resourceManager.getConfigurationSync();
            let direction = value.direction;
            let locale = value.locale;
        } catch (error) {
            console.error("getConfigurationSync error is " + error);
        }
    }
}
```

### getConfiguration

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getConfiguration(callback: _AsyncCallback<Configuration>): void

获取设备的Configuration。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------------------------|:-|:-----------------------|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<[Configuration](#configuration)>|是|回调函数，返回设备的Configuration。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            this.context.resourceManager.getConfiguration((error: BusinessError, config: resourceManager.Configuration) => {
                if (error != null) {
                    console.error("getConfiguration callback error is " + error);
                } else {
                    let direction = config.direction;
                    let locale = config.locale;
                }
            });
        } catch (error) {
            console.error("getConfiguration callback error is " + error);
        }
    }
}
```

### getConfiguration

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getConfiguration(): Promise<Configuration>

获取设备的Configuration。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:---------------------------------------|:----------------------------|
|Promise<[Configuration](#configuration)>|Promise对象，返回设备的Configuration。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            this.context.resourceManager.getConfiguration().then((config: resourceManager.Configuration) => {
                let direction = config.direction;
                let locale = config.locale;
            }).catch((error: BusinessError) => {
                console.error("getConfiguration promise error is " + error);
            });
        } catch (error) {
            console.error("getConfiguration promise error is " + error);
        }
    }
}
```

### getDeviceCapabilitySync^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDeviceCapabilitySync(): DeviceCapability

获取设备的DeviceCapability，使用同步形式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:------------------------------------|:-------------------|
|[DeviceCapability](#devicecapability)|设备的DeviceCapability。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            let value = this.context.resourceManager.getDeviceCapabilitySync();
            let screenDensity = value.screenDensity;
            let deviceType = value.deviceType;
        } catch (error) {
            console.error("getDeviceCapabilitySync error is " + error);
        }
    }
}
```

### getDeviceCapability

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDeviceCapability(callback: _AsyncCallback<DeviceCapability>): void

获取设备的DeviceCapability。使用callback异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------------------------------|:-|:--------------------------|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<[DeviceCapability](#devicecapability)>|是|回调函数，返回设备的DeviceCapability。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        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

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDeviceCapability(): Promise<DeviceCapability>

获取设备的DeviceCapability。使用Promise异步回调。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:---------------------------------------------|:-------------------------------|
|Promise<[DeviceCapability](#devicecapability)>|Promise对象，返回设备的DeviceCapability。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        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);
        }
    }
}
```

### addResource^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

addResource(path: string): void

应用运行时加载指定的overlay资源，实现主题切换或资源覆盖。
> 说明
>
> rawfile和resfile目录不支持资源覆盖。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|path|string|是|待加载的HSP或HAP资源包的绝对路径。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001010|Invalid overlay path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "/library1-default-signed.hsp"仅作示例，请替换为实际的文件路径
        let path = this.context.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}.`);
        }
    }
}
```

### removeResource^10+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

removeResource(path: string): void

应用运行时移除指定的overlay资源，还原被覆盖前的资源。
> 说明
>
> rawfile和resfile目录不支持资源覆盖。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-------------------|
|path|string|是|待移除的HSP或HAP资源包的绝对路径。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001010|Invalid overlay path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        // "/library1-default-signed.hsp"仅作示例，请替换为实际的文件路径
        let path = this.context.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}.`);
        }
    }
}
```

### getLocales^11+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getLocales(includeSystem?: boolean): Array<string>

获取应用的语言列表。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------------|:------|:-|:-----------------------------------------------------------------------------------------------------------------------|
|includeSystem|boolean|否|是否包含系统资源，默认值为false。 - false：表示仅获取应用资源的语言列表。 - true：表示获取系统资源和应用资源的语言列表。 当使用系统资源管理对象获取语言列表时，includeSystem值无效，始终返回系统资源语言列表。|

**返回值：**

|类型|说明|
|:------------|:---------------------------------------------------|
|Array<string>|返回获取的语言列表，列表中的字符串由语言、脚本（可选）、地区（可选），按照顺序使用中划线"-"连接组成。|

**错误码：**

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            this.context.resourceManager.getLocales(); // 仅获取应用资源语言列表
        } 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.getSysResourceManager().getLocales(); // 仅获取系统资源语言列表
        } 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); // 获取应用资源和系统资源语言列表
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getLocales failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getSymbol^11+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getSymbol(resId: number): number

获取指定资源ID对应的[Symbol字符](https://developer.huawei.com/consumer/cn/design/harmonyos-symbol)Unicode码，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:-----|:-----------------------------|
|number|资源ID值对应的Symbol字符Unicode码（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'sys.symbol.message'仅作示例，请替换为实际使用的资源
            let symbolValue = this.context.resourceManager.getSymbol($r('sys.symbol.message').id);
            console.info(`getSymbol, result: ${symbolValue}`);
            // 打印输出结果: getSymbol, result: 983183
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getSymbol failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getSymbolByName^11+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getSymbolByName(resName: string): number

获取指定资源名称对应的[Symbol字符](https://developer.huawei.com/consumer/cn/design/harmonyos-symbol)Unicode码，使用同步方式返回。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:----|
|resName|string|是|资源名称。|

**返回值：**

|类型|说明|
|:-----|:----------------------------|
|number|资源名称对应的Symbol字符Unicode码（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // "message"仅作示例，请替换为实际使用的资源
            let symbolValue = this.context.resourceManager.getSymbolByName("message");
            console.info(`getSymbolByName, result: ${symbolValue}`);
            // 打印输出结果: getSymbolByName, result: 983183
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getSymbolByName failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### isRawDir^12+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

isRawDir(path: string): boolean

判断指定路径是否为rawfile下的目录，使用同步方式返回。

**元服务API：** 从API version 12开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:---------------------------------------------------------------------------|
|path|string|是|相对于resources/rawfile目录的rawfile文件或子目录路径。格式为不以"/"开头的相对路径，如"test.txt"、"subdir"。|

**返回值：**

|类型|说明|
|:------|:-------------------------------------------------------------|
|boolean|是否为rawfile下的目录。 - true：表示是rawfile下的目录。 - false：表示非rawfile下的目录。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001005|Invalid relative path.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 假设rawfile根目录下存在非空文件夹sub，则isRawDir返回结果为true
            // "sub"仅作示例，请替换为实际使用的目录名称
            let isRawDir = this.context.resourceManager.isRawDir("sub");
            // 打印输出结果: sub isRawDir, result: true
            console.info(`sub isRawDir, result: ${isRawDir}`);

            // 假设rawfile根目录下存在test.txt文件，则isRawDir返回结果为false
            // "test.txt"仅作示例，请替换为实际使用的资源
            isRawDir = this.context.resourceManager.isRawDir("test.txt");
            // 打印输出结果: test.txt isRawDir, result: false
            console.info(`test.txt isRawDir, result: ${isRawDir}`);
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`isRawDir failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### getOverrideResourceManager^12+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOverrideResourceManager(configuration?: Configuration): ResourceManager

获取可以加载差异化资源的资源管理对象，使用同步方式返回。

普通的资源管理对象获取的资源的配置（语言、深浅色、分辨率、横竖屏等）是由系统决定的，而通过该接口返回的对象，应用可以获取符合指定配置的资源，即差异化资源，比如在浅色模式时可以获取深色资源。差异化资源仅限于应用自身资源和系统资源，不包括主题资源。

**元服务API：** 从API version 12开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------------|:------------------------------|:-|:-------------------------------------------------------------------------------------------------------------------------------|
|configuration|[Configuration](#configuration)|否|指定想要获取的资源配置。 通过[getOverrideConfiguration](#getoverrideconfiguration12)获取差异化配置后，根据需求修改配置项，再作为参数传入该函数。 若缺省则表示使用当前系统的configuration。|

**返回值：**

|类型|说明|
|:----------------------------------|:----------------|
|[ResourceManager](#resourcemanager)|可以加载差异化资源的资源管理对象。|

**错误码：**

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        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}.`);
        }
    }
}
```

### getOverrideConfiguration^12+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getOverrideConfiguration(): Configuration

获取差异化资源的配置，使用同步方式返回。

无论是普通资源管理对象，还是通过[getOverrideResourceManager](#getoverrideresourcemanager12)接口获取的差异化资源管理对象，调用该接口都会返回相同的配置信息。

**元服务API：** 从API version 12开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:------------------------------|:--------|
|[Configuration](#configuration)|差异化资源的配置。|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        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}.`);
        }
    }
}
```

### updateOverrideConfiguration^12+^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

updateOverrideConfiguration(configuration: Configuration): void

更新差异化资源管理对象的配置。

无论是普通资源管理对象，还是通过[getOverrideResourceManager](#getoverrideresourcemanager12)接口获取的差异化资源管理对象，调用该方法均可更新差异化资源管理对象的配置。

**元服务API：** 从API version 12开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------------|:------------------------------|:-|:----------------------------------------------------------------------------------------------|
|configuration|[Configuration](#configuration)|是|指定差异化资源的配置。通过[getOverrideConfiguration](#getoverrideconfiguration12)获取差异化配置后，根据需求修改配置项，再作为参数传入。|

**错误码：**

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|

**示例：**

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { resourceManager } from '@kit.LocalizationKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        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}.`);
        }
    }
}
```

### getResourceName

> phone 26.0.0+ | 2in1 26.0.0+ | tablet 26.0.0+ | tv 26.0.0+ | wearable 26.0.0+

getResourceName(resId: number): string

获取指定资源ID对应的资源名称。

**起始版本：** 26.0.0

**元服务API：** 从API版本26.0.0开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:-----|:------------|
|string|资源ID值对应的资源名称。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:-------------------|
|9001001|Invalid resource ID.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```ts
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        try {
            // 'app.string.test'仅作示例，请替换为实际使用的资源
            let resName: string = this.context.resourceManager.getResourceName($r('app.string.test').id);
            console.info(`getResourceName, result: ${resName}`);
            // 打印输出结果: getResourceName, result: test
        } catch (error) {
            let code = (error as BusinessError).code;
            let message = (error as BusinessError).message;
            console.error(`getResourceName failed, error code: ${code}, message: ${message}.`);
        }
    }
}
```

### release^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

release()

释放创建的resourceManager。此接口暂不支持，调用后无实际作用。
> 说明
>
> 从API version 7开始支持，从API version 12开始废弃。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**示例：**

```ts
try {
  this.context.resourceManager.release();
} catch (error) {
  console.error("release error is " + error);
}
```

### getString^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getString(resId: number, callback: AsyncCallback<string>): void

获取指定资源ID对应的字符串。使用callback异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getStringValue](#getstringvalue9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------|:-|:------------------|
|resId|number|是|资源ID值。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<string>|是|回调函数，返回资源ID值对应的字符串。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getString(resId: number): Promise<string>

获取指定资源ID对应的字符串。使用Promise异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getStringValue](#getstringvalue9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:--------------|:-----------------------|
|Promise<string>|Promise对象，返回资源ID值对应的字符串。|

**示例：**

```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);
    });
});
```

### getStringSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringSync(resource: Resource): string

获取指定resource对象对应的字符串，使用同步方式返回。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getStringSync](#getstringsync9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:-----|:----------------|
|string|resource对象对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```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 {
  let testStr = this.context.resourceManager.getStringSync(resource);
  console.info(`getStringSync, result: ${testStr}`);
  // 打印输出结果: getStringSync, result: I'm a test string resource.
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getStringSync failed, error code: ${code}, message: ${message}.`);
}
```

### getStringSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringSync(resource: Resource, ...args: Array<string | number>): string

获取指定resource对象对应的字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getStringSync](#getstringsync10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:-------------------|
|string|resource对象对应的格式化字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a %1$s, format int: %2$d, format float: %3$f."
    }
  ]
}
```

```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 {
  let testStr = this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
  console.info(`getStringSync, result: ${testStr}`);
  // 打印输出结果: getStringSync, result: I'm a format string, format int: 10, format float: 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}.`);
}
```

### getStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringValue(resource: Resource, callback: _AsyncCallback<string>): void

获取指定resource对象对应的字符串。使用callback异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getStringValue](#getstringvalue9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:-----------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回resource对象对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/string.json
{
  "string": [
    {
      "name": "test",
      "value": "I'm a test string resource."
    }
  ]
}
```

```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
};
this.context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
  if (error != null) {
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
  } else {
    console.info(`getStringValue, result: ${value}`);
    // 打印输出结果: getStringValue, result: I'm a test string resource.
  }
});
```

### getStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringValue(resource: Resource): Promise<string>

获取指定resource对象对应的字符串。使用Promise异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getStringValue](#getstringvalue9-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:--------------|:----------------------------|
|Promise<string>|Promise对象，返回resource对象对应的字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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
};
this.context.resourceManager.getStringValue(resource, (error: BusinessError, value: string) => {
  if (error != null) {
    console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
  } else {
    console.info(`getStringValue, result: ${value}`);
    // 打印输出结果: getStringValue, result: I'm a test string resource.
  }
});
```

### getStringArray^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void

获取指定资源ID对应的字符串数组。使用callback异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getStringArrayValue](#getstringarrayvalue9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------|:-|:--------------------|
|resId|number|是|资源ID值。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<Array<string>>|是|回调函数，返回资源ID值对应的字符串数组。|

**示例：**

```ts
resourceManager.getResourceManager((error, mgr) => {
    mgr.getStringArray($r('app.strarray.test').id, (error: Error, value: Array<string>) => {
        if (error != null) {
            console.error("error is " + error);
        } else {
            let strArray = value;
        }
    });
});
```

### getStringArray^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArray(resId: number): Promise<Array<string>>

获取指定资源ID对应的字符串数组。使用Promise异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getStringArrayValue](#getstringarrayvalue9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:---------------------|:-------------------------|
|Promise<Array<string>>|Promise对象，返回资源ID值对应的字符串数组。|

**示例：**

```ts
import { BusinessError } from '@kit.BasicServicesKit';

resourceManager.getResourceManager((error, mgr) => {
      mgr.getStringArray($r('app.strarray.test').id).then((value: Array<string>) => {
        let strArray = value;
    }).catch((error: BusinessError) => {
        console.error("getStringArray promise error is " + error);
    });
});
```

### getStringArrayValueSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValueSync(resource: Resource): Array<string>

获取指定resource对象对应的字符串数组，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getStringArrayValueSync](#getstringarrayvaluesync10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:------------|:------------------|
|Array<string>|resource对象对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```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 {
  let strArray: Array<string> = this.context.resourceManager.getStringArrayValueSync(resource);
  console.info(`getStringArrayValueSync, result: ${strArray[0]}`);
  // 打印输出结果: getStringArrayValueSync, result: I'm one of the array's values.
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getStringArrayValueSync failed, error code: ${code}, message: ${message}.`);
}
```

### getStringArrayValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValue(resource: Resource, callback: _AsyncCallback<Array<string>>): void

获取指定resource对象对应的字符串数组。使用callback异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getStringArrayValue](#getstringarrayvalue9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------------------------------------------------|:-|:-------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Array<string>>|是|回调函数，返回resource对象对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```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
};
this.context.resourceManager.getStringArrayValue(resource, (error: BusinessError, value: Array<string>) => {
  if (error != null) {
    console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
  } else {
    console.info(`getStringArrayValue, result: ${value[0]}`);
    // 打印输出结果: getStringArrayValue, result: I'm one of the array's values.
  }
});
```

### getStringArrayValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getStringArrayValue(resource: Resource): Promise<Array<string>>

获取指定resource对象对应的字符串数组。使用Promise异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getStringArrayValue](#getstringarrayvalue9-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:---------------------|:------------------------------|
|Promise<Array<string>>|Promise对象，返回resource对象对应的字符串数组。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/strarray.json
{
  "strarray": [
    {
      "name": "test",
      "value": [
        {
          "value": "I'm one of the array's values."
        }
      ]
    }
  ]
}
```

```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
};
this.context.resourceManager.getStringArrayValue(resource)
  .then((value: Array<string>) => {
    console.info(`getStringArrayValue, result: ${value[0]}`);
    // 打印输出结果: getStringArrayValue, result: I'm one of the array's values.
  })
  .catch((error: BusinessError) => {
    console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
  });
```

### getMedia^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void

获取指定资源ID对应的媒体文件内容。使用callback异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getMediaContent](#getmediacontent9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------|:-|:---------------------|
|resId|number|是|资源ID值。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<Uint8Array>|是|回调函数，返回资源ID值对应的媒体文件内容。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMedia(resId: number): Promise<Uint8Array>

获取指定资源ID对应的媒体文件内容。使用Promise异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getMediaContent](#getmediacontent9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:------------------|:--------------------------|
|Promise<Uint8Array>|Promise对象，返回资源ID值对应的媒体文件内容。|

**示例：**

```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);
    });
});
```

### getMediaContentSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentSync(resource: Resource, density?: number): Uint8Array

获取指定resource对象对应的默认或指定的屏幕密度媒体文件内容，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContentSync](#getmediacontentsync10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:---------|:-------------------|
|Uint8Array|resource对象对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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); // 默认屏幕密度
} 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); // 指定屏幕密度
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getMediaContentSync failed, error code: ${code}, message: ${message}.`);
}
```

### getMediaContent^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resource: Resource, callback: _AsyncCallback<Uint8Array>): void

获取指定resource对象对应的媒体文件内容。使用callback异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getMediaContent](#getmediacontent9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回resource对象对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```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}.`);
}
```

### getMediaContent^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resource: Resource, density: number, callback: _AsyncCallback<Uint8Array>): void

获取指定resource对象对应的指定屏幕密度媒体文件内容。使用callback异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContent](#getmediacontent10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<Uint8Array>|是|回调函数，返回resource对象对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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}.`);
}
```

### getMediaContent^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resource: Resource): Promise<Uint8Array>

获取指定resource对象对应的媒体文件内容。使用Promise异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getMediaContent](#getmediacontent9-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:------------------|:-------------------------------|
|Promise<Uint8Array>|Promise对象，返回resource对象对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```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}.`);
}
```

### getMediaContent^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContent(resource: Resource, density: number): Promise<Uint8Array>

获取指定resource对象对应的指定屏幕密度媒体文件内容。使用Promise异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContent](#getmediacontent10-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:--------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:------------------|:-------------------------------|
|Promise<Uint8Array>|Promise对象，返回resource对象对应的媒体文件内容。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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}.`);
}
```

### getMediaBase64^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64(resId: number, callback: AsyncCallback<string>): void

获取指定资源ID对应的图片资源Base64编码。使用callback异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase649)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------|:-|:---------------------------|
|resId|number|是|资源ID值。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<string>|是|回调函数，返回资源ID值对应的图片资源Base64编码。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaBase64(resId: number): Promise<string>

获取指定资源ID对应的图片资源Base64编码。使用Promise异步回调。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase649-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:-----|
|resId|number|是|资源ID值。|

**返回值：**

|类型|说明|
|:--------------|:--------------------------------|
|Promise<string>|Promise对象，返回资源ID值对应的图片资源Base64编码。|

**示例：**

```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);
    });
});
```

### getMediaContentBase64Sync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64Sync(resource: Resource, density?: number): string

获取指定resource对象对应的默认或指定的屏幕密度图片资源Base64编码，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContentBase64Sync](#getmediacontentbase64sync10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:-----|:-------------------------|
|string|resource对象对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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); // 默认屏幕密度
} 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); // 指定屏幕密度
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getMediaContentBase64Sync failed, error code: ${code}, message: ${message}.`);
}
```

### getMediaContentBase64^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resource: Resource, callback: _AsyncCallback<string>): void

获取指定resource对象对应的图片资源Base64编码。使用callback异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase649)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回resource对象对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```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}.`);
}
```

### getMediaContentBase64^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resource: Resource, density: number, callback: _AsyncCallback<string>): void

获取指定resource对象对应的指定屏幕密度图片资源Base64编码。使用callback异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase6410)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回resource对象对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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}.`);
}
```

### getMediaContentBase64^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resource: Resource): Promise<string>

获取指定resource对象对应的图片资源Base64编码。使用Promise异步回调。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase649-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------------|
|Promise<string>|Promise对象，返回resource对象对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. Possible causes: Incorrect parameter types.|
|9001001|Invalid resource ID.|
|9001002|No matching resource is found based on the resource ID.|

**示例：**

```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}.`);
}
```

### getMediaContentBase64^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getMediaContentBase64(resource: Resource, density: number): Promise<string>

获取指定resource对象对应的指定屏幕密度图片资源Base64编码。使用Promise异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getMediaContentBase64](#getmediacontentbase6410-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:--------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|是|资源获取需要的屏幕密度，0表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------------|
|Promise<string>|Promise对象，返回resource对象对应的图片资源Base64编码。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```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}.`);
}
```

### getDrawableDescriptor^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getDrawableDescriptor(resource: Resource, density?: number, type?: number): DrawableDescriptor

获取指定resource对应的DrawableDescriptor对象，用于图标的显示，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getDrawableDescriptor](#getdrawabledescriptor10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:--------|:---------------------|:-|:-----------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|density|number|否|资源获取需要的屏幕密度，0或缺省表示默认屏幕密度。取值具体请参考枚举[ScreenDensity](#screendensity)。|
|type^11+^|number|否|图标类型。默认值为0。 0：表示获取应用自身图标资源。 1：表示获取主题资源包中应用的分层图标资源。|

**返回值：**

|类型|说明|
|:------------------------------------------------------------------------------------------------------------------------------------------|:----------------------------|
|[DrawableDescriptor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-arkui-drawabledescriptor#drawabledescriptor)|资源ID值对应的DrawableDescriptor对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { DrawableDescriptor } from '@kit.ArkUI';

let resource: resourceManager.Resource = {
  bundleName: "com.example.myapplication",
  moduleName: "entry",
  id: $r('app.media.icon').id
};
try {
  let drawableDescriptor:DrawableDescriptor = 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 {
  let drawableDescriptor:DrawableDescriptor = 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 {
  let drawableDescriptor:DrawableDescriptor = 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}.`);
}
```

### getIntPluralStringValueSync^(deprecated)^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getIntPluralStringValueSync(resource: Resource, num: number, ...args: Array<string | number>): string

获取指定resource对象对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 从API version 18开始支持，从API version 20开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|num|number|是|数量值（整数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:----------------------|
|string|resource对象对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```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.format_test').id
};

try {
  // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
  // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
  let pluralStr = this.context.resourceManager.getIntPluralStringValueSync(resource, 1, 1, "basket", 0.3);
  console.info(`getIntPluralStringValueSync, result: ${pluralStr}`);
  // 打印输出结果: getIntPluralStringValueSync, result: There is 1 apple in the basket, the total amount is 0.3 kg.
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getIntPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
}
```

### getDoublePluralStringValueSync^(deprecated)^

> phone 18+ | 2in1 18+ | tablet 18+ | tv 19+ | wearable 18+

getDoublePluralStringValueSync(resource: Resource, num: number, ...args: Array<string | number>): string

获取指定resource对象对应的[单复数](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/l10n-singular-plural)字符串，并使用args参数依次替换字符串中的格式化占位符，使用同步方式返回。
> 说明
>
> * 从API version 18开始支持，从API version 20开始废弃，建议使用[getDoublePluralStringValueSync](#getdoublepluralstringvaluesync18)替代。
>
> * 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。

**元服务API：** 从API version 18开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|num|number|是|数量值（浮点数）。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|args|Array<string | number>|否|格式化字符串资源参数。支持的参数类型包括%d、%f、%s、%%、%数字$d、%数字$f和%数字$s。 **说明：** - %%转义为%，如%%d格式化后为%d。 - %数字$d中的数字表示参数索引，从1开始计数。如%1$d表示使用args[0]格式化，%2$d表示使用args[1]格式化，依此类推。|

**返回值：**

|类型|说明|
|:-----|:----------------------|
|string|resource对象对应的格式化单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:---------------------------------------------------------------|
|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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "format_test",
      "value": [
        {
          "quantity": "one",
          "value": "There is %d apple in the %s, the total amount is %f kg."
        },
        {
          "quantity": "other",
          "value": "There are %d apples in the %s, the total amount is %f kg."
        }
      ]
    }
  ]
}
```

```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.format_test').id
};

try {
  // 根据语言单复数规则，参数num取值为2.1，英文环境下对应单复数类别为other
  // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为other的字符串
  let pluralStr = this.context.resourceManager.getDoublePluralStringValueSync(resource, 2.1, 2, "basket", 0.6);
  console.info(`getDoublePluralStringValueSync, result: ${pluralStr}`);
  // 打印输出结果: getDoublePluralStringValueSync, result: There are 2 apples in the basket, the total amount is 0.6 kg.
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getDoublePluralStringValueSync failed, error code: ${code}, message: ${message}.`);
}
```

### getPluralStringValueSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValueSync(resId: number, num: number): string

获取指定资源ID，指定资源数量的单复数字符串，使用同步方式返回。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 10开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:--------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:-----|:------------------------|
|string|根据指定数量获取指定ID字符串表示的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
  // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
  let pluralValue = this.context.resourceManager.getPluralStringValueSync($r('app.plural.test').id, 1);
  console.info(`getPluralStringValueSync, result: ${pluralValue}`);
  // 打印输出结果: getPluralStringValueSync, result: 1 apple
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
}
```

### getPluralStringValueSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValueSync(resource: Resource, num: number): string

获取指定资源信息，指定资源数量的单复数字符串，使用同步方式返回。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 10开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:-----|:-----------------------------|
|string|根据指定数量获取指定resource对象表示的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```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 {
  // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
  // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
  let pluralValue = this.context.resourceManager.getPluralStringValueSync(resource, 1);
  console.info(`getPluralStringValueSync, result: ${pluralValue}`);
  // 打印输出结果: getPluralStringValueSync, result: 1 apple
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getPluralStringValueSync failed, error code: ${code}, message: ${message}.`);
}
```

### getPluralStringByNameSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringByNameSync(resName: string, num: number): string

获取指定资源名称，指定资源数量的单复数字符串，使用同步方式返回。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 10开始支持，从API version 18开始废弃，建议使用[getIntPluralStringByNameSync](#getintpluralstringbynamesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:-----|:-----------------------|
|string|根据指定数量获取指定资源名称表示的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

try {
  // 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
  // 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
  let pluralValue = this.context.resourceManager.getPluralStringByNameSync("test", 1);
  console.info(`getPluralStringByNameSync, result: ${pluralValue}`);
  // 打印输出结果: getPluralStringByNameSync, result: 1 apple
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getPluralStringByNameSync failed, error code: ${code}, message: ${message}.`);
}
```

### getPluralStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValue(resId: number, num: number, callback: _AsyncCallback<string>): void

获取指定资源ID，指定资源数量的单复数字符串。使用callback异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源ID值对应的指定数量的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1,
  (error: BusinessError, value: string) => {
    if (error != null) {
      console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
    } else {
      console.info(`getPluralStringValue, result: ${value}`);
      // 打印输出结果: getPluralStringValue, result: 1 apple
    }
  });
```

### getPluralStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValue(resId: number, num: number): Promise<string>

获取指定资源ID，指定资源数量的单复数字符串。使用Promise异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:--------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------|
|Promise<string>|Promise对象，返回资源ID值对应的指定数量的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1)
  .then((value: string) => {
    console.info(`getPluralStringValue, result: ${value}`);
    // 打印输出结果: getPluralStringValue, result: 1 apple
  })
  .catch((error: BusinessError) => {
    console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
  });
```

### getPluralStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValue(resource: Resource, num: number, callback: _AsyncCallback<string>): void

获取指定资源信息，指定资源数量的单复数字符串。使用callback异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回resource对象对应的指定数量的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```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
};
// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringValue(resource, 1,
  (error: BusinessError, value: string) => {
    if (error != null) {
      console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
    } else {
      console.info(`getPluralStringValue, result: ${value}`);
      // 打印输出结果: getPluralStringValue, result: 1 apple
    }
  });
```

### getPluralStringValue^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringValue(resource: Resource, num: number): Promise<string>

获取指定资源信息，指定资源数量的单复数字符串。使用Promise异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringValueSync](#getintpluralstringvaluesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:--------------|:------------------------------------|
|Promise<string>|Promise对象，返回resource对象对应的指定数量的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```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
};
// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringValue(resource, 1)
  .then((value: string) => {
    console.info(`getPluralStringValue, result: ${value}`);
    // 打印输出结果: getPluralStringValue, result: 1 apple
  })
  .catch((error: BusinessError) => {
    console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
  });
```

### getPluralStringByName^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringByName(resName: string, num: number, callback: _AsyncCallback<string>): void

获取指定资源名称，指定资源数量的单复数字符串。使用callback异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringByNameSync](#getintpluralstringbynamesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<string>|是|回调函数，返回资源名称对应的指定数量的单复数字符串。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringByName("test", 1, (error: BusinessError, value: string) => {
  if (error != null) {
    console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
  } else {
    console.info(`getPluralStringByName, result: ${value}`);
    // 打印输出结果: getPluralStringByName, result: 1 apple
  }
});
```

### getPluralStringByName^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralStringByName(resName: string, num: number): Promise<string>

获取指定资源名称，指定资源数量的单复数字符串。使用Promise异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 9开始支持，从API version 18开始废弃，建议使用[getIntPluralStringByNameSync](#getintpluralstringbynamesync18)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:------|:-----|:-|:--------------------------------------------------------------------------------------------------------------|
|resName|string|是|资源名称。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:--------------|:-----------------------|
|Promise<string>|根据传入的数量值，获取资源名称对应的字符串资源。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/plural.json
{
  "plural": [
    {
      "name": "test",
      "value": [
        {
          "quantity": "one",
          "value": "%d apple"
        },
        {
          "quantity": "other",
          "value": "%d apples"
        }
      ]
    }
  ]
}
```

```ts
import { BusinessError } from '@kit.BasicServicesKit';

// 根据语言单复数规则，参数num取值为1，英文环境下对应单复数类别为one
// 在资源文件中用quantity字段表示单复数类别，因此会获取quantity为one的字符串
this.context.resourceManager.getPluralStringByName("test", 1)
  .then((value: string) => {
    console.info(`getPluralStringByName, result: ${value}`);
    // 打印输出结果: getPluralStringByName, result: 1 apple
  })
  .catch((error: BusinessError) => {
    console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
  });
```

### getPluralString^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralString(resId: number, num: number): Promise<string>

获取指定资源ID，指定资源数量的单复数字符串。使用Promise异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getPluralStringValue](#getpluralstringvaluedeprecated-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:----|:-----|:-|:--------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|

**返回值：**

|类型|说明|
|:--------------|:-------------------------------|
|Promise<string>|Promise对象，返回资源ID值对应的指定数量的单复数字符串。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void

获取指定资源ID，指定资源数量的单复数字符串。使用callback异步回调。
> 说明
>
> 中文环境下，字符串不区分单复数；其他语言环境下，字符串区分单复数，具体规则参考[语言单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)。
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[getPluralStringValue](#getpluralstringvaluedeprecated)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------|:-|:--------------------------------------------------------------------------------------------------------------|
|resId|number|是|资源ID值。|
|num|number|是|数量值。根据当前语言的[单复数规则](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html)获取该数量值对应的字符串。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<string>|是|回调函数，返回资源ID值对应的指定数量的单复数字符串。|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';

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;
        }
    });
});
```

### getBoolean^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getBoolean(resource: Resource): boolean

获取指定resource对象对应的布尔值，使用同步方式返回。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getBoolean](#getboolean9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:------|:----------------|
|boolean|resource对象对应的布尔值。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/boolean.json
{
  "boolean": [
    {
      "name": "boolean_test",
      "value": true
    }
  ]
}
```

```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 {
  let boolTest = this.context.resourceManager.getBoolean(resource);
  console.info(`getBoolean, result: ${boolTest}`);
  // 打印输出结果: getBoolean, result: true
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getBoolean failed, error code: ${code}, message: ${message}.`);
}
```

### getNumber^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getNumber(resource: Resource): number

获取指定resource对象对应的integer数值或者float数值，使用同步方式返回。
> 说明
>
> 从API version 9开始支持，从API version 20开始废弃，建议使用[getNumber](#getnumber9)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:-----|:-----------------------------------------------------------------------------------------------------------------------------------|
|number|resource对象对应的数值。 integer类型资源返回资源文件中定义的原始数值。 float类型资源不带单位时返回资源文件中定义的原始数值，带"vp"或"fp"单位时返回转换后的像素(px)值。转换公式：像素值 = 原始数值 × densityPixels。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/integer.json
{
  "integer": [
    {
      "name": "integer_test",
      "value": 100
    }
  ]
}
```

```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 {
  let intValue = this.context.resourceManager.getNumber(resource);
  console.info(`getNumber, int value: ${intValue}`);
  // 打印输出结果: getNumber, int value: 100
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getNumber failed, error code: ${code}, message: ${message}.`);
}
```

### getColorSync^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColorSync(resource: Resource): number

获取指定resource对象对应的颜色值，使用同步方式返回。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getColorSync](#getcolorsync10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:-----|:---------------------|
|number|resource对象对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```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 {
  let colorValue = this.context.resourceManager.getColorSync(resource);
  console.info(`getColorSync, result: ${colorValue}`);
  // 打印输出结果: getColorSync, result: 4294967295
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getColorSync failed, error code: ${code}, message: ${message}.`);
}
```

### getColor^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColor(resource: Resource, callback: _AsyncCallback<number>): void

获取指定resource对象对应的颜色值。使用callback异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getColor](#getcolor10)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------------------------------------------------------------------------------------------------------|:-|:----------------------------|
|resource|[Resource](#resource9)|是|资源信息。|
|callback|[_AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)<number>|是|回调函数，返回resource对象对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```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
};
this.context.resourceManager.getColor(resource, (error: BusinessError, value: number) => {
  if (error != null) {
    console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
  } else {
    console.info(`getColor, result: ${value}`);
    // 打印输出结果: getColor, result: 4294967295
  }
});
```

### getColor^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getColor(resource: Resource): Promise<number>

获取指定resource对象对应的颜色值。使用Promise异步回调。
> 说明
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[getColor](#getcolor10-1)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:--------------|:---------------------------------|
|Promise<number>|Promise对象，返回resource对象对应的颜色值（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```json5
// 资源文件路径: src/main/resources/base/element/color.json
{
  "color": [
    {
      "name": "test",
      "value": "#FFFFFF"
    }
  ]
}
```

```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
};
this.context.resourceManager.getColor(resource)
  .then((value: number) => {
    console.info(`getColor, result: ${value}`);
    // 打印输出结果: getColor, result: 4294967295
  })
  .catch((error: BusinessError) => {
    console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
  });
```

### getSymbol^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getSymbol(resource: Resource): number

获取指定resource对象对应的[Symbol字符](https://developer.huawei.com/consumer/cn/design/harmonyos-symbol)Unicode码，使用同步方式返回。
> 说明
>
> 从API version 11开始支持，从API version 20开始废弃，建议使用[getSymbol](#getsymbol11)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**模型约束：** 此接口仅可在Stage模型下使用。

**参数：**

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----|
|resource|[Resource](#resource9)|是|资源信息。|

**返回值：**

|类型|说明|
|:-----|:----------------------------------|
|number|resource对象对应的Symbol字符Unicode码（十进制）。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)和[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:------|:-----------------------------------------------------------|
|401|Parameter error. 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.|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';
import { BusinessError } from '@kit.BasicServicesKit';

let resource: resourceManager.Resource = {
  bundleName: "com.example.myapplication",
  moduleName: "entry",
  id: $r('sys.symbol.message').id
};
try {
  let symbolValue = this.context.resourceManager.getSymbol(resource);
  console.info(`getSymbol, result: ${symbolValue}`);
  // 打印输出结果: getSymbol, result: 983183
} catch (error) {
  let code = (error as BusinessError).code;
  let message = (error as BusinessError).message;
  console.error(`getSymbol failed, error code: ${code}, message: ${message}.`);
}
```

### getRawFile^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void

获取resources/rawfile目录下对应的rawfile文件内容。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getRawFileContent](#getrawfilecontent9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<Uint8Array>|是|回调函数，返回rawfile文件内容。|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';

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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFile(path: string): Promise<Uint8Array>

获取resources/rawfile目录下对应的rawfile文件内容。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getRawFileContent](#getrawfilecontent9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------------|:-----------------------|
|Promise<Uint8Array>|Promise对象，返回rawfile文件内容。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void

获取resources/rawfile目录下对应rawfile文件的文件描述符（fd）。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getRawFd](#getrawfd9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<[RawFileDescriptor](#rawfiledescriptor9)>|是|回调函数，返回rawfile文件的文件描述符（fd）。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getRawFileDescriptor(path: string): Promise<RawFileDescriptor>

获取resources/rawfile目录下对应rawfile文件的文件描述符（fd）。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[getRawFd](#getrawfd9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------------------------------------------|:-------------------------------|
|Promise<[RawFileDescriptor](#rawfiledescriptor9)>|Promise对象，返回rawfile文件的文件描述符（fd）。|

**示例：**

```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)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void

关闭resources/rawfile目录下rawfile文件的文件描述符（fd）。使用callback异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[closeRawFd](#closerawfd9)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:-------|:----------------------------------------------|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|
|callback|[AsyncCallback](#asynccallbackdeprecated)<void>|是|回调函数。当关闭rawfile文件的文件描述符（fd）成功，err为undefined，否则为错误对象。|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';

resourceManager.getResourceManager((error, mgr) => {
    mgr.closeRawFileDescriptor("test.txt", (error: Error) => {
        if (error != null) {
            console.error("error is " + error);
        }
    });
});
```

### closeRawFileDescriptor^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

closeRawFileDescriptor(path: string): Promise<void>

关闭resources/rawfile目录下rawfile文件的文件描述符（fd）。使用Promise异步回调。
> 说明
>
> 从API version 8开始支持，从API version 9开始废弃，建议使用[closeRawFd](#closerawfd9-1)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:-----|:-|:-----------------------------------------------------------------------|
|path|string|是|相对resources/rawfile目录的rawfile文件路径，如"test.txt"、"subdir/test.txt"，不以"/"开头。|

**返回值：**

|类型|说明|
|:------------|:-------------------------|
|Promise<void>|Promise对象。无返回结果的Promise对象。|

**示例：**

```ts
import { resourceManager } from '@kit.LocalizationKit';

resourceManager.getResourceManager((error, mgr) => {
    mgr.closeRawFileDescriptor("test.txt");
});
```

## resourceManager.getSystemResourceManager^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

getSystemResourceManager(): ResourceManager

获取系统资源管理对象，用于访问系统预置的资源。
> 说明
>
> 该接口获取到的系统资源管理ResourceManager对象中的Configuration为默认值。默认值如下：{"locale": "", "direction": -1, "deviceType": -1, "screenDensity": 0, "colorMode": 1, "mcc": 0, "mnc": 0}。
>
> 从API version 10开始支持，从API version 20开始废弃，建议使用[resourceManager.getSysResourceManager](#resourcemanagergetsysresourcemanager20)替代。

**元服务API：** 从API version 11开始，该接口支持在元服务中使用。

**系统能力：** SystemCapability.Global.ResourceManager

**返回值：**

|类型|说明|
|:----------------------------------|:--------|
|[ResourceManager](#resourcemanager)|系统资源管理对象。|

**错误码：**

以下错误码的详细介绍请参见[资源管理错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-resource-manager)。

|错误码ID|错误信息|
|:------|:----------------------------------------------------------------------------------------------------------------|
|9001009|Failed to access the system resource. which is not mapped to application sandbox, This error code will be thrown.|

**示例：**

```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(`getSystemResourceManager failed, error code: ${code}, message: ${message}.`);
}
```

## AsyncCallback^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)替代。

### (err: Error, data: T)^(deprecated)^

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+ | wearable 18+

(err: Error, data: T): void;

异步回调函数，携带错误参数和异步返回值。
> 说明
>
> 从API version 6开始支持，从API version 9开始废弃，建议使用[AsyncCallback](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-base#asynccallback)替代。

**系统能力：** SystemCapability.Global.ResourceManager

**参数：**

|参数名|类型|必填|说明|
|:---|:----|:-|:-----------|
|err|Error|是|接口调用失败的错误信息。|
|data|T|是|接口调用时的回调信息。|

## 附录

> phone | 2in1 | tablet | tv | wearable

* 示例代码中用到的'app.string.test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/string.json
  {
    "string": [
      {
        "name": "test",
        "value": "I'm a test string resource."
      }
    ]
  }
  ```

  ```json5
  // 资源文件路径: src/main/resources/base/element/string.json
  {
    "string": [
      {
        "name": "test",
        "value": "I'm a %1$s, format int: %2$d, format float: %3$f."
      }
    ]
  }
  ```

* 示例代码中用到的'app.strarray.test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/strarray.json
  {
    "strarray": [
      {
        "name": "test",
        "value": [
          {
            "value": "I'm one of the array's values."
          }
        ]
      }
    ]
  }
  ```

* 示例代码中用到的'app.plural.test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/plural.json
  {
    "plural": [
      {
        "name": "test",
        "value": [
          {
            "quantity": "one",
            "value": "%d apple"
          },
          {
            "quantity": "other",
            "value": "%d apples"
          }
        ]
      }
    ]
  }
  ```

* 示例代码中用到的'app.plural.format_test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/plural.json
  {
    "plural": [
      {
        "name": "format_test",
        "value": [
          {
            "quantity": "one",
            "value": "There is %d apple in the %s, the total amount is %f kg."
          },
          {
            "quantity": "other",
            "value": "There are %d apples in the %s, the total amount is %f kg."
          }
        ]
      }
    ]
  }
  ```

* 示例代码中用到的'app.boolean.boolean_test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/boolean.json
  {
    "boolean": [
      {
        "name": "boolean_test",
        "value": true
      }
    ]
  }
  ```

* 示例代码中用到的"integer_test"和"float_test"文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/integer.json
  {
    "integer": [
      {
        "name": "integer_test",
        "value": 100
      }
    ]
  }
  ```

  ```json5
  // 资源文件路径: src/main/resources/base/element/float.json
  {
    "float": [
      {
        "name": "float_test",
        "value": "30.6vp"
      }
    ]
  }
  ```

* 示例代码中用到的'app.color.test'文件内容如下：

  ```json5
  // 资源文件路径: src/main/resources/base/element/color.json
  {
    "color": [
      {
        "name": "test",
        "value": "#FFFFFF"
      }
    ]
  }
  ```

