We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesApplication FrameworkArkDataArkTS APIs@ohos.data.uniformDataStruct (Uniform Data Structs)

@ohos.data.uniformDataStruct (Uniform Data Structs)

Phone12+PC/2in113+Tablet12+TV19+

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.

The APIs of this module can be used only in the stage model.

Modules to Import

Collapse
Word wrap
Dark theme
Copy code
  1. import { uniformDataStruct } from '@kit.ArkData';

PlainText

Phone12+PC/2in113+Tablet12+TV19+

Plain text typed data, used to describe and manage plain text content. After a PlainText object is created, it can be used in data sharing scenarios such as drag-and-drop and copy-paste to implement cross-application plain text data interaction.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'general.plain-text' Yes No The unified data type identifier is plain text typed data, fixed to "general.plain-text". For details about the data type description information, see UniformDataType.
textContent string No No Plain text content. The length limit is 20 MB.
abstract string No Yes Plain text abstract. This is an optional field. Pass this parameter when a brief abstract needs to be provided for the text (for example, for preview, search result display, and other scenarios). If not passed, the default value is an empty string, and no abstract information is provided.
details Record<string, string> No Yes

Dictionary type object. Both the key and value are of the string type, used to describe the detailed attributes of the text content. This is an optional field, and the default value is an empty dictionary object. For example, a data object whose details content is

{

"title":"title",

"content":"content"

}

can be generated. Pass this parameter when additional text attribute information needs to be stored. If not passed, the default value is an empty dictionary object, and no additional attributes are provided.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
  2. let plainTextDetails: Record<string, string> = {
  3. 'attr1': 'value1',
  4. 'attr2': 'value2'
  5. };
  6. let plainText: uniformDataStruct.PlainText = {
  7. uniformDataType: 'general.plain-text',
  8. textContent: 'This is plainText textContent example',
  9. abstract: 'this is abstract',
  10. details: plainTextDetails
  11. };
  12. console.info('plainText.uniformDataType: ' + plainText.uniformDataType);
  13. if (plainText.details != undefined) {
  14. let plainTextDetailsObj: Record<string, string> = plainText.details;
  15. for (let kv of Object.entries(plainTextDetailsObj)) {
  16. console.info('plainText.details.attr: ' + kv[0] + ', value:' + kv[1]);
  17. }
  18. }
  19. let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
Phone12+PC/2in113+Tablet12+TV19+

Defines the hyperlink typed data, which is used to describe and manage hyperlink information. After a Hyperlink object is created, it can be used in scenarios such as drag-and-drop and sharing to implement cross-application hyperlink data transfer and redirection.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'general.hyperlink' Yes No Uniform data type, which has a fixed value of general.hyperlink. For details, see UniformDataType.
url string No No URL of the link. It supports protocols such as http and https and must conform to the standard URL format. For example, https://www.example.com or file:///path/to/file.
description string No Yes Description of the link content. This is an optional field. Pass this parameter when a text description needs to be provided for the hyperlink (for example, for accessibility, link preview, and other scenarios). If it is not passed, the default value is an empty string, and no description information is provided.
details Record<string, string> No Yes

Dictionary type object whose keys and values are all of the string type. It is used to describe the detailed attribute content of Hyperlink. This is an optional field, and the default value is an empty dictionary object. For example, a data object whose details content is

{

"title":"title",

"content":"content"

}

can be generated. Pass this parameter when additional hyperlink attribute information needs to be stored. If it is not passed, the default value is an empty dictionary object, and no additional attributes are provided.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
  2. let hyperlinkDetails: Record<string, string> = {
  3. 'attr1': 'value1',
  4. 'attr2': 'value2'
  5. };
  6. let hyperlink: uniformDataStruct.Hyperlink = {
  7. uniformDataType: 'general.hyperlink',
  8. url: 'www.XXX.com',
  9. description: 'This is the description of this hyperlink',
  10. details: hyperlinkDetails
  11. };
  12. console.info('hyperlink.uniformDataType: ' + hyperlink.uniformDataType);
  13. let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);

HTML

Phone12+PC/2in113+Tablet12+TV19+

Defines the HTML typed data, which is used to describe HyperText Markup Language data. After an HTML object is created, it can be used to transfer rich text content in scenarios such as drag-and-drop and copy-paste, support cross-application HTML format data interaction, and control the URI authorization policy through uriAuthorizationPolicies.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'general.html' Yes No Uniform data type, which has a fixed value of general.html. For details, see UniformDataType.
htmlContent string No No Content text in HTML format, supporting standard HTML tags. It can be a complete HTML document or an HTML fragment. The length limit is 20 MB. UTF-8 encoding is recommended. For example: <div><p> title </p></div>.
plainContent string No Yes Plain text content after removing HTML tags. This is an optional field. Pass this parameter when a plain text version of the HTML content is required (for example, for text search, display in environments without HTML rendering, and other scenarios). If not passed, the default value is an empty string, and no plain text version is provided.
details Record<string, string> No Yes

Object of dictionary type, where both the key and value are of string type, used to describe the detailed attribute content of the HTML. This is an optional field, and the default value is an empty dictionary object. For example, a data object can be generated with the details content as

{

"title":"title",

"content":"content"

}

.

uriAuthorizationPolicies Array<number> No Yes

URI authorization policy for drag-and-drop scenarios. The default value is READ (read-only authorization), which takes effect only in scenarios such as the img tag. It applies only to a single record and has the highest priority. For details about the policy, see UriPermission.

Since: 26.0.0

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
  2. let htmlObjDetails: Record<string, string> = {
  3. 'attr1': 'value1',
  4. 'attr2': 'value2'
  5. };
  6. let htmlObj: uniformDataStruct.HTML = {
  7. uniformDataType: 'general.html',
  8. htmlContent: '<div><p>Title</p></div>',
  9. plainContent: 'this is plainContent',
  10. details: htmlObjDetails,
  11. // Starting from API version 26.0.0, URI authorization policy is supported.
  12. uriAuthorizationPolicies: [
  13. unifiedDataChannel.UriPermission.WRITE
  14. ]
  15. };
  16. console.info('htmlObj.uniformDataType: ' + htmlObj.uniformDataType);
  17. let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HTML, htmlObj);

OpenHarmonyAppItem

Phone12+PC/2in113+Tablet12+TV19+

Represents the system-defined desktop icon typed data, which is used to share desktop icon information across applications. Typical usage scenarios include dragging icons on the home screen launcher, sharing application icons in the app store, or creating shortcuts.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'openharmony.app-item' Yes No Uniform data type, which has a fixed value of openharmony.app-item. For details, see UniformDataType.
appId string No No ID of the application, for which the icon is used.
appName string No No Name of the application, for which the icon is used.
appIconId string No No Image ID of the icon.
appLabelId string No No Label ID corresponding to the icon name.
bundleName string No No Bundle name of the application corresponding to the icon. The format must comply with the application package name specification.
abilityName string No No Ability name of the application corresponding to the icon. It is recommended that the name follow the Ability component naming convention: a string no longer than 127 bytes that starts with a letter and can contain letters, digits, underscores (_), or periods (.). Ensure that the name is unique within the entire application. The "package name.Ability name" format is recommended (for example, "com.example.myapplication.MainAbility").
details Record<string, number | string | Uint8Array> No Yes Dictionary type object. The key is of the string type, and the value can contain data of the number (numeric type), string (string type), or Uint8Array (binary data) type. This is an optional field, and the default value is an empty dictionary object.

Example

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

ContentForm14+

Phone14+PC/2in114+Tablet14+TV19+

Defines the content card typed data, which is used to share content card information across applications. Typical usage scenarios include sharing article cards in news applications, sharing product cards in e-commerce applications, and sharing content previews in social applications.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'general.content-form' Yes No Uniform data type, which has a fixed value of general.content-form.
title string No No Title of the content widget.
thumbData Uint8Array No Yes Image data corresponding to the content card. The default value is empty.
description string No Yes Description information in the content card. The default value is an empty string.
appIcon Uint8Array No Yes Application icon data in the content card. The default value is empty.
appName string No Yes Application name in the content card. The default value is an empty string.
linkUri string No Yes Redirect hyperlink corresponding to the content card, which must comply with the URI format specification. The default value is an empty string.

Example

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

Form15+

Phone15+PC/2in115+Tablet15+TV19+

Represents the system-defined card typed data, which is used to share card information across applications. Typical usage scenarios include card drag-and-drop sharing, cross-application transfer of card content, and data sharing of home screen widgets.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'openharmony.form' Yes No Uniform data type, which has a fixed value of openharmony.form. For details, see UniformDataType.
formId number No No Widget ID.
formName string No No Widget name.
bundleName string No No Bundle name of the card. The format must comply with the application package name specification.
abilityName string No No Ability name corresponding to the card. It is recommended that the name follow the Ability component naming convention: a string no longer than 127 bytes, starting with a letter and containing letters, digits, underscores (_), or periods (.). Ensure that the name is unique within the entire application. The "package name.Ability name" format is recommended (for example, "com.example.myapplication.MainAbility").
module string No No Module to which the widget belongs.
details Record<string, number | string | Uint8Array> No Yes Dictionary type object. The key is of the string type, and the value can contain data of the number (numeric type), string (string type), or Uint8Array (binary data) type. This is an optional field, and the default value is an empty dictionary object.

Example

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

FileUri15+

Phone15+PC/2in115+Tablet15+TV19+

Defines a file URI typed data, which is used to describe the URI address information of a file. Once a FileUri object is created, it can be used in scenarios such as file dragging and file sharing. It supports controlling file access permissions through uriAuthorizationPolicies, enabling cross-application file data transfer and permission management.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'general.file-uri' Yes No Uniform data type, which has a fixed value of general.file-uri. For details, see UniformDataType.
oriUri string No No Original URI path of the file. Supports local file absolute paths, the file:// protocol, and http/https network URL formats. The length limit is 4096 bytes. For example: /data/local/tmp/test.txt, file:///data/local/tmp/test.txt, or http://example.com/file.txt.
fileType string No No The file type must be a standardized data type (that is, the UTD-ID corresponding to each type in the UTD preset list or a custom UTD-ID). The maximum length limit of fileType is 1024 bytes. An exception is thrown when the limit is exceeded.
details Record<string, number | string | Uint8Array> No Yes Dictionary type object. The key is of the string type, and the value can contain data of the number (numeric type), string (string type), or Uint8Array (binary byte array) type. This is an optional field, and the default value is an empty dictionary object.
uriAuthorizationPolicies Array<number> No Yes

URI authorization policy used in drag-and-drop scenarios. The default value is READ+WRITE+PERSIST (read + write + persistent authorization). It applies only to a single record and has the highest priority. For details about the policies, see UriPermission.

Since: 26.0.0

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
  2. let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  3. let fileUriDetails: Record<string, number | string | Uint8Array> = {
  4. 'fileUriKey1': 123,
  5. 'fileUriKey2': 'fileUriValue',
  6. 'fileUriKey3': u8Array
  7. };
  8. let fileUri: uniformDataStruct.FileUri = {
  9. uniformDataType: 'general.file-uri',
  10. oriUri: 'www.xx.com',
  11. fileType: 'general.image',
  12. details: fileUriDetails,
  13. // Since API version 26.0.0, URI authorization policy is supported.
  14. uriAuthorizationPolicies: [
  15. unifiedDataChannel.UriPermission.WRITE
  16. ]
  17. };
  18. console.info('fileUri.uniformDataType: ' + fileUri.uniformDataType);
  19. // You are advised to set type to uniformTypeDescriptor.UniformDataType.FILE_URI to use the uniform data struct of FileUri type to construct records.
  20. let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);

PixelMap15+

Phone15+PC/2in115+Tablet15+TV19+

Represents the system-defined pixel map typed data, used to describe image pixel data. After a PixelMap object is created, it can be used in scenarios such as image drag-and-drop and image sharing to implement cross-application image data transfer.

System capability: SystemCapability.DistributedDataManager.UDMF.Core

Expand
Name Type Read-Only Optional Description
uniformDataType 'openharmony.pixel-map' Yes No Unified data type identifier of the pixel map typed data, fixed to "openharmony.pixel-map". For details about the data type description information, see UniformDataType.
pixelMap image.PixelMap No No Pixel map object.
details Record<string, number | string | Uint8Array> No Yes Dictionary type object whose key is of the string type and whose value can contain data of the number (numeric type), string (string type), or Uint8Array (binary byte array) type. Optional field, and the default value is an empty dictionary object.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
  2. import { image } from '@kit.ImageKit';
  3. let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  4. let arrayBuffer = new ArrayBuffer(4 * 200 * 200);
  5. let opt: image.InitializationOptions = {
  6. editable: true,
  7. pixelFormat: 3,
  8. size: { height: 200, width: 200 },
  9. alphaType: 3
  10. };
  11. let pixelMapDetails: Record<string, number | string | Uint8Array> = {
  12. 'pixelMapKey1': 123,
  13. 'pixelMapKey2': 'pixelMapValue',
  14. 'pixelMapKey3': u8Array
  15. };
  16. let pixelMap: uniformDataStruct.PixelMap = {
  17. uniformDataType: 'openharmony.pixel-map',
  18. pixelMap: image.createPixelMapSync(arrayBuffer, opt),
  19. details: pixelMapDetails
  20. };
  21. console.info('pixelMap.uniformDataType: ' + pixelMap.uniformDataType);
  22. let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap);