1# @ohos.distributedMissionManager (Distributed Mission Management) (System API) 2 3The distributedMissionManager module implements mission management across devices. You can use the APIs provided by this module to register or unregister a mission status listener, start or stop synchronizing a remote mission list, and continue a mission on a remote device by mission ID or bundle name. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```js 14import { distributedMissionManager } from '@kit.AbilityKit'; 15``` 16 17## distributedMissionManager.registerMissionListener 18 19registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback, callback: AsyncCallback<void>): void; 20 21Registers a mission status listener. This API uses an asynchronous callback to return the result. 22 23**Required permissions**: ohos.permission.MANAGE_MISSIONS 24 25**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 26 27**Parameters** 28 29| Name | Type | Mandatory | Description | 30| --------- | --------------------------------------- | ---- | --------- | 31| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for.| 32| options | [MissionCallback](#missioncallback) | Yes | Callback to register.| 33| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the listener is registered, **err** is **undefined**; otherwise, **err** is an error object.| 34 35**Error codes** 36 37For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 38 39| ID| Error Message| 40| ------- | -------------------------------- | 41| 201 | Permission denied.| 42| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 43 44**Example** 45 46 ```ts 47 import { distributedMissionManager } from '@kit.AbilityKit'; 48 import { BusinessError } from '@kit.BasicServicesKit'; 49 50 // Implement a callback function. 51 function NotifyMissionsChanged(deviceId: string): void { 52 console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(deviceId)); 53 } 54 function NotifySnapshot(deviceId: string, missionId: number): void { 55 console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId)); 56 console.log('NotifySnapshot missionId ' + JSON.stringify(missionId)); 57 } 58 function NotifyNetDisconnect(deviceId: string, state: number): void { 59 console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId)); 60 console.log('NotifyNetDisconnect state ' + JSON.stringify(state)); 61 } 62 try { 63 // Call registerMissionListener. 64 distributedMissionManager.registerMissionListener( 65 { deviceId: "" }, 66 { 67 notifyMissionsChanged: NotifyMissionsChanged, 68 notifySnapshot: NotifySnapshot, 69 notifyNetDisconnect: NotifyNetDisconnect 70 }, 71 (error: BusinessError) => { 72 if (error) { 73 console.error('registerMissionListener failed, cause: ' + JSON.stringify(error)); 74 return; 75 } 76 console.info('registerMissionListener finished'); 77 }); 78 } catch (error) { 79 console.error('registerMissionListener failed, cause: ' + JSON.stringify(error)); 80 } 81 ``` 82## distributedMissionManager.registerMissionListener 83 84registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback): Promise<void> 85 86Registers a mission status listener. This API uses a promise to return the result. 87 88**Required permissions**: ohos.permission.MANAGE_MISSIONS 89 90**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 91 92**Parameters** 93 94| Name | Type | Mandatory | Description | 95| --------- | ---------------------------------------- | ---- | -------- | 96| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. | 97| options | <a href="#missioncallback">MissionCallback</a> | Yes | Callback to register.| 98 99**Return value** 100 101| Type | Description | 102| ------------------- | ---------------- | 103| Promise<void> | Promise that returns no value.| 104 105**Error codes** 106 107For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 108 109| ID| Error Message| 110| ------- | -------------------------------- | 111| 201 | Permission denied.| 112| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 113 114**Example** 115 116 ```ts 117 import { distributedMissionManager } from '@kit.AbilityKit'; 118 import { BusinessError } from '@kit.BasicServicesKit'; 119 120 // Implement a callback function. 121 function NotifyMissionsChanged(deviceId: string): void { 122 console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(deviceId)); 123 } 124 function NotifySnapshot(deviceId: string, missionId: number): void { 125 console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId)); 126 console.log('NotifySnapshot missionId ' + JSON.stringify(missionId)); 127 } 128 function NotifyNetDisconnect(deviceId: string, state: number): void { 129 console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId)); 130 console.log('NotifyNetDisconnect state ' + JSON.stringify(state)); 131 } 132 try { 133 // Call registerMissionListener. 134 distributedMissionManager.registerMissionListener( 135 { deviceId: "" }, 136 { 137 notifyMissionsChanged: NotifyMissionsChanged, 138 notifySnapshot: NotifySnapshot, 139 notifyNetDisconnect: NotifyNetDisconnect 140 }).then(() => { 141 console.info('registerMissionListener finished. '); 142 }).catch((error: BusinessError) => { 143 console.error('registerMissionListener failed, cause: ' + JSON.stringify(error)); 144 }) 145 } catch (error) { 146 console.error('registerMissionListener failed, cause: ' + JSON.stringify(error)); 147 } 148 ``` 149 150## distributedMissionManager.unRegisterMissionListener 151 152unRegisterMissionListener(parameter: MissionDeviceInfo, callback: AsyncCallback<void>): void; 153 154Unregisters a mission status listener. This API uses an asynchronous callback to return the result. 155 156**Required permissions**: ohos.permission.MANAGE_MISSIONS 157 158**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 159 160**Parameters** 161 162| Name | Type | Mandatory | Description | 163| --------- | --------------------------------------- | ---- | --------- | 164| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. | 165| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the listener is unregistered, **err** is **undefined**; otherwise, **err** is an error object.| 166 167**Error codes** 168 169For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 170 171| ID| Error Message| 172| ------- | -------------------------------- | 173| 201 | Permission denied.| 174| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 175 176**Example** 177 178 ```ts 179 import { distributedMissionManager } from '@kit.AbilityKit'; 180 import { BusinessError } from '@kit.BasicServicesKit'; 181 182 try { 183 distributedMissionManager.unRegisterMissionListener( 184 { deviceId: "" }, 185 (error: BusinessError) => { 186 if (error) { 187 console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error)); 188 return; 189 } 190 console.info('unRegisterMissionListener finished'); 191 }) 192 } catch (error) { 193 console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error)); 194 } 195 ``` 196 197## distributedMissionManager.unRegisterMissionListener 198 199unRegisterMissionListener(parameter: MissionDeviceInfo): Promise<void> 200 201Unregisters a mission status listener. This API uses a promise to return the result. 202 203**Required permissions**: ohos.permission.MANAGE_MISSIONS 204 205**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 206 207**Parameters** 208 209| Name | Type | Mandatory | Description | 210| --------- | --------------------------------------- | ---- | ----- | 211| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for.| 212 213**Return value** 214 215| Type | Description | 216| ------------------- | ---------------- | 217| Promise<void> |Promise that returns no value.| 218 219**Error codes** 220 221For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 222 223| ID| Error Message| 224| ------- | -------------------------------- | 225| 201 | Permission denied.| 226| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 227 228**Example** 229 230 ```ts 231 import { distributedMissionManager } from '@kit.AbilityKit'; 232 import { BusinessError } from '@kit.BasicServicesKit'; 233 234 try { 235 distributedMissionManager.unRegisterMissionListener({deviceId: ""}).then(() => { 236 console.info('unRegisterMissionListener finished successfully'); 237 }).catch((error: BusinessError) => { 238 console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error)); 239 }) 240 } catch (error) { 241 console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error)); 242 } 243 ``` 244 245## distributedMissionManager.startSyncRemoteMissions 246 247startSyncRemoteMissions(parameter: MissionParameter, callback: AsyncCallback<void>): void; 248 249Starts to synchronize the remote mission list. This API uses an asynchronous callback to return the result. 250 251**Required permissions**: ohos.permission.MANAGE_MISSIONS 252 253**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 254 255**Parameters** 256 257| Name | Type | Mandatory | Description | 258| --------- | ------------------------------------- | ---- | --------- | 259| parameter | [MissionParameter](#missionparameter) | Yes | Parameters required for synchronization. | 260| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the synchronization is started, **err** is **undefined**; otherwise, **err** is an error object.| 261 262**Error codes** 263 264For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 265 266| ID| Error Message| 267| ------- | -------------------------------- | 268| 201 | Permission denied.| 269| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 270 271**Example** 272 273 ```ts 274 import { distributedMissionManager } from '@kit.AbilityKit'; 275 import { BusinessError } from '@kit.BasicServicesKit'; 276 277 try { 278 distributedMissionManager.startSyncRemoteMissions( 279 { 280 deviceId: "", 281 fixConflict: false, 282 tag: 0 283 }, 284 (error: BusinessError) => { 285 if (error) { 286 console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 287 return; 288 } 289 console.info('startSyncRemoteMissions finished');} 290 ) 291 } catch (error) { 292 console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 293 } 294 ``` 295 296## distributedMissionManager.startSyncRemoteMissions 297 298startSyncRemoteMissions(parameter: MissionParameter): Promise<void> 299 300Starts to synchronize the remote mission list. This API uses a promise to return the result. 301 302**Required permissions**: ohos.permission.MANAGE_MISSIONS 303 304**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 305 306**Parameters** 307 308| Name | Type | Mandatory | Description | 309| --------- | ------------------------------------- | ---- | ----- | 310| parameter | [MissionParameter](#missionparameter) | Yes | Parameters required for synchronization.| 311 312**Return value** 313 314| Type | Description | 315| ------------------- | ---------------- | 316| Promise<void> | Promise that returns no value.| 317 318**Error codes** 319 320For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 321 322| ID| Error Message| 323| ------- | -------------------------------- | 324| 201 | Permission denied.| 325| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 326 327**Example** 328 329 ```ts 330 import { distributedMissionManager } from '@kit.AbilityKit'; 331 import { BusinessError } from '@kit.BasicServicesKit'; 332 333 try { 334 distributedMissionManager.startSyncRemoteMissions( 335 { 336 deviceId: "", 337 fixConflict: false, 338 tag: 0 339 } 340 ).then(() => { 341 console.info('startSyncRemoteMissions finished successfully'); 342 }).catch((error: BusinessError) => { 343 console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 344 }) 345 } catch (error) { 346 console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 347 } 348 ``` 349 350## distributedMissionManager.stopSyncRemoteMissions 351 352stopSyncRemoteMissions(parameter: MissionDeviceInfo, callback: AsyncCallback<void>): void; 353 354Stops synchronizing the remote mission list. This API uses an asynchronous callback to return the result. 355 356**Required permissions**: ohos.permission.MANAGE_MISSIONS 357 358**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 359 360**Parameters** 361 362| Name | Type | Mandatory | Description | 363| --------- | --------------------------------------- | ---- | --------- | 364| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Parameters required for synchronization. | 365| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the synchronization is stopped, **err** is **undefined**; otherwise, **err** is an error object.| 366 367**Error codes** 368 369For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 370 371| ID| Error Message| 372| ------- | -------------------------------- | 373| 201 | Permission denied.| 374| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 375 376**Example** 377 378 ```ts 379 import { distributedMissionManager } from '@kit.AbilityKit'; 380 import { BusinessError } from '@kit.BasicServicesKit'; 381 382 try { 383 distributedMissionManager.stopSyncRemoteMissions( 384 { 385 deviceId: "" 386 }, 387 (error: BusinessError) => { 388 if (error) { 389 console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 390 return; 391 } 392 console.info('stopSyncRemoteMissions finished');} 393 ) 394 } catch (error) { 395 console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 396 } 397 ``` 398 399## distributedMissionManager.stopSyncRemoteMissions 400 401stopSyncRemoteMissions(parameter: MissionDeviceInfo): Promise<void> 402 403Stops synchronizing the remote mission list. This API uses a promise to return the result. 404 405**Required permissions**: ohos.permission.MANAGE_MISSIONS 406 407**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 408 409**Parameters** 410 411| Name | Type | Mandatory | Description | 412| --------- | --------------------------------------- | ---- | ----- | 413| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Parameters required for synchronization.| 414 415**Return value** 416 417| Type | Description | 418| ------------------- | ---------------- | 419| Promise<void> | Promise that returns no value.| 420 421**Error codes** 422 423For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 424 425| ID| Error Message| 426| ------- | -------------------------------- | 427| 201 | Permission denied.| 428| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 429 430**Example** 431 432 ```ts 433 import { distributedMissionManager } from '@kit.AbilityKit'; 434 import { BusinessError } from '@kit.BasicServicesKit'; 435 436 try { 437 distributedMissionManager.stopSyncRemoteMissions( 438 { 439 deviceId: "" 440 }).then(() => { 441 console.info('stopSyncRemoteMissions finished successfully'); 442 }).catch((error: BusinessError) => { 443 console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 444 }) 445 } catch (error) { 446 console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error)); 447 } 448 ``` 449 450## distributedMissionManager.continueMission 451 452continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callback: AsyncCallback<void>): void; 453 454Continues a mission on a remote device, with the mission ID specified. This API uses an asynchronous callback to return the result. 455 456**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC 457 458**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 459 460**Parameters** 461 462| Name | Type | Mandatory | Description | 463| --------- | --------------------------------------- | ---- | ----- | 464| parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo-sys.md) | Yes | Parameters required for mission continuation.| 465| options | [ContinueCallback](js-apis-inner-application-continueCallback-sys.md) | Yes | Callback invoked when the mission continuation is complete.| 466| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**; otherwise, **err** is an error object.| 467 468**Error codes** 469 470For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 471 472| ID| Error Message| 473| ------- | -------------------------------------------- | 474| 201 | Permission denied.| 475| 202 | The application is not system-app, can not use system-api. | 476| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 477| 16300501 | The system ability work abnormally. | 478| 16300502 | Failed to get the missionInfo of the specified missionId. | 479| 16300503 | The application is not installed on the remote end and installation-free is not supported. | 480| 16300504 | The application is not installed on the remote end but installation-free is supported, try again with freeInstall flag. | 481| 16300505 | The operation device must be the device where the application to be continued is located or the target device to be continued. | 482| 16300506 | The local continuation task is already in progress. | 483 484**Example** 485 486 ```ts 487 import { distributedMissionManager } from '@kit.AbilityKit'; 488 import { BusinessError } from '@kit.BasicServicesKit'; 489 490 // Implement a callback function. 491 function onContinueDone(resultCode: number): void { 492 console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode)); 493 }; 494 try { 495 // Call continueMission. 496 distributedMissionManager.continueMission( 497 { 498 srcDeviceId: "", 499 dstDeviceId: "", 500 missionId: 1, 501 wantParam: {"key": "value"} 502 }, 503 { onContinueDone: onContinueDone }, 504 (error: BusinessError) => { 505 if (error) { 506 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 507 return; 508 } 509 console.info('continueMission finished'); 510 }) 511 } catch (error) { 512 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 513 } 514 ``` 515 516## distributedMissionManager.continueMission 517 518continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promise<void> 519 520Continues a mission on a remote device, with the mission ID specified. This API uses a promise to return the result. 521 522**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC 523 524**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 525 526**Parameters** 527 528| Name | Type | Mandatory | Description | 529| --------- | --------------------------------------- | ---- | ----- | 530| parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo-sys.md) | Yes | Parameters required for mission continuation.| 531| options | [ContinueCallback](js-apis-inner-application-continueCallback-sys.md) | Yes | Callback invoked when the mission continuation is complete.| 532 533**Return value** 534 535| Type | Description | 536| ------------------- | ---------------- | 537| Promise<void> |Promise that returns no value.| 538 539**Error codes** 540 541For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 542 543| ID| Error Message| 544| ------- | -------------------------------------------- | 545| 201 | Permission denied.| 546| 202 | The application is not system-app, can not use system-api. | 547| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 548| 16300501 | The system ability work abnormally. | 549| 16300502 | Failed to get the missionInfo of the specified missionId. | 550| 16300503 | The application is not installed on the remote end and installation-free is not supported. | 551| 16300504 | The application is not installed on the remote end but installation-free is supported, try again with freeInstall flag. | 552| 16300505 | The operation device must be the device where the application to be continued is located or the target device to be continued. | 553| 16300506 | The local continuation task is already in progress. | 554 555**Example** 556 557 ```ts 558 import { distributedMissionManager } from '@kit.AbilityKit'; 559 import { BusinessError } from '@kit.BasicServicesKit'; 560 561 // Implement a callback function. 562 function onContinueDone(resultCode: number): void { 563 console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode)); 564 }; 565 try { 566 // Call continueMission. 567 distributedMissionManager.continueMission( 568 { 569 srcDeviceId: "", 570 dstDeviceId: "", 571 missionId: 1, 572 wantParam: {"key": "value"} 573 }, 574 { onContinueDone: onContinueDone }).then(() => { 575 console.info('continueMission finished successfully'); 576 }).catch((error: BusinessError) => { 577 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 578 }) 579 } catch (error) { 580 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 581 } 582 ``` 583 584## distributedMissionManager.continueMission<sup>10+</sup> 585 586continueMission(parameter: ContinueMissionInfo, callback: AsyncCallback<void>): void; 587 588Continues a mission on a remote device, with the bundle name specified. This API uses an asynchronous callback to return the result. 589 590**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC 591 592**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 593 594**Parameters** 595 596| Name | Type | Mandatory | Description | 597| --------- | --------------------------------------- | ---- | ----- | 598| parameter | [ContinueMissionInfo](./js-apis-inner-application-continueMissionInfo-sys.md) | Yes | Parameters required for mission continuation.| 599| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**; otherwise, **err** is an error object.| 600 601**Error codes** 602 603For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 604 605| ID| Error Message| 606| ------- | -------------------------------------------- | 607| 201 | Permission denied.| 608| 202 | The application is not system-app, can not use system-api. | 609| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 610| 16300501 | The system ability work abnormally. | 611| 16300503 | The application is not installed on the remote end and installation-free is not supported. | 612| 16300504 | The application is not installed on the remote end but installation-free is supported, try again with freeInstall flag. | 613| 16300505 | The operation device must be the device where the application to be continued is located or the target device to be continued. | 614| 16300506 | The local continuation task is already in progress. | 615| 16300507 | Failed to get the missionInfo of the specified bundle name. | 616 617**Example** 618 619 ```ts 620 import { distributedMissionManager } from '@kit.AbilityKit'; 621 import { BusinessError } from '@kit.BasicServicesKit'; 622 623 try { 624 distributedMissionManager.continueMission( 625 { 626 srcDeviceId: "", 627 dstDeviceId: "", 628 bundleName: "ohos.test.continueapp", 629 wantParam: {"key": "value"} 630 }, 631 (error: BusinessError) => { 632 if (error) { 633 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 634 return; 635 } 636 console.info('continueMission finished'); 637 }) 638 } catch (error) { 639 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 640 } 641 ``` 642 643## distributedMissionManager.continueMission<sup>10+</sup> 644 645continueMission(parameter: ContinueMissionInfo): Promise<void> 646 647Continues a mission on a remote device, with the bundle name specified. This API uses a promise to return the result. 648 649**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC 650 651**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 652 653**Parameters** 654 655| Name | Type | Mandatory | Description | 656| --------- | --------------------------------------- | ---- | ----- | 657| parameter | [ContinueMissionInfo](./js-apis-inner-application-continueMissionInfo-sys.md) | Yes | Parameters required for mission continuation.| 658 659**Return value** 660 661| Type | Description | 662| ------------------- | ---------------- | 663| Promise<void> | Promise that returns no value.| 664 665**Error codes** 666 667For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Distributed Scheduler Error Codes](errorcode-DistributedSchedule.md). 668 669| ID| Error Message| 670| ------- | -------------------------------------------- | 671| 201 | Permission denied.| 672| 202 | The application is not system-app, can not use system-api. | 673| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 674| 16300501 | The system ability work abnormally. | 675| 16300503 | The application is not installed on the remote end and installation-free is not supported. | 676| 16300504 | The application is not installed on the remote end but installation-free is supported, try again with freeInstall flag. | 677| 16300505 | The operation device must be the device where the application to be continued is located or the target device to be continued. | 678| 16300506 | The local continuation task is already in progress. | 679| 16300507 | Failed to get the missionInfo of the specified bundle name. | 680 681**Example** 682 683 ```ts 684 import { distributedMissionManager } from '@kit.AbilityKit'; 685 import { BusinessError } from '@kit.BasicServicesKit'; 686 687 try { 688 distributedMissionManager.continueMission( 689 { 690 srcDeviceId: "", 691 dstDeviceId: "", 692 bundleName: "ohos.test.continueapp", 693 wantParam: {"key": "value"} 694 } 695 ).then(() => { 696 console.info('continueMission finished successfully'); 697 }).catch((error: BusinessError) => { 698 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 699 }) 700 } catch (error) { 701 console.error('continueMission failed, cause: ' + JSON.stringify(error)); 702 } 703 ``` 704 705## distributedMissionManager.on('continueStateChange')<sup>11+</sup> 706 707on(type: 'continueStateChange', callback: Callback<ContinueCallbackInfo>): void 708 709Subscribes to continuation state change events of the current mission. 710 711**Required permissions**: ohos.permission.MANAGE_MISSIONS 712 713**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 714 715**Parameters** 716 717| Name | Type | Mandatory | Description | 718| --------- | ---------------------------------------- | ---- | -------- | 719| type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. | 720| callback | Callback<[ContinueCallbackInfo](#continuecallbackinfo11)> | Yes | Callback used to return the continuation state and information of the current mission. | 721 722**Error codes** 723 724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 725 726| ID| Error Message| 727| ------- | -------------------------------- | 728| 201 | Permission denied.| 729| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 730 731**Example** 732 733```js 734 import { distributedMissionManager } from '@kit.AbilityKit'; 735 736 try { 737 distributedMissionManager.on('continueStateChange', (data) => { 738 console.info("continueStateChange on:" + JSON.stringify(data)); 739 }); 740 } catch (error) { 741 console.error("continueStateChange err: " + JSON.stringify(error)); 742 } 743``` 744 745## distributedMissionManager.off('continueStateChange')<sup>11+</sup> 746 747off(type: 'continueStateChange', callback?: Callback<ContinueCallbackInfo>): void 748 749Unsubscribes from continuation state change events of the current mission. 750 751**Required permissions**: ohos.permission.MANAGE_MISSIONS 752 753**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 754 755**Parameters** 756 757| Name | Type | Mandatory | Description | 758| --------- | ---------------------------------------- | ---- | -------- | 759| type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. | 760| callback | Callback<[ContinueCallbackInfo](#continuecallbackinfo11)> | No | Callback used for unsubscription.<br>If the callback is unspecified, all subscriptions to the specified event are canceled. | 761 762**Error codes** 763 764For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 765 766| ID| Error Message| 767| ------- | -------------------------------- | 768| 201 | Permission denied.| 769| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 770 771**Example** 772 773```js 774 import { distributedMissionManager } from '@kit.AbilityKit'; 775 776 try { 777 distributedMissionManager.off('continueStateChange', (data) => { 778 console.info("continueStateChange off:" + JSON.stringify(data)); 779 }); 780 } catch (err) { 781 console.error("continueStateChange err: " + JSON.stringify(err)); 782 } 783``` 784 785## MissionCallback 786 787Defines the callbacks that can be registered as a mission status listener. 788 789**Required permissions**: ohos.permission.MANAGE_MISSIONS 790 791**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 792 793| Name | Type | Readable | Writable | Description | 794| --------------------- | -------- | ---- | ---- | ------------------ | 795| notifyMissionsChanged | function | Yes | No | Callback used to notify the mission change event and return the device ID. | 796| notifySnapshot | function | Yes | No | Callback used to notify the snapshot change event and return the device ID and mission ID.| 797| notifyNetDisconnect | function | Yes | No | Callback used to notify the disconnection event and return the device ID and network status.| 798 799## MissionParameter 800 801Defines the parameters required for mission synchronization. 802 803**Required permissions**: ohos.permission.MANAGE_MISSIONS 804 805**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 806 807| Name | Type | Readable | Writable | Description | 808| ----------- | ------- | ---- | ---- | ----------- | 809| deviceId | string | Yes | Yes | Device ID. For details, see [getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync). | 810| fixConflict | boolean | Yes | Yes | Whether a version conflict occurs.| 811| tag | number | Yes | Yes | Tag of the mission. | 812 813## MissionDeviceInfo 814 815Defines the parameters required for registering a listener. 816 817**Required permissions**: ohos.permission.MANAGE_MISSIONS 818 819**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 820 821| Name | Type | Readable | Writable | Description | 822| -------- | ------ | ---- | ---- | ------- | 823| deviceId | string | Yes | Yes | Device ID. For details, see [getAvailableDeviceListSync](../apis-distributedservice-kit/js-apis-distributedDeviceManager.md#getavailabledevicelistsync).| 824 825## ContinueState<sup>10+</sup> 826 827Enumerates the mission continuation states. 828 829**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 830 831| Name | Value | Description | 832| ------------- | --------- | ------------------------------------------------------------ | 833| ACTIVE | 0 | Continuation is activated for the current mission. | 834| INACTIVE | 1 | Continuation is not activated for the current mission. | 835 836## ContinueCallbackInfo<sup>11+</sup> 837 838Defines the information about the callback that is triggered for mission continuation state changes. 839 840**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 841 842| Name | Type | Readable | Writable | Description | 843| -------- | ------ | ---- | ---- | ----------- | 844| state | [ContinueState](#continuestate10) | Yes | No | Continuation state of the mission.| 845| info | [ContinuableInfo](./js-apis-inner-application-continuableInfo-sys.md) | Yes | No | Continuation information of the mission.| 846