harmony 鸿蒙@ohos.sendableResourceManager (Resource Manager)
@ohos.sendableResourceManager (Resource Manager)
The sendableResourceManager module provides the resourceToSendableResource and sendableResourceToResource APIs to implement conversion between Resource and SendableResource objects.
A Resource object can be held by the Sendable class after being converted into a SendableResource object. After cross-thread transmission, the Sendable class converts the SendableResource object into a Resource object and uses it as an input parameter for the API used to obtain resources.
NOTE
The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import
import sendableResourceManager from '@ohos.sendableResourceManager';
sendableResourceManager.resourceToSendableResource
resourceToSendableResource(resource: Resource): SendableResource
Converts a Resource object to a SendableResource object.
System capability: SystemCapability.Global.ResourceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
resource | Resource | Yes | Resource object. |
Return value
Type | Description |
---|---|
SendableResource | SendableResource object after conversion. |
Error codes
For details about the error codes, see Universal Error Codes.
ID | Error Message |
---|---|
401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. |
Example
import sendableResourceManager from '@ohos.sendableResourceManager';
import { BusinessError } from '@ohos.base';
try {
let sendableResource: sendableResourceManager.SendableResource = sendableResourceManager.resourceToSendableResource($r('app.string.test'));
} catch (error) {
let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`resourceToSendableResource failed, error code: ${code}, message: ${message}.`);
}
sendableResourceManager.sendableResourceToResource
sendableResourceToResource(sendableResource: SendableResource): Resource
Converts a SendableResource object to a Resource object.
System capability: SystemCapability.Global.ResourceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
sendableResource | SendableResource | Yes | SendableResource object. |
Return value
Type | Description |
---|---|
Resource | Resource object after conversion. |
Error codes
For details about the error codes, see Universal Error Codes.
ID | Error Message |
---|---|
401 | If the input parameter invalid. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed. |
Example
import sendableResourceManager from '@ohos.sendableResourceManager';
import { BusinessError } from '@ohos.base';
try {
let resource: sendableResourceManager.Resource = sendableResourceManager.sendableResourceToResource(sendableResourceManager.resourceToSendableResource($r('app.string.test')));
} catch (error) {
let code = (error as BusinessError).code;
let message = (error as BusinessError).message;
console.error(`resourceToSendableResource failed, error code: ${code}, message: ${message}.`);
}
Resource
Defines a Resource object.
System capability: SystemCapability.Global.ResourceManager
Parameters
Name | Type | Read-Only | Optional | Description |
---|---|---|---|---|
bundleName | string | No | No | Bundle name of the application. |
moduleName | string | No | No | Module name of the application. |
id | number | No | No | Resource ID. |
params | any[] | No | Yes | Other resource parameters, including the resource name, substitution value for the formatting API, and quantifier for the singular-plural formatting API. |
type | number | No | Yes | Resource type. |
SendableResource
type SendableResource = _SendableResource
System capability: SystemCapability.Global.ResourceManager
Type | Description |
---|---|
_SendableResource | Defines a SendableResource object. |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙ResourceManager_Configuration
harmony 鸿蒙Font Management Error Codes
harmony 鸿蒙Resource Manager Error Codes
harmony 鸿蒙@ohos.fontManager (Font Management)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦