1# @ohos.sendableResourceManager (Resource Manager) 2 3The **sendableResourceManager** module provides the [resourceToSendableResource](#sendableresourcemanagerresourcetosendableresource) and [sendableResourceToResource](#sendableresourcemanagersendableresourcetoresource) APIs to implement conversion between [Resource](#resource) and [SendableResource](#sendableresource) objects. 4 5A **Resource** object can be held by the [Sendable](../../arkts-utils/arkts-sendable.md) 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. 6 7> **NOTE** 8> 9> 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. 10 11## Modules to Import 12 13```js 14import sendableResourceManager from '@ohos.sendableResourceManager'; 15``` 16 17## sendableResourceManager.resourceToSendableResource 18 19resourceToSendableResource(resource: Resource): SendableResource 20 21Converts a **Resource** object to a **SendableResource** object. 22 23**System capability**: SystemCapability.Global.ResourceManager 24 25**Parameters** 26 27| Name | Type | Mandatory | Description | 28| -------- | ---------------------------------------- | ---- | ----------------------------- | 29| resource | [Resource](#resource) | Yes | **Resource** object.| 30 31**Return value** 32 33| Type | Description | 34| ------ | ---------------------------- | 35| [SendableResource](#sendableresource) | **SendableResource** object after conversion.| 36 37**Error codes** 38 39For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 40 41| ID| Error Message| 42| -------- | ---------------------------------------- | 43| 401 | If the input parameter invalid. Possible causes: <br>1.Incorrect parameter types; <br>2.Parameter verification failed. | 44 45**Example** 46 ```js 47import sendableResourceManager from '@ohos.sendableResourceManager'; 48import { BusinessError } from '@ohos.base'; 49 50try { 51 let sendableResource: sendableResourceManager.SendableResource = sendableResourceManager.resourceToSendableResource($r('app.string.test')); 52} catch (error) { 53 let code = (error as BusinessError).code; 54 let message = (error as BusinessError).message; 55 console.error(`resourceToSendableResource failed, error code: ${code}, message: ${message}.`); 56} 57 ``` 58 59## sendableResourceManager.sendableResourceToResource 60 61sendableResourceToResource(sendableResource: SendableResource): Resource 62 63Converts a **SendableResource** object to a **Resource** object. 64 65**System capability**: SystemCapability.Global.ResourceManager 66 67**Parameters** 68 69| Name | Type | Mandatory | Description | 70| -------- | ---------------------------------------- | ---- | ----------------------------- | 71| sendableResource | [SendableResource](#sendableresource) | Yes | **SendableResource** object.| 72 73**Return value** 74 75| Type | Description | 76| ------ | ---------------------------- | 77| [Resource](#resource) | **Resource** object after conversion.| 78 79**Error codes** 80 81For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 82 83| ID| Error Message| 84| -------- | ---------------------------------------- | 85| 401 | If the input parameter invalid. Possible causes: <br>1.Incorrect parameter types; <br>2.Parameter verification failed. | 86 87**Example** 88 ```js 89import sendableResourceManager from '@ohos.sendableResourceManager'; 90import { BusinessError } from '@ohos.base'; 91 92try { 93 let resource: sendableResourceManager.Resource = sendableResourceManager.sendableResourceToResource(sendableResourceManager.resourceToSendableResource($r('app.string.test'))); 94} catch (error) { 95 let code = (error as BusinessError).code; 96 let message = (error as BusinessError).message; 97 console.error(`resourceToSendableResource failed, error code: ${code}, message: ${message}.`); 98} 99 ``` 100 101## Resource 102 103Defines a **Resource** object. 104 105**System capability**: SystemCapability.Global.ResourceManager 106 107**Parameters** 108 109| Name | Type | Read-Only | Optional |Description | 110| ---------- | ------ | ----- | ---- | ---------------| 111| bundleName | string | No | No| Bundle name of the application.| 112| moduleName | string | No | No| Module name of the application.| 113| id | number | No | No| Resource ID. | 114| 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. | 115| type | number | No | Yes| Resource type. | 116 117## SendableResource 118 119type SendableResource = _SendableResource 120 121**System capability**: SystemCapability.Global.ResourceManager 122 123| Type | Description | 124| ---------- | ------ | 125| [_SendableResource](sendableResource.md#sendableresource-1)|Defines a **SendableResource** object.| 126