1# @ohos.continuation.continuationManager (continuationManager) 2 3The **continuationManager** module provides the continuation management entry. You can use the APIs of this module to connect to and cancel the continuation management service, subscribe to and unsubscribe from device connection events, start the device selection module, and update the device connection state. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import continuationManager from '@ohos.continuation.continuationManager' 13``` 14 15## continuationManager.register<sup>(deprecated)</sup> 16 17register(callback: AsyncCallback\<number>): void 18 19Registers the continuation management service and obtains a token. This API does not involve any filter parameters and uses an asynchronous callback to return the result. 20 21> **NOTE** 22> 23> This API is deprecated since API version 9. You are advised to use [registerContinuation](#continuationmanagerregistercontinuation9) instead. 24 25**System capability**: SystemCapability.Ability.DistributedAbilityManager 26 27**Parameters** 28 29 | Name| Type| Mandatory| Description| 30 | -------- | -------- | -------- | -------- | 31 | callback | AsyncCallback\<number> | Yes| Callback used to return the token generated after the continuation management service is connected.| 32 33**Example** 34 35 ```ts 36 import continuationManager from '@ohos.continuation.continuationManager' 37 38 let token: number = -1; 39 continuationManager.register((err, data) => { 40 if (err.code != 0) { 41 console.error('register failed, cause: ' + JSON.stringify(err)); 42 return; 43 } 44 console.info('register finished, ' + JSON.stringify(data)); 45 token = data; 46 }); 47 ``` 48 49## continuationManager.register<sup>(deprecated)</sup> 50 51register(options: ContinuationExtraParams, callback: AsyncCallback\<number>): void 52 53Registers the continuation management service and obtains a token. This API uses an asynchronous callback to return the result. 54 55> **NOTE** 56> 57> This API is deprecated since API version 9. You are advised to use [registerContinuation](#continuationmanagerregistercontinuation9-1) instead. 58 59**System capability**: SystemCapability.Ability.DistributedAbilityManager 60 61**Parameters** 62 63 | Name| Type| Mandatory| Description| 64 | -------- | -------- | -------- | -------- | 65 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | Yes| Extra parameters used to filter the list of available devices.| 66 | callback | AsyncCallback\<number> | Yes| Callback used to return the token generated after the continuation management service is connected.| 67 68**Example** 69 70 ```ts 71 import continuationManager from '@ohos.continuation.continuationManager' 72 73 let token: number = -1; 74 continuationManager.register( 75 { 76 deviceType: ["00E"] 77 }, 78 (err, data) => { 79 if (err.code != 0) { 80 console.error('register failed, cause: ' + JSON.stringify(err)); 81 return; 82 } 83 console.info('register finished, ' + JSON.stringify(data)); 84 token = data; 85 }); 86 ``` 87 88## continuationManager.register<sup>(deprecated)</sup> 89 90register(options?: ContinuationExtraParams): Promise\<number> 91 92Registers the continuation management service and obtains a token. This API uses a promise to return the result. 93 94> **NOTE** 95> 96> This API is deprecated since API version 9. You are advised to use [registerContinuation](#continuationmanagerregistercontinuation9-2) instead. 97 98**System capability**: SystemCapability.Ability.DistributedAbilityManager 99 100**Parameters** 101 102 | Name| Type| Mandatory| Description| 103 | -------- | -------- | -------- | -------- | 104 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | No| Extra parameters used to filter the list of available devices. This parameter can be null.| 105 106**Return value** 107 108| Type | Description | 109| ------------------------- | ------------------ | 110| Promise\<number> | Promise used to return the token generated after the continuation management service is connected.| 111 112**Example** 113 114 ```ts 115 import continuationManager from '@ohos.continuation.continuationManager' 116 import { BusinessError } from '@ohos.base'; 117 118 let token: number = -1; 119 continuationManager.register( 120 { deviceType: ["00E"] }).then((data) => { 121 console.info('register finished, ' + JSON.stringify(data)); 122 token = data; 123 }).catch((err: BusinessError) => { 124 console.error('register failed, cause: ' + JSON.stringify(err)); 125 }); 126 ``` 127 128## continuationManager.registerContinuation<sup>9+</sup> 129 130registerContinuation(callback: AsyncCallback\<number>): void 131 132Registers the continuation management service and obtains a token. This API does not involve any filter parameters and uses an asynchronous callback to return the result. 133 134**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 135 136**System capability**: SystemCapability.Ability.DistributedAbilityManager 137 138**Parameters** 139 140 | Name| Type| Mandatory| Description| 141 | -------- | -------- | -------- | -------- | 142 | callback | AsyncCallback\<number> | Yes| Callback used to return the token generated after the continuation management service is connected.| 143 144**Error codes** 145 146For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 147 148| ID| Error Message| 149| ------- | -------------------------------------------- | 150| 16600001 | The system ability works abnormally. | 151| 16600003 | The number of token registration times has reached the upper limit. | 152 153**Example** 154 155 ```ts 156 import continuationManager from '@ohos.continuation.continuationManager' 157 158 let token: number = -1; 159 try { 160 continuationManager.registerContinuation((err, data) => { 161 if (err.code != 0) { 162 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 163 return; 164 } 165 console.info('registerContinuation finished, ' + JSON.stringify(data)); 166 token = data; 167 }); 168 } catch (err) { 169 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 170 } 171 ``` 172 173## continuationManager.registerContinuation<sup>9+</sup> 174 175registerContinuation(options: ContinuationExtraParams, callback: AsyncCallback\<number>): void 176 177Registers the continuation management service and obtains a token. This API uses an asynchronous callback to return the result. 178 179**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 180 181**System capability**: SystemCapability.Ability.DistributedAbilityManager 182 183**Parameters** 184 185 | Name| Type| Mandatory| Description| 186 | -------- | -------- | -------- | -------- | 187 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | Yes| Extra parameters used to filter the list of available devices.| 188 | callback | AsyncCallback\<number> | Yes| Callback used to return the token generated after the continuation management service is connected.| 189 190**Error codes** 191 192For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 193 194| ID| Error Message| 195| ------- | -------------------------------------------- | 196| 16600001 | The system ability works abnormally. | 197| 16600003 | The number of token registration times has reached the upper limit. | 198 199**Example** 200 201 ```ts 202 import continuationManager from '@ohos.continuation.continuationManager'; 203 204 let token: number = -1; 205 try { 206 continuationManager.registerContinuation( 207 { 208 deviceType: ["00E"] 209 }, 210 (err, data) => { 211 if (err.code != 0) { 212 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 213 return; 214 } 215 console.info('registerContinuation finished, ' + JSON.stringify(data)); 216 token = data; 217 }); 218 } catch (err) { 219 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 220 } 221 ``` 222 223## continuationManager.registerContinuation<sup>9+</sup> 224 225registerContinuation(options?: ContinuationExtraParams): Promise\<number> 226 227Registers the continuation management service and obtains a token. This API uses a promise to return the result. 228 229**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 230 231**System capability**: SystemCapability.Ability.DistributedAbilityManager 232 233**Parameters** 234 235 | Name| Type| Mandatory| Description| 236 | -------- | -------- | -------- | -------- | 237 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | No| Extra parameters used to filter the list of available devices. This parameter can be null.| 238 239**Return value** 240 241| Type | Description | 242| ------------------------- | ------------------ | 243| Promise\<number> | Promise used to return the token generated after the continuation management service is connected.| 244 245**Error codes** 246 247For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 248 249| ID| Error Message| 250| ------- | -------------------------------------------- | 251| 16600001 | The system ability works abnormally. | 252| 16600003 | The number of token registration times has reached the upper limit. | 253 254**Example** 255 256 ```ts 257 import continuationManager from '@ohos.continuation.continuationManager'; 258 import { BusinessError } from '@ohos.base'; 259 260 let token: number = -1; 261 try { 262 continuationManager.registerContinuation( 263 { 264 deviceType: ["00E"] 265 }).then((data) => { 266 console.info('registerContinuation finished, ' + JSON.stringify(data)); 267 token = data; 268 }).catch((err: BusinessError) => { 269 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 270 }); 271 } catch (err) { 272 console.error('registerContinuation failed, cause: ' + JSON.stringify(err)); 273 } 274 ``` 275 276 277## continuationManager.on("deviceConnect")<sup>(deprecated)</sup> 278 279on(type: "deviceConnect", callback: Callback\<ContinuationResult>): void 280 281Subscribes to device connection events. This API uses an asynchronous callback to return the result. 282 283> **NOTE** 284> 285> This API is deprecated since API version 9. You are advised to use [on](#continuationmanagerondeviceselected9) instead. 286 287**System capability**: SystemCapability.Ability.DistributedAbilityManager 288 289**Parameters** 290 291 | Name| Type| Mandatory| Description| 292 | -------- | -------- | -------- | -------- | 293 | type | string | Yes| Event type. The value is fixed at **deviceConnect**.| 294 | callback | Callback\<[ContinuationResult](js-apis-continuation-continuationResult.md)> | Yes| Callback invoked when a device is selected from the device list provided by the device selection module. This callback returns the device ID, type, and name.| 295 296**Example** 297 298 ```ts 299 import continuationManager from '@ohos.continuation.continuationManager'; 300 301 continuationManager.on("deviceConnect", (data) => { 302 console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id)); 303 console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type)); 304 console.info('onDeviceConnect deviceName: ' + JSON.stringify(data.name)); 305 }); 306 ``` 307 308## continuationManager.on("deviceDisconnect")<sup>(deprecated)</sup> 309 310on(type: "deviceDisconnect", callback: Callback\<string>): void 311 312Subscribes to device disconnection events. This API uses an asynchronous callback to return the result. 313 314> **NOTE** 315> 316> This API is deprecated since API version 9. You are advised to use [on](#continuationmanagerondeviceunselected9) instead. 317 318**System capability**: SystemCapability.Ability.DistributedAbilityManager 319 320**Parameters** 321 322 | Name| Type| Mandatory| Description| 323 | -------- | -------- | -------- | -------- | 324 | type | string | Yes| Event type. The value is fixed at **deviceDisconnect**.| 325 | callback | Callback\<string> | Yes| Callback invoked when a device is unselected from the device list provided by the device selection module. This callback returns the device ID.| 326 327**Example** 328 329 ```ts 330 import continuationManager from '@ohos.continuation.continuationManager'; 331 332 continuationManager.on("deviceDisconnect", (data) => { 333 console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data)); 334 }); 335 ``` 336 337## continuationManager.off("deviceConnect")<sup>(deprecated)</sup> 338 339off(type: "deviceConnect", callback?: Callback\<ContinuationResult>): void 340 341Unsubscribes from device connection events. This API uses an asynchronous callback to return the result. 342 343> **NOTE** 344> 345> This API is deprecated since API version 9. You are advised to use [off](#continuationmanageroffdeviceselected9) instead. 346 347**System capability**: SystemCapability.Ability.DistributedAbilityManager 348 349**Parameters** 350 351 | Name| Type| Mandatory| Description| 352 | -------- | -------- | -------- | -------- | 353 | type | string | Yes| Event type. The value is fixed at **deviceConnect**.| 354 | callback | Callback\<[ContinuationResult](js-apis-continuation-continuationResult.md)> | No| Callback invoked when a device is selected from the device list provided by the device selection module. This callback returns the device ID, type, and name.| 355 356**Example** 357 358 ```ts 359 import continuationManager from '@ohos.continuation.continuationManager'; 360 361 continuationManager.off("deviceConnect", (data) => { 362 console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id)); 363 console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type)); 364 console.info('onDeviceConnect deviceName: ' + JSON.stringify(data.name)); 365 }); 366 ``` 367 368## continuationManager.off("deviceDisconnect")<sup>(deprecated)</sup> 369 370off(type: "deviceDisconnect", callback?: Callback\<string>): void 371 372Unsubscribes from device disconnection events. This API uses an asynchronous callback to return the result. 373 374> **NOTE** 375> 376> This API is deprecated since API version 9. You are advised to use [off](#continuationmanageroffdeviceunselected9) instead. 377 378**System capability**: SystemCapability.Ability.DistributedAbilityManager 379 380**Parameters** 381 382 | Name| Type| Mandatory| Description| 383 | -------- | -------- | -------- | -------- | 384 | type | string | Yes| Event type. The value is fixed at **deviceDisconnect**.| 385 | callback | Callback\<string> | No| Callback invoked when a device is unselected from the device list provided by the device selection module. This callback returns the device ID.| 386 387**Example** 388 389 ```ts 390 import continuationManager from '@ohos.continuation.continuationManager'; 391 392 continuationManager.off("deviceDisconnect", (data) => { 393 console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data)); 394 }); 395 ``` 396 397## continuationManager.on("deviceSelected")<sup>9+</sup> 398 399on(type: "deviceSelected", token: number, callback: Callback\<Array\<ContinuationResult>>): void 400 401Subscribes to device connection events. This API uses an asynchronous callback to return the result. 402 403**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 404 405**System capability**: SystemCapability.Ability.DistributedAbilityManager 406 407**Parameters** 408 409 | Name| Type| Mandatory| Description| 410 | -------- | -------- | -------- | -------- | 411 | type | string | Yes| Event type. The value is fixed at **deviceSelected**.| 412 | token | number | Yes| Token obtained after the registration of the continuation management service.| 413 | callback | Callback\<Array\<[ContinuationResult](js-apis-continuation-continuationResult.md)>> | Yes| Callback invoked when a device is selected from the device list provided by the device selection module. This callback returns the device ID, type, and name.| 414 415**Error codes** 416 417For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 418 419| ID| Error Message| 420| ------- | -------------------------------------------- | 421| 16600001 | The system ability works abnormally. | 422| 16600002 | The specified token or callback is not registered. | 423| 16600004 | The specified callback has been registered. | 424 425**Example** 426 427 ```ts 428 import continuationManager from '@ohos.continuation.continuationManager'; 429 430 let token: number = 1; 431 try { 432 continuationManager.on("deviceSelected", token, (data) => { 433 console.info('onDeviceSelected len: ' + data.length); 434 for (let i = 0; i < data.length; i++) { 435 console.info('onDeviceSelected deviceId: ' + JSON.stringify(data[i].id)); 436 console.info('onDeviceSelected deviceType: ' + JSON.stringify(data[i].type)); 437 console.info('onDeviceSelected deviceName: ' + JSON.stringify(data[i].name)); 438 } 439 }); 440 } catch (err) { 441 console.error('on failed, cause: ' + JSON.stringify(err)); 442 } 443 ``` 444 445## continuationManager.on("deviceUnselected")<sup>9+</sup> 446 447on(type: "deviceUnselected", token: number, callback: Callback\<Array\<ContinuationResult>>): void 448 449Subscribes to device disconnection events. This API uses an asynchronous callback to return the result. 450 451**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 452 453**System capability**: SystemCapability.Ability.DistributedAbilityManager 454 455**Parameters** 456 457 | Name| Type| Mandatory| Description| 458 | -------- | -------- | -------- | -------- | 459 | type | string | Yes| Event type. The value is fixed at **deviceUnselected**.| 460 | token | number | Yes| Token obtained after the registration of the continuation management service.| 461 | callback | Callback\<Array\<[ContinuationResult](js-apis-continuation-continuationResult.md)>> | Yes| Callback invoked when a device is unselected from the device list provided by the device selection module. This callback returns the device ID, type, and name.| 462 463**Error codes** 464 465For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 466 467| ID| Error Message| 468| ------- | -------------------------------------------- | 469| 16600001 | The system ability works abnormally. | 470| 16600002 | The specified token or callback is not registered. | 471| 16600004 | The specified callback has been registered. | 472 473**Example** 474 475 ```ts 476 import continuationManager from '@ohos.continuation.continuationManager'; 477 478 let token: number = 1; 479 try { 480 continuationManager.on("deviceUnselected", token, (data) => { 481 console.info('onDeviceUnselected len: ' + data.length); 482 for (let i = 0; i < data.length; i++) { 483 console.info('onDeviceUnselected deviceId: ' + JSON.stringify(data[i].id)); 484 console.info('onDeviceUnselected deviceType: ' + JSON.stringify(data[i].type)); 485 console.info('onDeviceUnselected deviceName: ' + JSON.stringify(data[i].name)); 486 } 487 console.info('onDeviceUnselected finished.'); 488 }); 489 } catch (err) { 490 console.error('on failed, cause: ' + JSON.stringify(err)); 491 } 492 ``` 493 494## continuationManager.off("deviceSelected")<sup>9+</sup> 495 496off(type: "deviceSelected", token: number): void 497 498Unsubscribes from device connection events. 499 500**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 501 502**System capability**: SystemCapability.Ability.DistributedAbilityManager 503 504**Parameters** 505 506 | Name| Type| Mandatory| Description| 507 | -------- | -------- | -------- | -------- | 508 | type | string | Yes| Event type. The value is fixed at **deviceSelected**.| 509 | token | number | Yes| Token obtained after the registration of the continuation management service.| 510 511**Error codes** 512 513For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 514 515| ID| Error Message| 516| ------- | -------------------------------------------- | 517| 16600001 | The system ability works abnormally. | 518| 16600002 | The specified token or callback is not registered. | 519| 16600004 | The specified callback has been registered. | 520 521**Example** 522 523 ```ts 524 import continuationManager from '@ohos.continuation.continuationManager'; 525 526 let token: number = 1; 527 try { 528 continuationManager.off("deviceSelected", token); 529 } catch (err) { 530 console.error('off failed, cause: ' + JSON.stringify(err)); 531 } 532 ``` 533 534## continuationManager.off("deviceUnselected")<sup>9+</sup> 535 536off(type: "deviceUnselected", token: number): void 537 538Unsubscribes from device disconnection events. 539 540**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 541 542**System capability**: SystemCapability.Ability.DistributedAbilityManager 543 544**Parameters** 545 546 | Name| Type| Mandatory| Description| 547 | -------- | -------- | -------- | -------- | 548 | type | string | Yes| Event type. The value is fixed at **deviceUnselected**.| 549 | token | number | Yes| Token obtained after the registration of the continuation management service.| 550 551**Error codes** 552 553For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 554 555| ID| Error Message| 556| ------- | -------------------------------------------- | 557| 16600001 | The system ability works abnormally. | 558| 16600002 | The specified token or callback is not registered. | 559| 16600004 | The specified callback has been registered. | 560 561**Example** 562 563 ```ts 564 import continuationManager from '@ohos.continuation.continuationManager'; 565 566 let token: number = 1; 567 try { 568 continuationManager.off("deviceUnselected", token); 569 } catch (err) { 570 console.error('off failed, cause: ' + JSON.stringify(err)); 571 } 572 ``` 573 574## continuationManager.startDeviceManager<sup>(deprecated)</sup> 575 576startDeviceManager(token: number, callback: AsyncCallback\<void>): void 577 578Starts the device selection module to show the list of available devices on the network. This API does not involve any filter parameters and uses an asynchronous callback to return the result. 579 580> **NOTE** 581> 582> This API is deprecated since API version 9. You are advised to use [startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9) instead. 583 584**System capability**: SystemCapability.Ability.DistributedAbilityManager 585 586**Parameters** 587 588 | Name| Type| Mandatory| Description| 589 | -------- | -------- | -------- | -------- | 590 | token | number | Yes| Token obtained after the registration of the continuation management service.| 591 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the module is started, **err** is **undefined**; otherwise, **err** is an error object.| 592 593**Example** 594 595 ```ts 596 import continuationManager from '@ohos.continuation.continuationManager'; 597 598 let token: number = 1; 599 continuationManager.startDeviceManager(token, (err) => { 600 if (err.code != 0) { 601 console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 602 return; 603 } 604 console.info('startDeviceManager finished. '); 605 }); 606 ``` 607 608## continuationManager.startDeviceManager<sup>(deprecated)</sup> 609 610startDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback\<void>): void 611 612Starts the device selection module to show the list of available devices on the network. This API uses an asynchronous callback to return the result. 613 614> **NOTE** 615> 616> This API is deprecated since API version 9. You are advised to use [startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9-1) instead. 617 618**System capability**: SystemCapability.Ability.DistributedAbilityManager 619 620**Parameters** 621 622 | Name| Type| Mandatory| Description| 623 | -------- | -------- | -------- | -------- | 624 | token | number | Yes| Token obtained after the registration of the continuation management service.| 625 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | Yes| Extra parameters used to filter the list of available devices.| 626 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the module is started, **err** is **undefined**; otherwise, **err** is an error object.| 627 628**Example** 629 630 ```ts 631 import continuationManager from '@ohos.continuation.continuationManager'; 632 633 let token: number = 1; 634 continuationManager.startDeviceManager( 635 token, 636 { 637 deviceType: ["00E"] 638 }, 639 (err) => { 640 if (err.code != 0) { 641 console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 642 return; 643 } 644 console.info('startDeviceManager finished. '); 645 }); 646 ``` 647 648## continuationManager.startDeviceManager<sup>(deprecated)</sup> 649 650startDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<void> 651 652Starts the device selection module to show the list of available devices on the network. This API uses a promise to return the result. 653 654> **NOTE** 655> 656> This API is deprecated since API version 9. You are advised to use [startContinuationDeviceManager](#continuationmanagerstartcontinuationdevicemanager9-2) instead. 657 658**System capability**: SystemCapability.Ability.DistributedAbilityManager 659 660**Parameters** 661 662 | Name| Type| Mandatory| Description| 663 | -------- | -------- | -------- | -------- | 664 | token | number | Yes| Token obtained after the registration of the continuation management service.| 665 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | No| Extra parameters used to filter the list of available devices. This parameter can be null.| 666 667**Return value** 668 669| Type | Description | 670| ------------------------- | ------------------ | 671| Promise\<void> | Promise used to return the result.| 672 673**Example** 674 675 ```ts 676 import continuationManager from '@ohos.continuation.continuationManager'; 677 import { BusinessError } from '@ohos.base'; 678 679 let token: number = -1; 680 continuationManager.startDeviceManager( 681 token, 682 { 683 deviceType: ["00E"] 684 }).then(() => { 685 console.info('startDeviceManager finished. '); 686 }).catch((err: BusinessError) => { 687 console.error('startDeviceManager failed, cause: ' + JSON.stringify(err)); 688 }); 689 ``` 690 691## continuationManager.startContinuationDeviceManager<sup>9+</sup> 692 693startContinuationDeviceManager(token: number, callback: AsyncCallback\<void>): void 694 695Starts the device selection module to show the list of available devices on the network. This API does not involve any filter parameters and uses an asynchronous callback to return the result. 696 697**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 698 699**System capability**: SystemCapability.Ability.DistributedAbilityManager 700 701**Parameters** 702 703 | Name| Type| Mandatory| Description| 704 | -------- | -------- | -------- | -------- | 705 | token | number | Yes| Token obtained after the registration of the continuation management service.| 706 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the module is started, **err** is **undefined**; otherwise, **err** is an error object.| 707 708**Error codes** 709 710For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 711 712| ID| Error Message| 713| ------- | -------------------------------------------- | 714| 16600001 | The system ability works abnormally. | 715| 16600002 | The specified token or callback is not registered. | 716 717**Example** 718 719 ```ts 720 import continuationManager from '@ohos.continuation.continuationManager'; 721 722 let token: number = -1; 723 try { 724 continuationManager.startContinuationDeviceManager(token, (err) => { 725 if (err.code != 0) { 726 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 727 return; 728 } 729 console.info('startContinuationDeviceManager finished. '); 730 }); 731 } catch (err) { 732 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 733 } 734 ``` 735 736## continuationManager.startContinuationDeviceManager<sup>9+</sup> 737 738startContinuationDeviceManager(token: number, options: ContinuationExtraParams, callback: AsyncCallback\<void>): void 739 740Starts the device selection module to show the list of available devices on the network. This API uses an asynchronous callback to return the result. 741 742**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 743 744**System capability**: SystemCapability.Ability.DistributedAbilityManager 745 746**Parameters** 747 748 | Name| Type| Mandatory| Description| 749 | -------- | -------- | -------- | -------- | 750 | token | number | Yes| Token obtained after the registration of the continuation management service.| 751 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | Yes| Extra parameters used to filter the list of available devices.| 752 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the module is started, **err** is **undefined**; otherwise, **err** is an error object.| 753 754**Error codes** 755 756For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 757 758| ID| Error Message| 759| ------- | -------------------------------------------- | 760| 16600001 | The system ability works abnormally. | 761| 16600002 | The specified token or callback is not registered. | 762 763**Example** 764 765 ```ts 766 import continuationManager from '@ohos.continuation.continuationManager'; 767 768 let token: number = -1; 769 try { 770 continuationManager.startContinuationDeviceManager( 771 token, 772 { 773 deviceType: ["00E"] 774 }, 775 (err) => { 776 if (err.code != 0) { 777 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 778 return; 779 } 780 console.info('startContinuationDeviceManager finished. '); 781 }); 782 } catch (err) { 783 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 784 } 785 ``` 786 787## continuationManager.startContinuationDeviceManager<sup>9+</sup> 788 789startContinuationDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<void> 790 791Starts the device selection module to show the list of available devices on the network. This API uses a promise to return the result. 792 793**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 794 795**System capability**: SystemCapability.Ability.DistributedAbilityManager 796 797**Parameters** 798 799 | Name| Type| Mandatory| Description| 800 | -------- | -------- | -------- | -------- | 801 | token | number | Yes| Token obtained after the registration of the continuation management service.| 802 | options | [ContinuationExtraParams](js-apis-continuation-continuationExtraParams.md) | No| Extra parameters used to filter the list of available devices. This parameter can be null.| 803 804**Return value** 805 806| Type | Description | 807| ------------------------- | ------------------ | 808| Promise\<void> | Promise used to return the result.| 809 810**Error codes** 811 812For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 813 814| ID| Error Message| 815| ------- | -------------------------------------------- | 816| 16600001 | The system ability works abnormally. | 817| 16600002 | The specified token or callback is not registered. | 818 819**Example** 820 821 ```ts 822 import continuationManager from '@ohos.continuation.continuationManager'; 823 import { BusinessError } from '@ohos.base'; 824 825 let token: number = -1; 826 try { 827 continuationManager.startContinuationDeviceManager( 828 token, 829 { 830 deviceType: ["00E"] 831 }).then(() => { 832 console.info('startContinuationDeviceManager finished. '); 833 }).catch((err: BusinessError) => { 834 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 835 }); 836 } catch (err) { 837 console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err)); 838 } 839 ``` 840 841## continuationManager.updateConnectStatus<sup>(deprecated)</sup> 842 843updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback\<void>): void 844 845Instructs the device selection module to update the device connection state. This API uses an asynchronous callback to return the result. 846 847> **NOTE** 848> 849> This API is deprecated since API version 9. You are advised to use [updateContinuationState](#continuationmanagerupdatecontinuationstate9) instead. 850 851**System capability**: SystemCapability.Ability.DistributedAbilityManager 852 853**Parameters** 854 855 | Name| Type| Mandatory| Description| 856 | -------- | -------- | -------- | -------- | 857 | token | number | Yes| Token obtained after the registration of the continuation management service.| 858 | deviceId | string | Yes| Device ID.| 859 | status | [DeviceConnectState](#deviceconnectstate) | Yes| Device connection state.| 860 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the state is updated, **err** is **undefined**; otherwise, **err** is an error object.| 861 862**Example** 863 864 ```ts 865 import continuationManager from '@ohos.continuation.continuationManager'; 866 867 let token: number = -1; 868 let deviceId: string = "test deviceId"; 869 continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err) => { 870 if (err.code != 0) { 871 console.error('updateConnectStatus failed, cause: ' + JSON.stringify(err)); 872 return; 873 } 874 console.info('updateConnectStatus finished. '); 875 }); 876 ``` 877 878## continuationManager.updateConnectStatus<sup>(deprecated)</sup> 879 880updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState): Promise\<void> 881 882Instructs the device selection module to update the device connection state. This API uses a promise to return the result. 883 884> **NOTE** 885> 886> This API is deprecated since API version 9. You are advised to use [updateContinuationState](#continuationmanagerupdatecontinuationstate9-1) instead. 887 888**System capability**: SystemCapability.Ability.DistributedAbilityManager 889 890**Parameters** 891 892 | Name| Type| Mandatory| Description| 893 | -------- | -------- | -------- | -------- | 894 | token | number | Yes| Token obtained after the registration of the continuation management service.| 895 | deviceId | string | Yes| Device ID.| 896 | status | [DeviceConnectState](#deviceconnectstate) | Yes| Device connection state.| 897 898**Return value** 899 900| Type | Description | 901| ------------------------- | ------------------ | 902| Promise\<void> | Promise used to return the result.| 903 904**Example** 905 906 ```ts 907 import continuationManager from '@ohos.continuation.continuationManager'; 908 import { BusinessError } from '@ohos.base'; 909 910 let token: number = 1; 911 let deviceId: string = "test deviceId"; 912 continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED) 913 .then(() => { 914 console.info('updateConnectStatus finished. '); 915 }) 916 .catch((err: BusinessError) => { 917 console.error('updateConnectStatus failed, cause: ' + JSON.stringify(err)); 918 }); 919 ``` 920 921## continuationManager.updateContinuationState<sup>9+</sup> 922 923updateContinuationState(token: number, deviceId: string, status: DeviceConnectState, callback: AsyncCallback\<void>): void 924 925Instructs the device selection module to update the device connection state. This API uses an asynchronous callback to return the result. 926 927**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 928 929**System capability**: SystemCapability.Ability.DistributedAbilityManager 930 931**Parameters** 932 933 | Name| Type| Mandatory| Description| 934 | -------- | -------- | -------- | -------- | 935 | token | number | Yes| Token obtained after the registration of the continuation management service.| 936 | deviceId | string | Yes| Device ID.| 937 | status | [DeviceConnectState](#deviceconnectstate) | Yes| Device connection state.| 938 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the state is updated, **err** is **undefined**; otherwise, **err** is an error object.| 939 940**Error codes** 941 942For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 943 944| ID| Error Message| 945| ------- | -------------------------------------------- | 946| 16600001 | The system ability works abnormally. | 947| 16600002 | The specified token or callback is not registered. | 948 949**Example** 950 951 ```ts 952 import continuationManager from '@ohos.continuation.continuationManager'; 953 954 let token: number = 1; 955 let deviceId: string = "test deviceId"; 956 try { 957 continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err) => { 958 if (err.code != 0) { 959 console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 960 return; 961 } 962 console.info('updateContinuationState finished. '); 963 }); 964 } catch (err) { 965 console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 966 } 967 ``` 968 969## continuationManager.updateContinuationState<sup>9+</sup> 970 971updateContinuationState(token: number, deviceId: string, status: DeviceConnectState): Promise\<void> 972 973Instructs the device selection module to update the device connection state. This API uses a promise to return the result. 974 975**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 976 977**System capability**: SystemCapability.Ability.DistributedAbilityManager 978 979**Parameters** 980 981 | Name| Type| Mandatory| Description| 982 | -------- | -------- | -------- | -------- | 983 | token | number | Yes| Token obtained after the registration of the continuation management service.| 984 | deviceId | string | Yes| Device ID.| 985 | status | [DeviceConnectState](#deviceconnectstate) | Yes| Device connection state.| 986 987**Return value** 988 989| Type | Description | 990| ------------------------- | ------------------ | 991| Promise\<void> | Promise used to return the result.| 992 993**Error codes** 994 995For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 996 997| ID| Error Message| 998| ------- | -------------------------------------------- | 999| 16600001 | The system ability works abnormally. | 1000| 16600002 | The specified token or callback is not registered. | 1001 1002**Example** 1003 1004 ```ts 1005 import continuationManager from '@ohos.continuation.continuationManager'; 1006 import { BusinessError } from '@ohos.base'; 1007 1008 let token: number = 1; 1009 let deviceId: string = "test deviceId"; 1010 try { 1011 continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED) 1012 .then(() => { 1013 console.info('updateContinuationState finished. '); 1014 }) 1015 .catch((err: BusinessError) => { 1016 console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1017 }); 1018 } catch (err) { 1019 console.error('updateContinuationState failed, cause: ' + JSON.stringify(err)); 1020 } 1021 ``` 1022 1023 1024## continuationManager.unregister<sup>(deprecated)</sup> 1025 1026unregister(token: number, callback: AsyncCallback\<void>): void 1027 1028Unregisters the continuation management service. This API uses an asynchronous callback to return the result. 1029 1030> **NOTE** 1031> 1032> This API is deprecated since API version 9. You are advised to use [unregisterContinuation](#continuationmanagerunregistercontinuation9) instead. 1033 1034**System capability**: SystemCapability.Ability.DistributedAbilityManager 1035 1036**Parameters** 1037 1038 | Name| Type| Mandatory| Description| 1039 | -------- | -------- | -------- | -------- | 1040 | token | number | Yes| Token obtained after the registration of the continuation management service.| 1041 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the unregistration is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1042 1043**Example** 1044 1045 ```ts 1046 import continuationManager from '@ohos.continuation.continuationManager'; 1047 1048 let token: number = 1; 1049 continuationManager.unregister(token, (err) => { 1050 if (err.code != 0) { 1051 console.error('unregister failed, cause: ' + JSON.stringify(err)); 1052 return; 1053 } 1054 console.info('unregister finished. '); 1055 }); 1056 ``` 1057 1058## continuationManager.unregister<sup>(deprecated)</sup> 1059 1060unregister(token: number): Promise\<void> 1061 1062Unregisters the continuation management service. This API uses a promise to return the result. 1063 1064> **NOTE** 1065> 1066> This API is deprecated since API version 9. You are advised to use [unregisterContinuation](#continuationmanagerunregistercontinuation9-1) instead. 1067 1068**System capability**: SystemCapability.Ability.DistributedAbilityManager 1069 1070**Parameters** 1071 1072 | Name| Type| Mandatory| Description| 1073 | -------- | -------- | -------- | -------- | 1074 | token | number | Yes| Token obtained after the registration of the continuation management service.| 1075 1076**Return value** 1077 1078| Type | Description | 1079| ------------------------- | ------------------ | 1080| Promise\<void> | Promise used to return the result.| 1081 1082**Example** 1083 1084 ```ts 1085 import continuationManager from '@ohos.continuation.continuationManager'; 1086 import { BusinessError } from '@ohos.base'; 1087 1088 let token: number = 1; 1089 continuationManager.unregister(token) 1090 .then(() => { 1091 console.info('unregister finished. '); 1092 }).catch((err: BusinessError) => { 1093 console.error('unregister failed, cause: ' + JSON.stringify(err)); 1094 }); 1095 ``` 1096 1097## continuationManager.unregisterContinuation<sup>9+</sup> 1098 1099unregisterContinuation(token: number, callback: AsyncCallback\<void>): void 1100 1101Unregisters the continuation management service. This API uses an asynchronous callback to return the result. 1102 1103**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 1104 1105**System capability**: SystemCapability.Ability.DistributedAbilityManager 1106 1107**Parameters** 1108 1109 | Name| Type| Mandatory| Description| 1110 | -------- | -------- | -------- | -------- | 1111 | token | number | Yes| Token obtained after the registration of the continuation management service.| 1112 | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the unregistration is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1113 1114**Error codes** 1115 1116For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 1117 1118| ID| Error Message| 1119| ------- | -------------------------------------------- | 1120| 16600001 | The system ability works abnormally. | 1121| 16600002 | The specified token or callback is not registered. | 1122 1123**Example** 1124 1125 ```ts 1126 import continuationManager from '@ohos.continuation.continuationManager'; 1127 import { BusinessError } from '@ohos.base'; 1128 1129 let token: number = 1; 1130 try { 1131 continuationManager.unregisterContinuation(token, (err) => { 1132 if (err.code != 0) { 1133 console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1134 return; 1135 } 1136 console.info('unregisterContinuation finished. '); 1137 }); 1138 } catch (err) { 1139 console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1140 } 1141 ``` 1142 1143## continuationManager.unregisterContinuation<sup>9+</sup> 1144 1145unregisterContinuation(token: number): Promise\<void> 1146 1147Unregisters the continuation management service. This API uses a promise to return the result. 1148 1149**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 1150 1151**System capability**: SystemCapability.Ability.DistributedAbilityManager 1152 1153**Parameters** 1154 1155 | Name| Type| Mandatory| Description| 1156 | -------- | -------- | -------- | -------- | 1157 | token | number | Yes| Token obtained after the registration of the continuation management service.| 1158 1159**Return value** 1160 1161| Type | Description | 1162| ------------------------- | ------------------ | 1163| Promise\<void> | Promise used to return the result.| 1164 1165**Error codes** 1166 1167For details about the error codes, see [Distributed Scheduler Error Codes](../errorcodes/errorcode-DistributedSchedule.md). 1168 1169| ID| Error Message| 1170| ------- | -------------------------------------------- | 1171| 16600001 | The system ability works abnormally. | 1172| 16600002 | The specified token or callback is not registered. | 1173 1174**Example** 1175 1176 ```ts 1177 import continuationManager from '@ohos.continuation.continuationManager'; 1178 import { BusinessError } from '@ohos.base'; 1179 1180 let token: number = -1; 1181 try { 1182 continuationManager.unregisterContinuation(token).then(() => { 1183 console.info('unregisterContinuation finished. '); 1184 }).catch((err: BusinessError) => { 1185 console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1186 }); 1187 } catch (err) { 1188 console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err)); 1189 } 1190 ``` 1191 1192 1193## DeviceConnectState 1194 1195Enumerates the device connection states. 1196 1197**System capability**: SystemCapability.Ability.DistributedAbilityManager 1198 1199| Name| Value| Description| 1200| -------- | -------- | -------- | 1201| IDLE | 0 | The device is in the initial state.| 1202| CONNECTING | 1 | The device is being connected.| 1203| CONNECTED | 2 | The device is connected.| 1204| DISCONNECTING | 3 | The device is being disconnected.| 1205 1206## ContinuationMode 1207 1208Enumerates the continuation modes provided by the device selection module. 1209 1210**System capability**: SystemCapability.Ability.DistributedAbilityManager 1211 1212| Name| Value| Description| 1213| -------- | -------- | -------- | 1214| COLLABORATION_SINGLE | 0 | Single-choice mode.| 1215| COLLABORATION_MULTIPLE | 1 | Multi-choice mode.| 1216