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 011b9cc217a06a07416cb37cc689d093f86c3947..5205bc6c9bdf5cbb741258be4425d032fab454a7 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -1,1329 +1,786 @@ -# Resource Manager +# Resource Management +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. -## Modules to Import +## Modules to Import ``` import resourceManager from '@ohos.resourceManager'; ``` -## Required Permissions - -None - -## resourceManager.getResourceManager - -getResourceManager\(callback: AsyncCallback\): void - -Obtains the **ResourceManager** object of the current application. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<ResourceManager>

-

Yes

-

Asynchronous callback used to return the ResourceManager object.

-
- - -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - if (error != null) { - console.log("error occurs" + error); - return; - } - mgr.getString(0x1000000, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager\(bundleName: string, callback: AsyncCallback\): void - -Obtains the **ResourceManager** object of the specified application. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

bundleName

-

string

-

Yes

-

Bundle name of the specified application.

-

callback

-

AsyncCallback<ResourceManager>

-

Yes

-

Asynchronous callback used to return the ResourceManager object.

-
- -- Example - - ``` - resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => { - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager\(\): Promise - -Obtains the **ResourceManager** object of the current application. This method uses a promise to return the result. - -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<ResourceManager>

-

Promise used to return the ResourceManager object.

-
- -- Example - - ``` - resourceManager.getResourceManager().then(mgr => { - mgr.getString(0x1000000, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }).catch(error => { - console.log(error); - }); - ``` - - -## resourceManager.getResourceManager - -getResourceManager\(bundleName: string\): Promise - -Obtains the **ResourceManager** object of the specified application. This method uses a promise to return the result. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

bundleName

-

string

-

Yes

-

Bundle name of the specified application.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<ResourceManager>

-

Promise used to return the ResourceManager object.

-
- -- Example - - ``` - resourceManager.getResourceManager("com.example.myapplication").then(mgr => { - - }).catch(error => { - - }); - ``` - - -## Direction - -Enumerates screen directions. - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

DIRECTION_VERTICAL

-

0

-

Portrait

-

DIRECTION_HORIZONTAL

-

1

-

Landscape

-
- -## DeviceType - -Enumerates device types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default 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

-

Smart TV

-

DEVICE_TYPE_WEARABLE

-

0x06

-

Wearable

-
- -## ScreenDensity - -Enumerates screen density types. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Default Value

-

Description

-

SCREEN_SDPI

-

120

-

Screen density with small-scale dots per inch (SDPI).

-

SCREEN_MDPI

-

160

-

Screen density with medium-scale dots per inch (MDPI)

-

SCREEN_LDPI

-

240

-

Screen density with large-scale dots per inch (LDPI).

-

SCREEN_XLDPI

-

320

-

Screen density with extra-large-scale dots per inch (XLDPI).

-

SCREEN_XXLDPI

-

480

-

Screen density with extra-extra-large-scale dots per inch (XXLDPI).

-

SCREEN_XXXLDPI

-

640

-

Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).

-
- -## Configuration - -Provides the device configuration. - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

direction

-

Direction

-

Yes

-

No

-

Screen direction of the current device.

-

locale

-

string

-

Yes

-

No

-

Current system language.

-
- -## DeviceCapability - -Provides the device capability. - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

screenDensity

-

ScreenDensity

-

Yes

-

No

-

Screen density of the current device.

-

deviceType

-

DeviceType

-

Yes

-

No

-

Type of the current device.

-
- -## ResourceManager - -Provides the capability of accessing application resources. - ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->- The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. ->- Resource files are defined in the **resources** directory of the project. You can obtain the resource ID from **$r\(resource address\).id**, for example, **$r\(?app.string.test?\).id**. - -### getString - -getString\(resId: number, callback: AsyncCallback\): void - -Obtains the string corresponding to the specified resource ID. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

callback

-

AsyncCallback<string>

-

Yes

-

Asynchronous callback used to return the obtained string.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getString($r('app.string.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getString - -getString\(resId: number\): Promise +## resourceManager.getResourceManager + +getResourceManager(callback: AsyncCallback<ResourceManager>): void + +Obtains the **ResourceManager** object of this application. This method uses a callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes| Callback used to return the **ResourceManager** object obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + if (error != null) { + console.log("error occurs" + error); + return; + } + mgr.getString(0x1000000, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +## resourceManager.getResourceManager + +getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void + +Obtains the **ResourceManager** object of an application. This method uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | bundleName | string | Yes| Bundle name of the target application.| + | callback | AsyncCallback<[ResourceManager](#resourcemanager)> | Yes| Callback used to return the **ResourceManager** object obtained.| + +- Example + ``` + resourceManager.getResourceManager("com.example.myapplication", (error, mgr) => { + }); + ``` + + +## resourceManager.getResourceManager + +getResourceManager(): Promise<ResourceManager> + +Obtains the **ResourceManager** object of this application. This method uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the **ResourceManager** object obtained.| + +- Example + ``` + resourceManager.getResourceManager().then(mgr => { + mgr.getString(0x1000000, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }).catch(error => { + console.log(error); + }); + ``` + + +## resourceManager.getResourceManager + +getResourceManager(bundleName: string): Promise<ResourceManager> + +Obtains the **ResourceManager** object of an application. This method uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | bundleName | string | Yes| Bundle name of the target application.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<[ResourceManager](#resourcemanager)> | Promise used to return the **ResourceManager** object obtained.| + +- Example + ``` + resourceManager.getResourceManager("com.example.myapplication").then(mgr => { + + }).catch(error => { + + }); + ``` + + +## Direction + +Enumerates the screen directions. + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| DIRECTION_VERTICAL | 0 | Portrait
**System capability**: SystemCapability.Global.ResourceManager| +| DIRECTION_HORIZONTAL | 1 | Landscape
**System capability**: SystemCapability.Global.ResourceManager| + + +## DeviceType + +Enumerates the device types. + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| DEVICE_TYPE_PHONE | 0x00 | Mobile phone.
**System capability**: SystemCapability.Global.ResourceManager| +| DEVICE_TYPE_TABLET | 0x01 | Tablet.
**System capability**: SystemCapability.Global.ResourceManager| +| DEVICE_TYPE_CAR | 0x02 | Automobile.
**System capability**: SystemCapability.Global.ResourceManager| +| DEVICE_TYPE_PC | 0x03 | Computer.
**System capability**: SystemCapability.Global.ResourceManager| +| DEVICE_TYPE_TV | 0x04 | TV.
**System capability**: SystemCapability.Global.ResourceManager| +| DEVICE_TYPE_WEARABLE | 0x06 | Wearable.
**System capability**: SystemCapability.Global.ResourceManager| + + +## ScreenDensity + +Enumerates the screen density types. + +| Name| Default Value| Description| +| -------- | -------- | -------- | +| SCREEN_SDPI | 120 | Screen density with small-scale dots per inch (SDPI).
**System capability**: SystemCapability.Global.ResourceManager| +| SCREEN_MDPI | 160 | Screen density with medium-scale dots per inch (MDPI).
**System capability**: SystemCapability.Global.ResourceManager| +| SCREEN_LDPI | 240 | Screen density with large-scale dots per inch (LDPI).
**System capability**: SystemCapability.Global.ResourceManager| +| SCREEN_XLDPI | 320 | Screen density with extra-large-scale dots per inch (XLDPI).
**System capability**: SystemCapability.Global.ResourceManager| +| SCREEN_XXLDPI | 480 | Screen density with extra-extra-large-scale dots per inch (XXLDPI).
**System capability**: SystemCapability.Global.ResourceManager| +| SCREEN_XXXLDPI | 640 | Screen density with extra-extra-extra-large-scale dots per inch (XXXLDPI).
**System capability**: SystemCapability.Global.ResourceManager| + + +## Configuration + +Defines the device configuration. + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| direction | [Direction](#direction) | Yes| No| Screen direction of the device.
**System capability**: SystemCapability.Global.ResourceManager| +| locale | string | Yes| No| Current system language.
**System capability**: SystemCapability.Global.ResourceManager| + + +## DeviceCapability + +Defines the device capability. + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| screenDensity | [ScreenDensity](#screendensity) | Yes| No| Screen density of the device.
**System capability**: SystemCapability.Global.ResourceManager| +| deviceType | [DeviceType](#devicetype) | Yes| No| Type of the device.
**System capability**: SystemCapability.Global.ResourceManager| + + +## RawFileDescriptor8+ + +Defines the descriptor information of the raw file. +
**System capability**: SystemCapability.Global.ResourceManager + +| Name| Type| Description| +| -------- | -------- | -------- | +| fd | number | Descriptor of a raw file.| +| offset | number | Offset to the start position of the raw file.| +| length | number | Length of the raw file.| + + +## ResourceManager + +Defines the capability of accessing application resources. + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> - The methods involved in **ResourceManager** are applicable only to the TypeScript-based declarative development paradigm. +> +> - Resource files are defined in the **resources** directory of the project. You can obtain the resource ID using **$r(resource address).id**, for example, **$r('app.string.test').id**. + + +### getString + +getString(resId: number, callback: AsyncCallback<string>): void + +Obtains the string corresponding to the specified resource ID. This method 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 string obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getString($r('app.string.test').id, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getString + +getString(resId: number): Promise<string> Obtains the string corresponding to the specified resource ID. This method uses a promise to return the result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<string>

-

String corresponding to the resource ID.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getString($r('app.string.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getStringArray - -getStringArray\(resId: number, callback: AsyncCallback\>\): void - -Obtains the array of strings corresponding to the specified resource ID. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

callback

-

AsyncCallback<Array<string>>

-

Yes

-

Asynchronous callback used to return the obtained array of strings.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray($r('app.strarray.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getStringArray - -getStringArray\(resId: number\): Promise\> +**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 string obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getString($r('app.string.test').id).then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getStringArray + +getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void + +Obtains the array of strings corresponding to the specified resource ID. This method 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 obtained array of strings.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getStringArray($r('app.strarray.test').id, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getStringArray + +getStringArray(resId: number): Promise<Array<string>> Obtains the array of strings corresponding to the specified resource ID. This method uses a promise to return the result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Array<string>>

-

Array of strings corresponding to the specified resource ID.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getStringArray($r('app.strarray.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getMedia - -getMedia\(resId: number, callback: AsyncCallback\): void - -Obtains the content of the media file corresponding to the specified resource ID. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

callback

-

AsyncCallback<Uint8Array>

-

Yes

-

Asynchronous callback used to return the content of the obtained media file.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getMedia - -getMedia\(resId: number\): Promise +**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 array of strings obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getStringArray($r('app.strarray.test').id).then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getMedia + +getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void + +Obtains the content of the media file corresponding to the specified resource ID. This method 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 content of the media file obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getMedia($r('app.media.test').id, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getMedia + +getMedia(resId: number): Promise<Uint8Array> Obtains the content of the media file corresponding to the specified resource ID. This method uses a promise to return the result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Promise used to return the content of the obtained media file.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMedia($r('app.media.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getMediaBase64 - -getMediaBase64\(resId: number, callback: AsyncCallback\): void - -Obtains the Base64 code of the image corresponding to the specified resource ID. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

callback

-

AsyncCallback<string>

-

Yes

-

Asynchronous callback used to return the obtained Base64 code of the image.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64($r('app.media.test').id, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getMediaBase64 - -getMediaBase64\(resId: number\): Promise +**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 content of the media file obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getMedia($r('app.media.test').id).then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getMediaBase64 + +getMediaBase64(resId: number, callback: AsyncCallback<string>): void + +Obtains the Base64 code of the image corresponding to the specified resource ID. This method 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 Base64 code of the image obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getMediaBase64($r('app.media.test').id, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getMediaBase64 + +getMediaBase64(resId: number): Promise<string> Obtains the Base64 code of the image corresponding to the specified resource ID. This method uses a promise to return the result. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<string>

-

Promise used to return the obtained Base64 code of the image.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getMediaBase64($r('app.media.test').id).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getConfiguration - -getConfiguration\(callback: AsyncCallback\): void - -Obtains the device configuration. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<Configuration>

-

Yes

-

Asynchronous callback used to return the obtained device configuration.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration((error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getConfiguration - -getConfiguration\(\): Promise +**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 Base64 code of the image obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getMediaBase64($r('app.media.test').id).then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getConfiguration + +getConfiguration(callback: AsyncCallback<Configuration>): void + +Obtains the device configuration. This method uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[Configuration](#configuration)> | Yes| Callback used to return the obtained device configuration.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getConfiguration((error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getConfiguration + +getConfiguration(): Promise<Configuration> Obtains the device configuration. This method uses a promise to return the result. -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Configuration>

-

Promise used to return the device configuration.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration().then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getDeviceCapability - -getDeviceCapability\(callback: AsyncCallback\): void - -Obtains the device capability. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

callback

-

AsyncCallback<DeviceCapability>

-

Yes

-

Asynchronous callback used to return the obtained device capability.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability((error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getDeviceCapability - -getDeviceCapability\(\): Promise +**System capability**: SystemCapability.Global.ResourceManager + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<[Configuration](#configuration)> | Promise used to return the device configuration.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getConfiguration().then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getDeviceCapability + +getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void + +Obtains the device capability. This method uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[DeviceCapability](#devicecapability)> | Yes| Callback used to return the obtained device capability.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getDeviceCapability((error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getDeviceCapability + +getDeviceCapability(): Promise<DeviceCapability> Obtains the device capability. This method uses a promise to return the result. -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<DeviceCapability>

-

Promise used to return the obtained device capability.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability().then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getPluralString - -getPluralString\(resId: number, num: number, callback: AsyncCallback\): void - -Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method uses a callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

num

-

number

-

Yes

-

Number that determines the plural or singular form.

-

callback

-

AsyncCallback<string>

-

Yes

-

Asynchronous callback used to return the obtained singular-plural string.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getPluralString - -getPluralString\(resId: number, num: number\): Promise +**System capability**: SystemCapability.Global.ResourceManager -Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method uses a promise to return the result. +- Return value + | Type| Description| + | -------- | -------- | + | Promise<[DeviceCapability](#devicecapability)> | Promise used to return the obtained device capability.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getDeviceCapability().then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + + +### getPluralString -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

resId

-

number

-

Yes

-

Resource ID.

-

num

-

number

-

Yes

-

Number that determines the plural or singular form.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<string>

-

Promise used to return the obtained singular-plural string.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getPluralString($r("app.plural.test").id, 1).then(value => { - console.log(value); - }).catch(error => { - console.log("getstring promise " + error); - }); - }); - ``` - - -### getRawFile8+ - -getRawFile\(path: string, callback: AsyncCallback\): void - -Obtains the content of rawfile in the specified path. This method uses an asynchronous callback to return the result. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

path

-

string

-

Yes

-

Path of the rawfile.

-

callback

-

AsyncCallback<Uint8Array>

-

Yes

-

Asynchronous callback used to return the rawfile content, in byte arrays.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getRawFile("test.xml", (error, value) => { - if (error != null) { - console.log(value); - } else { - console.log(value); - } - }); - }); - ``` - - -### getRawFile8+ - -getRawFile\(path: string\): Promise - -Obtains the content of the rawfile in the specified path. This method uses a promise to return the result. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

path

-

string

-

Yes

-

Path of the rawfile.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Promise<Uint8Array>

-

Promise used to return the rawfile content, in byte arrays.

-
- -- Example - - ``` - resourceManager.getResourceManager((error, mgr) => { - mgr.getRawFile("test.xml").then(value => { - console.log(value); - }).catch(error => { - console.log("getrawfile promise " + error); - }); - }); - ``` +getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void + +Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method 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 that determines the plural or singular form.| + | callback | AsyncCallback<string> | Yes| Callback used to return the singular-plural string obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getPluralString($r("app.plural.test").id, 1, (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + + +### getPluralString + +getPluralString(resId: number, num: number): Promise<string> + +Obtains the specified number of singular-plural strings corresponding to the specified resource ID. This method uses a promise to return the result. +**System capability**: SystemCapability.Global.ResourceManager + +- **Parameters** + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | resId | number | Yes| Resource ID.| + | num | number | Yes| Number that determines the plural or singular form.| + +- Return value + | Type| Description| + | -------- | -------- | + | Promise<string> | Promise used to return the singular-plural string obtained.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getPluralString($r("app.plural.test").id, 1).then(value => { + console.log(value); + }).catch(error => { + console.log("getstring promise " + error); + }); + }); + ``` + +### getRawFile8+ + +getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void + +Obtains the content of the raw file in the specified path. This method 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 raw file content, in byte arrays.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getRawFile("test.xml", (error, value) => { + if (error != null) { + console.log(value); + } else { + console.log(value); + } + }); + }); + ``` + +### getRawFile8+ + +getRawFile(path: string): Promise<Uint8Array> + +Obtains the content of the raw file in the specified path. This method 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<Uint8Array> | Promise used to return the raw file content, in byte arrays.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getRawFile("test.xml").then(value => { + console.log(value); + }).catch(error => { + console.log("getrawfile promise " + error); + }); + }); + ``` + +### getRawFileDescriptor8+ + +getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void + +Obtains the descriptor of the raw file in the specified path. This method 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 raw file descriptor.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.getRawFileDescriptor("test.xml", (error, value) => { + if (error != null) { + console.log(value); + } else { + let fd = value.fd; + let offset = value.offset; + let length = value.length; + } + }); + }); + ``` + +### getRawFileDescriptor8+ + +getRawFileDescriptor(path: string): Promise<RawFileDescriptor> + +Obtains the descriptor of the raw file in the specified path. This method 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<[RawFileDescriptor](#RawFileDescriptor8+)> | Promise used to return the raw file descriptor.| + +- 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); + }); + }); + ``` + +### closeRawFileDescriptor8+ + +closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void + +Closes the descriptor of the raw file in the specified path. This method 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.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.closeRawFileDescriptor("test.xml", (error, value) => { + if (error != null) { + console.log(value); + } + }); + }); + ``` + +### closeRawFileDescriptor8+ + +closeRawFileDescriptor(path: string): Promise<void> + +Closes the descriptor of the raw file in the specified path. This method 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> | No value is returned.| + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.closeRawFileDescriptor("test.xml").then(value => { + console.log(value); + }).catch(error => { + console.log("closeRawFileDescriptor promise " + error); + }); + }); + ``` + +### release7+ + +release(); + +Releases the created **resourceManager**. + +**System capability**: SystemCapability.Global.ResourceManager + +- Example + ``` + resourceManager.getResourceManager((error, mgr) => { + mgr.release((error, value) => { + if (error != null) { + console.log(value); + } + }); + }); + ```