1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
resource-management.md 94.99 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Resource Management

Imported Modules

import resmgr from '@ohos.resmgr';

Permissions

None.

Methods

getResourceManager

Obtains the ResourceManager object of the current application.

Parameters

Name

Type

Mandatory

Description

callback

AsyncCallback<ResourceManager>

Yes

Indicates the callback containing the ResourceManager object.

Return Values

None.

Example

resmgr.getResourceManager((error, mgr) => {
    // callback
    mgr.getString(0x1000000, (error, value) => {
        if (error != null) {
            console.log(value);
        } else {
            console.log(value);
        }
    });

    // promise
    mgr.getString(0x1000000).then(value => {
        console.log(value);
    }).catch(error => {
        console.log("getstring promise " + error);
    });
}

getResourceManager

Obtains the ResourceManager object of the specified application.

Parameters

Name

Type

Mandatory

Description

bundleName

string

Yes

Indicates the bundle name of the specified application.

callback

AsyncCallback<ResourceManager>

Yes

Indicates the callback containing the ResourceManager object.

Return Values

None.

Example

resmgr.getResourceManager("com.example.myapplication", (error, mgr) => {
}

getResourceManager

Obtains the ResourceManager object of the current application.

Parameters

None.

Return Values

Type

Description

Promise<ResourceManager>

Indicates that the ResourceManager object is returned in Promise mode.

Example

resmgr.getResourceManager().then(mgr => {
    // callback
    mgr.getString(0x1000000, (error, value) => {
        if (error != null) {
            console.log(value);
        } else {
            console.log(value);
        }
    });

    // promise
    mgr.getString(0x1000000).then(value => {
        console.log(value);
    }).catch(error => {
        console.log("getstring promise " + error);
    });
}).catch(error => {

});

getResourceManager

Obtains the ResourceManager object of the specified application.

Parameters

Name

Type

Mandatory

Description

bundleName

string

Yes

Indicates the bundle name of the specified application.

Return Values

Type

Description

Promise<ResourceManager>

Indicates that the ResourceManager object is returned in Promise mode.

Example

resmgr.getResourceManager("com.example.myapplication").then(mgr => {

}).catch(error => {

});

Enum

Direction

Enumerates screen directions

Name

Default Value

Description

DIRECTION_VERTICAL

0

Indicates the vertical direction.

DIRECTION_HORIZONTAL

1

Indicates the horizontal direction.

DeviceType

Enumerates device types.

Name

Default Value

Description

DEVICE_TYPE_PHONE

0x00

Indicates a phone.

DEVICE_TYPE_TABLET

0x01

Indicates a tablet.

DEVICE_TYPE_CAR

0x02

Indicates a head unit.

DEVICE_TYPE_PC

0x03

Indicates a PC.

DEVICE_TYPE_TV

0x04

Indicates a smart TV.

DEVICE_TYPE_WEARABLE

0x06

Indicates a wearable.

ScreenDensity

Enumerates screen density types.

Name

Default Value

Description

SCREEN_SDPI

120

Indicates small screen density.

SCREEN_MDPI

160

Indicates medium screen density.

SCREEN_LDPI

240

Indicates large screen density.

SCREEN_XLDPI

320

Indicates extra-large screen density.

SCREEN_XXLDPI

480

Indicates extra-extra-large screen density.

SCREEN_XXXLDPI

640

Indicates extra-extra-extra-large screen density.

Appendix

AsyncCallback<T>

Name

Parameter Type

Mandatory

Description

error

Error

No

Returns an error if an exception is thrown during execution; returns an empty value otherwise.

data

T

No

Returns a T object if the execution is successful; returns an empty value otherwise.

Configuration

Provides the device configuration.

Attributes

Name

Parameter Type

Readable

Writable

Description

direction

Direction

Yes

No

Indicates the screen direction of the current device.

locale

string

Yes

No

Indicates the current system language, for example, zh-Hans-CN.

DeviceCapability

Provides the device capability.

Attributes

Name

Parameter Type

Readable

Writable

Description

screenDensity

ScreenDensity

Yes

No

Indicates the screen density of the current device.

deviceType

DeviceType

Yes

No

Indicates the type of the current device.

ResourceManager

Provides the capability of accessing application resources.

getString

Obtains the character string corresponding to a specified resource ID in callback mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

callback

AsyncCallback<string>

Yes

Indicates the asynchronous callback used to return the obtained character string.

Return Values

None.

getString

Obtains string resources associated with a specified resource ID in Promise mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

Return Values

Type

Description

Promise<string>

Indicates the character string corresponding to the resource ID.

getStringArray

Obtains the array of character strings corresponding to a specified resource ID in callback mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

callback

AsyncCallback<Array<string>>

Yes

Indicates the asynchronous callback used to return the obtained array of character strings.

Return Values

None.

getStringArray

Obtains the array of character strings corresponding to a specified resource ID in Promise mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

Return Values

Type

Description

Promise<Array<string>>

Indicates the array of character strings corresponding to the specified resource ID.

getMedia

Obtains the content of the media file corresponding to a specified resource ID in callback mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

callback

AsyncCallback<Array<Uint8Array>>

Yes

Indicates the asynchronous callback used to return the obtained media file content.

Return Values

None.

getMedia

Obtains the content of the media file corresponding to a specified resource ID in Promise mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

Return Values

Type

Description

Promise<Array<Uint8Array>>

Indicates the content of the media file corresponding to the specified resource ID.

getMediaBase64

Obtains the Base64 code of the image resource corresponding to the specified resource ID in callback mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

callback

AsyncCallback<string>

Yes

Indicates the asynchronous callback used to return the obtained Base64 code of the image resource.

Return Values

None.

getMediaBase64

Obtains the Base64 code of the image resource corresponding to the specified resource ID in Promise mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

Return Values

Type

Description

Promise<string>

Indicates the Base64 code of the image resource corresponding to the specified resource ID.

getConfiguration

Obtains the device configuration in callback mode.

Parameters

Name

Type

Mandatory

Description

callback

AsyncCallback<Configuration>

Yes

Indicates the asynchronous callback used to return the obtained device configuration.

Return Values

None.

getConfiguration

Obtains the device configuration in Promise mode.

Parameters

None.

Return Values

Type

Description

Promise<Configuration>

Indicates the device configuration.

getDeviceCapability

Obtains the device capability in callback mode.

Parameters

Name

Type

Mandatory

Description

callback

AsyncCallback<DeviceCapability>

Yes

Indicates the asynchronous callback used to return the obtained device capability.

Return Values

None.

getDeviceCapability

Obtains the device capability in Promise mode.

Parameters

None.

Return Values

Type

Description

Promise<DeviceCapability>

Indicates the device capability.

Return Values

None.

getPluralString

Obtains the singular-plural character string represented by the ID string corresponding to the specified number in callback mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

num:

number

Yes

Indicates the number.

callback

AsyncCallback<string>

Yes

Indicates the asynchronous callback used to return the singular-plural character string represented by the ID string corresponding to the specified number.

Return Values

None.

getPluralString

Obtains the singular-plural character string represented by the ID string corresponding to the specified number in Promise mode.

Parameters

Name

Type

Mandatory

Description

resId

number

Yes

Indicates the resource ID.

num:

number

Yes

Indicates the number.

Return Values

Type

Description

Promise<string>

Indicates the singular-plural character string represented by the ID string corresponding to the specified number.

1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891