diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md
index 3abc771bff725718ccd5df3eb0334331701faea4..2bf99718384799dead1106c5523b5f970af01592 100644
--- a/en/application-dev/reference/apis/js-apis-resource-manager.md
+++ b/en/application-dev/reference/apis/js-apis-resource-manager.md
@@ -1,6 +1,6 @@
-# Resource Management
+# Resource Manager
-The resource management module provides APIs to obtain information about the current device configuration (including the language, region, screen direction, and MCC/MNC) and device capability (including the device type and resolution).
+The Resource Manager module provides APIs to obtain information about application resources based on the current configuration, including the language, region, screen direction, MCC/MNC, as well as device capability and density.
> **NOTE**
>
@@ -9,16 +9,23 @@ The resource management module provides APIs to obtain information about the cur
## Modules to Import
-```
+```js
import resourceManager from '@ohos.resourceManager';
```
-## How to Use
+## Instruction
-Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This method, however, is not applicable to the FA model.
+Since API version 9, the stage model allows an application to obtain a **ResourceManager** object based on **context** and call its resource management APIs without first importing the required bundle. This approach, however, is not applicable to the FA model.
+For details about how to reference **context** in the stage model, see [Context in the Stage Model](../../ability/context-userguide.md).
-```
-this.context.resourceManager;
+```ts
+import Ability from '@ohos.application.Ability';
+class MainAbility extends Ability {
+ onWindowStageCreate(windowStage) {
+ let context = this.context;
+ let resourceManager = context.resourceManager;
+ }
+}
```
## resourceManager.getResourceManager
@@ -27,17 +34,18 @@ getResourceManager(callback: AsyncCallback<ResourceManager>): void
Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result.
-This API can be used only in the FA model.
+**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------------------- |
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result.|
**Example**
- ```
+ ```js
resourceManager.getResourceManager((error, mgr) => {
if (error != null) {
console.log("error is " + error);
@@ -60,18 +68,19 @@ getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManage
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result.
-This API can be used only in the FA model.
+**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ---------- | ---------------------------------------- | ---- | ----------------------------- |
-| bundleName | string | Yes | Bundle name of the target application. |
+| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes | Callback used to return the result.|
**Example**
- ```
+ ```js
resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => {
});
```
@@ -83,7 +92,7 @@ getResourceManager(): Promise<ResourceManager>
Obtains the **ResourceManager** object of this application. This API uses a promise to return the result.
-This API can be used only in the FA model.
+**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager
@@ -93,7 +102,7 @@ This API can be used only in the FA model.
| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.|
**Example**
- ```
+ ```js
resourceManager.getResourceManager().then(mgr => {
mgr.getString(0x1000000, (error, value) => {
if (error != null) {
@@ -114,14 +123,15 @@ getResourceManager(bundleName: string): Promise<ResourceManager>
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result.
-This API can be used only in the FA model.
+**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------- |
-| bundleName | string | Yes | Bundle name of the target application.|
+| bundleName | string | Yes | Bundle name of the application.|
**Return value**
| Type | Description |
@@ -129,11 +139,9 @@ This API can be used only in the FA model.
| Promise<[ResourceManager](#resourcemanager)> | Promise used to return the result.|
**Example**
- ```
+ ```js
resourceManager.getResourceManager("com.example.myapplication").then(mgr => {
-
}).catch(error => {
-
});
```
@@ -144,7 +152,7 @@ Enumerates the screen directions.
**System capability**: SystemCapability.Global.ResourceManager
-| Name | Default Value | Description |
+| Name | Value | Description |
| -------------------- | ---- | ---- |
| DIRECTION_VERTICAL | 0 | Portrait. |
| DIRECTION_HORIZONTAL | 1 | Landscape. |
@@ -156,14 +164,14 @@ Enumerates the device types.
**System capability**: SystemCapability.Global.ResourceManager
-| Name | Default Value | Description |
+| Name | Value | Description |
| -------------------- | ---- | ---- |
-| DEVICE_TYPE_PHONE | 0x00 | Phone. |
-| DEVICE_TYPE_TABLET | 0x01 | Tablet. |
-| DEVICE_TYPE_CAR | 0x02 | Head unit. |
-| DEVICE_TYPE_PC | 0x03 | PC. |
-| DEVICE_TYPE_TV | 0x04 | TV. |
-| DEVICE_TYPE_WEARABLE | 0x06 | Wearable. |
+| DEVICE_TYPE_PHONE | 0x00 | Phone |
+| DEVICE_TYPE_TABLET | 0x01 | Tablet |
+| DEVICE_TYPE_CAR | 0x02 | Head unit |
+| DEVICE_TYPE_PC | 0x03 | PC |
+| DEVICE_TYPE_TV | 0x04 | TV |
+| DEVICE_TYPE_WEARABLE | 0x06 | Wearable |
## ScreenDensity
@@ -172,7 +180,7 @@ Enumerates the screen density types.
**System capability**: SystemCapability.Global.ResourceManager
-| Name | Default Value | Description |
+| Name | Value | Description |
| -------------- | ---- | ---------- |
| SCREEN_SDPI | 120 | Screen density with small-scale dots per inch (SDPI). |
| SCREEN_MDPI | 160 | Screen density with medium-scale dots per inch (MDPI). |
@@ -188,6 +196,7 @@ Defines the device configuration.
**System capability**: SystemCapability.Global.ResourceManager
+**Parameters**
| Name | Type | Readable | Writable | Description |
| --------- | ----------------------- | ---- | ---- | -------- |
@@ -196,7 +205,7 @@ Defines the device configuration.
**Example**
- ```
+ ```js
resourceManager.getResourceManager((error, mgr) => {
mgr.getConfiguration((error, value) => {
let direction = value.direction;
@@ -211,6 +220,7 @@ Defines the device capability.
**System capability**: SystemCapability.Global.ResourceManager
+**Parameters**
| Name | Type | Readable | Writable | Description |
| ------------- | ------------------------------- | ---- | ---- | -------- |
@@ -219,7 +229,7 @@ Defines the device capability.
**Example**
- ```
+ ```js
resourceManager.getResourceManager((error, mgr) => {
mgr.getDeviceCapability((error, value) => {
let screenDensity = value.screenDensity;
@@ -230,14 +240,17 @@ resourceManager.getResourceManager((error, mgr) => {
## RawFileDescriptor8+
-Defines the descriptor of the raw file.
+Defines the descriptor of the raw file.
+
**System capability**: SystemCapability.Global.ResourceManager
-| Name | Type | Description |
-| ------ | ------ | ------------------ |
-| fd | number | Descriptor of the raw file.|
-| offset | number | Start offset of the raw file. |
-| length | number | Length of the raw file. |
+**Parameters**
+
+| Name | Type | Readable | Writable | Description |
+| ------ | ------ | ---- | ---- | ------------------ |
+| fd | number | Yes | No| Descriptor of the raw file.|
+| offset | number | Yes | No| Start offset of the raw file. |
+| length | number | Yes | No| Length of the raw file. |
## Resource9+
@@ -245,11 +258,13 @@ Defines the resource information of an application.
**System capability**: SystemCapability.Global.ResourceManager
-| Name | Type | Description |
-| ------ | ------ | ------------------ |
-| bundleName | string | Bundle name of the application.|
-| moduleName | string | Module name of the application. |
-| id | number | Resource ID. |
+**Parameters**
+
+| Name | Type | Readable | Writable |Description |
+| ---------- | ------ | ----- | ---- | ---------------|
+| bundleName | string | Yes | No| Bundle name of the application.|
+| moduleName | string | Yes | No| Module name of the application.|
+| id | number | Yes | No| Resource ID. |
## ResourceManager
@@ -258,48 +273,61 @@ Defines the capability of accessing application resources.
> **NOTE**
>
-> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
+> - The APIs involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm.
>
> - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**.
+### getStringValue9+
-### getString
-
-getString(resId: number, callback: AsyncCallback<string>): void
+getStringValue(resId: number, callback: AsyncCallback<string>): void
Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------- |
| resId | number | Yes | Resource ID. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
-**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getString($r('app.string.test').id, (error, value) => {
+**Error codes**
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the module resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
+**Example stage**
+ ```ts
+ try {
+ this.context.getStringValue($r('app.string.test').id, (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let str = value;
}
});
- });
+ } catch (error) {
+ console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getString
+### getStringValue9+
-getString(resId: number): Promise<string>
+getStringValue(resId: number): Promise<string>
Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
@@ -309,117 +337,176 @@ Obtains the string corresponding to the specified resource ID. This API uses a p
| --------------------- | ----------- |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getString($r('app.string.test').id).then(value => {
- let str = value;
- }).catch(error => {
- console.log("getstring promise error is " + error);
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringValue($r('app.string.test').id).then(value => {
+ let str = value;
+ }).catch(error => {
+ console.log("getStringValue promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getString9+
+### getStringValue9+
-getString(resource: Resource, callback: AsyncCallback<string>): void
+getStringValue(resource: Resource, callback: AsyncCallback<string>): void
Obtains the string corresponding to the specified resource object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------- |
-| resource | [Resource](#resource9) | Yes | Resource object. |
+| resource | [Resource](#resource9) | Yes | Resource object. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.string.test').id
};
- this.context.resourceManager.getString(resource, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let str = value;
- }
- });
+ try {
+ this.context.resourceManager.getStringValue(resource, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
```
-### getString9+
-getString(resource: Resource): Promise<string>
+### getStringValue9+
+
+getStringValue(resource: Resource): Promise<string>
Obtains the string corresponding to the specified resource object. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| --------------------- | ---------------- |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.string.test').id
};
- this.context.resourceManager.getString(resource).then(value => {
+ try {
+ this.context.resourceManager.getStringValue(resource).then(value => {
let str = value;
- }).catch(error => {
- console.log("getstring promise error is " + error);
- });
+ }).catch(error => {
+ console.log("getStringValue promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getStringArray
-getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void
+### getStringArrayValue9+
+
+getStringArrayValue(resId: number, callback: AsyncCallback<Array<string>>): void
Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------- |
| resId | number | Yes | Resource ID. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let strArray = value;
- }
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let strArray = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getStringArray
+### getStringArrayValue9+
-getStringArray(resId: number): Promise<Array<string>>
+getStringArrayValue(resId: number): Promise<Array<string>>
Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
@@ -429,116 +516,172 @@ Obtains the string array corresponding to the specified resource ID. This API us
| ---------------------------------- | ------------- |
| Promise<Array<string>> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getStringArray($r('app.strarray.test').id).then(value => {
- let strArray = value;
- }).catch(error => {
- console.log("getStringArray promise error is " + error);
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringArrayValue($r('app.strarray.test').id).then(value => {
+ let strArray = value;
+ }).catch(error => {
+ console.log("getStringArrayValue promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getStringArray9+
+### getStringArrayValue9+
-getStringArray(resource: Resource, callback: AsyncCallback<Array<string>>): void
+getStringArrayValue(resource: Resource, callback: AsyncCallback<Array<string>>): void
Obtains the string array corresponding to the specified resource object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------- | ---- | --------------- |
-| resource | [Resource](#resource9) | Yes | Resource object. |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------------------------- | ---- | ----------------- |
+| resource | [Resource](#resource9) | Yes | Resource object. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.strarray.test').id
};
- this.context.resourceManager.getStringArray(resource, (error, value) => {
+ try {
+ this.context.resourceManager.getStringArrayValue(resource, (error, value) => {
if (error != null) {
console.log("error is " + error);
} else {
let strArray = value;
}
- });
+ });
+ } catch (error) {
+ console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getStringArray9+
+### getStringArrayValue9+
-getStringArray(resource: Resource): Promise<Array<string>>
+getStringArrayValue(resource: Resource): Promise<Array<string>>
Obtains the string array corresponding to the specified resource object. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ---------------------------------- | ------------------ |
| Promise<Array<string>> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.strarray.test').id
};
- this.context.resourceManager.getStringArray(resource).then(value => {
+ try {
+ this.context.resourceManager.getStringArrayValue(resource).then(value => {
let strArray = value;
- }).catch(error => {
- console.log("getStringArray promise error is " + error);
- });
+ }).catch(error => {
+ console.log("getStringArray promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMedia
-getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void
+### getMediaContent9+
+
+getMediaContent(resId: number, callback: AsyncCallback<Uint8Array>): void
Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ------------------ |
| resId | number | Yes | Resource ID. |
| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getMedia($r('app.media.test').id, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let media = value;
- }
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaContent($r('app.media.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMedia
+### getMediaContent9+
-getMedia(resId: number): Promise<Uint8Array>
+getMediaContent(resId: number): Promise<Uint8Array>
Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
@@ -548,116 +691,169 @@ Obtains the content of the media file corresponding to the specified resource ID
| ------------------------- | -------------- |
| Promise<Uint8Array> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getMedia($r('app.media.test').id).then(value => {
+ ```ts
+ try {
+ this.context.resourceManager.getMediaContent($r('app.media.test').id).then(value => {
let media = value;
}).catch(error => {
- console.log("getMedia promise error is " + error);
+ console.log("getMediaContent promise error is " + error);
});
- });
+ } catch (error) {
+ console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMedia9+
+### getMediaContent9+
-getMedia(resource: Resource, callback: AsyncCallback<Uint8Array>): void
+getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void
Obtains the content of the media file corresponding to the specified resource object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------- | ---- | --------------- |
-| resource | [Resource](#resource9) | Yes | Resource object. |
+
+| Name | Type | Mandatory | Description |
+| -------- | ------------------------------- | ---- | ------------------ |
+| resource | [Resource](#resource9) | Yes | Resource object. |
| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
- this.context.resourceManager.getMedia(resource, (error, value) => {
- if (error != null) {
+ try {
+ this.context.resourceManager.getMediaContent(resource, (error, value) => {
+ if (error != null) {
console.log("error is " + error);
- } else {
+ } else {
let media = value;
- }
- });
+ }
+ });
+ } catch (error) {
+ console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMedia9+
+### getMediaContent9+
-getMedia(resource: Resource): Promise<Uint8Array>
+getMediaContent(resource: Resource): Promise<Uint8Array>
Obtains the content of the media file corresponding to the specified resource object. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------------------------- | ------------------- |
| Promise<Uint8Array> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
- this.context.resourceManager.getMedia(resource).then(value => {
+ try {
+ this.context.resourceManager.getMediaContent(resource).then(value => {
let media = value;
- }).catch(error => {
- console.log("getMedia promise error is " + error);
- });
+ }).catch(error => {
+ console.log("getMediaContent promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMediaBase64
-getMediaBase64(resId: number, callback: AsyncCallback<string>): void
+### getMediaContentBase649+
+
+getMediaContentBase64(resId: number, callback: AsyncCallback<string>): void
Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------ |
| resId | number | Yes | Resource ID. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let media = value;
- }
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaContentBase64($r('app.media.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMediaBase64
+### getMediaContentBase649+
-getMediaBase64(resId: number): Promise<string>
+getMediaContentBase64(resId: number): Promise<string>
Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
@@ -667,77 +863,116 @@ Obtains the Base64 code of the image corresponding to the specified resource ID.
| --------------------- | -------------------- |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getMediaBase64($r('app.media.test').id).then(value => {
- let media = value;
- }).catch(error => {
- console.log("getMediaBase64 promise error is " + error);
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaContentBase64($r('app.media.test').id).then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMediaContentBase64 promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMediaBase649+
+### getMediaContentBase649+
-getMediaBase64(resource: Resource, callback: AsyncCallback<string>): void
+getMediaContentBase64(resource: Resource, callback: AsyncCallback<string>): void
Obtains the Base64 code of the image corresponding to the specified resource object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------ |
-| resource | [Resource](#resource9) | Yes | Resource object. |
+| resource | [Resource](#resource9) | Yes | Resource object. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
- this.context.resourceManager.getMediaBase64(resource, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let media = value;
- }
- });
+ try {
+ this.context.resourceManager.getMediaContentBase64(resource, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ } catch (error) {
+ console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getMediaBase649+
+### getMediaContentBase649+
-getMediaBase64(resource: Resource): Promise<string>
+getMediaContentBase64(resource: Resource): Promise<string>
Obtains the Base64 code of the image corresponding to the specified resource object. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | -------------------- |
-| Promise<string> | Promise used to return the result.|
+| Type | Description |
+| --------------------- | ------------------------- |
+| Promise<string> | Promise used to return the result.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.media.test').id
};
- this.context.resourceManager.getMediaBase64(resource).then(value => {
- let media = value;
- }).catch(error => {
- console.log("getMediaBase64 promise error is " + error);
- });
+ try {
+ this.context.resourceManager.getMediaContentBase64(resource).then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMediaContentBase64 promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
@@ -750,12 +985,13 @@ Obtains the device configuration. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------- |
| callback | AsyncCallback<[Configuration](#configuration)> | Yes | Callback used to return the result.|
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.getConfiguration((error, value) => {
if (error != null) {
@@ -783,7 +1019,7 @@ Obtains the device configuration. This API uses a promise to return the result.
| Promise<[Configuration](#configuration)> | Promise used to return the result.|
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.getConfiguration().then(value => {
let direction = value.direction;
@@ -804,12 +1040,13 @@ Obtains the device capability. This API uses an asynchronous callback to return
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes | Callback used to return the result.|
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.getDeviceCapability((error, value) => {
if (error != null) {
@@ -837,7 +1074,7 @@ Obtains the device capability. This API uses a promise to return the result.
| Promise<[DeviceCapability](#devicecapability)> | Promise used to return the result.|
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.getDeviceCapability().then(value => {
let screenDensity = value.screenDensity;
@@ -849,44 +1086,58 @@ Obtains the device capability. This API uses a promise to return the result.
```
-### getPluralString
+### getPluralStringValue9+
-getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void
+getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void
Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------------- |
| resId | number | Yes | Resource ID. |
| num | number | Yes | Number. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let str = value;
- }
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getPluralString
+### getPluralStringValue9+
-getPluralString(resId: number, num: number): Promise<string>
+getPluralStringValue(resId: number, num: number): Promise<string>
Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
@@ -897,46 +1148,74 @@ Obtains the singular-plural string corresponding to the specified resource ID ba
| --------------------- | ------------------------- |
| Promise<string> | Promise used to return the result.|
-**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getPluralString($r("app.plural.test").id, 1).then(value => {
- let str = value;
- }).catch(error => {
- console.log("getPluralString promise error is " + error);
- });
- });
- ```
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
-### getPluralString9+
+**Error codes**
-getPluralString(resource: Resource, num: number, callback: AsyncCallback<string>): void
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
+**Example**
+ ```ts
+ try {
+ this.context.resourceManager.getPluralStringValue($r("app.plural.test").id, 1).then(value => {
+ let str = value;
+ }).catch(error => {
+ console.log("getPluralStringValue promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+ ```
+
+### getPluralStringValue9+
+
+getPluralStringValue(resource: Resource, num: number, callback: AsyncCallback<string>): void
Obtains the singular-plural string corresponding to the specified resource object based on the specified number. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------- | ---- | ------------------------------- |
-| resource | [Resource](#resource9) | Yes | Resource object. |
-| num | number | Yes | Number. |
+
+| Name | Type | Mandatory | Description |
+| -------- | --------------------------- | ---- | ------------------------------------ |
+| resource | [Resource](#resource9) | Yes | Resource object. |
+| num | number | Yes | Number. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.plural.test').id
};
- this.context.resourceManager.getPluralString(resource, 1, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let str = value;
- }
- });
+ try {
+ this.context.resourceManager.getPluralStringValue(resource, 1, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
```
### getPluralString9+
@@ -948,66 +1227,95 @@ Obtains the singular-plural string corresponding to the specified resource objec
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
-| num | number | Yes | Number. |
+| num | number | Yes | Number. |
**Return value**
-| Type | Description |
-| --------------------- | ------------------------- |
+| Type | Description |
+| --------------------- | ------------------------------ |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.plural.test').id
};
- this.context.resourceManager.getPluralString(resource, 1).then(value => {
- let str = value;
- }).catch(error => {
- console.log("getPluralString promise error is " + error);
- });
+ try {
+ this.context.resourceManager.getPluralString(resource, 1).then(value => {
+ let str = value;
+ }).catch(error => {
+ console.log("getPluralString promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getRawFile8+
-getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void
+### getRawFileContent9+
+
+getRawFileContent(path: string, callback: AsyncCallback<Uint8Array>): void
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------------- |
| path | string | Yes | Path of the raw file. |
| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | If the resource not found by path. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getRawFile("test.xml", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let rawFile = value;
- }
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getRawFileContent("test.xml", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let rawFile = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
```
-### getRawFile8+
+### getRawFileContent9+
-getRawFile(path: string): Promise<Uint8Array>
+getRawFileContent(path: string): Promise<Uint8Array>
Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
@@ -1017,55 +1325,77 @@ Obtains the content of the raw file in the **resources/rawfile** directory. This
| ------------------------- | ----------- |
| Promise<Uint8Array> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | If the resource not found by path. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getRawFile("test.xml").then(value => {
- let rawFile = value;
- }).catch(error => {
- console.log("getRawFile promise error is " + error);
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getRawFileContent("test.xml").then(value => {
+ let rawFile = value;
+ }).catch(error => {
+ console.log("getRawFileContent promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
-### getRawFileDescriptor8+
-getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void
+### getRawFd9+
+
+getRawFd(path: string, callback: AsyncCallback<RawFileDescriptor>): void
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------------------- |
| path | string | Yes | Path of the raw file. |
| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | If the resource not found by path. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getRawFileDescriptor("test.xml", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let fd = value.fd;
- let offset = value.offset;
- let length = value.length;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getRawFd("test.xml", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let fd = value.fd;
+ let offset = value.offset;
+ let length = value.length;
+ }
+ }).catch(error => {
+ console.log("getRawFd callback error is " + error);
});
```
-### getRawFileDescriptor8+
+### getRawFd9+
-getRawFileDescriptor(path: string): Promise<RawFileDescriptor>
+getRawFd(path: string): Promise<RawFileDescriptor>
Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
@@ -1075,17 +1405,27 @@ Obtains the descriptor of the raw file in the **resources/rawfile** directory. T
| ---------------------------------------- | ------------------- |
| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | If the resource not found by path. |
+
**Example**
- ```
- resourceManager.getResourceManager((error, mgr) => {
- mgr.getRawFileDescriptor("test.xml").then(value => {
- let fd = value.fd;
- let offset = value.offset;
- let length = value.length;
- }).catch(error => {
- console.log("getRawFileDescriptor promise error is " + error);
- });
- });
+ ```ts
+ try {
+ this.context.resourceManager.getRawFd("test.xml").then(value => {
+ let fd = value.fd;
+ let offset = value.offset;
+ let length = value.length;
+ }).catch(error => {
+ console.log("getRawFd promise error is " + error);
+ });
+ } catch (error) {
+ console.log("getRawFd promise error is " + error);
+ };
```
### closeRawFileDescriptor8+
@@ -1097,13 +1437,14 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml", (error, value) => {
if (error != null) {
@@ -1122,6 +1463,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
@@ -1132,7 +1474,7 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th
| Promise<void> | Promise that returns no value.|
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml").then(value => {
let result = value;
@@ -1142,6 +1484,84 @@ Closes the descriptor of the raw file in the **resources/rawfile** directory. Th
});
```
+
+### closeRawFd9+
+
+closeRawFd(path: string, callback: AsyncCallback<void>): void
+
+Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | ------------------------- | ---- | ----------- |
+| path | string | Yes | Path of the raw file.|
+| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | The resource not found by path. |
+
+**Example**
+ ```ts
+ try {
+ this.context.resourceManager.closeRawFd("test.xml", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ }
+ });
+ } catch (error) {
+ console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
+ ```
+
+### closeRawFd8+
+
+closeRawFd(path: string): Promise<void>
+
+Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ---- | ------ | ---- | ----------- |
+| path | string | Yes | Path of the raw file.|
+
+**Return value**
+| Type | Description |
+| ------------------- | ---- |
+| Promise<void> | Promise that returns no value.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001005 | If the resource not found by path. |
+
+**Example**
+ ```ts
+ try {
+ this.context.resourceManager.closeRawFd("test.xml").then(value => {
+ let result = value;
+ }).catch(error => {
+ console.log("closeRawFd promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+ ```
+
### release7+
release()
@@ -1151,7 +1571,7 @@ Releases a created **resourceManager** object.
**System capability**: SystemCapability.Global.ResourceManager
**Example**
- ```
+ ```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.release();
});
@@ -1166,20 +1586,36 @@ Obtains the string corresponding to the specified resource name. This API uses a
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------- |
-| resName | string | Yes | Resource name. |
-| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+| resName | string | Yes | Resource name. |
+| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
**Example**
- ```
- this.context.resourceManager.getStringByName("test", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let string = value;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringByName("test", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let string = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
```
### getStringByName9+
@@ -1191,22 +1627,37 @@ Obtains the string corresponding to the specified resource name. This API uses a
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
+
+| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---- |
-| resName | string | Yes | Resource name.|
+| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
-| Promise<string> | Promise used to return the result.|
+| Type | Description |
+| --------------------- | ---------- |
+| Promise<string> | String corresponding to the resource name.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
**Example**
- ```
- this.context.resourceManager.getStringByName("test").then(value => {
- let string = value;
- }).catch(error => {
- console.log("getStringByName promise error is " + error);
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringByName("test").then(value => {
+ let string = value;
+ }).catch(error => {
+ console.log("getStringByName promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getStringArrayByName9+
@@ -1218,20 +1669,35 @@ Obtains the string array corresponding to the specified resource name. This API
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------- |
-| resName | string | Yes | Resource name. |
+| resName | string | Yes | Resource name. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getStringArrayByName("test", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let strArray = value;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringArrayByName("test", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let strArray = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getStringArrayByName9+
@@ -1243,22 +1709,37 @@ Obtains the string array corresponding to the specified resource name. This API
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------ | ---- | ----- |
-| resName | string | Yes | Resource name.|
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
+| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| ---------------------------------- | ------------- |
+| Type | Description |
+| ---------------------------------- | ------------ |
| Promise<Array<string>> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getStringArrayByName("test").then(value => {
- let strArray = value;
- }).catch(error => {
- console.log("getStringArrayByName promise error is " + error);
- });
+ ```ts
+ try {
+ this.context.resourceManager.getStringArrayByName("test").then(value => {
+ let strArray = value;
+ }).catch(error => {
+ console.log("getStringArrayByName promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getMediaByName9+
@@ -1270,20 +1751,35 @@ Obtains the content of the media file corresponding to the specified resource na
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ------------------ |
-| resName | string | Yes | Resource name. |
+| resName | string | Yes | Resource name. |
| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getMediaByName("test", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let media = value;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaByName("test", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getMediaByName9+
@@ -1295,22 +1791,37 @@ Obtains the content of the media file corresponding to the specified resource na
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| ------------------------- | -------------- |
+| Type | Description |
+| ------------------------- | ------------- |
| Promise<Uint8Array> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getMediaByName("test").then(value => {
- let media = value;
- }).catch(error => {
- console.log("getMediaByName promise error is " + error);
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaByName("test").then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMediaByName promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getMediaBase64ByName9+
@@ -1322,20 +1833,35 @@ Obtains the Base64 code of the image corresponding to the specified resource nam
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ------------------------ |
-| resName | string | Yes | Resource name. |
+| resName | string | Yes | Resource name. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let media = value;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaBase64ByName("test", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getMediaBase64ByName9+
@@ -1347,22 +1873,37 @@ Obtains the Base64 code of the image corresponding to the specified resource nam
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------ | ---- | ----- |
-| resName | string | Yes | Resource name.|
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
+| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| --------------------- | -------------------- |
+| Type | Description |
+| --------------------- | ------------------- |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getMediaBase64ByName("test").then(value => {
- let media = value;
- }).catch(error => {
- console.log("getMediaBase64ByName promise error is " + error);
- });
+ ```ts
+ try {
+ this.context.resourceManager.getMediaBase64ByName("test").then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMediaBase64ByName promise error is " + error);
+ });
+ } catch (error) {
+ console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getPluralStringByName9+
@@ -1374,21 +1915,37 @@ Obtains the plural string corresponding to the specified resource name based on
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------- | ---- | ------------------------------- |
-| resName | string | Yes | Resource name. |
-| num | number | Yes | Number. |
+
+| Name | Type | Mandatory | Description |
+| -------- | --------------------------- | ---- | ----------------------------- |
+| resName | string | Yes | Resource name. |
+| num | number | Yes | Number. |
| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
- if (error != null) {
- console.log("error is " + error);
- } else {
- let str = value;
- }
- });
+ ```ts
+ try {
+ this.context.resourceManager.getPluralStringByName("test", 1, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ } catch (error) {
+ console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
```
### getPluralStringByName9+
@@ -1400,23 +1957,38 @@ Obtains the plural string corresponding to the specified resource name based on
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
| resName | string | Yes | Resource name.|
-| num | number | Yes | Number. |
+| num | number | Yes | Number. |
**Return value**
-| Type | Description |
-| --------------------- | ------------------------- |
+| Type | Description |
+| --------------------- | ---------------------- |
| Promise<string> | Promise used to return the result.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
+ ```ts
+ try {
+ this.context.resourceManager.getPluralStringByName("test", 1).then(value => {
let str = value;
- }).catch(error => {
+ }).catch(error => {
console.log("getPluralStringByName promise error is " + error);
- });
+ });
+ } catch (error) {
+ console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getStringSync9+
@@ -1428,18 +2000,33 @@ Obtains the string corresponding to the specified resource ID. This API returns
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
-| string | String corresponding to the specified resource ID.|
+| Type | Description |
+| ------ | ----------- |
+| string | Promise used to return the result.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
**Example**
- ```
- this.context.resourceManager.getStringSync($r('app.string.test').id);
+ ```ts
+ try {
+ this.context.resourceManager.getStringSync($r('app.string.test').id);
+ } catch (error) {
+ console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getStringSync9+
@@ -1451,23 +2038,38 @@ Obtains the string corresponding to the specified resource object. This API retu
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
-| string | String corresponding to the resource object.|
+| Type | Description |
+| ------ | ---------------- |
+| string | Promise used to return the result.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.string.test').id
};
- this.context.resourceManager.getStringSync(resource);
+ try {
+ this.context.resourceManager.getStringSync(resource);
+ } catch (error) {
+ console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getStringByNameSync9+
@@ -1479,18 +2081,33 @@ Obtains the string corresponding to the specified resource name. This API return
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
-| string | String corresponding to the resource name.|
+| Type | Description |
+| ------ | ---------- |
+| string | String corresponding to the specified resource name.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
**Example**
- ```
- this.context.resourceManager.getStringByNameSync("test");
+ ```ts
+ try {
+ this.context.resourceManager.getStringByNameSync("test");
+ } catch (error) {
+ console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getBoolean9+
@@ -1502,18 +2119,33 @@ Obtains the Boolean result corresponding to the specified resource ID. This API
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------- | ------------ |
| boolean | Boolean result corresponding to the specified resource ID.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
+ ```ts
+ try {
+ this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
+ } catch (error) {
+ console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getBoolean9+
@@ -1524,23 +2156,38 @@ Obtains the Boolean result corresponding to the specified resource object. This
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------- | ----------------- |
| boolean | Boolean result corresponding to the specified resource object.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.boolean.boolean_test').id
};
- this.context.resourceManager.getBoolean(resource);
+ try {
+ this.context.resourceManager.getBoolean(resource);
+ } catch (error) {
+ console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getBooleanByName9+
@@ -1552,18 +2199,33 @@ Obtains the Boolean result corresponding to the specified resource name. This AP
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------ | ---- | ----- |
-| resName | string | Yes | Resource name.|
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
+| resName | string | Yes | Resource name.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------- | ----------- |
| boolean | Boolean result corresponding to the specified resource name.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getBooleanByName("boolean_test");
+ ```ts
+ try {
+ this.context.resourceManager.getBooleanByName("boolean_test");
+ } catch (error) {
+ console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getNumber9+
@@ -1575,19 +2237,39 @@ Obtains the integer or float value corresponding to the specified resource ID. T
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
| resId | number | Yes | Resource ID.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------ | ---------- |
| number | Integer or float value corresponding to the specified resource ID.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
- this.context.resourceManager.getNumber($r('app.integer.integer_test').id);
- this.context.resourceManager.getNumber($r('app.float.float_test').id);
+ ```ts
+ try {
+ this.context.resourceManager.getNumber($r('app.integer.integer_test').id);
+ } catch (error) {
+ console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
+ try {
+ this.context.resourceManager.getNumber($r('app.float.float_test').id);
+ } catch (error) {
+ console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getNumber9+
@@ -1599,23 +2281,38 @@ Obtains the integer or float value corresponding to the specified resource objec
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
-| Name | Type | Mandatory | Description |
-| ----- | ------ | ---- | ----- |
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------- | ---- | ---- |
| resource | [Resource](#resource9) | Yes | Resource object.|
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
+| Type | Description |
+| ------ | --------------- |
| number | Integer or float value corresponding to the specified resource object.|
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001001 | If the resId invalid. |
+| 9001002 | If the resource not found by resId. |
+| 9001006 | If the resource re-ref too much. |
+
**Example**
- ```
+ ```ts
let resource = {
bundleName: "com.example.myapplication",
moduleName: "entry",
id: $r('app.integer.integer_test').id
};
- this.context.resourceManager.getNumber(resource);
+ try {
+ this.context.resourceManager.getNumber(resource);
+ } catch (error) {
+ console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`)
+ }
```
### getNumberByName9+
@@ -1627,17 +2324,490 @@ Obtains the integer or float value corresponding to the specified resource name.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ------- | ------ | ---- | ---- |
+| resName | string | Yes | Resource name.|
+
+**Return value**
+| Type | Description |
+| ------ | --------- |
+| number | Integer or float value corresponding to the specified resource name.|
+
+For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md).
+
+**Error codes**
+
+| ID| Error Message|
+| -------- | ---------------------------------------- |
+| 9001003 | If the resName invalid. |
+| 9001004 | If the resource not found by resName. |
+| 9001006 | If the resource re-ref too much. |
+
+**Example**
+ ```ts
+ try {
+ this.context.resourceManager.getNumberByName("integer_test");
+ } catch (error) {
+ console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+
+ try {
+ this.context.resourceManager.getNumberByName("float_test");
+ } catch (error) {
+ console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`)
+ }
+ ```
+
+
+### getString(deprecated)
+
+getString(resId: number, callback: AsyncCallback<string>): void
+
+Obtains the string corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | --------------------------- | ---- | --------------- |
+| resId | number | Yes | Resource ID. |
+| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getString($r('app.string.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ });
+ ```
+
+
+### getString(deprecated)
+
+getString(resId: number): Promise<string>
+
+Obtains the string corresponding to the specified resource ID. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getStringValue](#getstringvalue9-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----- |
-| resName | string | Yes | Resource name.|
+| resId | number | Yes | Resource ID.|
**Return value**
| Type | Description |
| --------------------- | ----------- |
-| number | Integer or float value corresponding to the specified resource name.|
+| Promise<string> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getString($r('app.string.test').id).then(value => {
+ let str = value;
+ }).catch(error => {
+ console.log("getstring promise error is " + error);
+ });
+ });
+ ```
+
+
+### getStringArray(deprecated)
+
+getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void
+
+Obtains the string array corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------------------------- | ---- | ----------------- |
+| resId | number | Yes | Resource ID. |
+| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the result.|
**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getStringArray($r('app.strarray.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let strArray = value;
+ }
+ });
+ });
```
- this.context.resourceManager.getNumberByName("integer_test");
- this.context.resourceManager.getNumberByName("float_test");
+
+
+### getStringArray(deprecated)
+
+getStringArray(resId: number): Promise<Array<string>>
+
+Obtains the string array corresponding to the specified resource ID. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getStringArrayValue](#getstringarrayvalue9-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ----- | ------ | ---- | ----- |
+| resId | number | Yes | Resource ID.|
+
+**Return value**
+| Type | Description |
+| ---------------------------------- | ------------- |
+| Promise<Array<string>> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getStringArray($r('app.strarray.test').id).then(value => {
+ let strArray = value;
+ }).catch(error => {
+ console.log("getStringArray promise error is " + error);
+ });
+ });
+ ```
+
+
+### getMedia(deprecated)
+
+getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void
+
+Obtains the content of the media file corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | ------------------------------- | ---- | ------------------ |
+| resId | number | Yes | Resource ID. |
+| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getMedia($r('app.media.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ });
+ ```
+
+
+### getMedia(deprecated)
+
+getMedia(resId: number): Promise<Uint8Array>
+
+Obtains the content of the media file corresponding to the specified resource ID. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getMediaContent](#getmediacontent-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ----- | ------ | ---- | ----- |
+| resId | number | Yes | Resource ID.|
+
+**Return value**
+| Type | Description |
+| ------------------------- | -------------- |
+| Promise<Uint8Array> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getMedia($r('app.media.test').id).then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMedia promise error is " + error);
+ });
+ });
+ ```
+
+
+### getMediaBase64(deprecated)
+
+getMediaBase64(resId: number, callback: AsyncCallback<string>): void
+
+Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | --------------------------- | ---- | ------------------------ |
+| resId | number | Yes | Resource ID. |
+| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getMediaBase64($r('app.media.test').id, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let media = value;
+ }
+ });
+ });
+ ```
+
+
+### getMediaBase64(deprecated)
+
+getMediaBase64(resId: number): Promise<string>
+
+Obtains the Base64 code of the image corresponding to the specified resource ID. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getMediaContentBase64](#getmediacontentbase64-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ----- | ------ | ---- | ----- |
+| resId | number | Yes | Resource ID.|
+
+**Return value**
+| Type | Description |
+| --------------------- | -------------------- |
+| Promise<string> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getMediaBase64($r('app.media.test').id).then(value => {
+ let media = value;
+ }).catch(error => {
+ console.log("getMediaBase64 promise error is " + error);
+ });
+ });
+ ```
+
+
+### getPluralString(deprecated)
+
+getPluralString(resId: number, num: number): Promise<string>
+
+Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ----- | ------ | ---- | ----- |
+| resId | number | Yes | Resource ID.|
+| num | number | Yes | Number. |
+
+**Return value**
+| Type | Description |
+| --------------------- | ------------------------- |
+| Promise<string> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getPluralString($r("app.plural.test").id, 1).then(value => {
+ let str = value;
+ }).catch(error => {
+ console.log("getPluralString promise error is " + error);
+ });
+ });
+ ```
+
+
+### getPluralString(deprecated)
+
+getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void
+
+Obtains the singular-plural string corresponding to the specified resource ID based on the specified number. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getPluralStringValue](#getpluralstringvalue-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | --------------------------- | ---- | ------------------------------- |
+| resId | number | Yes | Resource ID. |
+| num | number | Yes | Number. |
+| callback | AsyncCallback<string> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let str = value;
+ }
+ });
+ });
+ ```
+
+
+### getRawFile(deprecated)
+
+getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void
+
+Obtains the content of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | ------------------------------- | ---- | ----------------------- |
+| path | string | Yes | Path of the raw file. |
+| callback | AsyncCallback<Uint8Array> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getRawFile("test.xml", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let rawFile = value;
+ }
+ });
+ });
+ ```
+
+
+### getRawFile(deprecated)
+
+getRawFile(path: string): Promise<Uint8Array>
+
+Obtains the content of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getRawFileContent](#getrawfilecontent9-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ---- | ------ | ---- | ----------- |
+| path | string | Yes | Path of the raw file.|
+
+**Return value**
+| Type | Description |
+| ------------------------- | ----------- |
+| Promise<Uint8Array> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getRawFile("test.xml").then(value => {
+ let rawFile = value;
+ }).catch(error => {
+ console.log("getRawFile promise error is " + error);
+ });
+ });
+ ```
+
+
+### getRawFileDescriptor(deprecated)
+
+getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void
+
+Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| -------- | ---------------------------------------- | ---- | -------------------------------- |
+| path | string | Yes | Path of the raw file. |
+| callback | AsyncCallback<[RawFileDescriptor](#rawfiledescriptor8)> | Yes | Callback used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getRawFileDescriptor("test.xml", (error, value) => {
+ if (error != null) {
+ console.log("error is " + error);
+ } else {
+ let fd = value.fd;
+ let offset = value.offset;
+ let length = value.length;
+ }
+ });
+ });
+ ```
+
+### getRawFileDescriptor(deprecated)
+
+getRawFileDescriptor(path: string): Promise<RawFileDescriptor>
+
+Obtains the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
+
+This API is deprecated since API version 9. You are advised to use [getRawFd](#getrawfd9-1) instead.
+
+**System capability**: SystemCapability.Global.ResourceManager
+
+**Parameters**
+
+| Name | Type | Mandatory | Description |
+| ---- | ------ | ---- | ----------- |
+| path | string | Yes | Path of the raw file.|
+
+**Return value**
+| Type | Description |
+| ---------------------------------------- | ------------------- |
+| Promise<[RawFileDescriptor](#rawfiledescriptor8)> | Promise used to return the result.|
+
+**Example**
+ ```ts
+ resourceManager.getResourceManager((error, mgr) => {
+ mgr.getRawFileDescriptor("test.xml").then(value => {
+ let fd = value.fd;
+ let offset = value.offset;
+ let length = value.length;
+ }).catch(error => {
+ console.log("getRawFileDescriptor promise error is " + error);
+ });
+ });
```
diff --git a/en/application-dev/reference/errorcodes/errorcode-resource-manager.md b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md
new file mode 100644
index 0000000000000000000000000000000000000000..cb6852a1f2a184284b98967f3f18fde57e7ce39d
--- /dev/null
+++ b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md
@@ -0,0 +1,113 @@
+# Resource Manager Error Codes
+
+## 9001001 Invalid Resource ID
+
+**Error Message**
+
+The resId invalid.
+
+**Description**
+
+This error code is reported if the specified resource ID meets the type requirement but the resource ID does not exist.
+
+**Possible Causes**
+
+The specified resource ID does not exist.
+
+**Solution**
+
+Check whether the specified resource ID exists.
+
+## 9001002 Matching Resource Not Found Based on the Specified Resource ID
+
+**Error Message**
+
+The resource not found by resId.
+
+**Description**
+
+This error code is reported if the specified resource ID meets the type requirement but the no resource is found based on the resource ID.
+
+**Possible Causes**
+
+1. The specified resource ID is incorrect.
+
+2. Resource parsing is incorrect.
+
+**Solution**
+
+Check whether the specified resource ID is correct.
+
+## 9001003 Invalid Resource Name
+
+**Error Message**
+
+The resName invalid.
+
+**Description**
+
+This error code is reported if the specified resource name meets the type requirement but the resource name does not exist.
+
+**Possible Causes**
+
+The specified resource name does not exist.
+
+**Solution**
+
+Check whether the specified resource name is correct.
+
+## 9001004 Matching Resource Not Found Based on the Specified Resource Name
+
+**Error Message**
+
+The resource not found by resName.
+
+**Description**
+
+This error code is reported if the specified resource ID meets the type requirement but the no resource is found based on the resource ID.
+
+**Possible Causes**
+
+1. The specified resource name is incorrect.
+
+2. Resource parsing is incorrect.
+
+**Solution**
+
+Check whether the specified resource name is correct.
+
+## 9001005 Invalid Relative Path
+
+**Error Message**
+
+The resource not found by path.
+
+**Description**
+
+This error code is reported if no resource is found based on the specified relative path.
+
+**Possible Causes**
+
+The specified relative path is incorrect.
+
+**Solution**
+
+Check whether the specified relative path is correct.
+
+## 9001006 Cyclic Reference
+
+**Error Message**
+
+the resource re-ref too much.
+
+**Description**
+
+This error code is reported if resources are referenced cyclically.
+
+**Possible Causes**
+
+Resources are referenced cyclically.
+
+**Solution**
+
+Check the reference of resource $, and remove the cyclic reference, if any.