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