openharmony 鸿蒙 js-apis-data-uniformDataStruct

2025-06-12 浏览 (1)

@ohos.data.uniformDataStruct (Uniform Data Structs)

As a part of the Unified Data Management Framework (UDMF), the uniformDataStruct module provides data structs corresponding to certain UniformDataTypes for service scenarios of many-to-many data sharing across applications. It helps simplify data interaction and reduce the data type adaptation workload.

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 { uniformDataStruct } from '@kit.ArkData';

PlainText

Represents data of the plain text type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'general.plain-text'YesNoUniform data type, which has a fixed value of general.plain-text. For details, see UniformDataType.
textContentstringNoNoPlaintext content.
abstractstringNoYesText abstract. It is an empty string by default.
detailsRecord<string, string>NoYesObject of the dictionary type used to describe the attributes of the text content. Both the key and value of the object are of the string type. For example, the following is a details object used to describe the properties of a file:
{
"title":"Title of the file",
"content":"Content of the file"
}
By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let plainTextDetails : Record<string, string> = {
  'attr1': 'value1',
  'attr2': 'value2'
}
let plainText : uniformDataStruct.PlainText = {
  uniformDataType: 'general.plain-text',
  textContent : 'This is plainText textContent example',
  abstract : 'this is abstract',
  details : plainTextDetails
}
console.info('plainText.uniformDataType: ' + plainText.uniformDataType);
if(plainText.details != undefined){
  let plainTextDetailsObj : Record<string, string> = plainText.details;
  for(let kv of Object.entries(plainTextDetailsObj)) {
    console.info('plainText.details.attr: ' + kv[0] + ', value:' + kv[1]);
  }
}
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);

Hyperlink

Represents data of the hyperlink type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'general.hyperlink'YesNoUniform data type, which has a fixed value of general.hyperlink. For details, see UniformDataType.
urlstringNoNoURL.
descriptionstringNoYesDescription of the linked content. This parameter is optional. By default, it is an empty string.
detailsRecord<string, string>NoYesObject of the dictionary type used to describe the attributes of the hyperlink. Both the key and value of the object are of the string type. For example, the following is a details object used to describe the properties of a file:
{
"title":"Title of the hyperlink",
"content":"Content"
}
By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let hyperlinkDetails : Record<string, string> = {
  'attr1': 'value1',
  'attr2': 'value2'
}
let hyperlink : uniformDataStruct.Hyperlink = {
  uniformDataType:'general.hyperlink',
  url : 'www.XXX.com',
  description : 'This is the description of this hyperlink',
  details : hyperlinkDetails
}
console.info('hyperlink.uniformDataType: ' + hyperlink.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);

HTML

Represents data of the HTML type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'general.html'YesNoUniform data type, which has a fixed value of general.html. For details, see UniformDataType.
htmlContentstringNoNoContent in HTML format.
plainContentstringNoYesPlaintext without HTML tags. This parameter is optional. By default, it is an empty string.
detailsRecord<string, string>NoYesObject of the dictionary type used to describe the attributes of the HTML content. Both the key and value of the object are of the string type. For example, the following is a details object used to describe the properties of a file:
{
"title":"Title of the HTML content",
"content":"Content"
}
By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let htmlObjDetails : Record<string, string> = {
  'attr1': 'value1',
  'attr2': 'value2'
}
let htmlObj : uniformDataStruct.HTML = {
  uniformDataType :'general.html',
  htmlContent: '<div><p>Title</p></div>',
  plainContent : 'this is plainContent',
  details : htmlObjDetails
}
console.info('htmlObj.uniformDataType: ' + htmlObj.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HTML, htmlObj);

OpenHarmonyAppItem

Represents data of the home screen icon type defined by the system.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'openharmony.app-item'YesNoUniform data type, which has a fixed value of openharmony.app-item. For details, see UniformDataType.
appIdstringNoNoID of the application, for which the icon is used.
appNamestringNoNoName of the application, for which the icon is used.
appIconIdstringNoNoImage ID of the icon.
appLabelIdstringNoNoLabel ID corresponding to the icon name.
bundleNamestringNoNoBundle name corresponding to the icon.
abilityNamestringNoNoApplication ability name corresponding to the icon.
detailsRecord<string, number |string |Uint8Array>NoYesObject of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let appItemDetails : Record<string, number|string|Uint8Array> = {
  'appItemKey1': 123,
  'appItemKey2': 'appItemValue',
  'appItemKey3': u8Array
}
let appItem : uniformDataStruct.OpenHarmonyAppItem = {
  uniformDataType:'openharmony.app-item',
  appId : 'MyAppId',
  appName : 'MyAppName',
  appIconId : 'MyAppIconId',
  appLabelId : 'MyAppLabelId',
  bundleName : 'MyBundleName',
  abilityName : 'MyAbilityName',
  details : appItemDetails
}
console.info('appItem.uniformDataType: ' + appItem.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_APP_ITEM, appItem);

ContentForm14+

Represents data of the content widget type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'general.content-form'YesNoUniform data type, which has a fixed value of general.content-form.
titlestringNoNoTitle of the content widget.
thumbDataUint8ArrayNoYesImage data in the content widget.
descriptionstringNoYesDescription of the content widget.
appIconUint8ArrayNoYesApplication icon data in the content widget.
appNamestringNoYesApplication name in the content widget.
linkUristringNoYesHyperlink in the content widget.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let thumbDataU8Array = new Uint8Array([1, 2, 3, 4, 5]);
let appIconU8Array = new Uint8Array([6, 7, 8, 9, 10]);
let contentForm : uniformDataStruct.ContentForm = {
  uniformDataType : 'general.content-form',
  title : 'MyTitle',
  thumbData : thumbDataU8Array,
  description : 'MyDescription',
  appName : 'MyAppName',
  linkUri : 'MyLinkUri',
  appIcon : appIconU8Array
}
console.info('contentForm.uniformDataType: ' + contentForm.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.CONTENT_FORM, contentForm);

Form15+

Represents data of the widget type defined by the system.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'openharmony.form'YesNoUniform data type, which has a fixed value of openharmony.form. For details, see UniformDataType.
formIdnumberNoNoWidget ID.
formNamestringNoNoWidget name.
bundleNamestringNoNoBundle to which the widget belongs.
abilityNamestringNoNoAbility name corresponding to the widget.
modulestringNoNoModule to which the widget belongs.
detailsRecord<string, number |string |Uint8Array>NoYesObject of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let formDetails : Record<string, number|string|Uint8Array> = {
  'formKey1': 123,
  'formKey2': 'formValue',
  'formKey3': u8Array
}
let form : uniformDataStruct.Form = {
  uniformDataType : 'openharmony.form',
  formId : 1,
  formName : 'formName',
  bundleName : 'com.xx.app',
  abilityName : 'abilityName',
  module : 'module',
  details : formDetails
}
console.info('form.uniformDataType: ' + form.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form);

FileUri15+

Represents data of the file URI type.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'general.file-uri'YesNoUniform data type, which has a fixed value of general.file-uri. For details, see UniformDataType.
oriUristringNoNoFile URI.
fileTypestringNoNoFile type.
detailsRecord<string, number |string |Uint8Array>NoYesObject of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let fileUriDetails : Record<string, number|string|Uint8Array> = {
  'fileUriKey1': 123,
  'fileUriKey2': 'fileUriValue',
  'fileUriKey3': u8Array
}
let fileUri : uniformDataStruct.FileUri = {
  uniformDataType : 'general.file-uri',
  oriUri : 'www.xx.com',
  fileType : 'general.image',
  details : fileUriDetails
}
console.info('fileUri.uniformDataType: ' + fileUri.uniformDataType);
// You are advised to set type to uniformTypeDescriptor.UniformDataType.FILE_URI to use the uniform data struct of FileUri type to construct records.
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);

PixelMap15+

Represents data of the pixel map type defined by the system.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

NameTypeRead-OnlyOptionalDescription
uniformDataType'openharmony.pixel-map'YesNoUniform data type, which has a fixed value of openharmony.pixel-map. For details, see UniformDataType.
pixelMapimage.PixelMapNoNoBinary data of the pixel map.
detailsRecord<string, number |string |Uint8Array>NoYesObject of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.

Example

import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
import { image } from '@kit.ImageKit';

let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let arrayBuffer = new ArrayBuffer(4*200*200);
let opt : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 }, alphaType: 3 };
let pixelMapDetails : Record<string, number|string|Uint8Array> = {
  'pixelMapKey1': 123,
  'pixelMapKey2': 'pixelMapValue',
  'pixelMapKey3': u8Array
}
let pixelMap : uniformDataStruct.PixelMap = {
  uniformDataType : 'openharmony.pixel-map',
  pixelMap : image.createPixelMapSync(arrayBuffer, opt),
  details : pixelMapDetails
}
console.info('pixelMap.uniformDataType: ' + pixelMap.uniformDataType);
let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap);

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

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