openharmony 鸿蒙 js-apis-sendable-resource-manager

2025-06-12 浏览 (1)

@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

NameTypeMandatoryDescription
resourceResourceYesResource object.

Return value

TypeDescription
SendableResourceSendableResource object after conversion.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401If 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

NameTypeMandatoryDescription
sendableResourceSendableResourceYesSendableResource object.

Return value

TypeDescription
ResourceResource object after conversion.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401If 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

NameTypeRead-OnlyOptionalDescription
bundleNamestringNoNoBundle name of the application.
moduleNamestringNoNoModule name of the application.
idnumberNoNoResource ID.
paramsany[]NoYesOther resource parameters, including the resource name, substitution value for the formatting API, and quantifier for the singular-plural formatting API.
typenumberNoYesResource type.

SendableResource

type SendableResource = _SendableResource

System capability: SystemCapability.Global.ResourceManager

TypeDescription
_SendableResourceDefines a SendableResource object.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Localization Kit

harmony 鸿蒙RawFileDescriptor

harmony 鸿蒙RawFileDescriptor64

harmony 鸿蒙ResourceManager_Configuration

harmony 鸿蒙Font Management Error Codes

harmony 鸿蒙I18N Error Codes

harmony 鸿蒙Resource Manager Error Codes

harmony 鸿蒙@ohos.fontManager (Font Management)

harmony 鸿蒙@ohos.i18n (Internationalization) (System API)

harmony 鸿蒙@ohos.i18n (Internationalization)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/aoZmZE