1# @ohos.data.unifiedDataChannel (标准化数据通路)(系统接口) 2 3本模块为统一数据管理框架(Unified Data Management Framework,UDMF)的组成部分,针对拖拽通道的数据分享的范围,提供应用级别的管控,允许设置应用内数据的拖拽范围。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> - 当前页面仅包含本模块的系统接口,其他公开接口参见[ @ohos.data.unifiedDataChannel](js-apis-data-unifiedDataChannel.md)。 10 11## 导入模块 12 13```ts 14import { unifiedDataChannel } from '@kit.ArkData'; 15``` 16 17## Intention 18 19UDMF已经支持的数据通路枚举类型。其主要用途是标识各种UDMF数据通路所面向的不同业务场景。 20 21**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 22 23| 名称 | 值 | 说明 | 24| ---- | ------ | ----------------------------------- | 25| DRAG<sup>12+</sup> | 'Drag' | 拖拽类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。<br/>**系统接口:** 此接口为系统接口。 | 26 27## unifiedDataChannel.setAppShareOptions<sup>12+</sup> 28 29setAppShareOptions(intention: Intention, shareOptions: ShareOptions): void 30 31设置应用内拖拽通道数据可使用的范围[ShareOptions](js-apis-data-unifiedDataChannel.md#shareoptions12),目前仅支持DRAG类型数据通道的管控设置。 32 33**模型约束:** 此接口仅可在Stage模型下使用。 34 35**系统接口:** 此接口为系统接口。 36 37**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 38 39**参数:** 40 41| 参数名 | 类型 | 必填 | 说明 | 42|----------|----------------------------|----|------------------------------| 43| intention | [Intention](#intention) | 是 | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 | 44| shareOptions | [ShareOptions](js-apis-data-unifiedDataChannel.md#shareoptions12) | 是 | 指示[UnifiedData](js-apis-data-unifiedDataChannel.md#unifieddata)支持的设备内使用范围。 | 45 46**错误码:** 47 48以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[统一数据管理框架错误码](errorcode-udmf.md)。 49 50| **错误码ID** | **错误信息** | 51| ------------ | ------------------------------------------------------------ | 52| 202 | Permission verification failed, application which is not a system application uses system API. | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 54| 20400001 | Settings already exist. | 55 56**示例:** 57 58```ts 59import { BusinessError } from '@kit.BasicServicesKit'; 60try { 61 unifiedDataChannel.setAppShareOptions(unifiedDataChannel.Intention.DRAG, unifiedDataChannel.ShareOptions.IN_APP); 62 console.info(`[UDMF]setAppShareOptions success. `); 63}catch (e){ 64 let error: BusinessError = e as BusinessError; 65 console.error(`[UDMF]setAppShareOptions throws an exception. code is ${error.code},message is ${error.message} `); 66} 67``` 68 69## unifiedDataChannel.removeAppShareOptions<sup>12+</sup> 70 71removeAppShareOptions(intention: Intention): void 72 73清除[setAppShareOptions](#unifieddatachannelsetappshareoptions12)设置的管控信息。 74 75**模型约束:** 此接口仅可在Stage模型下使用。 76 77**系统接口:** 此接口为系统接口。 78 79**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core 80 81**参数:** 82 83| 参数名 | 类型 | 必填 | 说明 | 84| --------- | ----------------------- | ---- | ------------------------------------------------------------ | 85| intention | [Intention](#intention) | 是 | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 | 86 87**错误码:** 88 89以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 90 91| **错误码ID** | **错误信息** | 92| ------------ | ------------------------------------------------------------ | 93| 202 | Permission verification failed, application which is not a system application uses system API. | 94| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 95 96**示例:** 97 98```ts 99import { BusinessError } from '@kit.BasicServicesKit'; 100try { 101 unifiedDataChannel.removeAppShareOptions(unifiedDataChannel.Intention.DRAG); 102 console.info(`[UDMF]removeAppShareOptions success. `); 103}catch (e){ 104 let error: BusinessError = e as BusinessError; 105 console.error(`[UDMF]removeAppShareOptions throws an exception. code is ${error.code},message is ${error.message} `); 106} 107``` 108