Resource Management
Imported Modules
import resmgr from '@ohos.resmgr';
Permissions
None.
Methods
getResourceManager
Obtains the ResourceManager object of the current application.
Parameters
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
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
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
Return Values
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
DeviceType
Enumerates device types.
ScreenDensity
Enumerates screen density types.
Appendix
AsyncCallback<T>
Returns an error if an exception is thrown during execution; returns an empty value otherwise. |
|||
Returns a T object if the execution is successful; returns an empty value otherwise. |
Configuration
Provides the device configuration.
Attributes
Indicates the current system language, for example, zh-Hans-CN. |
DeviceCapability
Provides the device capability.
Attributes
ResourceManager
Provides the capability of accessing application resources.
getString
Obtains the character string corresponding to a specified resource ID in callback mode.
Parameters
AsyncCallback<string> |
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
Return Values
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
AsyncCallback<Array<string>> |
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
Return Values
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
AsyncCallback<Array<Uint8Array>> |
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
Return Values
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
AsyncCallback<string> |
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
Return Values
Indicates the Base64 code of the image resource corresponding to the specified resource ID. |
getConfiguration
Obtains the device configuration in callback mode.
Parameters
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
Promise<Configuration> |
getDeviceCapability
Obtains the device capability in callback mode.
Parameters
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
Promise<DeviceCapability> |
Return Values
None.
getPluralString
Obtains the singular-plural character string represented by the ID string corresponding to the specified number in callback mode.
Parameters
AsyncCallback<string> |
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
Return Values
Indicates the singular-plural character string represented by the ID string corresponding to the specified number. |