# @ohos.data.cloudData (Device-Cloud Synergy and Sharing) The **cloudData** module provides device-cloud synergy and sharing. Device-cloud synergy provides capabilities of synchronizing the structured data (in RDB stores) between devices and the cloud. The cloud serves as a data hub to implement data backup in the cloud and data consistency between the devices with the same account. Device-cloud sharing enables data sharing across accounts based on device-cloud synergy. Understanding the following concepts helps you better understand the device-cloud sharing process: - **sharingResource**: an identifier of the string type generated for each data record shared by an application before device-cloud sync is performed. It uniquely identifies the data record being shared. - **Participant**: all participants involved in a share, including the inviter and invitees. - **invitationCode**: an invitation code generated by the share server for a share operation. It is generated after a data share is initiated and attached to an invitation to be pushed to the devices of target invitees. The target invitees then confirm the invitation via this code. The **cloudData** module provides the following device-cloud synergy features: - [Config](#config): provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud sync, clearing data, and notifying data changes. - [sharing11+](#sharing11): provides APIs for device-cloud sharing, including sharing or unsharing data, exiting a share, changing the privilege on the shared data, querying participants, confirming an invitation, changing invitation confirmation state, and querying the shared resource. > **NOTE** > > - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. > > - The APIs provided by this module are system APIs. > > - Before using this module, ensure that the cloud service is available. ## Modules to Import ```ts import cloudData from '@ohos.data.cloudData'; ``` ## ClearAction Enumerates the operations for clearing the downloaded cloud data locally. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config | Name | Description | | --------- | ---------------------------- | | CLEAR_CLOUD_INFO | Clear the cloud identifier of the data downloaded from the cloud and retain the data locally.| | CLEAR_CLOUD_DATA_AND_INFO |Clear the data downloaded from the cloud, excluding the cloud data that has been modified locally. | ## ExtraData11+ Represents the transparently transmitted data, which contains information required for a data change notification. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config | Name | Type | Mandatory| Description | | --------- | ------ | ---- | ------------------------------------------------------------ | | eventId | string | Yes | Event ID. The value **cloud_data_change** indicates cloud data changes. | | extraData | string | Yes | Transparently transmitted data, where:
- **header** contains information required for verifying the application in the cloud.
- **data** contains information required for the change notification, including **accountId** (account ID), **bundleName** (application name), **containerName** (name of the cloud database), and **recordTypes** (database table names). **accountId** and **bundleName** cannot be empty.| **Example** ```ts // token: used to verify application information. // accountId: ID of the cloud account. // bundleName: application bundle name. // containerName: name of the cloud database. // containerName: name of the table in the cloud database. interface ExtraData { eventId: "cloud_data_change", extraData: '{"header": { "token": "bbbbbb" },"data": {"accountId": "aaa","bundleName": "com.bbb.xxx","containerName": "alias","recordTypes": ["xxx", "yyy", "zzz",] }}' } ``` ## Config Provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud synergy, clearing data, and notifying data changes. ### enableCloud static enableCloud(accountId: string, switches: Record, callback: AsyncCallback<void>): void Enables device-cloud synergy. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ------------------------------------------------------------ | | accountId | string | Yes | ID of the cloud account. | | switches | Record | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let switches: Record = { 'test_bundleName1': true, 'test_bundleName2': false }; try { cloudData.Config.enableCloud(account, switches, (err) => { if (err === undefined) { console.info('Succeeded in enabling cloud'); } else { console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### enableCloud static enableCloud(accountId: string, switches: Record): Promise<void> Enables device-cloud synergy. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ------------------------------------------------------------ | | accountId | string | Yes | ID of the cloud account. | | switches | Record | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let switches: Record = { 'test_bundleName1': true, 'test_bundleName2': false }; try { cloudData.Config.enableCloud(account, switches).then(() => { console.info('Succeeded in enabling cloud'); }).catch((err: BusinessError) => { console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### disableCloud static disableCloud(accountId: string, callback: AsyncCallback<void>): void Disables device-cloud synergy. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------- | ---- | -------------------- | | accountId | string | Yes | ID of the cloud account.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; try { cloudData.Config.disableCloud(account, (err) => { if (err === undefined) { console.info('Succeeded in disabling cloud'); } else { console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### disableCloud static disableCloud(accountId: string): Promise<void> Disables device-cloud synergy. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------ | ---- | -------------------- | | accountId | string | Yes | ID of the cloud account.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; try { cloudData.Config.disableCloud(account).then(() => { console.info('Succeeded in disabling cloud'); }).catch((err: BusinessError) => { console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### changeAppCloudSwitch static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void Changes the device-cloud synergy setting for an application. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | accountId | string | Yes | ID of the cloud account.| | bundleName| string | Yes | Bundle name of the application.| | status | boolean | Yes | Device-cloud synergy setting for the application. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let bundleName = 'test_bundleName'; try { cloudData.Config.changeAppCloudSwitch(account, bundleName, true, (err) => { if (err === undefined) { console.info('Succeeded in changing App cloud switch'); } else { console.error(`Failed to change App cloud switch. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### changeAppCloudSwitch static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> Changes the device-cloud synergy setting for an application. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | accountId | string | Yes | ID of the cloud account.| | bundleName| string | Yes | Bundle name of the application.| | status | boolean | Yes | Device-cloud synergy setting for the application. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let bundleName = 'test_bundleName'; try { cloudData.Config.changeAppCloudSwitch(account, bundleName, true).then(() => { console.info('Succeeded in changing App cloud switch'); }).catch((err: BusinessError) => { console.error(`Failed to change App cloud switch. Code is ${err.code}, message is ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### notifyDataChange static notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void Notifies the data changes in the cloud. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Server **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------------------------- | ---- | -------------------- | | accountId | string | Yes | ID of the cloud account.| | bundleName | string | Yes | Bundle name of the application. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let bundleName = 'test_bundleName'; try { cloudData.Config.notifyDataChange(account, bundleName, (err) => { if (err === undefined) { console.info('Succeeded in notifying the change of data'); } else { console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### notifyDataChange static notifyDataChange(accountId: string,bundleName: string): Promise<void> Notifies the data changes in the cloud. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Server **Parameters** | Name | Type | Mandatory| Description | | ---------- | ------ | ---- | -------------------- | | accountId | string | Yes | ID of the cloud account.| | bundleName | string | Yes | Bundle name of the application. | **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let account = 'test_id'; let bundleName = 'test_bundleName'; try { cloudData.Config.notifyDataChange(account, bundleName).then(() => { console.info('Succeeded in notifying the change of data'); }).catch((err: BusinessError) => { console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### notifyDataChange11+ **static** notifyDataChange(extInfo: ExtraData, callback: AsyncCallback<void>):void Notifies the data changes in the cloud with the information, such as the database and table names, specified by the **extraData** field in **extInfo**. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | --------------------------------------- | | extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```ts import { BusinessError } from '@ohos.base'; let eventId = "cloud_data_change"; let extraData = '{header:"bbbbbb",data:"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias","recordTypes":"["xxx","yyy","zzz"]"}"}'; try { cloudData.Config.notifyDataChange({ eventId: eventId, extraData: extraData }, (err) => { if (err === undefined) { console.info('Succeeded in notifying the change of data'); } else { console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### notifyDataChange11+ static notifyDataChange(extInfo: ExtraData, userId: number,callback: AsyncCallback<void>):void Notifies the data changes of a user in the cloud. This API uses an asynchronous callback to return the result. You can also specify the database and tables in the **extraData** field in **extInfo**. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ----------------------------------------------- | | extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | | userId | number | Yes | User ID in the system.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| ```ts import { BusinessError } from '@ohos.base'; let eventId = "cloud_data_change"; let extraData = '{header:"bbbbbb",data:"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias","recordTypes":"["xxx","yyy","zzz"]"}"}'; let userId = 100; try { cloudData.Config.notifyDataChange({ eventId: eventId, extraData: extraData }, userId, (err) => { if (err === undefined) { console.info('Succeeded in notifying the change of data'); } else { console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### notifyDataChange11+ **static** notifyDataChange(extInfo: ExtraData, userId?: number): Promise<void> Notifies the data changes in the cloud. This API uses a promise to return the result. You can specify the database and tables with data changes in the **extraData** field in **extInfo**, and specify the user ID. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | ------- | ----------------------- | ---- | ----------------------------------------------- | | extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | | userId | number | No | User ID. This parameter is optional. The default value is the current user ID. If this parameter is specified, the value must be an existing user ID in the system.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let eventId = "cloud_data_change"; let extraData = '{header:"bbbbbb",data:"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias","recordTypes":"["xxx","yyy","zzz"]"}"}'; let userId = 100; try { cloudData.Config.notifyDataChange({ eventId: eventId, extraData: extraData }, userId).then(() => { console.info('Succeeded in notifying the change of data'); }).catch((err: BusinessError) => { console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### clear static clear(accountId: string, appActions: Record, callback: AsyncCallback<void>): void Clears the cloud data locally. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | ---------- | --------------------------------------------------- | ---- | -------------------------------- | | accountId | string | Yes | ID of the cloud account. | | appActions | Record | Yes | Information about the application whose data is to be cleared and the operation to perform.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```ts import { BusinessError } from '@ohos.base'; let account = "test_id"; type dataType = Record let appActions: dataType = { 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO }; try { cloudData.Config.clear(account, appActions, (err) => { if (err === undefined) { console.info('Succeeding in clearing cloud data'); } else { console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); } }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ### clear static clear(accountId: string, appActions: Record): Promise<void> Clears the cloud data locally. This API uses a promise to return the result. **Required permissions**: ohos.permission.CLOUDDATA_CONFIG **System capability**: SystemCapability.DistributedDataManager.CloudSync.Config **Parameters** | Name | Type | Mandatory| Description | | ---------- | --------------------------------------------------- | ---- | -------------------------------- | | accountId | string | Yes | ID of the cloud account. | | appActions | Record | Yes | Information about the application whose data is to be cleared and the operation to perform.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<void> | Promise that returns no value.| **Example** ```ts import { BusinessError } from '@ohos.base'; let account = "test_id"; type dataType = Record; let appActions: dataType = { 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO }; try { cloudData.Config.clear(account, appActions).then(() => { console.info('Succeeding in clearing cloud data'); }).catch((err: BusinessError) => { console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); }); } catch (e) { let error = e as BusinessError; console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); } ``` ## sharing11+ Provides APIs for device-cloud data sharing, including sharing or unsharing data, exiting a share, changing the privilege on the shared data, querying participants, confirming an invitation, changing the invitation confirmation state, and querying the shared resource. ### Role11+ Enumerates the roles of the participants in a device-cloud share. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Value | Description | | --------------| ---- | ---------------------------------- | | ROLE_INVITER | 0 | Inviter, the one who shares data. Use the enum name rather than the enum value.| | ROLE_INVITEE | 1 | Invitee, the one who can use the shared data. Use the enum name rather than the enum value.| ### State11+ Enumerates the device-cloud sharing states. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Value | Description | | --------------| ---- | ---------------------------------- | | STATE_UNKNOWN | 0 | Unknown state. Use the enum name rather than the enum value. | | STATE_ACCEPTED | 1 | The device-cloud sharing invitation is accepted. Use the enum name rather than the enum value.| | STATE_REJECTED | 2 | The device-cloud sharing invitation is rejected. Use the enum name rather than the enum value.| | STATE_SUSPENDED | 3 | The device-cloud sharing is suspended temporarily and not processed. Use the enum name rather than the enum value.| ### SharingCode11+ Enumerates the error codes for device-cloud sharing. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Value | Description | | --------------| ---- | ---------------------------------- | | SUCCESS | 0 | Operation successful. Use the enum name rather than the enum value. | | REPEATED_REQUEST | 1 | Repeated invitation, which means the participant has been invited. Use the enum name rather than the enum value.| | NOT_INVITER | 2 | The participant is not the inviter of this share. Use the enum name rather than the enum value.| | NOT_INVITER_OR_INVITEE | 3 | Invalid participant, which means the participant is neither the inviter nor the invitee. Use the enum name rather than the enum value.| | OVER_QUOTA | 4 | The number of device-cloud sharing times has reached the limit for the current account. Use the enum name rather than the enum value. | | TOO_MANY_PARTICIPANTS | 5 | The number of device-cloud sharing participants has reached the limit. Use the enum name rather than the enum value.| | INVALID_ARGS | 6 | Invalid parameter. Use the enum name rather than the enum value.| | NETWORK_ERROR | 7 | Network error. Use the enum name rather than the enum value.| | CLOUD_DISABLED | 8 | Cloud is disabled. Use the enum name rather than the enum value. | | SERVER_ERROR | 9 | Server error. Use the enum name rather than the enum value.| | INNER_ERROR | 10 | System internal error. Use the enum name rather than the enum value.| | INVALID_INVITATION | 11 | Invalid invitation, which means the current invitation has expired or does not exist. Use the enum name rather than the enum value.| | RATE_LIMIT | 12 | The amount of data to be synchronized at a time has reached the limit. Use the enum name rather than the enum value. | | CUSTOM_ERROR | 1000 | Customized error. Error codes smaller than **1000** are used to define internal error codes, and error codes greater than **1000** are used to customize error codes. Use the enum name rather than the enum value.| ### Result<T>11+ Represents the device-cloud sharing result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Type | Mandatory | Description | | ----------- | --------------------------- | --- | ------------ | | code | number | Yes | Error code. | | description | string | No | Detailed description of the error code. The default value is **undefined**. | | value | T | No | Value returned. The specific type is specified by the **T** parameter. The default value is **undefined**.| ### Privilege11+ Defines the privilege (permissions) on the shared data. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Type | Mandatory | Description | | ----------- | --------------------------- | --- | ------------ | | writable | boolean | No | Whether the participant can modify the shared data. The value **true** means the participant can modify the data; the value **false** means the opposite. The default value is **false**. | | readable | boolean | No | Whether the participant can read the shared data. The value **true** means the participant can read the data; the value **false** means the opposite. The default value is **false**. | | creatable | boolean | No | Whether the participant can create data to share. The value **true** means the participant can create data; the value **false** means the opposite. The default value is **false**. | | deletable | boolean | No | Whether the participant can delete the shared data. The value **true** means the participant can delete the data; the value **false** means the opposite. The default value is **false**. | | shareable | boolean | No | Whether the participant can share the data to others. The value **true** means the participant can share the data; the value **false** means the opposite. The default value is **false**. | ### Participant11+ Represents information about a participant of device-cloud sharing. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client | Name | Type | Mandatory | Description | | ----------- | --------------------------- | --- | ------------ | | identity | string | Yes | ID of the participant. | | role | [Role](#role11) | No | Role of the participant, inviter or invitee. The default value is **undefined**. | | state | [State](#state11) | No | State of the device-cloud sharing. The default value is **undefined**.| | privilege | [Privilege](#privilege11) | No | Permissions on the shared data. The [Privilege](#privilege11) defaults are used by default.| | attachInfo | string | No | Additional information, such as the verification code used for participant identity verification. The default value is an empty string.| ### allocResourceAndShare11+ allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns?: Array<string>): Promise<relationalStore.ResultSet> Allocates a shared resource ID based on the data that matches the specified predicates. This API uses a promise to return the result set of the data to share, which also includes the column names if they are specified. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | storeId | string | Yes | Name of the RDB store.| | predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| | columns | Array<string> | No | Columns in which the data is located. The default value is **undefined**, which means column names are not returned.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Promise used to return the result set of the data to share.| **Example** ```ts import { BusinessError } from "@ohos.base"; import relationalStore from '@ohos.data.relationalStore'; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) let sharingResource: string; let predicates = new relationalStore.RdbPredicates('test_table'); predicates.equalTo('data', 'data_test'); cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data']).then((resultSet) => { if (!resultSet.goToFirstRow()) { console.error(`row error`); return; } const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); console.info(`sharing resource: ${res}`); sharingResource = res; }).catch((err: BusinessError) => { console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); }) ``` ### allocResourceAndShare11+ allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns: Array<string>, callback: AsyncCallback<relationalStore.ResultSet>): void Allocates a shared resource ID based on the data that matches the specified predicates. This API uses an asynchronous callback to return the result set of the data to share, which includes the shared resource ID and column names. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | storeId | string | Yes | Name of the RDB store.| | predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| | columns | Array<string> | Yes | Columns in which the data is located.| | callback | AsyncCallback<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Yes | Callback invoked to return the result set of data to share.| **Example** ```ts import relationalStore from '@ohos.data.relationalStore'; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) let sharingResource: string; let predicates = new relationalStore.RdbPredicates('test_table'); predicates.equalTo('data', 'data_test'); cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data'], (err, resultSet) => { if (err) { console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); return; } if (!resultSet.goToFirstRow()) { console.error(`row error`); return; } const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); console.info(`sharing resource: ${res}`); sharingResource = res; }) ``` ### allocResourceAndShare11+ allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, callback: AsyncCallback<relationalStore.ResultSet>): void Allocates a shared resource ID based on the data that matches the specified predicates. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | storeId | string | Yes | Name of the RDB store.| | predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| | callback | AsyncCallback<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Yes | Callback invoked to return the result set of data to share.| **Example** ```ts import relationalStore from '@ohos.data.relationalStore'; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) let sharingResource: string; let predicates = new relationalStore.RdbPredicates('test_table'); predicates.equalTo('data', 'data_test'); cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, (err, resultSet) => { if (err) { console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); return; } if (!resultSet.goToFirstRow()) { console.error(`row error`); return; } const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); console.info(`sharing resource: ${res}`); sharingResource = res; }) ``` ### share11+ share(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> Shares data based on the specified shared resource ID and participants. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.share('sharing_resource_test', participants).then((result) => { console.info(`share success, result: ${result}`); }).catch((err: BusinessError) => { console.error(`share failed, code is ${err.code},message is ${err.message}`); }) ``` ### share11+ share(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void Shares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| | callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback invoked to return the result. | **Example** ```ts let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.share('sharing_resource_test', participants, ((err, result) => { if (err) { console.error(`share failed, code is ${err.code},message is ${err.message}`); return; } console.info(`share succeeded, result: ${result}`); })) ``` ### unshare11+ unshare(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> Unshares data based on the specified shared resource ID and participants. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.unshare('sharing_resource_test', participants).then((result) => { console.info(`unshare succeeded, result: ${result}`); }).catch((err: BusinessError) => { console.error(`unshare failed, code is ${err.code},message is ${err.message}`); }) ``` ### unshare11+ unshare(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void Unshares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| | callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback invoked to return the result. | **Example** ```ts let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.unshare('sharing_resource_test', participants, ((err, result) => { if (err) { console.error(`unshare failed, code is ${err.code},message is ${err.message}`); return; } console.info(`unshare succeeded, result: ${result}`); })) ``` ### exit11+ exit(sharingResource: string): Promise<Result<void>> Exits the share of the specified shared resource. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<void>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; cloudData.sharing.exit('sharing_resource_test').then((result) => { console.info(`exit share success, result: ${result}`); }).catch((err: BusinessError) => { console.error(`exit share failed, code is ${err.code},message is ${err.message}`); }) ``` ### exit11+ exit(sharingResource: string, callback: AsyncCallback<Result<void>>): void Exits the share of the specified shared resource. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback invoked to return the result. | **Example** ```ts cloudData.sharing.exit('sharing_resource_test', ((err, result) => { if (err) { console.error(`exit share failed, code is ${err.code},message is ${err.message}`); return; } console.info(`exit share succeeded, result: ${result}`); })) ``` ### changePrivilege11+ changePrivilege(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> Changes the privilege on the shared data. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants with new privilege. | **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.changePrivilege('sharing_resource_test', participants).then((result) => { console.info(`change privilege succeeded, result: ${result}`); }).catch((err: BusinessError) => { console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); }) ``` ### changePrivilege11+ changePrivilege(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void Changes the privilege on the shared data. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | participants | Array<[Participant](#participant11)> | Yes | Participants with new privilege. | | callback | callback: AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback invoked to return the result. | **Example** ```ts let participants = new Array(); participants.push({ identity: '000000000', role: cloudData.sharing.Role.ROLE_INVITER, state: cloudData.sharing.State.STATE_UNKNOWN, privilege: { writable: true, readable: true, creatable: false, deletable: false, shareable: false }, attachInfo: '' }) cloudData.sharing.changePrivilege('sharing_resource_test', participants, ((err, result) => { if (err) { console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); return; } console.info(`change privilege succeeded, result: ${result}`); })) ``` ### queryParticipants11+ queryParticipants(sharingResource: string): Promise<Result<Array<Participant>>> Queries the participants of the specified shared data. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| **Example** ```ts import { BusinessError } from "@ohos.base"; cloudData.sharing.queryParticipants('sharing_resource_test').then((result) => { console.info(`query participants succeeded, result: ${result}`); }).catch((err: BusinessError) => { console.error(`query participants failed, code is ${err.code},message is ${err.message}`); }) ``` ### queryParticipants11+ queryParticipants(sharingResource: string, callback: AsyncCallback<Result<Array<Participant>>>): void Queries the participants of the specified shared data. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback invoked to return the participants obtained.| **Example** ```ts cloudData.sharing.queryParticipants('sharing_resource_test', ((err, result) => { if (err) { console.error(`query participants failed, code is ${err.code},message is ${err.message}`); return; } console.info(`query participants succeeded, result: ${result}`); })) ``` ### queryParticipantsByInvitation11+ queryParticipantsByInvitation(invitationCode: string): Promise<Result<Array<Participant>>> Queries the participants based on the sharing invitation code. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | invitationCode | string | Yes | Invitation code of the share.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| **Example** ```ts import { BusinessError } from "@ohos.base"; cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test').then((result) => { console.info(`query participants by invitation succeeded, result: ${result}`); }).catch((err: BusinessError) => { console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); }) ``` ### queryParticipantsByInvitation11+ queryParticipantsByInvitation(invitationCode: string, callback: AsyncCallback<Result<Array<Participant>>>): void Queries the participants based on the sharing invitation code. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | invitationCode | string | Yes | Invitation code of the share.| | callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback invoked to return the participants obtained.| **Example** ```ts cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test', ((err, result) => { if (err) { console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); return; } console.info(`query participants by invitation succeeded, result: ${result}`); })) ``` ### confirmInvitation11+ confirmInvitation(invitationCode: string, state: State): Promise<Result<string>> Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | invitationCode | string | Yes | Invitation code of the share.| | state | [State](#state11) | Yes | Confirmation state.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<string>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; let shareResource: string; cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED).then((result) => { console.info(`confirm invitation succeeded, result: ${result}`); shareResource = result.value; }).catch((err: BusinessError) => { console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); }) ``` ### confirmInvitation11+ confirmInvitation(invitationCode: string, state: State, callback: AsyncCallback<Result<string>>): void Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | invitationCode | string | Yes | Invitation code of the share.| | state | [State](#state11) | Yes | Confirmation state.| | callback | AsyncCallback<[Result](#resultt11)<string>> | Yes | Callback invoked to return the result. | **Example** ```ts let shareResource: string; cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED, ((err, result) => { if (err) { console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); return; } console.info(`confirm invitation succeeded, result: ${result}`); shareResource = result.value; })) ``` ### changeConfirmation11+ changeConfirmation(sharingResource: string, state: State): Promise<Result<void>> Changes the invitation confirmation state based on the shared resource ID. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | state | [State](#state11) | Yes | New confirmation state of the invitation.| **Return value** | Type | Description | | ------------------- | ------------------------- | | Promise<[Result](#resultt11)<void>> | Promise used to return the result.| **Example** ```ts import { BusinessError } from "@ohos.base"; cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED).then((result) => { console.info(`change confirmation succeeded, result: ${result}`); }).catch((err: BusinessError) => { console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); }) ``` ### changeConfirmation11+ changeConfirmation(sharingResource: string, state: State, callback: AsyncCallback<Result<void>>): void; Changes the invitation confirmation state based on the shared resource ID. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.CloudSync.Client **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------- | ---- | ---------------------------- | | sharingResource | string | Yes | Shared resource ID.| | state | [State](#state11) | Yes | New confirmation state of the invitation.| | callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback invoked to return the result. | **Example** ```ts cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED, ((err, result) => { if (err) { console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); return; } console.info(`change confirmation succeeded, result: ${result}`); })) ```