1# @ohos.data.unifiedDataChannel (标准化数据通路) 2 3本模块为统一数据管理框架(Unified Data Management Framework,UDMF)的组成部分,针对多对多跨应用数据共享的不同业务场景提供了标准化的数据通路,提供了标准化的数据接入与读取接口。同时对文本、图片等数据类型提供了标准化定义,方便不同应用间进行数据交互,减少数据类型适配的工作量。 4 5> **说明:** 6> 7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import { unifiedDataChannel } from '@kit.ArkData'; 13``` 14 15## ShareOptions<sup>12+</sup> 16 17UDMF支持的设备内使用范围类型枚举。 18 19**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 20 21**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 22 23| 名称 | 值 | 说明 | 24|-------------|---|-------------------| 25| IN_APP | 0 | 表示允许在本设备同应用内使用。 | 26| CROSS_APP | 1 | 表示允许在本设备内跨应用使用。 | 27 28## GetDelayData<sup>12+</sup> 29 30type GetDelayData = (type: string) => UnifiedData 31 32对UnifiedData的延迟封装,支持延迟获取数据。当前只支持同设备剪贴板场景,后续场景待开发。 33 34**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 35 36**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 37 38**参数:** 39 40| 参数名 | 类型 | 必填 | 说明 | 41| -------- | -------- | -------- | -------- | 42| type | string | 是 | 作为延迟封装的标识。 | 43 44**返回值:** 45 46| 类型 | 说明 | 47| ---------------------------------------- |-------------------------| 48| [UnifiedData](#unifieddata) | 当延迟封装触发时,返回一个UnifiedData对象。 | 49 50**示例:** 51 52```ts 53import { uniformTypeDescriptor } from '@kit.ArkData'; 54 55let getDelayData: unifiedDataChannel.GetDelayData = ((type: string) => { 56 if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 57 let text = new unifiedDataChannel.Text(); 58 text.details = { 59 Key: 'textKey', 60 Value: 'textValue', 61 }; 62 let textData = new unifiedDataChannel.UnifiedData(text); 63 return textData; 64 } 65 return new unifiedDataChannel.UnifiedData(); 66}); 67``` 68 69## ValueType<sup>12+</sup> 70 71type ValueType = number | string | boolean | image.PixelMap | Want | ArrayBuffer | object | null | undefined 72 73用于表示统一数据记录允许的数据字段类型。 74 75**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 76 77**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 78 79| 类型 | 说明 | 80| -------- | -------- | 81| number | 表示number的类型。 | 82| string | 表示string的类型。 | 83| boolean | 表示boolean的类型。 | 84| image.PixelMap | 表示[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)的类型。 | 85| Want | 表示[Want](../apis-ability-kit/js-apis-app-ability-want.md)的类型。 | 86| ArrayBuffer | 表示ArrayBuffer的类型。 | 87| object | 表示object的类型。 | 88| null | 表示null。 | 89| undefined | 表示undefined。 | 90 91## UnifiedDataProperties<sup>12+</sup> 92 93定义统一数据对象中所有数据记录的属性,包含时间戳、标签、粘贴范围以及一些附加数据等。 94 95**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 96 97**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 98 99| 名称 | 类型 | 只读 | 可选 | 说明 | 100| -------- | -------- | -------- | -------- | -------- | 101| extras<sup>12+</sup> | Record<string, object> | 否 | 是 | 是一个字典类型对象,用于设置其他附加属性数据。非必填字段,默认值为空字典对象。 | 102| tag<sup>12+</sup> | string | 否 | 是 | 用户自定义标签。非必填字段,默认值为空字符串。 | 103| timestamp<sup>12+</sup> | Date | 是 | 是 | [UnifiedData](#unifieddata)的生成时间戳。默认值为1970年1月1日(UTC)。 | 104| shareOptions<sup>12+</sup> | [ShareOptions](#shareoptions12) | 否 | 是 | 指示[UnifiedData](#unifieddata)支持的设备内使用范围,非必填字段,默认值为CROSS_APP。 | 105| getDelayData<sup>12+</sup> | [GetDelayData](#getdelaydata12) | 否 | 是 | 延迟获取数据回调。当前只支持同设备剪贴板场景,后续场景待开发。非必填字段,默认值为undefined。 | 106 107**示例:** 108 109```ts 110import { uniformTypeDescriptor } from '@kit.ArkData'; 111 112let properties = new unifiedDataChannel.UnifiedDataProperties(); 113properties.extras = { 114 key: { 115 title: 'MyTitle', 116 content: 'MyContent' 117 } 118}; 119properties.tag = "this is tag of properties"; 120properties.shareOptions = unifiedDataChannel.ShareOptions.CROSS_APP; 121properties.getDelayData = ((type: string) => { 122 if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 123 let text = new unifiedDataChannel.Text(); 124 text.details = { 125 Key: 'textKey', 126 Value: 'textValue', 127 }; 128 let textData = new unifiedDataChannel.UnifiedData(text); 129 return textData; 130 } 131 return new unifiedDataChannel.UnifiedData(); 132}); 133``` 134 135## UnifiedData 136 137表示UDMF统一数据对象,提供封装一组数据记录的方法。 138 139**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 140 141### 属性 142 143| 名称 | 类型 | 只读 | 可选 | 说明 | 144| -------- | -------- | -------- | -------- |-------------------------------------------------------------------------------------------------| 145| properties<sup>12+</sup> | [UnifiedDataProperties](#unifieddataproperties12) | 否 | 否 | 当前统一数据对象中所有数据记录的属性,包含时间戳、标签、粘贴范围以及一些附加数据等。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 146 147### constructor<sup>12+</sup> 148 149constructor() 150 151用于创建统一数据对象。 152 153**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 154 155**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 156 157**示例:** 158 159```ts 160let unifiedData = new unifiedDataChannel.UnifiedData(); 161``` 162 163### constructor 164 165constructor(record: UnifiedRecord) 166 167用于创建带有一条数据记录的统一数据对象。 168 169**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 170 171**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 172 173**参数:** 174 175| 参数名 | 类型 | 必填 | 说明 | 176| ------ | ------------------------------- | ---- |-----------------------------------------| 177| record | [UnifiedRecord](#unifiedrecord) | 是 | 要添加到统一数据对象中的数据记录,该记录为UnifiedRecord或其子类对象。 | 178 179**错误码:** 180 181以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 182 183| **错误码ID** | **错误信息** | 184| ------------ | ------------------------------------------- | 185| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 186 187**示例:** 188 189```ts 190let text = new unifiedDataChannel.PlainText(); 191text.textContent = 'this is textContent of text'; 192let unifiedData = new unifiedDataChannel.UnifiedData(text); 193``` 194 195### addRecord 196 197addRecord(record: UnifiedRecord): void 198 199在当前统一数据对象中添加一条数据记录。 200 201**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 202 203**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 204 205**参数:** 206 207| 参数名 | 类型 | 必填 | 说明 | 208| ------ | ------------------------------- | ---- |---------------------------------------------| 209| record | [UnifiedRecord](#unifiedrecord) | 是 | 要添加到统一数据对象中的数据记录,该记录为UnifiedRecord子类对象。| 210 211**错误码:** 212 213以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 214 215| **错误码ID** | **错误信息** | 216| ------------ | ------------------------------------------- | 217| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 218 219**示例:** 220 221```ts 222let text1 = new unifiedDataChannel.PlainText(); 223text1.textContent = 'this is textContent of text1'; 224let unifiedData = new unifiedDataChannel.UnifiedData(text1); 225 226let text2 = new unifiedDataChannel.PlainText(); 227text2.textContent = 'this is textContent of text2'; 228unifiedData.addRecord(text2); 229``` 230 231### getRecords 232 233getRecords(): Array\<UnifiedRecord\> 234 235将当前统一数据对象中的所有数据记录取出。通过本接口取出的数据为UnifiedRecord类型,需通过[getType](#gettype)获取数据类型后转为子类再使用。 236 237**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 238 239**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 240 241**返回值:** 242 243| 类型 | 说明 | 244| ---------------------------------------- |-------------------------| 245| Array\<[UnifiedRecord](#unifiedrecord)\> | 当前统一数据对象内所添加的记录。 | 246 247**示例:** 248 249```ts 250import { uniformTypeDescriptor } from '@kit.ArkData'; 251 252let text = new unifiedDataChannel.PlainText(); 253text.textContent = 'this is textContent of text'; 254let unifiedData = new unifiedDataChannel.UnifiedData(text); 255 256let link = new unifiedDataChannel.Hyperlink(); 257link.url = 'www.XXX.com'; 258unifiedData.addRecord(link); 259 260let records = unifiedData.getRecords(); 261for (let i = 0; i < records.length; i++) { 262 let record = records[i]; 263 if (record.getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 264 let plainText = record as unifiedDataChannel.PlainText; 265 console.info(`textContent: ${plainText.textContent}`); 266 } else if (record.getType() == uniformTypeDescriptor.UniformDataType.HYPERLINK) { 267 let hyperlink = record as unifiedDataChannel.Hyperlink; 268 console.info(`linkUrl: ${hyperlink.url}`); 269 } 270} 271``` 272 273### hasType<sup>12+</sup> 274 275hasType(type: string): boolean 276 277检查当前统一数据对象中是否有指定的数据类型。 278 279**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 280 281**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 282 283| 参数名 | 类型 | 必填 | 说明 | 284| ------ | ------------------------------- | ---- |---------------------------------------------| 285| type | string | 是 | 要查询的数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。| 286 287**返回值:** 288 289| 类型 | 说明 | 290| ---------------------------------------- |-------------------------| 291| boolean | 有指定的数据类型返回true,否则返回false。 | 292 293**错误码:** 294 295以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 296 297| **错误码ID** | **错误信息** | 298| ------------ | ------------------------------------------- | 299| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 300 301**示例:** 302 303```ts 304import { uniformTypeDescriptor } from '@kit.ArkData'; 305 306let text = new unifiedDataChannel.PlainText(); 307text.textContent = 'this is textContent of text'; 308let unifiedData = new unifiedDataChannel.UnifiedData(text); 309 310let link = new unifiedDataChannel.Hyperlink(); 311link.url = 'www.XXX.com'; 312unifiedData.addRecord(link); 313 314let hasPlainText = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT); 315let hasLink = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.HYPERLINK); 316``` 317 318### getTypes<sup>12+</sup> 319 320getTypes(): Array\<string\> 321 322获取当前统一数据对象所有数据记录的类型。 323 324**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 325 326**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 327 328**返回值:** 329 330| 类型 | 说明 | 331| ---------------------------------------- |-------------------------| 332| Array\<string\> | [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)类型的数组,表示当前统一数据对象所有数据记录对应的数据类型。 | 333 334**示例:** 335 336```ts 337let text = new unifiedDataChannel.PlainText(); 338text.textContent = 'this is textContent of text'; 339let unifiedData = new unifiedDataChannel.UnifiedData(text); 340 341let link = new unifiedDataChannel.Hyperlink(); 342link.url = 'www.XXX.com'; 343unifiedData.addRecord(link); 344 345let types = unifiedData.getTypes(); 346``` 347 348## Summary 349 350描述某一统一数据对象的数据摘要,包括所含数据类型及大小。 351 352**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 353 354**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 355 356| 名称 | 类型 | 只读 | 可选 | 说明 | 357| -------- | -------- | -------- | -------- | -------- | 358| summary | Record<string, number> | 否 | 否 | 是一个字典类型对象,key表示数据类型(见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)),value为统一数据对象中该类型记录大小总和(单位:Byte)。 | 359| totalSize | number | 否 | 否 | 统一数据对象内记录总大小(单位:Byte)。 | 360 361## UnifiedRecord 362 363对UDMF支持的数据内容的抽象定义,称为数据记录。一个统一数据对象内包含一条或多条数据记录,例如一条文本记录、一条图片记录、一条HTML记录等。 364 365### constructor<sup>12+</sup> 366 367constructor() 368 369用于创建数据记录。 370 371**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 372 373**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 374 375**示例:** 376 377```ts 378let unifiedRecord = new unifiedDataChannel.UnifiedRecord(); 379``` 380 381### constructor<sup>12+</sup> 382 383constructor(type: string, value: ValueType) 384 385用于创建指定类型和值的数据记录。<br/>当参数value为[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)类型时,参数type必须对应为[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)中OPENHARMONY_PIXEL_MAP的值;<br/>当参数value为[Want](../apis-ability-kit/js-apis-app-ability-want.md)类型时,参数type必须对应为[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)中OPENHARMONY_WANT的值。 386 387**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 388 389**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 390 391**参数:** 392 393| 参数名 | 类型 | 必填 | 说明 | 394| ------ | ------------------------------- | ---- |-----------------------------------------| 395| type | string | 是 | 要创建的数据记录的类型。 | 396| value | [ValueType](#valuetype12) | 是 | 要创建的数据记录的值。 | 397 398**错误码:** 399 400以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 401 402| **错误码ID** | **错误信息** | 403| ------------ | ------------------------------------------- | 404| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 405 406**示例:** 407 408```ts 409import { image } from '@kit.ImageKit'; 410import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 411import { Want } from '@kit.AbilityKit'; 412 413let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, 'this is value of text'); 414let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, 'www.XXX.com'); 415let object: Want = { 416 bundleName: 'com.example.myapplication', 417 abilityName: 'entryAbility', 418}; 419let wantRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_WANT, object); 420 421const color = new ArrayBuffer(96); 422let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }; 423let pixelMap = image.createPixelMapSync(color, opts); 424let pixelMapRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap); 425 426let hyperlinkDetails : Record<string, string> = { 427 'attr1': 'value1', 428 'attr2': 'value2', 429} 430let hyperlink : uniformDataStruct.Hyperlink = { 431 uniformDataType:'general.hyperlink', 432 url : 'www.XXX.com', 433 description : 'This is the description of this hyperlink', 434 details : hyperlinkDetails, 435} 436let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink); 437``` 438 439### getType 440 441getType(): string 442 443获取当前数据记录的类型。由于从统一数据对象中调用[getRecords](#getrecords)所取出的数据是UnifiedRecord对象,因此需要通过本接口查询此记录的具体类型,再将该UnifiedRecord对象转换为其子类,调用子类接口。 444 445**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 446 447**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 448 449**返回值:** 450 451| 类型 | 说明 | 452| ------ |------------------------------------------------------| 453| string | 当前数据记录对应的具体数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。| 454 455**示例:** 456 457```ts 458import { uniformTypeDescriptor } from '@kit.ArkData'; 459 460let text = new unifiedDataChannel.PlainText(); 461text.textContent = 'this is textContent of text'; 462let unifiedData = new unifiedDataChannel.UnifiedData(text); 463 464let records = unifiedData.getRecords(); 465if (records[0].getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 466 let plainText = records[0] as unifiedDataChannel.PlainText; 467 console.info(`textContent: ${plainText.textContent}`); 468} 469``` 470 471### getValue<sup>12+</sup> 472 473getValue(): ValueType 474 475获取当前数据记录的值。 476 477**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 478 479**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 480 481**返回值:** 482 483| 类型 | 说明 | 484| ------ |------------------------------------------------------| 485| [ValueType](#valuetype12) | 当前数据记录对应的值。 | 486 487**示例:** 488 489```ts 490import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 491 492let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, 'this is value of text'); 493let value = text.getValue(); 494 495let hyperlinkDetails : Record<string, string> = { 496 'attr1': 'value1', 497 'attr2': 'value2', 498} 499let hyperlink : uniformDataStruct.Hyperlink = { 500 uniformDataType:'general.hyperlink', 501 url : 'www.XXX.com', 502 description : 'This is the description of this hyperlink', 503 details : hyperlinkDetails, 504} 505let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink); 506let hyperlinkValue = hyperlinkRecord.getValue(); 507``` 508 509### addEntry<sup>15+</sup> 510 511addEntry(type: string, value: ValueType): void 512 513在当前数据记录中添加一条指定数据类型和内容的数据。 514 515**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 516 517**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 518 519**参数:** 520 521| 参数名 | 类型 | 必填 | 说明 | 522| ------ | ------------------------------- | ---- |-----------------------------------------| 523| type | string | 是 | 要创建的数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 | 524| value | [ValueType](#valuetype12) | 是 | 要创建的数据的值。 | 525 526**错误码:** 527 528以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 529 530| **错误码ID** | **错误信息** | 531| ------------ | ------------------------------------------- | 532| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 533 534**示例:** 535 536```ts 537import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 538 539let fileUriDetails : Record<string, string> = { 540 'attr1': 'value1', 541 'attr2': 'value2', 542} 543let fileUri : uniformDataStruct.FileUri = { 544 uniformDataType : 'general.file-uri', 545 oriUri : 'file://data/image/1.png', 546 fileType : 'general.image', 547 details : fileUriDetails, 548} 549let formDetails : Record<string, string> = { 550 'attr1': 'value1', 551 'attr2': 'value2', 552} 553let form : uniformDataStruct.Form = { 554 uniformDataType : 'openharmony.form', 555 formId : 1, 556 formName : 'form', 557 bundleName : 'com.xx.app', 558 abilityName : 'ability', 559 module : 'module', 560 details : formDetails, 561} 562 563let unifiedData = new unifiedDataChannel.UnifiedData(); 564let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form); 565record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri); 566unifiedData.addRecord(record); 567``` 568 569### getEntry<sup>15+</sup> 570 571getEntry(type: string): ValueType 572 573通过数据类型获取当前数据记录中的数据内容。 574 575**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 576 577**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 578 579**参数:** 580 581| 参数名 | 类型 | 必填 | 说明 | 582| ------ | ------------------------------- | ---- |-----------------------------------------| 583| type | string | 是 | 要获取数据的类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 | 584 585**返回值:** 586 587| 类型 | 说明 | 588| ------ |------------------------------------------------------| 589| [ValueType](#valuetype12) | 当前数据记录对应的值。 | 590 591**错误码:** 592 593以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 594 595| **错误码ID** | **错误信息** | 596| ------------ | ------------------------------------------- | 597| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 598 599**示例:** 600 601```ts 602import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 603 604let fileUriDetails : Record<string, string> = { 605 'attr1': 'value1', 606 'attr2': 'value2', 607} 608let fileUri : uniformDataStruct.FileUri = { 609 uniformDataType : 'general.file-uri', 610 oriUri : 'file://data/image/1.png', 611 fileType : 'general.image', 612 details : fileUriDetails, 613} 614let formDetails : Record<string, string> = { 615 'attr1': 'value1', 616 'attr2': 'value2', 617} 618let form : uniformDataStruct.Form = { 619 uniformDataType : 'openharmony.form', 620 formId : 1, 621 formName : 'form', 622 bundleName : 'com.xx.app', 623 abilityName : 'ability', 624 module : 'module', 625 details : formDetails, 626} 627 628let unifiedData = new unifiedDataChannel.UnifiedData(); 629let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form); 630record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri); 631unifiedData.addRecord(record); 632 633let records = unifiedData.getRecords(); 634for (let i = 0; i < records.length; i++) { 635 let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord; 636 let fileUriRead : uniformDataStruct.FileUri = unifiedDataRecord.getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri 637 if (fileUriRead != undefined) { 638 console.info(`oriUri: ${fileUriRead.oriUri}`); 639 } 640} 641``` 642 643### getEntries<sup>15+</sup> 644 645getEntries(): Record<string, ValueType> 646 647获取当前数据记录中所有数据的类型和内容。 648 649**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 650 651**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 652 653**返回值:** 654 655| 类型 | 说明 | 656| ------ |------------------------------------------------------| 657| Record<string, [ValueType](#valuetype12)> | 当前数据记录对应的类型和内容。 | 658 659**示例:** 660 661```ts 662import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 663 664let fileUriDetails : Record<string, string> = { 665 'attr1': 'value1', 666 'attr2': 'value2', 667} 668let fileUri : uniformDataStruct.FileUri = { 669 uniformDataType : 'general.file-uri', 670 oriUri : 'file://data/image/1.png', 671 fileType : 'general.image', 672 details : fileUriDetails, 673} 674let formDetails : Record<string, string> = { 675 'attr1': 'value1', 676 'attr2': 'value2', 677} 678let form : uniformDataStruct.Form = { 679 uniformDataType : 'openharmony.form', 680 formId : 1, 681 formName : 'form', 682 bundleName : 'com.xx.app', 683 abilityName : 'ability', 684 module : 'module', 685 details : formDetails, 686} 687 688let unifiedData = new unifiedDataChannel.UnifiedData(); 689let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form); 690record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri); 691unifiedData.addRecord(record); 692 693let records = unifiedData.getRecords(); 694for (let i = 0; i < records.length; i++) { 695 let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord; 696 let entries : Record<string, unifiedDataChannel.ValueType> = unifiedDataRecord.getEntries(); 697 let formRead : uniformDataStruct.Form = entries[uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM] as uniformDataStruct.Form 698 if (formRead != undefined) { 699 console.info(`formName: ${formRead.formName}`); 700 } 701} 702``` 703 704### getTypes<sup>15+</sup> 705 706getTypes(): Array\<string\> 707 708获取当前数据记录中数据的所有类型集合。可通过UnifiedRecord数据记录对象调用本接口,能查询出此记录中数据的所有类型集合。 709 710**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 711 712**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core 713 714**返回值:** 715 716| 类型 | 说明 | 717| ---------------------------------------- |-------------------------| 718| Array\<string\> | [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)类型的数组,表示当前记录的数据类型集合。 | 719 720**示例:** 721 722```ts 723import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData'; 724 725let fileUriDetails : Record<string, string> = { 726 'attr1': 'value1', 727 'attr2': 'value2', 728} 729let fileUri : uniformDataStruct.FileUri = { 730 uniformDataType : 'general.file-uri', 731 oriUri : 'file://data/image/1.png', 732 fileType : 'general.image', 733 details : fileUriDetails, 734} 735let formDetails : Record<string, string> = { 736 'attr1': 'value1', 737 'attr2': 'value2', 738} 739let form : uniformDataStruct.Form = { 740 uniformDataType : 'openharmony.form', 741 formId : 1, 742 formName : 'form', 743 bundleName : 'com.xx.app', 744 abilityName : 'ability', 745 module : 'module', 746 details : formDetails, 747} 748 749let unifiedData = new unifiedDataChannel.UnifiedData(); 750let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form); 751record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri); 752unifiedData.addRecord(record); 753 754let records = unifiedData.getRecords(); 755for (let i = 0; i < records.length; i++) { 756 let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord; 757 let types : Array<string> = unifiedDataRecord.getTypes(); 758 if (types.includes(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM)) { 759 console.info(`types include: ${uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM}`); 760 } 761} 762``` 763 764## Text 765 766文本类型数据,是[UnifiedRecord](#unifiedrecord)的子类,也是文本类型数据的基类,用于描述文本类数据,推荐开发者优先使用Text的子类描述数据,如[PlainText](#plaintext)、[Hyperlink](#hyperlink)、[HTML](#html)等具体子类。 767 768**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 769 770**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 771 772| 名称 | 类型 | 只读 | 可选 | 说明 | 773| -------- | -------- | -------- | -------- | -------- | 774| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述文本内容。例如,可生成一个details内容为<br/>{<br/>"title":"标题",<br/>"content":"内容"<br/>}<br/>的数据对象,用于描述一篇文章。非必填字段,默认值为空字典对象。 | 775 776**示例:** 777 778```ts 779let text = new unifiedDataChannel.Text(); 780text.details = { 781 title: 'MyTitle', 782 content: 'this is content', 783}; 784let unifiedData = new unifiedDataChannel.UnifiedData(text); 785``` 786 787## PlainText 788 789纯文本类型数据,是[Text](#text)的子类,用于描述纯文本类数据。 790 791**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 792 793**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 794 795| 名称 | 类型 | 只读 | 可选 | 说明 | 796| -------- | -------- | -------- | -------- | -------- | 797| textContent | string | 否 | 否 | 纯文本内容。 | 798| abstract | string | 否 | 是 | 纯文本摘要,非必填字段,默认值为空字符串。 | 799 800**示例:** 801 802```ts 803let text = new unifiedDataChannel.PlainText(); 804text.textContent = 'this is textContent'; 805text.abstract = 'this is abstract'; 806``` 807 808## Hyperlink 809 810超链接类型数据,是[Text](#text)的子类,用于描述超链接类型数据。 811 812**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 813 814**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 815 816| 名称 | 类型 | 只读 | 可选 | 说明 | 817| -------- | -------- | -------- | -------- | -------- | 818| url | string | 否 | 否 | 链接url。 | 819| description | string | 否 | 是 | 链接内容描述,非必填字段,默认值为空字符串。 | 820 821**示例:** 822 823```ts 824let link = new unifiedDataChannel.Hyperlink(); 825link.url = 'www.XXX.com'; 826link.description = 'this is description'; 827``` 828 829## HTML 830 831HTML类型数据,是[Text](#text)的子类,用于描述超文本标记语言数据。 832 833**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 834 835**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 836 837| 名称 | 类型 | 只读 | 可选 | 说明 | 838| -------- | -------- | -------- | -------- | -------- | 839| htmlContent | string | 否 | 否 | html格式内容。 | 840| plainContent | string | 否 | 是 | 去除html标签后的纯文本内容,非必填字段,默认值为空字符串。 | 841 842**示例:** 843 844```ts 845let html = new unifiedDataChannel.HTML(); 846html.htmlContent = '<div><p>标题</p></div>'; 847html.plainContent = 'this is plainContent'; 848``` 849 850## File 851 852File类型数据,是[UnifiedRecord](#unifiedrecord)的子类,也是文件类型数据的基类,用于描述文件类型数据,推荐开发者优先使用File的子类描述数据,如[Image](#image)、[Video](#video)、[Folder](#folder)等具体子类。 853 854**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 855 856**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 857 858| 名称 | 类型 | 只读 | 可选 | 说明 | 859| -------- | -------- | -------- | -------- | -------- | 860| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述文件相关信息。例如,可生成一个details内容为<br/>{<br/>"name":"文件名",<br/>"type":"文件类型"<br/>}<br/>的数据对象,用于描述一个文件。非必填字段,默认值为空字典对象。 | 861| uri | string | 否 | 否 | 文件数据uri。 | 862 863**示例:** 864 865```ts 866let file = new unifiedDataChannel.File(); 867file.details = { 868 name: 'test', 869 type: 'txt', 870}; 871file.uri = 'schema://com.samples.test/files/test.txt'; 872``` 873 874## Image 875 876图片类型数据,是[File](#file)的子类,用于描述图片文件。 877 878**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 879 880**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 881 882| 名称 | 类型 | 只读 | 可选 | 说明 | 883| -------- | -------- | -------- | -------- | -------- | 884| imageUri | string | 否 | 否 | 图片数据uri。 | 885 886**示例:** 887 888```ts 889let image = new unifiedDataChannel.Image(); 890image.imageUri = 'schema://com.samples.test/files/test.jpg'; 891``` 892 893## Video 894 895视频类型数据,是[File](#file)的子类,用于描述视频文件。 896 897**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 898 899**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 900 901| 名称 | 类型 | 只读 | 可选 | 说明 | 902| -------- | -------- | -------- | -------- | -------- | 903| videoUri | string | 否 | 否 | 视频数据uri。 | 904 905**示例:** 906 907```ts 908let video = new unifiedDataChannel.Video(); 909video.videoUri = 'schema://com.samples.test/files/test.mp4'; 910``` 911 912## Audio 913 914音频类型数据,是[File](#file)的子类,用于描述音频文件。 915 916**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 917 918**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 919 920| 名称 | 类型 | 只读 | 可选 | 说明 | 921| -------- | -------- | -------- | -------- | -------- | 922| audioUri | string | 否 | 否 | 音频数据uri。 | 923 924**示例:** 925 926```ts 927let audio = new unifiedDataChannel.Audio(); 928audio.audioUri = 'schema://com.samples.test/files/test.mp3'; 929``` 930 931## Folder 932 933文件夹类型数据,是[File](#file)的子类,用于描述文件夹。 934 935**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 936 937**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 938 939| 名称 | 类型 | 只读 | 可选 | 说明 | 940| -------- | -------- | -------- | -------- | -------- | 941| folderUri | string | 否 | 否 | 文件夹uri。 | 942 943**示例:** 944 945```ts 946let folder = new unifiedDataChannel.Folder(); 947folder.folderUri = 'schema://com.samples.test/files/folder/'; 948``` 949 950## SystemDefinedRecord 951 952SystemDefinedRecord是[UnifiedRecord](#unifiedrecord)的子类,也是OpenHarmony系统特有数据类型的基类,用于描述仅在OpenHarmony系统范围内流通的特有数据类型,推荐开发者优先使用SystemDefinedRecord的子类描述数据,如[SystemDefinedForm](#systemdefinedform)、[SystemDefinedAppItem](#systemdefinedappitem)、[SystemDefinedPixelMap](#systemdefinedpixelmap)等具体子类。 953 954**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 955 956**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 957 958| 名称 | 类型 | 只读 | 可选 | 说明 | 959| -------- | -------- | -------- | -------- | -------- | 960| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。| 961 962**示例:** 963 964```ts 965let sdr = new unifiedDataChannel.SystemDefinedRecord(); 966let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 967sdr.details = { 968 title: 'recordTitle', 969 version: 1, 970 content: u8Array, 971}; 972let unifiedData = new unifiedDataChannel.UnifiedData(sdr); 973``` 974 975## SystemDefinedForm 976 977系统定义的桌面卡片类型数据,是[SystemDefinedRecord](#systemdefinedrecord)的子类。 978 979**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 980 981**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 982 983| 名称 | 类型 | 只读 | 可选 | 说明 | 984| -------- | -------- | -------- | -------- | -------- | 985| formId | number | 否 | 否 | 卡片id。 | 986| formName | string | 否 | 否 | 卡片名称。 | 987| bundleName | string | 否 | 否 | 卡片所属的bundle名。 | 988| abilityName | string | 否 | 否 | 卡片对应的ability名。 | 989| module | string | 否 | 否 | 卡片所属的module名。 | 990 991**示例:** 992 993```ts 994let form = new unifiedDataChannel.SystemDefinedForm(); 995form.formId = 123456; 996form.formName = 'MyFormName'; 997form.bundleName = 'MyBundleName'; 998form.abilityName = 'MyAbilityName'; 999form.module = 'MyModule'; 1000let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 1001form.details = { 1002 formKey1: 123, 1003 formKey2: 'formValue', 1004 formKey3: u8Array, 1005}; 1006let unifiedData = new unifiedDataChannel.UnifiedData(form); 1007``` 1008 1009## SystemDefinedAppItem 1010 1011系统定义的桌面图标类型数据,是[SystemDefinedRecord](#systemdefinedrecord)的子类。 1012 1013**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1014 1015**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 1016 1017| 名称 | 类型 | 只读 | 可选 | 说明 | 1018| -------- | -------- | -------- | -------- | -------- | 1019| appId | string | 否 | 否 | 图标对应的应用id。 | 1020| appName | string | 否 | 否 | 图标对应的应用名。 | 1021| appIconId | string | 否 | 否 | 图标的图片id。 | 1022| appLabelId | string | 否 | 否 | 图标名称对应的标签id。 | 1023| bundleName | string | 否 | 否 | 图标对应的应用bundle名。 | 1024| abilityName | string | 否 | 否 | 图标对应的应用ability名。 | 1025 1026**示例:** 1027 1028```ts 1029let appItem = new unifiedDataChannel.SystemDefinedAppItem(); 1030appItem.appId = 'MyAppId'; 1031appItem.appName = 'MyAppName'; 1032appItem.appIconId = 'MyAppIconId'; 1033appItem.appLabelId = 'MyAppLabelId'; 1034appItem.bundleName = 'MyBundleName'; 1035appItem.abilityName = 'MyAbilityName'; 1036let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 1037appItem.details = { 1038 appItemKey1: 123, 1039 appItemKey2: 'appItemValue', 1040 appItemKey3: u8Array, 1041}; 1042let unifiedData = new unifiedDataChannel.UnifiedData(appItem); 1043``` 1044 1045## SystemDefinedPixelMap 1046 1047与系统侧定义的[PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)数据类型对应的图片数据类型,是[SystemDefinedRecord](#systemdefinedrecord)的子类,仅保存PixelMap的二进制数据。 1048 1049**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1050 1051**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 1052 1053| 名称 | 类型 | 只读 | 可选 | 说明 | 1054| -------- | -------- | -------- | -------- | -------- | 1055| rawData | Uint8Array | 否 | 否 | PixelMap对象的二进制数据。 | 1056 1057**示例:** 1058 1059```ts 1060import { image } from '@kit.ImageKit'; // PixelMap类定义所在模块 1061import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData'; 1062import { BusinessError } from '@kit.BasicServicesKit'; 1063 1064const color = new ArrayBuffer(96); // 创建pixelmap对象 1065let opts: image.InitializationOptions = { 1066 editable: true, pixelFormat: 3, size: { 1067 height: 4, width: 6 1068 } 1069} 1070image.createPixelMap(color, opts, (error, pixelmap) => { 1071 if (error) { 1072 console.error('Failed to create pixelmap.'); 1073 } else { 1074 console.info('Succeeded in creating pixelmap.'); 1075 let arrayBuf = new ArrayBuffer(pixelmap.getPixelBytesNumber()); 1076 pixelmap.readPixelsToBuffer(arrayBuf); 1077 let u8Array = new Uint8Array(arrayBuf); 1078 let sdpixel = new unifiedDataChannel.SystemDefinedPixelMap(); 1079 sdpixel.rawData = u8Array; 1080 let unifiedData = new unifiedDataChannel.UnifiedData(sdpixel); 1081 1082 // 从unifiedData中读取pixelMap类型的record 1083 let records = unifiedData.getRecords(); 1084 for (let i = 0; i < records.length; i++) { 1085 if (records[i].getType() === uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP) { 1086 let pixelmapRecord = records[i] as unifiedDataChannel.SystemDefinedPixelMap; 1087 let newArraybuf = pixelmapRecord.rawData.buffer; 1088 pixelmap.writeBufferToPixels(newArraybuf).then(() => { 1089 console.info('Succeeded in writing data from buffer to a pixelMap'); 1090 }).catch((error: BusinessError) => { 1091 console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`); 1092 }) 1093 } 1094 } 1095 } 1096}) 1097``` 1098 1099## ApplicationDefinedRecord 1100 1101ApplicationDefinedRecord是[UnifiedRecord](#unifiedrecord)的子类,也是应用自定义数据类型的基类,用于描述仅在应用生态内部流通的自定义数据类型,应用可基于此类进行自定义数据类型的扩展。 1102 1103**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1104 1105**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 1106 1107| 名称 | 类型 | 只读 | 可选 | 说明 | 1108| -------- | -------- | -------- | -------- | -------- | 1109| applicationDefinedType | string | 否 | 否 | 应用自定义类型标识符,必须以'ApplicationDefined'开头。 | 1110| rawData | Uint8Array | 否 | 否 | 应用自定义数据类型的二进制数据。 | 1111 1112**示例:** 1113 1114```ts 1115let record = new unifiedDataChannel.ApplicationDefinedRecord(); 1116let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 1117record.applicationDefinedType = 'ApplicationDefinedType'; 1118record.rawData = u8Array; 1119let unifiedData = new unifiedDataChannel.UnifiedData(record); 1120``` 1121 1122## Intention 1123 1124UDMF已经支持的数据通路枚举类型。其主要用途是标识各种UDMF数据通路所面向的不同业务场景。 1125 1126**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1127 1128| 名称 | 值 | 说明 | 1129|----------|-----------|---------| 1130| DATA_HUB | 'DataHub' | 公共数据通路。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。| 1131| DRAG<sup>14+</sup> | 'Drag' | 拖拽类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。 | 1132 1133## Options 1134 1135type Options = { intention?: Intention; key?: string; } 1136 1137UDMF提供的数据操作接口可选项,包含intention和key两个可选参数。无默认值,当对应接口不需要此参数时可不填,具体要求参照方法接口的参数说明。 1138 1139**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1140 1141**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1142 1143| 名称 | 类型 | 必填 | 说明 | 1144| --------- | ----------------------- | ---- | ------------------------------------------------------------ | 1145| intention | [Intention](#intention) | 否 | 表示数据操作相关的数据通路类型。 | 1146| key | string | 否 | UDMF中数据对象的唯一标识符,可通过[insertData](#unifieddatachannelinsertdata)接口的返回值获取。<br>由udmf:/、intention、bundleName和groupId四部分组成,以'/'连接,比如:udmf://DataHub/com.ohos.test/0123456789。<br>其中udmf:/固定,DataHub为对应枚举的取值,com.ohos.test为包名,0123456789为随机生成的groupId。 | 1147 1148## FileConflictOptions<sup>15+</sup> 1149 1150表示文件拷贝冲突时的可选策略的枚举。 1151 1152**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1153 1154**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1155 1156| 名称 | 值 | 说明 | 1157| --------- | ---- |----------------| 1158| OVERWRITE | 0 | 目标路径存在同文件名时覆盖。 | 1159| SKIP | 1 | 目标路径存在同文件名时跳过。 | 1160 1161## ProgressIndicator<sup>15+</sup> 1162 1163表示进度条指示选项的枚举,可选择是否采用系统默认进度显示。 1164 1165**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1166 1167**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1168 1169| 名称 | 值 | 说明 | 1170| ------- | ---- |------------------------------------| 1171| NONE | 0 | 不采用系统默认进度显示。 | 1172| DEFAULT | 1 | 采用系统默认进度显示,500ms内获取数据完成将不会拉起默认进度条。 | 1173 1174## ListenerStatus<sup>15+</sup> 1175 1176表示从UDMF获取数据时的状态码的枚举。 1177 1178**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1179 1180**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1181 1182| 名称 | 值 | 说明 | 1183| ------- |-----|----------------------------------------------| 1184| FINISHED | 0 | 表示已完成。 | 1185| PROCESSING | 1 | 表示正在处理中。 | 1186| CANCELED | 2 | 表明本次处理已被取消。 | 1187| INNER_ERROR | 200 | 表明发生了内部错误。 | 1188| INVALID_PARAMETERS | 201 | 表示 [GetDataParams](#getdataparams15) 包含无效参数。 | 1189| DATA_NOT_FOUND | 202 | 表示没有获取到数据。 | 1190| SYNC_FAILED | 203 | 表示同步过程中出现错误。 | 1191| COPY_FILE_FAILED | 204 | 表示文件拷贝过程中出现错误。 | 1192 1193## ProgressInfo<sup>15+</sup> 1194 1195定义进度上报的数据。 1196 1197**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1198 1199**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1200 1201| 名称 | 类型 | 可读 | 可写 | 说明 | 1202| -------- |-------------------------------------| ---- | ---- |----------------------------------------------------------------| 1203| progress | number | 是 | 否 | 系统上报拖拽任务进度百分比。取值范围为[-1-100]的整数,其中-1时代表本次获取数据失败,100时表示本次获取数据完成。 | 1204| status | [ListenerStatus](#listenerstatus15) | 是 | 否 | 系统上报拖拽任务的状态码。 | 1205 1206## DataProgressListener<sup>15+</sup> 1207 1208type DataProgressListener = (progressInfo: ProgressInfo, data: UnifiedData | null) => void 1209 1210定义获取进度信息和数据的监听回调函数。 1211 1212**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1213 1214**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1215 1216**参数:** 1217 1218| 参数名 | 类型 | 必填 | 说明 | 1219|----------|-------------------------------|-------|--------------| 1220| progressInfo| [ProgressInfo](#progressinfo15) | 是 | 定义进度上报的进度信息。 | 1221| data | [UnifiedData](#unifieddata) \| null | 是 | 进度达到100时获取的数据,进度未到100时返回null。 | 1222 1223## GetDataParams<sup>15+</sup> 1224 1225表示从UDMF获取数据时的参数,包含目标路径、文件冲突选项、进度条类型等。 1226 1227**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 1228 1229**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1230 1231| 名称 | 类型 | 必填 | 说明 | 1232|----------------------|-------------------------------------------------| ---- |----------------------------------------------------------------------------------------------------------------------------------------------------| 1233| progressIndicator | [ProgressIndicator](#progressindicator15) | 是 | 定义进度条指示选项,可选择是否采用系统默认进度显示。 | 1234| dataProgressListener | [DataProgressListener](#dataprogresslistener15) | 是 | 表示获取统一数据时的进度和数据监听器。 | 1235| destUri | string | 否 | 拷贝文件的目标路径。若不支持文件处理,则不需要设置此参数,默认为空;若支持文件处理,须设置一个已经存在的目录。若应用涉及复杂文件处理策略或需要区分文件多路径存储,建议不设置此参数,由应用自行完成文件copy处理。 不填写时获取到到的uri为源端路径URI,填写后获取到的uri为目标路径uri | 1236| fileConflictOptions | [FileConflictOptions](#fileconflictoptions15) | 否 | 定义文件拷贝冲突时的选项,默认为OVERWRITE。 | 1237 1238## unifiedDataChannel.insertData 1239 1240insertData(options: Options, data: UnifiedData, callback: AsyncCallback<string>): void 1241 1242将数据写入UDMF的公共数据通路中,并生成数据的唯一标识符,使用callback异步回调。 1243 1244**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1245 1246**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1247 1248**参数:** 1249 1250| 参数名 | 类型 | 必填 | 说明 | 1251|----------|----------------------------|----|------------------------------| 1252| options | [Options](#options) | 是 | 配置项参数,仅需要intention的值。 | 1253| data | [UnifiedData](#unifieddata) | 是 | 目标数据。 | 1254| callback | AsyncCallback<string> | 是 | 回调函数,返回写入UDMF的数据的唯一标识符key的值。 | 1255 1256**错误码:** 1257 1258以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1259 1260| **错误码ID** | **错误信息** | 1261| ------------ | ------------------------------------------- | 1262| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1263 1264**示例:** 1265 1266```ts 1267import { unifiedDataChannel } from '@kit.ArkData'; 1268import { BusinessError } from '@kit.BasicServicesKit'; 1269 1270let plainText = new unifiedDataChannel.PlainText(); 1271plainText.textContent = 'hello world!'; 1272let unifiedData = new unifiedDataChannel.UnifiedData(plainText); 1273 1274let options: unifiedDataChannel.Options = { 1275 intention: unifiedDataChannel.Intention.DATA_HUB 1276} 1277try { 1278 unifiedDataChannel.insertData(options, unifiedData, (err, data) => { 1279 if (err === undefined) { 1280 console.info(`Succeeded in inserting data. key = ${data}`); 1281 } else { 1282 console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `); 1283 } 1284 }); 1285 } catch (e) { 1286 let error: BusinessError = e as BusinessError; 1287 console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `); 1288} 1289 1290``` 1291 1292## unifiedDataChannel.insertData 1293 1294insertData(options: Options, data: UnifiedData): Promise<string> 1295 1296将数据写入UDMF的公共数据通路中,并生成数据的唯一标识符,使用Promise异步回调。 1297 1298**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1299 1300**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1301 1302**参数:** 1303 1304| 参数名 | 类型 | 必填 | 说明 | 1305|---------|-----------------------------|----|-----------------------| 1306| options | [Options](#options) | 是 | 配置项参数,仅需要intention的值。 | 1307| data | [UnifiedData](#unifieddata) | 是 | 目标数据。 | 1308 1309**返回值:** 1310 1311| 类型 | 说明 | 1312|-----------------------|-----------------------------------| 1313| Promise<string> | Promise对象,返回写入UDMF的数据的唯一标识符key的值。 | 1314 1315**错误码:** 1316 1317以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1318 1319| **错误码ID** | **错误信息** | 1320| ------------ | ------------------------------------------- | 1321| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1322 1323**示例:** 1324 1325```ts 1326import { unifiedDataChannel } from '@kit.ArkData'; 1327import { BusinessError } from '@kit.BasicServicesKit'; 1328 1329let plainText = new unifiedDataChannel.PlainText(); 1330plainText.textContent = 'hello world!'; 1331let unifiedData = new unifiedDataChannel.UnifiedData(plainText); 1332 1333let options: unifiedDataChannel.Options = { 1334 intention: unifiedDataChannel.Intention.DATA_HUB 1335} 1336try { 1337 unifiedDataChannel.insertData(options, unifiedData).then((data) => { 1338 console.info(`Succeeded in inserting data. key = ${data}`); 1339 }).catch((err: BusinessError) => { 1340 console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `); 1341 }); 1342} catch (e) { 1343 let error: BusinessError = e as BusinessError; 1344 console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `); 1345} 1346``` 1347 1348## unifiedDataChannel.updateData 1349 1350updateData(options: Options, data: UnifiedData, callback: AsyncCallback<void>): void 1351 1352更新已写入UDMF的公共数据通路的数据,使用callback异步回调。 1353 1354**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1355 1356**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1357 1358**参数:** 1359 1360| 参数名 | 类型 | 必填 | 说明 | 1361|----------|-----------------------------|----|-------------------------------------| 1362| options | [Options](#options) | 是 | 配置项参数,仅需要key的值。 | 1363| data | [UnifiedData](#unifieddata) | 是 | 目标数据。 | 1364| callback | AsyncCallback<void> | 是 | 回调函数。当更新数据成功,err为undefined,否则为错误对象。 | 1365 1366**错误码:** 1367 1368以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1369 1370| **错误码ID** | **错误信息** | 1371| ------------ | ------------------------------------------- | 1372| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1373 1374**示例:** 1375 1376```ts 1377import { unifiedDataChannel } from '@kit.ArkData'; 1378import { BusinessError } from '@kit.BasicServicesKit'; 1379 1380let plainText = new unifiedDataChannel.PlainText(); 1381plainText.textContent = 'hello world!'; 1382let unifiedData = new unifiedDataChannel.UnifiedData(plainText); 1383 1384let options: unifiedDataChannel.Options = { 1385 key: 'udmf://DataHub/com.ohos.test/0123456789' 1386}; 1387 1388try { 1389 unifiedDataChannel.updateData(options, unifiedData, (err) => { 1390 if (err === undefined) { 1391 console.info('Succeeded in updating data.'); 1392 } else { 1393 console.error(`Failed to update data. code is ${err.code},message is ${err.message} `); 1394 } 1395 }); 1396} catch (e) { 1397 let error: BusinessError = e as BusinessError; 1398 console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `); 1399} 1400``` 1401 1402## unifiedDataChannel.updateData 1403 1404updateData(options: Options, data: UnifiedData): Promise<void> 1405 1406更新已写入UDMF的公共数据通路的数据,使用Promise异步回调。 1407 1408**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1409 1410**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1411 1412**参数:** 1413 1414| 参数名 | 类型 | 必填 | 说明 | 1415|---------|-----------------------------|----|-----------------| 1416| options | [Options](#options) | 是 | 配置项参数,仅需要key的值。 | 1417| data | [UnifiedData](#unifieddata) | 是 | 目标数据。 | 1418 1419**返回值:** 1420 1421| 类型 | 说明 | 1422|---------------------|----------------------------| 1423| Promise<void> | Promise对象。无返回结果的Promise对象。 | 1424 1425**错误码:** 1426 1427以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1428 1429| **错误码ID** | **错误信息** | 1430| ------------ | ------------------------------------------- | 1431| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1432 1433**示例:** 1434 1435```ts 1436import { unifiedDataChannel } from '@kit.ArkData'; 1437import { BusinessError } from '@kit.BasicServicesKit'; 1438 1439let plainText = new unifiedDataChannel.PlainText(); 1440plainText.textContent = 'hello world!'; 1441let unifiedData = new unifiedDataChannel.UnifiedData(plainText); 1442 1443let options: unifiedDataChannel.Options = { 1444 key: 'udmf://DataHub/com.ohos.test/0123456789' 1445}; 1446 1447try { 1448 unifiedDataChannel.updateData(options, unifiedData).then(() => { 1449 console.info('Succeeded in updating data.'); 1450 }).catch((err: BusinessError) => { 1451 console.error(`Failed to update data. code is ${err.code},message is ${err.message} `); 1452 }); 1453} catch (e) { 1454 let error: BusinessError = e as BusinessError; 1455 console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `); 1456} 1457``` 1458 1459## unifiedDataChannel.queryData 1460 1461queryData(options: Options, callback: AsyncCallback<Array<UnifiedData>>): void 1462 1463查询UDMF公共数据通路的数据,使用callback异步回调。 1464 1465**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1466 1467**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1468 1469**参数:** 1470 1471| 参数名 | 类型 | 必填 | 说明 | 1472|----------|---------------------------------------------------------------|----|------------------------------------------------------------------------------------------------------------------------------------------------------------------| 1473| options | [Options](#options) | 是 | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 | 1474| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | 是 | 回调函数,返回查询到的所有数据。<br>如果options中填入的是key,则返回key对应的数据。<br>如果options中填入的是intention,则返回intention下所有数据。<br>如intention和key均填写了,取两者查询数据的交集,与options只填入key的获取结果一致;如没有交集报错。 | 1475 1476**错误码:** 1477 1478以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1479 1480| **错误码ID** | **错误信息** | 1481| ------------ | ------------------------------------------- | 1482| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1483 1484**示例:** 1485 1486```ts 1487import { unifiedDataChannel } from '@kit.ArkData'; 1488import { uniformTypeDescriptor } from '@kit.ArkData'; 1489import { BusinessError } from '@kit.BasicServicesKit'; 1490 1491let options: unifiedDataChannel.Options = { 1492 intention: unifiedDataChannel.Intention.DATA_HUB 1493}; 1494 1495try { 1496 unifiedDataChannel.queryData(options, (err, data) => { 1497 if (err === undefined) { 1498 console.info(`Succeeded in querying data. size = ${data.length}`); 1499 for (let i = 0; i < data.length; i++) { 1500 let records = data[i].getRecords(); 1501 for (let j = 0; j < records.length; j++) { 1502 if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 1503 let text = records[j] as unifiedDataChannel.PlainText; 1504 console.info(`${i + 1}.${text.textContent}`); 1505 } 1506 } 1507 } 1508 } else { 1509 console.error(`Failed to query data. code is ${err.code},message is ${err.message} `); 1510 } 1511 }); 1512} catch (e) { 1513 let error: BusinessError = e as BusinessError; 1514 console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `); 1515} 1516``` 1517 1518## unifiedDataChannel.queryData 1519 1520queryData(options: Options): Promise<Array<UnifiedData>> 1521 1522查询UDMF公共数据通路的数据,使用Promise异步回调。 1523 1524**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1525 1526**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1527 1528**参数:** 1529 1530| 参数名 | 类型 | 必填 | 说明 | 1531|---------|---------------------|----|-----------------------------------------------| 1532| options | [Options](#options) | 是 | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 | 1533 1534**返回值:** 1535 1536| 类型 | 说明 | 1537|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------| 1538| Promise<Array<[UnifiedData](#unifieddata)>> | Promise对象,返回查询到的所有数据。<br>如果options中填入的是key,则返回key对应的数据。<br>如果options中填入的是intention,则返回intention下所有数据。<br>如intention和key均填写了,取两者查询数据的交集,与options只填入key的获取结果一致;如没有交集报错。 | 1539 1540**错误码:** 1541 1542以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1543 1544| **错误码ID** | **错误信息** | 1545| ------------ | ------------------------------------------- | 1546| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1547 1548**示例:** 1549 1550```ts 1551import { unifiedDataChannel } from '@kit.ArkData'; 1552import { uniformTypeDescriptor } from '@kit.ArkData'; 1553import { BusinessError } from '@kit.BasicServicesKit'; 1554 1555let options: unifiedDataChannel.Options = { 1556 key: 'udmf://DataHub/com.ohos.test/0123456789' 1557}; 1558 1559try { 1560 unifiedDataChannel.queryData(options).then((data) => { 1561 console.info(`Succeeded in querying data. size = ${data.length}`); 1562 for (let i = 0; i < data.length; i++) { 1563 let records = data[i].getRecords(); 1564 for (let j = 0; j < records.length; j++) { 1565 if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 1566 let text = records[j] as unifiedDataChannel.PlainText; 1567 console.info(`${i + 1}.${text.textContent}`); 1568 } 1569 } 1570 } 1571 }).catch((err: BusinessError) => { 1572 console.error(`Failed to query data. code is ${err.code},message is ${err.message} `); 1573 }); 1574} catch (e) { 1575 let error: BusinessError = e as BusinessError; 1576 console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `); 1577} 1578``` 1579 1580## unifiedDataChannel.deleteData 1581 1582deleteData(options: Options, callback: AsyncCallback<Array<UnifiedData>>): void 1583 1584删除UDMF公共数据通路的数据,返回删除的数据集,使用callback异步回调。 1585 1586**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1587 1588**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1589 1590**参数:** 1591 1592| 参数名 | 类型 | 必填 | 说明 | 1593|----------|---------------------------------------------------------------|----|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 1594| options | [Options](#options) | 是 | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 | 1595| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | 是 | 回调函数,返回删除的所有数据。<br>如果options中填入的是key,则删除key对应的数据并返回该数据。<br>如果options中填入的是intention,则删除intention下所有数据并返回删除的数据。<br>如intention和key均填写了,取两者数据的交集进行删除,并返回删除的数据,与options只填入key的结果一致;如没有交集报错。 | 1596 1597**错误码:** 1598 1599以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1600 1601| **错误码ID** | **错误信息** | 1602| ------------ | ------------------------------------------- | 1603| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1604 1605**示例:** 1606 1607```ts 1608import { unifiedDataChannel } from '@kit.ArkData'; 1609import { uniformTypeDescriptor } from '@kit.ArkData'; 1610import { BusinessError } from '@kit.BasicServicesKit'; 1611 1612let options: unifiedDataChannel.Options = { 1613 intention: unifiedDataChannel.Intention.DATA_HUB 1614}; 1615 1616try { 1617 unifiedDataChannel.deleteData(options, (err, data) => { 1618 if (err === undefined) { 1619 console.info(`Succeeded in deleting data. size = ${data.length}`); 1620 for (let i = 0; i < data.length; i++) { 1621 let records = data[i].getRecords(); 1622 for (let j = 0; j < records.length; j++) { 1623 if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 1624 let text = records[j] as unifiedDataChannel.PlainText; 1625 console.info(`${i + 1}.${text.textContent}`); 1626 } 1627 } 1628 } 1629 } else { 1630 console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `); 1631 } 1632 }); 1633} catch (e) { 1634 let error: BusinessError = e as BusinessError; 1635 console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `); 1636} 1637``` 1638 1639## unifiedDataChannel.deleteData 1640 1641deleteData(options: Options): Promise<Array<UnifiedData>> 1642 1643删除UDMF公共数据通路的数据,返回删除的数据集,使用Promise异步回调。 1644 1645**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 1646 1647**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1648 1649**参数:** 1650 1651| 参数名 | 类型 | 必填 | 说明 | 1652|---------|---------------------|----|--------| 1653| options | [Options](#options) | 是 | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 | 1654 1655**返回值:** 1656 1657| 类型 | 说明 | 1658|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| 1659| Promise<Array<[UnifiedData](#unifieddata)>> | Promise对象,返回删除的所有数据。<br>如果options中填入的是key,则删除key对应的数据并返回该数据。<br>如果options中填入的是intention,则删除intention下所有数据并返回删除的数据。<br>如intention和key均填写了,取两者数据的交集进行删除,并返回删除的数据,与options只填入key的结果一致;如没有交集报错。 | 1660 1661**错误码:** 1662 1663以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1664 1665| **错误码ID** | **错误信息** | 1666| ------------ | ------------------------------------------- | 1667| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. | 1668 1669**示例:** 1670 1671```ts 1672import { unifiedDataChannel } from '@kit.ArkData'; 1673import { uniformTypeDescriptor } from '@kit.ArkData'; 1674import { BusinessError } from '@kit.BasicServicesKit'; 1675 1676let options: unifiedDataChannel.Options = { 1677 key: 'udmf://DataHub/com.ohos.test/0123456789' 1678}; 1679 1680try { 1681 unifiedDataChannel.deleteData(options).then((data) => { 1682 console.info(`Succeeded in deleting data. size = ${data.length}`); 1683 for (let i = 0; i < data.length; i++) { 1684 let records = data[i].getRecords(); 1685 for (let j = 0; j < records.length; j++) { 1686 if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) { 1687 let text = records[j] as unifiedDataChannel.PlainText; 1688 console.info(`${i + 1}.${text.textContent}`); 1689 } 1690 } 1691 } 1692 }).catch((err: BusinessError) => { 1693 console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `); 1694 }); 1695} catch (e) { 1696 let error: BusinessError = e as BusinessError; 1697 console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `); 1698} 1699``` 1700 1701## unifiedDataChannel.setAppShareOptions<sup>14+</sup> 1702 1703setAppShareOptions(intention: Intention, shareOptions: ShareOptions): void 1704 1705设置应用内拖拽通道数据可使用的范围[ShareOptions](#shareoptions12),目前仅支持DRAG类型数据通道的管控设置。 1706 1707**需要权限:** ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION 1708 1709**模型约束:** 此接口仅可在Stage模型下使用。 1710 1711**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1712 1713**参数:** 1714 1715| 参数名 | 类型 | 必填 | 说明 | 1716|----------|----------------------------|----|------------------------------| 1717| intention | [Intention](#intention) | 是 | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 | 1718| shareOptions | [ShareOptions](#shareoptions12) | 是 | 指示[UnifiedData](#unifieddata)支持的设备内使用范围。 | 1719 1720**错误码:** 1721 1722以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[统一数据管理框架错误码](errorcode-udmf.md)。 1723 1724| **错误码ID** | **错误信息** | 1725| ------------ | ------------------------------------------------------------ | 1726| 201 | Permission denied. Interface caller does not have permission "ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION". | 1727| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1728| 20400001 | Settings already exist. | 1729 1730**示例:** 1731 1732```ts 1733import { BusinessError } from '@kit.BasicServicesKit'; 1734try { 1735 unifiedDataChannel.setAppShareOptions(unifiedDataChannel.Intention.DRAG, unifiedDataChannel.ShareOptions.IN_APP); 1736 console.info(`[UDMF]setAppShareOptions success. `); 1737}catch (e){ 1738 let error: BusinessError = e as BusinessError; 1739 console.error(`[UDMF]setAppShareOptions throws an exception. code is ${error.code},message is ${error.message} `); 1740} 1741``` 1742 1743## unifiedDataChannel.removeAppShareOptions<sup>14+</sup> 1744 1745removeAppShareOptions(intention: Intention): void 1746 1747清除[setAppShareOptions](#unifieddatachannelsetappshareoptions14)设置的管控信息。 1748 1749**需要权限:** ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION 1750 1751**模型约束:** 此接口仅可在Stage模型下使用。 1752 1753**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 1754 1755**参数:** 1756 1757| 参数名 | 类型 | 必填 | 说明 | 1758| --------- | ----------------------- | ---- | ------------------------------------------------------------ | 1759| intention | [Intention](#intention) | 是 | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 | 1760 1761**错误码:** 1762 1763以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1764 1765| **错误码ID** | **错误信息** | 1766| ------------ | ------------------------------------------------------------ | 1767| 201 | Permission denied. Interface caller does not have permission "ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION". | 1768| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1769 1770**示例:** 1771 1772```ts 1773import { BusinessError } from '@kit.BasicServicesKit'; 1774try { 1775 unifiedDataChannel.removeAppShareOptions(unifiedDataChannel.Intention.DRAG); 1776 console.info(`[UDMF]removeAppShareOptions success. `); 1777}catch (e){ 1778 let error: BusinessError = e as BusinessError; 1779 console.error(`[UDMF]removeAppShareOptions throws an exception. code is ${error.code},message is ${error.message} `); 1780} 1781``` 1782