1# @ohos.data.cloudData (Cloud Service) (System API) 2 3The **cloudData** module provides APIs for implementing device-cloud synergy and device-cloud sharing and setting the device-cloud sync strategy. 4 5Device-cloud synergy enables sync of 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. 6 7Device-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. 8 9**Participant**: all participants involved in a share, including the inviter and invitees. 10 11**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 pushed to the devices of target invitees. The target invitees then confirm the invitation via this code. 12 13The **cloudData** module provides the following functionalities: 14 15- [Config](#config): provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud sync, clearing data, and notifying data changes. 16- [sharing](#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. 17 18> **NOTE** 19> 20> - 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. 21> 22> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.data.cloudData (Cloud Service)](js-apis-data-cloudData.md). 23> 24> - Before using this module, ensure that the cloud service is available. 25 26## Modules to Import 27 28```ts 29import { cloudData } from '@kit.ArkData'; 30``` 31 32## ClearAction 33 34Enumerates the operations for clearing the downloaded cloud data locally. 35 36**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 37 38| Name | Description | 39| --------- | ---------------------------- | 40| CLEAR_CLOUD_INFO | Clear the cloud identifier of the data downloaded from the cloud and retain the data locally.| 41| CLEAR_CLOUD_DATA_AND_INFO |Clear the data downloaded from the cloud, excluding the cloud data that has been modified locally. | 42 43## ExtraData<sup>11+</sup> 44 45Represents the transparently transmitted data, which contains information required for a data change notification. 46 47**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 48 49| Name | Type | Mandatory| Description | 50| --------- | ------ | ---- | ------------------------------------------------------------ | 51| eventId | string | Yes | Event ID. The value **cloud_data_change** indicates cloud data changes. | 52| extraData | string | Yes | Data to be transmitted transparently. **extraData** is a JSON string that must contain the **data** field. The **data** field contains information required for a change notification, including the account ID, application name, database name, database type, and database table name. All the fields cannot be empty. 53 54**Example** 55 56```ts 57// accountId: ID of the cloud account. 58// bundleName: application bundle name. 59// containerName: name of the cloud database. 60// databaseScopes: type of the cloud database. 61// recordTypes: names of the tables in the cloud database. 62 63interface ExtraData { 64 eventId: "cloud_data_change", 65 extraData: '{ 66 "data": "{ 67 "accountId": "aaa", 68 "bundleName": "com.bbb.xxx", 69 "containerName": "alias", 70 "databaseScopes": ["private", "shared"], 71 "recordTypes": ["xxx", "yyy", "zzz"] 72 }" 73 }' 74} 75 76``` 77 78## StatisticInfo<sup>12+</sup> 79 80Represents the device-cloud sync statistics. 81 82**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 83 84| Name | Type | Mandatory| Description | 85| --------- | ------ | ---- |-----------------------------------------------------| 86| table | string | Yes | Name of the table queried. For example, the value **cloud_notes** indicates that the sync information of the **cloud_notes** table is queried.| 87| inserted | number | Yes | Number of data records that are added locally and have not been synced to the cloud. For example, the value **2** indicates that the table has two data records that are added locally but not synced to the cloud. | 88| updated | number | Yes | Number of data records that are modified locally or on the cloud but have not been synced. For example, the value **2** indicates that the table has two data records that are updated locally or on the cloud but not synced. | 89| normal | number | Yes | Number of consistent data records between the device and the cloud. For example, the value **2** indicates that table has two data records that are consistent between the device and the cloud. | 90 91## SyncStatus<sup>18+</sup> 92 93Enumerates the device-cloud sync task statuses. 94 95**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 96 97| Name | Value | Description | 98| -------- |-----|-----------------| 99| RUNNING | 0 | The device-cloud sync task is running.| 100| FINISHED | 1 | The device-cloud sync task is completed.| 101 102## SyncInfo<sup>12+</sup> 103 104Represents information about the last device-cloud sync. 105 106**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 107 108| Name | Type | Mandatory| Description | 109| ---------- | ------------------------------------------------------------ | ---- | -------------------------- | 110| startTime | Date | Yes | Start time of the last device-cloud sync.| 111| finishTime | Date | Yes | End time of the last device-cloud sync.| 112| code | [relationalStore.ProgressCode](arkts-apis-data-relationalStore-e.md#progresscode10) | Yes | Result of the last device-cloud sync.| 113| syncStatus<sup>18+</sup> | [SyncStatus](#syncstatus18) | No| Status of the last device-cloud sync. The default value is **cloudData.SyncStatus.RUNNING**.| 114 115## Config 116 117Provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud synergy, clearing data, and notifying data changes. 118 119### enableCloud 120 121static enableCloud(accountId: string, switches: Record<string, boolean>, callback: AsyncCallback<void>): void 122 123Enables device-cloud synergy. This API uses an asynchronous callback to return the result. 124 125**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 126 127**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 128 129**Parameters** 130 131| Name | Type | Mandatory| Description | 132| --------- | ------------------------------- | ---- | ------------------------------------------------------------ | 133| accountId | string | Yes | ID of the cloud account. | 134| switches | Record<string, boolean> | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 135| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 136 137**Error codes** 138 139For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 140 141| ID| Error Message | 142| -------- | ---------------------------------------------------- | 143| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 144| 202 | Permission verification failed, application which is not a system application uses system API.| 145| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 146| 801 | Capability not supported.| 147 148**Example** 149 150```ts 151import { BusinessError } from '@kit.BasicServicesKit'; 152 153let account: string = 'test_id'; 154let switches: Record<string, boolean> = { 'test_bundleName1': true, 'test_bundleName2': false }; 155try { 156 cloudData.Config.enableCloud(account, switches, (err: BusinessError) => { 157 if (err === undefined) { 158 console.info('Succeeded in enabling cloud'); 159 } else { 160 console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); 161 } 162 }); 163} catch (e) { 164 let error = e as BusinessError; 165 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 166} 167``` 168 169### enableCloud 170 171static enableCloud(accountId: string, switches: Record<string, boolean>): Promise<void> 172 173Enables device-cloud synergy. This API uses a promise to return the result. 174 175**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 176 177**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 178 179**Parameters** 180 181| Name | Type | Mandatory| Description | 182| --------- | ------------------------------- | ---- | ------------------------------------------------------------ | 183| accountId | string | Yes | ID of the cloud account. | 184| switches | Record<string, boolean> | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 185 186**Return value** 187 188| Type | Description | 189| ------------------- | ------------------------- | 190| Promise<void> | Promise that returns no value.| 191 192**Error codes** 193 194For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 195 196| ID| Error Message | 197| -------- | ---------------------------------------------------- | 198| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 199| 202 | Permission verification failed, application which is not a system application uses system API.| 200| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 201| 801 | Capability not supported.| 202 203**Example** 204 205```ts 206import { BusinessError } from '@kit.BasicServicesKit'; 207 208let account: string = 'test_id'; 209let switches: Record<string, boolean> = { 'test_bundleName1': true, 'test_bundleName2': false }; 210try { 211 cloudData.Config.enableCloud(account, switches).then(() => { 212 console.info('Succeeded in enabling cloud'); 213 }).catch((err: BusinessError) => { 214 console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); 215 }); 216} catch (e) { 217 let error = e as BusinessError; 218 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 219} 220``` 221 222### disableCloud 223 224static disableCloud(accountId: string, callback: AsyncCallback<void>): void 225 226Disables device-cloud synergy. This API uses an asynchronous callback to return the result. 227 228**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 229 230**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 231 232**Parameters** 233 234| Name | Type | Mandatory| Description | 235| --------- | ------------------------- | ---- | -------------------- | 236| accountId | string | Yes | ID of the cloud account.| 237| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 238 239**Error codes** 240 241For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 242 243| ID| Error Message | 244| -------- | ---------------------------------------------------- | 245| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 246| 202 | Permission verification failed, application which is not a system application uses system API.| 247| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 248| 801 | Capability not supported.| 249 250**Example** 251 252```ts 253import { BusinessError } from '@kit.BasicServicesKit'; 254 255let account: string = 'test_id'; 256try { 257 cloudData.Config.disableCloud(account, (err: BusinessError) => { 258 if (err === undefined) { 259 console.info('Succeeded in disabling cloud'); 260 } else { 261 console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); 262 } 263 }); 264} catch (e) { 265 let error = e as BusinessError; 266 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 267} 268``` 269 270### disableCloud 271 272static disableCloud(accountId: string): Promise<void> 273 274Disables device-cloud synergy. This API uses a promise to return the result. 275 276**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 277 278**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 279 280**Parameters** 281 282| Name | Type | Mandatory| Description | 283| --------- | ------ | ---- | -------------------- | 284| accountId | string | Yes | ID of the cloud account.| 285 286**Return value** 287 288| Type | Description | 289| ------------------- | ------------------------- | 290| Promise<void> | Promise that returns no value.| 291 292**Error codes** 293 294For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 295 296| ID| Error Message | 297| -------- | ---------------------------------------------------- | 298| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 299| 202 | Permission verification failed, application which is not a system application uses system API.| 300| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 301| 801 | Capability not supported.| 302 303**Example** 304 305```ts 306import { BusinessError } from '@kit.BasicServicesKit'; 307 308let account: string = 'test_id'; 309try { 310 cloudData.Config.disableCloud(account).then(() => { 311 console.info('Succeeded in disabling cloud'); 312 }).catch((err: BusinessError) => { 313 console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); 314 }); 315} catch (e) { 316 let error = e as BusinessError; 317 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 318} 319``` 320 321### changeAppCloudSwitch 322 323static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void 324 325Changes the device-cloud synergy setting for an application. This API uses an asynchronous callback to return the result. 326 327**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 328 329**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 330 331**Parameters** 332 333| Name | Type | Mandatory| Description | 334| --------- | ------------------------------- | ---- | ---------------------------- | 335| accountId | string | Yes | ID of the cloud account.| 336| bundleName| string | Yes | Bundle name of the application.| 337| status | boolean | Yes | New device-cloud synergy setting. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 338| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 339 340**Error codes** 341 342For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 343 344| ID| Error Message | 345| -------- | ---------------------------------------------------- | 346| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 347| 202 | Permission verification failed, application which is not a system application uses system API.| 348| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 349| 801 | Capability not supported.| 350 351**Example** 352 353```ts 354import { BusinessError } from '@kit.BasicServicesKit'; 355 356let account: string = 'test_id'; 357let bundleName: string = 'test_bundleName'; 358try { 359 cloudData.Config.changeAppCloudSwitch(account, bundleName, true, (err: BusinessError) => { 360 if (err === undefined) { 361 console.info('Succeeded in changing App cloud switch'); 362 } else { 363 console.error(`Failed to change App cloud switch. Code: ${err.code}, message: ${err.message}`); 364 } 365 }); 366} catch (e) { 367 let error = e as BusinessError; 368 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 369} 370``` 371 372### changeAppCloudSwitch 373 374static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> 375 376Changes the device-cloud synergy setting for an application. This API uses a promise to return the result. 377 378**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 379 380**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 381 382**Parameters** 383 384| Name | Type | Mandatory| Description | 385| --------- | ------------------------------- | ---- | ---------------------------- | 386| accountId | string | Yes | ID of the cloud account.| 387| bundleName| string | Yes | Bundle name of the application.| 388| status | boolean | Yes | New device-cloud synergy setting. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 389 390**Return value** 391 392| Type | Description | 393| ------------------- | ------------------------- | 394| Promise<void> | Promise that returns no value.| 395 396**Error codes** 397 398For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 399 400| ID| Error Message | 401| -------- | ---------------------------------------------------- | 402| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 403| 202 | Permission verification failed, application which is not a system application uses system API.| 404| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 405| 801 | Capability not supported.| 406 407**Example** 408 409```ts 410import { BusinessError } from '@kit.BasicServicesKit'; 411 412let account: string = 'test_id'; 413let bundleName: string = 'test_bundleName'; 414try { 415 cloudData.Config.changeAppCloudSwitch(account, bundleName, true).then(() => { 416 console.info('Succeeded in changing App cloud switch'); 417 }).catch((err: BusinessError) => { 418 console.error(`Failed to change App cloud switch. Code is ${err.code}, message is ${err.message}`); 419 }); 420} catch (e) { 421 let error = e as BusinessError; 422 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 423} 424``` 425 426### notifyDataChange 427 428static notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void 429 430Notifies the data changes in the cloud. This API uses an asynchronous callback to return the result. 431 432**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 433 434**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 435 436**Parameters** 437 438| Name | Type | Mandatory| Description | 439| ---------- | ------------------------- | ---- | -------------------- | 440| accountId | string | Yes | ID of the cloud account.| 441| bundleName | string | Yes | Bundle name of the application. | 442| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 443 444**Error codes** 445 446For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 447 448| ID| Error Message | 449| -------- | ---------------------------------------------------- | 450| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 451| 202 | Permission verification failed, application which is not a system application uses system API.| 452| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 453| 801 | Capability not supported.| 454 455**Example** 456 457```ts 458import { BusinessError } from '@kit.BasicServicesKit'; 459 460let account: string = 'test_id'; 461let bundleName: string = 'test_bundleName'; 462try { 463 cloudData.Config.notifyDataChange(account, bundleName, (err: BusinessError) => { 464 if (err === undefined) { 465 console.info('Succeeded in notifying the change of data'); 466 } else { 467 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 468 } 469 }); 470} catch (e) { 471 let error = e as BusinessError; 472 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 473} 474``` 475 476### notifyDataChange 477 478static notifyDataChange(accountId: string,bundleName: string): Promise<void> 479 480Notifies the data changes in the cloud. This API uses a promise to return the result. 481 482**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 483 484**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 485 486**Parameters** 487 488| Name | Type | Mandatory| Description | 489| ---------- | ------ | ---- | -------------------- | 490| accountId | string | Yes | ID of the cloud account.| 491| bundleName | string | Yes | Bundle name of the application. | 492 493**Return value** 494 495| Type | Description | 496| ------------------- | ------------------------- | 497| Promise<void> | Promise that returns no value.| 498 499**Error codes** 500 501For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 502 503| ID| Error Message | 504| -------- | ---------------------------------------------------- | 505| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 506| 202 | Permission verification failed, application which is not a system application uses system API.| 507| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 508| 801 | Capability not supported.| 509 510**Example** 511 512```ts 513import { BusinessError } from '@kit.BasicServicesKit'; 514 515let account: string = 'test_id'; 516let bundleName: string = 'test_bundleName'; 517try { 518 cloudData.Config.notifyDataChange(account, bundleName).then(() => { 519 console.info('Succeeded in notifying the change of data'); 520 }).catch((err: BusinessError) => { 521 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 522 }); 523} catch (e) { 524 let error = e as BusinessError; 525 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 526} 527``` 528 529### notifyDataChange<sup>11+</sup> 530 531 static notifyDataChange(extInfo: ExtraData, callback: AsyncCallback<void>):void 532 533Notifies the data changes in the cloud with the specified 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. 534 535**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 536 537**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 538 539**Parameters** 540 541| Name | Type | Mandatory| Description | 542| -------- | ------------------------- | ---- | --------------------------------------- | 543| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes.| 544| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 545 546**Error codes** 547 548For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 549 550| ID| Error Message | 551| -------- | ---------------------------------------------------- | 552| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 553| 202 | Permission verification failed, application which is not a system application uses system API.| 554| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 555| 801 | Capability not supported.| 556 557**Example** 558 559```ts 560import { BusinessError } from '@kit.BasicServicesKit'; 561 562let eventId: string = "cloud_data_change"; 563let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 564try { 565 cloudData.Config.notifyDataChange({ 566 eventId: eventId, extraData: extraData 567 }, (err: BusinessError) => { 568 if (err === undefined) { 569 console.info('Succeeded in notifying the change of data'); 570 } else { 571 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 572 } 573 }); 574} catch (e) { 575 let error = e as BusinessError; 576 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 577} 578``` 579 580### notifyDataChange<sup>11+</sup> 581 582static notifyDataChange(extInfo: ExtraData, userId: number,callback: AsyncCallback<void>):void 583 584Notifies 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 with data changes in the **extraData** field in **extInfo**, and specify the user ID. 585 586**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 587 588**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 589 590**Parameters** 591 592| Name | Type | Mandatory| Description | 593| -------- | ------------------------- | ---- | ----------------------------------------------- | 594| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | 595| userId | number | Yes | User ID in the system.| 596| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 597 598**Error codes** 599 600For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 601 602| ID| Error Message | 603| -------- | ---------------------------------------------------- | 604| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 605| 202 | Permission verification failed, application which is not a system application uses system API.| 606| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 607| 801 | Capability not supported.| 608 609**Example** 610 611```ts 612import { BusinessError } from '@kit.BasicServicesKit'; 613 614let eventId: string = "cloud_data_change"; 615let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 616let userId: number = 100; 617try { 618 cloudData.Config.notifyDataChange({ 619 eventId: eventId, extraData: extraData 620 }, userId, (err: BusinessError) => { 621 if (err === undefined) { 622 console.info('Succeeded in notifying the change of data'); 623 } else { 624 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 625 } 626 }); 627} catch (e) { 628 let error = e as BusinessError; 629 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 630} 631``` 632 633### notifyDataChange<sup>11+</sup> 634 635static notifyDataChange(extInfo: ExtraData, userId?: number): Promise<void> 636 637Notifies 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. 638 639**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 640 641**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 642 643**Parameters** 644 645| Name | Type | Mandatory| Description | 646| ------- | ----------------------- | ---- | ----------------------------------------------- | 647| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | 648| 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.| 649 650**Return value** 651 652| Type | Description | 653| ------------------- | ------------------------- | 654| Promise<void> | Promise that returns no value.| 655 656**Error codes** 657 658For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 659 660| ID| Error Message | 661| -------- | ---------------------------------------------------- | 662| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 663| 202 | Permission verification failed, application which is not a system application uses system API.| 664| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 665| 801 | Capability not supported.| 666 667**Example** 668 669```ts 670import { BusinessError } from '@kit.BasicServicesKit'; 671 672let eventId: string = "cloud_data_change"; 673let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 674let userId: number = 100; 675try { 676 cloudData.Config.notifyDataChange({ 677 eventId: eventId, extraData: extraData 678 }, userId).then(() => { 679 console.info('Succeeded in notifying the change of data'); 680 }).catch((err: BusinessError) => { 681 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 682 }); 683} catch (e) { 684 let error = e as BusinessError; 685 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 686} 687``` 688 689### queryStatistics<sup>12+</sup> 690 691static queryStatistics(accountId: string, bundleName: string, storeId?: string): Promise<Record<string, Array<StatisticInfo>>> 692 693Queries device-cloud data statistics, which include the data not synced, data synced and consistent, and data synced but inconsistent between the device and the cloud. This API uses a promise to return the result. 694 695**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 696 697**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 698 699**Parameters** 700 701| Name | Type | Mandatory| Description | 702| ------- |---------| ---- |-----------------------------------| 703| accountId | string | Yes | ID of the cloud account. | 704| bundleName | string | Yes | Bundle name of the application. | 705| storeId | string | No | Name of the RDB store. If this parameter is not specified, all local databases of this application are queried by default.| 706 707**Return value** 708 709| Type | Description | 710|--------------------------------------------------------------------------------------| ------------------------ | 711| Promise<Record<string, Array<[StatisticInfo](#statisticinfo12)>>> | Promise used to return the table name and statistics.| 712 713**Error codes** 714 715For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 716 717| ID| Error Message | 718| -------- | ---------------------------------------------------- | 719| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 720| 202 | Permission verification failed, application which is not a system application uses system API.| 721| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 722| 801 | Capability not supported.| 723 724**Example** 725 726```ts 727import { BusinessError } from '@kit.BasicServicesKit'; 728 729const accountId:string = "accountId"; 730const bundleName:string = "bundleName"; 731const storeId:string = "storeId"; 732 733cloudData.Config.queryStatistics(accountId, bundleName, storeId).then((result) => { 734 console.info(`Succeeded in querying statistics. Info is ${JSON.stringify(result)}`); 735}).catch((err: BusinessError) => { 736 console.error(`Failed to query statistics. Error code is ${err.code}, message is ${err.message}`); 737}); 738``` 739 740### queryLastSyncInfo<sup>12+</sup> 741 742static queryLastSyncInfo(accountId: string, bundleName: string, storeId?: string): Promise<Record<string, SyncInfo>> 743 744Queries information about the last device-cloud sync. This API uses a promise to return the result. 745 746**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 747 748**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 749 750**Parameters** 751 752| Name | Type | Mandatory| Description | 753| ---------- | ------ | ---- | ------------------------------------------------------------ | 754| accountId | string | Yes | ID of the cloud account. | 755| bundleName | string | Yes | Bundle name of the application. | 756| storeId | string | No | Name of the RDB store. The default value is an empty string. If the default value is used, this API queries the last device-cloud sync information of all databases of this application.| 757 758**Return value** 759 760| Type | Description | 761| ------------------------------------------------------------ | -------------------------------------------- | 762| Promise<Record<string, [SyncInfo](#syncinfo12)>> | Promise used to return the database name and the result set of the last device-cloud sync.| 763 764**Error codes** 765 766For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 767 768| ID| Error Message | 769| -------- | ---------------------------------------------------- | 770| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 771| 202 | Permission verification failed, application which is not a system application uses system API.| 772| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 773| 801 | Capability not supported.| 774 775**Example** 776 777```ts 778import { BusinessError } from '@kit.BasicServicesKit'; 779 780const accountId:string = "accountId"; 781const bundleName:string = "bundleName"; 782const storeId:string = "storeId"; 783try { 784 cloudData.Config.queryLastSyncInfo(accountId, bundleName, storeId).then((result) => { 785 console.info(`Succeeded in querying last syncinfo. Info is ${JSON.stringify(result)}`); 786 }).catch((err: BusinessError) => { 787 console.error(`Failed to query last syncinfo. Error code is ${err.code}, message is ${err.message}`); 788 }); 789} catch(e) { 790 let error = e as BusinessError; 791 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 792} 793``` 794 795### setGlobalCloudStrategy<sup>12+</sup> 796 797static setGlobalCloudStrategy(strategy: StrategyType, param?: Array<commonType.ValueType>): Promise<void> 798 799Sets a global device-cloud sync strategy. This API uses a promise to return the result. 800 801**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 802 803**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 804 805**Parameters** 806 807| Name | Type | Mandatory| Description | 808| ---------- |------------------------------------------------------------------------| ---- |-------------------| 809| strategy | [StrategyType](js-apis-data-cloudData.md#strategytype) | Yes | Type of the strategy to set. | 810| param | Array<[commonType.ValueType](js-apis-data-commonType.md#valuetype)> | No | Strategy parameters to set. If this parameter is not specified, the strategy configuration is deleted by default. | 811 812**Return value** 813 814| Type | Description | 815| ------------------- | ------------------------- | 816| Promise<void> | Promise that returns no value.| 817 818**Error codes** 819 820For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 821 822| ID| Error Message | 823| -------- | ---------------------------------------------------- | 824| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 825| 202 | Permission verification failed, application which is not a system application uses system API.| 826| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 827| 801 | Capability not supported.| 828 829**Example** 830 831```ts 832import { BusinessError } from '@kit.BasicServicesKit'; 833 834cloudData.Config.setGlobalCloudStrategy(cloudData.StrategyType.NETWORK, [cloudData.NetWorkStrategy.WIFI]).then(() => { 835 console.info('Succeeded in setting the global cloud strategy'); 836}).catch((err: BusinessError) => { 837 console.error(`Failed to set global cloud strategy. Code: ${err.code}, message: ${err.message}`); 838}); 839``` 840 841### cloudSync<sup>20+</sup> 842 843static cloudSync(bundleName: string, storeId: string, mode: relationalStore.SyncMode, progress: Callback<relationalStore.ProgressDetails>): Promise<void> 844 845Synchronizes data of a specified application on the device to the cloud. This API uses a promise to return the result. 846 847**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 848 849**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 850 851**Parameters** 852 853| Name | Type | Mandatory| Description | 854| ---------- |--------| ---- |-----------------------| 855| bundleName | string | Yes | Name of the application to sync.| 856| storeId | string | Yes | Name of the database to sync. | 857| mode | [relationalStore.SyncMode](arkts-apis-data-relationalStore-e.md#syncmode) | Yes| Device-cloud sync mode.| 858| progress | Callback<[relationalStore.ProgressDetails](arkts-apis-data-relationalStore-i.md#progressdetails10)> | Yes| Callback used to return the sync progress.| 859 860**Return value** 861 862| Type | Description | 863| ------------------- | ----------------------- | 864| Promise<void> | Promise that returns no value.| 865 866**Error codes** 867 868For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [RDB Store Error Codes](errorcode-data-rdb.md). 869 870| ID| Error Message | 871| -------- | ---------------------------------------------------- | 872| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 873| 202 | Permission verification failed, application which is not a system application uses system API.| 874| 801 | Capability not supported.| 875| 14800001 | Invalid arguments. Possible causes: 1. Parameter is out of valid range. | 876 877**Example** 878 879```ts 880import { BusinessError } from '@kit.BasicServicesKit'; 881import { relationalStore } from '@kit.ArkData'; 882 883try{ 884 cloudData.Config.cloudSync("bundleName", "storeId", relationalStore.SyncMode.SYNC_MODE_TIME_FIRST, (progress)=>{ 885 console.info('Succeeded in getting progress details.'); 886 }).then(() => { 887 console.info('Succeeded in syncing cloud data.'); 888 }).catch((err: BusinessError) => { 889 console.error(`Failed to sync cloud data. Code: ${err.code}, message: ${err.message}`); 890 }); 891} catch (e) { 892 let error = e as BusinessError; 893 console.error(`Failed to sync cloud data. Code: ${e.code}, message: ${e.message}`); 894} 895``` 896 897### clear 898 899static clear(accountId: string, appActions: Record<string, ClearAction>, callback: AsyncCallback<void>): void 900 901Clears the cloud data locally. This API uses an asynchronous callback to return the result. 902 903**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 904 905**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 906 907**Parameters** 908 909| Name | Type | Mandatory| Description | 910| ---------- | --------------------------------------------------- | ---- | -------------------------------- | 911| accountId | string | Yes | ID of the cloud account. | 912| appActions | Record<string, [ClearAction](#clearaction)> | Yes | Information about the application whose data is to be cleared and the operation to perform.| 913| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 914 915**Error codes** 916 917For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 918 919| ID| Error Message | 920| -------- | ---------------------------------------------------- | 921| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 922| 202 | Permission verification failed, application which is not a system application uses system API.| 923| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 924| 801 | Capability not supported.| 925 926**Example** 927 928```ts 929import { BusinessError } from '@kit.BasicServicesKit'; 930 931let account: string = "test_id"; 932type dataType = Record<string, cloudData.ClearAction> 933let appActions: dataType = { 934 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 935 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO 936}; 937try { 938 cloudData.Config.clear(account, appActions, (err: BusinessError) => { 939 if (err === undefined) { 940 console.info('Succeeding in clearing cloud data'); 941 } else { 942 console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); 943 } 944 }); 945} catch (e) { 946 let error = e as BusinessError; 947 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 948} 949``` 950 951### clear 952 953static clear(accountId: string, appActions: Record<string, ClearAction>): Promise<void> 954 955Clears the cloud data locally. This API uses a promise to return the result. 956 957**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 958 959**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 960 961**Parameters** 962 963| Name | Type | Mandatory| Description | 964| ---------- | --------------------------------------------------- | ---- | -------------------------------- | 965| accountId | string | Yes | ID of the cloud account. | 966| appActions | Record<string, [ClearAction](#clearaction)> | Yes | Information about the application whose data is to be cleared and the operation to perform.| 967 968**Return value** 969 970| Type | Description | 971| ------------------- | ------------------------- | 972| Promise<void> | Promise that returns no value.| 973 974**Error codes** 975 976For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 977 978| ID| Error Message | 979| -------- | ---------------------------------------------------- | 980| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 981| 202 | Permission verification failed, application which is not a system application uses system API.| 982| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 983| 801 | Capability not supported.| 984 985**Example** 986 987```ts 988import { BusinessError } from '@kit.BasicServicesKit'; 989 990let account: string = "test_id"; 991type dataType = Record<string, cloudData.ClearAction>; 992let appActions: dataType = { 993 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 994 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO 995}; 996try { 997 cloudData.Config.clear(account, appActions).then(() => { 998 console.info('Succeeding in clearing cloud data'); 999 }).catch((err: BusinessError) => { 1000 console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); 1001 }); 1002} catch (e) { 1003 let error = e as BusinessError; 1004 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 1005} 1006``` 1007 1008## sharing<sup>11+</sup> 1009 1010Provides 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. 1011 1012### Role<sup>11+</sup> 1013 1014Enumerates the roles of the participants in a device-cloud share. 1015 1016**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1017 1018| Name | Value | Description | 1019| --------------| ---- | ---------------------------------- | 1020| ROLE_INVITER | 0 | Inviter, the one who shares data. Use the enum name rather than the enum value.| 1021| ROLE_INVITEE | 1 | Invitee, the one who can use the shared data. Use the enum name rather than the enum value.| 1022 1023### State<sup>11+</sup> 1024 1025Enumerates the device-cloud sharing states. 1026 1027**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1028 1029| Name | Value | Description | 1030| --------------| ---- | ---------------------------------- | 1031| STATE_UNKNOWN | 0 | Unknown state. Use the enum name rather than the enum value. | 1032| STATE_ACCEPTED | 1 | The device-cloud sharing invitation is accepted. Use the enum name rather than the enum value.| 1033| STATE_REJECTED | 2 | The device-cloud sharing invitation is rejected. Use the enum name rather than the enum value.| 1034| STATE_SUSPENDED | 3 | The device-cloud sharing is suspended temporarily. Use the enum name rather than the enum value.| 1035| STATE_UNAVAILABLE<sup>12+</sup> | 4 | The device-cloud sharing is unavailable. Use the enum name rather than the enum value.| 1036 1037### SharingCode<sup>11+</sup> 1038 1039Enumerates the error codes for device-cloud sharing. 1040 1041**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1042 1043| Name | Value | Description | 1044| --------------| ---- | ---------------------------------- | 1045| SUCCESS | 0 | Operation successful. Use the enum name rather than the enum value. | 1046| REPEATED_REQUEST | 1 | Repeated invitation, which means the participant has been invited. Use the enum name rather than the enum value.| 1047| NOT_INVITER | 2 | The participant is not the inviter of this share. Use the enum name rather than the enum value.| 1048| 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.| 1049| 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. | 1050| TOO_MANY_PARTICIPANTS | 5 | The number of device-cloud sharing participants has reached the limit. Use the enum name rather than the enum value.| 1051| INVALID_ARGS | 6 | Invalid parameter. Use the enum name rather than the enum value.| 1052| NETWORK_ERROR | 7 | Network error. Use the enum name rather than the enum value.| 1053| CLOUD_DISABLED | 8 | Cloud is disabled. Use the enum name rather than the enum value. | 1054| SERVER_ERROR | 9 | Server error. Use the enum name rather than the enum value.| 1055| INNER_ERROR | 10 | System internal error. Use the enum name rather than the enum value.| 1056| 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.| 1057| RATE_LIMIT | 12 | The amount of data to be synced at a time has reached the limit. Use the enum name rather than the enum value. | 1058| 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.| 1059 1060### Result<T><sup>11+</sup> 1061 1062Represents the device-cloud sharing result. 1063 1064**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1065 1066| Name | Type | Mandatory | Description | 1067| ----------- | --------------------------- | --- | ------------ | 1068| code | number | Yes | Error code. | 1069| description | string | No | Detailed description of the error code. The default value is **undefined**. | 1070| value | T | No | Value returned. The specific type is specified by the **T** parameter. The default value is **undefined**.| 1071 1072### Privilege<sup>11+</sup> 1073 1074Defines the privilege (permissions) on the shared data. 1075 1076**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1077 1078| Name | Type | Mandatory | Description | 1079| ----------- | --------------------------- | --- | ------------ | 1080| 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**. | 1081| 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**. | 1082| 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**. | 1083| 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**. | 1084| 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**. | 1085 1086### Participant<sup>11+</sup> 1087 1088Represents information about a participant of device-cloud sharing. 1089 1090**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1091 1092| Name | Type | Mandatory | Description | 1093| ----------- | --------------------------- | --- | ------------ | 1094| identity | string | Yes | ID of the participant. | 1095| role | [Role](#role11) | No | Role of the participant, inviter or invitee. The default value is **undefined**. | 1096| state | [State](#state11) | No | State of the device-cloud sharing. The default value is **undefined**.| 1097| privilege | [Privilege](#privilege11) | No | Permissions on the shared data. The [Privilege](#privilege11) defaults are used by default.| 1098| attachInfo | string | No | Additional information, such as the verification code used for participant identity verification. The default value is an empty string.| 1099 1100### allocResourceAndShare<sup>11+</sup> 1101 1102allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns?: Array<string>): Promise<relationalStore.ResultSet> 1103 1104Allocates 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. 1105 1106**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1107 1108**Parameters** 1109 1110| Name | Type | Mandatory| Description | 1111| --------- | ------------------------------- | ---- | ---------------------------- | 1112| storeId | string | Yes | Name of the RDB store.| 1113| predicates | [relationalStore.RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Yes | Predicates for matching the data to share.| 1114| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1115| columns | Array<string> | No | Columns in which the data is located. The default value is **undefined**, which means column names are not returned.| 1116 1117**Return value** 1118 1119| Type | Description | 1120| ------------------- | ------------------------- | 1121| Promise<[relationalStore.ResultSet](arkts-apis-data-relationalStore-ResultSet.md)> | Promise used to return the result set of the data to share.| 1122 1123**Error codes** 1124 1125For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1126 1127| ID| Error Message | 1128| -------- | ---------------------------------------------------- | 1129| 202 | Permission verification failed, application which is not a system application uses system API.| 1130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1131| 801 | Capability not supported.| 1132 1133**Example** 1134 1135```ts 1136import { BusinessError } from '@kit.BasicServicesKit'; 1137import { relationalStore } from '@kit.ArkData'; 1138 1139let participants = new Array<cloudData.sharing.Participant>(); 1140participants.push({ 1141 identity: '000000000', 1142 role: cloudData.sharing.Role.ROLE_INVITER, 1143 state: cloudData.sharing.State.STATE_UNKNOWN, 1144 privilege: { 1145 writable: true, 1146 readable: true, 1147 creatable: false, 1148 deletable: false, 1149 shareable: false 1150 }, 1151 attachInfo: '' 1152}) 1153let sharingResource: string; 1154let predicates = new relationalStore.RdbPredicates('test_table'); 1155predicates.equalTo('data', 'data_test'); 1156cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data']).then((resultSet) => { 1157 if (!resultSet.goToFirstRow()) { 1158 console.error(`row error`); 1159 return; 1160 } 1161 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1162 console.info(`sharing resource: ${res}`); 1163 sharingResource = res; 1164}).catch((err: BusinessError) => { 1165 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1166}) 1167 1168``` 1169 1170### allocResourceAndShare<sup>11+</sup> 1171 1172allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns: Array<string>, callback: AsyncCallback<relationalStore.ResultSet>): void 1173 1174Allocates 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. 1175 1176**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1177 1178**Parameters** 1179 1180| Name | Type | Mandatory| Description | 1181| --------- | ------------------------------- | ---- | ---------------------------- | 1182| storeId | string | Yes | Name of the RDB store.| 1183| predicates | [relationalStore.RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Yes | Predicates for matching the data to share.| 1184| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1185| columns | Array<string> | Yes | Columns in which the data is located.| 1186| callback | AsyncCallback<[relationalStore.ResultSet](arkts-apis-data-relationalStore-ResultSet.md)> | Yes | Callback used to return the result set of the data to share.| 1187 1188**Error codes** 1189 1190For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1191 1192| ID| Error Message | 1193| -------- | ---------------------------------------------------- | 1194| 202 | Permission verification failed, application which is not a system application uses system API.| 1195| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1196| 801 | Capability not supported.| 1197 1198**Example** 1199 1200```ts 1201import { relationalStore } from '@kit.ArkData'; 1202import { BusinessError } from '@kit.BasicServicesKit'; 1203 1204let participants = new Array<cloudData.sharing.Participant>(); 1205participants.push({ 1206 identity: '000000000', 1207 role: cloudData.sharing.Role.ROLE_INVITER, 1208 state: cloudData.sharing.State.STATE_UNKNOWN, 1209 privilege: { 1210 writable: true, 1211 readable: true, 1212 creatable: false, 1213 deletable: false, 1214 shareable: false 1215 }, 1216 attachInfo: '' 1217}) 1218let sharingResource: string; 1219let predicates = new relationalStore.RdbPredicates('test_table'); 1220predicates.equalTo('data', 'data_test'); 1221cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data'], (err: BusinessError, resultSet) => { 1222 if (err) { 1223 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1224 return; 1225 } 1226 if (!resultSet.goToFirstRow()) { 1227 console.error(`row error`); 1228 return; 1229 } 1230 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1231 console.info(`sharing resource: ${res}`); 1232 sharingResource = res; 1233}) 1234 1235``` 1236 1237### allocResourceAndShare<sup>11+</sup> 1238 1239allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, callback: AsyncCallback<relationalStore.ResultSet>): void 1240 1241Allocates a shared resource ID based on the data that matches the specified predicates. This API uses an asynchronous callback to return the result. 1242 1243**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1244 1245**Parameters** 1246 1247| Name | Type | Mandatory| Description | 1248| --------- | ------------------------------- | ---- | ---------------------------- | 1249| storeId | string | Yes | Name of the RDB store.| 1250| predicates | [relationalStore.RdbPredicates](arkts-apis-data-relationalStore-RdbPredicates.md) | Yes | Predicates for matching the data to share.| 1251| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1252| callback | AsyncCallback<[relationalStore.ResultSet](arkts-apis-data-relationalStore-ResultSet.md)> | Yes | Callback used to return the result set of the data to share.| 1253 1254**Error codes** 1255 1256For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1257 1258| ID| Error Message | 1259| -------- | ---------------------------------------------------- | 1260| 202 | Permission verification failed, application which is not a system application uses system API.| 1261| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1262| 801 | Capability not supported.| 1263 1264**Example** 1265 1266```ts 1267import { relationalStore } from '@kit.ArkData'; 1268import { BusinessError } from '@kit.BasicServicesKit'; 1269 1270let participants = new Array<cloudData.sharing.Participant>(); 1271participants.push({ 1272 identity: '000000000', 1273 role: cloudData.sharing.Role.ROLE_INVITER, 1274 state: cloudData.sharing.State.STATE_UNKNOWN, 1275 privilege: { 1276 writable: true, 1277 readable: true, 1278 creatable: false, 1279 deletable: false, 1280 shareable: false 1281 }, 1282 attachInfo: '' 1283}) 1284let sharingResource: string; 1285let predicates = new relationalStore.RdbPredicates('test_table'); 1286predicates.equalTo('data', 'data_test'); 1287cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, (err: BusinessError, resultSet) => { 1288 if (err) { 1289 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1290 return; 1291 } 1292 if (!resultSet.goToFirstRow()) { 1293 console.error(`row error`); 1294 return; 1295 } 1296 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1297 console.info(`sharing resource: ${res}`); 1298 sharingResource = res; 1299}) 1300 1301``` 1302 1303### share<sup>11+</sup> 1304 1305share(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1306 1307Shares data based on the specified shared resource ID and participants. This API uses a promise to return the result. 1308 1309**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1310 1311**Parameters** 1312 1313| Name | Type | Mandatory| Description | 1314| --------- | ------------------------------- | ---- | ---------------------------- | 1315| sharingResource | string | Yes | Shared resource ID.| 1316| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1317 1318**Return value** 1319 1320| Type | Description | 1321| ------------------- | ------------------------- | 1322| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1323 1324**Error codes** 1325 1326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1327 1328| ID| Error Message | 1329| -------- | ---------------------------------------------------- | 1330| 202 | Permission verification failed, application which is not a system application uses system API.| 1331| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1332| 801 | Capability not supported.| 1333 1334**Example** 1335 1336```ts 1337import { BusinessError } from '@kit.BasicServicesKit'; 1338 1339let participants = new Array<cloudData.sharing.Participant>(); 1340participants.push({ 1341 identity: '000000000', 1342 role: cloudData.sharing.Role.ROLE_INVITER, 1343 state: cloudData.sharing.State.STATE_UNKNOWN, 1344 privilege: { 1345 writable: true, 1346 readable: true, 1347 creatable: false, 1348 deletable: false, 1349 shareable: false 1350 }, 1351 attachInfo: '' 1352}) 1353cloudData.sharing.share('sharing_resource_test', participants).then((result) => { 1354 console.info(`share success, result: ${result}`); 1355}).catch((err: BusinessError) => { 1356 console.error(`share failed, code is ${err.code},message is ${err.message}`); 1357}) 1358 1359``` 1360 1361### share<sup>11+</sup> 1362 1363share(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1364 1365Shares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. 1366 1367**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1368 1369**Parameters** 1370 1371| Name | Type | Mandatory| Description | 1372| --------- | ------------------------------- | ---- | ---------------------------- | 1373| sharingResource | string | Yes | Shared resource ID.| 1374| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1375| callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1376 1377**Error codes** 1378 1379For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1380 1381| ID| Error Message | 1382| -------- | ---------------------------------------------------- | 1383| 202 | Permission verification failed, application which is not a system application uses system API.| 1384| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1385| 801 | Capability not supported.| 1386 1387**Example** 1388 1389```ts 1390import { BusinessError } from '@kit.BasicServicesKit'; 1391 1392let participants = new Array<cloudData.sharing.Participant>(); 1393participants.push({ 1394 identity: '000000000', 1395 role: cloudData.sharing.Role.ROLE_INVITER, 1396 state: cloudData.sharing.State.STATE_UNKNOWN, 1397 privilege: { 1398 writable: true, 1399 readable: true, 1400 creatable: false, 1401 deletable: false, 1402 shareable: false 1403 }, 1404 attachInfo: '' 1405}) 1406cloudData.sharing.share('sharing_resource_test', participants, ((err: BusinessError, result) => { 1407 if (err) { 1408 console.error(`share failed, code is ${err.code},message is ${err.message}`); 1409 return; 1410 } 1411 console.info(`share succeeded, result: ${result}`); 1412})) 1413 1414``` 1415 1416### unshare<sup>11+</sup> 1417 1418unshare(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1419 1420Unshares data based on the specified shared resource ID and participants. This API uses a promise to return the result. 1421 1422**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1423 1424**Parameters** 1425 1426| Name | Type | Mandatory| Description | 1427| --------- | ------------------------------- | ---- | ---------------------------- | 1428| sharingResource | string | Yes | Shared resource ID.| 1429| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1430 1431**Return value** 1432 1433| Type | Description | 1434| ------------------- | ------------------------- | 1435| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1436 1437**Error codes** 1438 1439For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1440 1441| ID| Error Message | 1442| -------- | ---------------------------------------------------- | 1443| 202 | Permission verification failed, application which is not a system application uses system API.| 1444| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1445| 801 | Capability not supported.| 1446 1447**Example** 1448 1449```ts 1450import { BusinessError } from '@kit.BasicServicesKit'; 1451 1452let participants = new Array<cloudData.sharing.Participant>(); 1453participants.push({ 1454 identity: '000000000', 1455 role: cloudData.sharing.Role.ROLE_INVITER, 1456 state: cloudData.sharing.State.STATE_UNKNOWN, 1457 privilege: { 1458 writable: true, 1459 readable: true, 1460 creatable: false, 1461 deletable: false, 1462 shareable: false 1463 }, 1464 attachInfo: '' 1465}) 1466cloudData.sharing.unshare('sharing_resource_test', participants).then((result) => { 1467 console.info(`unshare succeeded, result: ${result}`); 1468}).catch((err: BusinessError) => { 1469 console.error(`unshare failed, code is ${err.code},message is ${err.message}`); 1470}) 1471 1472``` 1473 1474### unshare<sup>11+</sup> 1475 1476unshare(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1477 1478Unshares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. 1479 1480**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1481 1482**Parameters** 1483 1484| Name | Type | Mandatory| Description | 1485| --------- | ------------------------------- | ---- | ---------------------------- | 1486| sharingResource | string | Yes | Shared resource ID.| 1487| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1488| callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1489 1490**Error codes** 1491 1492For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1493 1494| ID| Error Message | 1495| -------- | ---------------------------------------------------- | 1496| 202 | Permission verification failed, application which is not a system application uses system API.| 1497| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1498| 801 | Capability not supported.| 1499 1500**Example** 1501 1502```ts 1503import { BusinessError } from '@kit.BasicServicesKit'; 1504 1505let participants = new Array<cloudData.sharing.Participant>(); 1506participants.push({ 1507 identity: '000000000', 1508 role: cloudData.sharing.Role.ROLE_INVITER, 1509 state: cloudData.sharing.State.STATE_UNKNOWN, 1510 privilege: { 1511 writable: true, 1512 readable: true, 1513 creatable: false, 1514 deletable: false, 1515 shareable: false 1516 }, 1517 attachInfo: '' 1518}) 1519cloudData.sharing.unshare('sharing_resource_test', participants, ((err: BusinessError, result) => { 1520 if (err) { 1521 console.error(`unshare failed, code is ${err.code},message is ${err.message}`); 1522 return; 1523 } 1524 console.info(`unshare succeeded, result: ${result}`); 1525})) 1526 1527``` 1528 1529### exit<sup>11+</sup> 1530 1531exit(sharingResource: string): Promise<Result<void>> 1532 1533Exits the share of the specified shared resource. This API uses a promise to return the result. 1534 1535**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1536 1537**Parameters** 1538 1539| Name | Type | Mandatory| Description | 1540| --------- | ------------------------------- | ---- | ---------------------------- | 1541| sharingResource | string | Yes | Shared resource ID.| 1542 1543**Return value** 1544 1545| Type | Description | 1546| ------------------- | ------------------------- | 1547| Promise<[Result](#resultt11)<void>> | Promise used to return the result.| 1548 1549**Error codes** 1550 1551For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1552 1553| ID| Error Message | 1554| -------- | ---------------------------------------------------- | 1555| 202 | Permission verification failed, application which is not a system application uses system API.| 1556| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1557| 801 | Capability not supported.| 1558 1559**Example** 1560 1561```ts 1562import { BusinessError } from '@kit.BasicServicesKit'; 1563 1564cloudData.sharing.exit('sharing_resource_test').then((result) => { 1565 console.info(`exit share success, result: ${result}`); 1566}).catch((err: BusinessError) => { 1567 console.error(`exit share failed, code is ${err.code},message is ${err.message}`); 1568}) 1569 1570``` 1571 1572### exit<sup>11+</sup> 1573 1574exit(sharingResource: string, callback: AsyncCallback<Result<void>>): void 1575 1576Exits the share of the specified shared resource. This API uses an asynchronous callback to return the result. 1577 1578**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1579 1580**Parameters** 1581 1582| Name | Type | Mandatory| Description | 1583| --------- | ------------------------------- | ---- | ---------------------------- | 1584| sharingResource | string | Yes | Shared resource ID.| 1585| callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback used to return the result. | 1586 1587**Error codes** 1588 1589For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1590 1591| ID| Error Message | 1592| -------- | ---------------------------------------------------- | 1593| 202 | Permission verification failed, application which is not a system application uses system API.| 1594| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1595| 801 | Capability not supported.| 1596 1597**Example** 1598 1599```ts 1600import { BusinessError } from '@kit.BasicServicesKit'; 1601 1602cloudData.sharing.exit('sharing_resource_test', ((err: BusinessError, result) => { 1603 if (err) { 1604 console.error(`exit share failed, code is ${err.code},message is ${err.message}`); 1605 return; 1606 } 1607 console.info(`exit share succeeded, result: ${result}`); 1608})) 1609 1610``` 1611 1612### changePrivilege<sup>11+</sup> 1613 1614changePrivilege(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1615 1616Changes the privilege on the shared data. This API uses a promise to return the result. 1617 1618**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1619 1620**Parameters** 1621 1622| Name | Type | Mandatory| Description | 1623| --------- | ------------------------------- | ---- | ---------------------------- | 1624| sharingResource | string | Yes | Shared resource ID.| 1625| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1626 1627**Return value** 1628 1629| Type | Description | 1630| ------------------- | ------------------------- | 1631| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1632 1633**Error codes** 1634 1635For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1636 1637| ID| Error Message | 1638| -------- | ---------------------------------------------------- | 1639| 202 | Permission verification failed, application which is not a system application uses system API.| 1640| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1641| 801 | Capability not supported.| 1642 1643**Example** 1644 1645```ts 1646import { BusinessError } from '@kit.BasicServicesKit'; 1647 1648let participants = new Array<cloudData.sharing.Participant>(); 1649participants.push({ 1650 identity: '000000000', 1651 role: cloudData.sharing.Role.ROLE_INVITER, 1652 state: cloudData.sharing.State.STATE_UNKNOWN, 1653 privilege: { 1654 writable: true, 1655 readable: true, 1656 creatable: false, 1657 deletable: false, 1658 shareable: false 1659 }, 1660 attachInfo: '' 1661}) 1662 1663cloudData.sharing.changePrivilege('sharing_resource_test', participants).then((result) => { 1664 console.info(`change privilege succeeded, result: ${result}`); 1665}).catch((err: BusinessError) => { 1666 console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); 1667}) 1668 1669``` 1670 1671### changePrivilege<sup>11+</sup> 1672 1673changePrivilege(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1674 1675Changes the privilege on the shared data. This API uses an asynchronous callback to return the result. 1676 1677**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1678 1679**Parameters** 1680 1681| Name | Type | Mandatory| Description | 1682| --------- | ------------------------------- | ---- | ---------------------------- | 1683| sharingResource | string | Yes | Shared resource ID.| 1684| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1685| callback | callback: AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1686 1687**Error codes** 1688 1689For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1690 1691| ID| Error Message | 1692| -------- | ---------------------------------------------------- | 1693| 202 | Permission verification failed, application which is not a system application uses system API.| 1694| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1695| 801 | Capability not supported.| 1696 1697**Example** 1698 1699```ts 1700import { BusinessError } from '@kit.BasicServicesKit'; 1701 1702let participants = new Array<cloudData.sharing.Participant>(); 1703participants.push({ 1704 identity: '000000000', 1705 role: cloudData.sharing.Role.ROLE_INVITER, 1706 state: cloudData.sharing.State.STATE_UNKNOWN, 1707 privilege: { 1708 writable: true, 1709 readable: true, 1710 creatable: false, 1711 deletable: false, 1712 shareable: false 1713 }, 1714 attachInfo: '' 1715}) 1716 1717cloudData.sharing.changePrivilege('sharing_resource_test', participants, ((err: BusinessError, result) => { 1718 if (err) { 1719 console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); 1720 return; 1721 } 1722 console.info(`change privilege succeeded, result: ${result}`); 1723})) 1724 1725``` 1726 1727### queryParticipants<sup>11+</sup> 1728 1729queryParticipants(sharingResource: string): Promise<Result<Array<Participant>>> 1730 1731Queries the participants of the specified shared data. This API uses a promise to return the result. 1732 1733**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1734 1735**Parameters** 1736 1737| Name | Type | Mandatory| Description | 1738| --------- | ------------------------------- | ---- | ---------------------------- | 1739| sharingResource | string | Yes | Shared resource ID.| 1740 1741**Return value** 1742 1743| Type | Description | 1744| ------------------- | ------------------------- | 1745| Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| 1746 1747**Error codes** 1748 1749For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1750 1751| ID| Error Message | 1752| -------- | ---------------------------------------------------- | 1753| 202 | Permission verification failed, application which is not a system application uses system API.| 1754| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1755| 801 | Capability not supported.| 1756 1757**Example** 1758 1759```ts 1760import { BusinessError } from '@kit.BasicServicesKit'; 1761 1762cloudData.sharing.queryParticipants('sharing_resource_test').then((result) => { 1763 console.info(`query participants succeeded, result: ${result}`); 1764}).catch((err: BusinessError) => { 1765 console.error(`query participants failed, code is ${err.code},message is ${err.message}`); 1766}) 1767 1768``` 1769 1770### queryParticipants<sup>11+</sup> 1771 1772queryParticipants(sharingResource: string, callback: AsyncCallback<Result<Array<Participant>>>): void 1773 1774Queries the participants of the specified shared data. This API uses an asynchronous callback to return the result. 1775 1776**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1777 1778**Parameters** 1779 1780| Name | Type | Mandatory| Description | 1781| --------- | ------------------------------- | ---- | ---------------------------- | 1782| sharingResource | string | Yes | Shared resource ID.| 1783| callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback used to return the participants obtained.| 1784 1785**Error codes** 1786 1787For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1788 1789| ID| Error Message | 1790| -------- | ---------------------------------------------------- | 1791| 202 | Permission verification failed, application which is not a system application uses system API.| 1792| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1793| 801 | Capability not supported.| 1794 1795**Example** 1796 1797```ts 1798import { BusinessError } from '@kit.BasicServicesKit'; 1799 1800cloudData.sharing.queryParticipants('sharing_resource_test', ((err: BusinessError, result) => { 1801 if (err) { 1802 console.error(`query participants failed, code is ${err.code},message is ${err.message}`); 1803 return; 1804 } 1805 console.info(`query participants succeeded, result: ${result}`); 1806})) 1807 1808``` 1809 1810### queryParticipantsByInvitation<sup>11+</sup> 1811 1812queryParticipantsByInvitation(invitationCode: string): Promise<Result<Array<Participant>>> 1813 1814Queries the participants based on the sharing invitation code. This API uses a promise to return the result. 1815 1816**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1817 1818**Parameters** 1819 1820| Name | Type | Mandatory| Description | 1821| --------- | ------------------------------- | ---- | ---------------------------- | 1822| invitationCode | string | Yes | Invitation code of the share.| 1823 1824**Return value** 1825 1826| Type | Description | 1827| ------------------- | ------------------------- | 1828| Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| 1829 1830**Error codes** 1831 1832For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1833 1834| ID| Error Message | 1835| -------- | ---------------------------------------------------- | 1836| 202 | Permission verification failed, application which is not a system application uses system API.| 1837| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1838| 801 | Capability not supported.| 1839 1840**Example** 1841 1842```ts 1843import { BusinessError } from '@kit.BasicServicesKit'; 1844 1845cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test').then((result) => { 1846 console.info(`query participants by invitation succeeded, result: ${result}`); 1847}).catch((err: BusinessError) => { 1848 console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); 1849}) 1850 1851``` 1852 1853### queryParticipantsByInvitation<sup>11+</sup> 1854 1855queryParticipantsByInvitation(invitationCode: string, callback: AsyncCallback<Result<Array<Participant>>>): void 1856 1857Queries the participants based on the sharing invitation code. This API uses an asynchronous callback to return the result. 1858 1859**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1860 1861**Parameters** 1862 1863| Name | Type | Mandatory| Description | 1864| --------- | ------------------------------- | ---- | ---------------------------- | 1865| invitationCode | string | Yes | Invitation code of the share.| 1866| callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback used to return the participants obtained.| 1867 1868**Error codes** 1869 1870For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1871 1872| ID| Error Message | 1873| -------- | ---------------------------------------------------- | 1874| 202 | Permission verification failed, application which is not a system application uses system API.| 1875| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1876| 801 | Capability not supported.| 1877 1878**Example** 1879 1880```ts 1881import { BusinessError } from '@kit.BasicServicesKit'; 1882 1883cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test', ((err: BusinessError, result) => { 1884 if (err) { 1885 console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); 1886 return; 1887 } 1888 console.info(`query participants by invitation succeeded, result: ${result}`); 1889})) 1890 1891``` 1892 1893### confirmInvitation<sup>11+</sup> 1894 1895confirmInvitation(invitationCode: string, state: State): Promise<Result<string>> 1896 1897Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses a promise to return the result. 1898 1899**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1900 1901**Parameters** 1902 1903| Name | Type | Mandatory| Description | 1904| --------- | ------------------------------- | ---- | ---------------------------- | 1905| invitationCode | string | Yes | Invitation code of the share.| 1906| state | [State](#state11) | Yes | Confirmation state.| 1907 1908**Return value** 1909 1910| Type | Description | 1911| ------------------- | ------------------------- | 1912| Promise<[Result](#resultt11)<string>> | Promise used to return the result.| 1913 1914**Error codes** 1915 1916For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1917 1918| ID| Error Message | 1919| -------- | ---------------------------------------------------- | 1920| 202 | Permission verification failed, application which is not a system application uses system API.| 1921| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1922| 801 | Capability not supported.| 1923 1924**Example** 1925 1926```ts 1927import { BusinessError } from '@kit.BasicServicesKit'; 1928 1929let shareResource: string | undefined; 1930cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED).then((result: cloudData.sharing.Result<string>) => { 1931 console.info(`confirm invitation succeeded, result: ${result}`); 1932 shareResource = result.value; 1933}).catch((err: BusinessError) => { 1934 console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); 1935}) 1936 1937``` 1938 1939### confirmInvitation<sup>11+</sup> 1940 1941confirmInvitation(invitationCode: string, state: State, callback: AsyncCallback<Result<string>>): void 1942 1943Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses an asynchronous callback to return the result. 1944 1945**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1946 1947**Parameters** 1948 1949| Name | Type | Mandatory| Description | 1950| --------- | ------------------------------- | ---- | ---------------------------- | 1951| invitationCode | string | Yes | Invitation code of the share.| 1952| state | [State](#state11) | Yes | Confirmation state.| 1953| callback | AsyncCallback<[Result](#resultt11)<string>> | Yes | Callback used to return the result. | 1954 1955**Error codes** 1956 1957For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1958 1959| ID| Error Message | 1960| -------- | ---------------------------------------------------- | 1961| 202 | Permission verification failed, application which is not a system application uses system API.| 1962| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1963| 801 | Capability not supported.| 1964 1965**Example** 1966 1967```ts 1968import { BusinessError } from '@kit.BasicServicesKit'; 1969 1970let shareResource: string; 1971cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED, ((err: BusinessError, result) => { 1972 if (err) { 1973 console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); 1974 return; 1975 } 1976 console.info(`confirm invitation succeeded, result: ${result}`); 1977 shareResource = result.value; 1978})) 1979 1980``` 1981 1982### changeConfirmation<sup>11+</sup> 1983 1984changeConfirmation(sharingResource: string, state: State): Promise<Result<void>> 1985 1986Changes the invitation confirmation state based on the shared resource ID. This API uses a promise to return the result. 1987 1988**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1989 1990**Parameters** 1991 1992| Name | Type | Mandatory| Description | 1993| --------- | ------------------------------- | ---- | ---------------------------- | 1994| sharingResource | string | Yes | Shared resource ID.| 1995| state | [State](#state11) | Yes | New confirmation state of the invitation.| 1996 1997**Return value** 1998 1999| Type | Description | 2000| ------------------- | ------------------------- | 2001| Promise<[Result](#resultt11)<void>> | Promise used to return the result.| 2002 2003**Error codes** 2004 2005For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2006 2007| ID| Error Message | 2008| -------- | ---------------------------------------------------- | 2009| 202 | Permission verification failed, application which is not a system application uses system API.| 2010| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 2011| 801 | Capability not supported.| 2012 2013**Example** 2014 2015```ts 2016import { BusinessError } from '@kit.BasicServicesKit'; 2017 2018cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED).then((result) => { 2019 console.info(`change confirmation succeeded, result: ${result}`); 2020}).catch((err: BusinessError) => { 2021 console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); 2022}) 2023 2024``` 2025 2026### changeConfirmation<sup>11+</sup> 2027 2028changeConfirmation(sharingResource: string, state: State, callback: AsyncCallback<Result<void>>): void; 2029 2030Changes the invitation confirmation state based on the shared resource ID. This API uses an asynchronous callback to return the result. 2031 2032**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 2033 2034**Parameters** 2035 2036| Name | Type | Mandatory| Description | 2037| --------- | ------------------------------- | ---- | ---------------------------- | 2038| sharingResource | string | Yes | Shared resource ID.| 2039| state | [State](#state11) | Yes | New confirmation state of the invitation.| 2040| callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback used to return the result. | 2041 2042**Error codes** 2043 2044For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2045 2046| ID| Error Message | 2047| -------- | ---------------------------------------------------- | 2048| 202 | Permission verification failed, application which is not a system application uses system API.| 2049| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 2050| 801 | Capability not supported.| 2051 2052**Example** 2053 2054```ts 2055import { BusinessError } from '@kit.BasicServicesKit'; 2056 2057cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED, ((err: BusinessError, result) => { 2058 if (err) { 2059 console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); 2060 return; 2061 } 2062 console.info(`change confirmation succeeded, result: ${result}`); 2063})) 2064 2065``` 2066 2067