1# @ohos.app.ability.missionManager (missionManager) 2 3The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground. 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## Modules to Import 10 11```ts 12import missionManager from '@ohos.app.ability.missionManager'; 13``` 14 15## Required Permissions 16 17ohos.permission.MANAGE_MISSIONS 18 19## missionManager.on 20 21on(type:'mission', listener: MissionListener): number; 22 23Registers a listener to observe the mission status. 24 25**Required permissions**: ohos.permission.MANAGE_MISSIONS 26 27**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 28 29**System API**: This is a system API and cannot be called by third-party applications. 30 31**Parameters** 32 33 | Name| Type| Mandatory| Description| 34 | -------- | -------- | -------- | -------- | 35 | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Listener to register.| 36 37**Return value** 38 39 | Type| Description| 40 | -------- | -------- | 41 | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.| 42 43**Example** 44 45```ts 46import missionManager from '@ohos.app.ability.missionManager'; 47import UIAbility from '@ohos.app.ability.UIAbility'; 48 49let listener = { 50 onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');}, 51 onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');}, 52 onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');}, 53 onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');}, 54 onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');}, 55 onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}, 56 onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');} 57}; 58 59let listenerId = -1; 60 61export default class EntryAbility extends UIAbility { 62 onCreate(want, launchParam) { 63 console.log('[Demo] EntryAbility onCreate'); 64 globalThis.abilityWant = want; 65 globalThis.context = this.context; 66 } 67 68 onDestroy() { 69 try { 70 if (listenerId !== -1) { 71 missionManager.off('mission', listenerId).catch(function (err) { 72 console.log(err); 73 }); 74 } 75 } catch (paramError) { 76 console.error('error: ${paramError.code}, ${paramError.message}'); 77 } 78 console.log('[Demo] EntryAbility onDestroy'); 79 } 80 81 onWindowStageCreate(windowStage) { 82 // The main window is created. Set a main page for this ability. 83 console.log('[Demo] EntryAbility onWindowStageCreate'); 84 try { 85 listenerId = missionManager.on('mission', listener); 86 } catch (paramError) { 87 console.error('error: ${paramError.code}, ${paramError.message}'); 88 } 89 90 windowStage.loadContent('pages/index', (err, data) => { 91 if (err.code) { 92 console.error('Failed to load the content. Cause: ${JSON.stringify(err)}'); 93 return; 94 } 95 console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}'); 96 }); 97 98 if (globalThis.flag) { 99 return; 100 } 101 } 102}; 103``` 104 105 106## missionManager.off 107 108off(type: 'mission', listenerId: number, callback: AsyncCallback<void>): void; 109 110Deregisters a mission status listener. This API uses an asynchronous callback to return the result. 111 112**Required permissions**: ohos.permission.MANAGE_MISSIONS 113 114**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 115 116**System API**: This is a system API and cannot be called by third-party applications. 117 118**Parameters** 119 120 | Name| Type| Mandatory| Description| 121 | -------- | -------- | -------- | -------- | 122 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.| 123 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 124 125**Error codes** 126 127| ID| Error Message| 128| ------- | -------- | 129| 16300002 | Input error. The specified mission listener does not exist. | 130 131For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 132 133**Example** 134 135```ts 136import missionManager from '@ohos.app.ability.missionManager'; 137import UIAbility from '@ohos.app.ability.UIAbility'; 138 139let listener = { 140 onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');}, 141 onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');}, 142 onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');}, 143 onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');}, 144 onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');}, 145 onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}, 146 onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');} 147}; 148 149let listenerId = -1; 150 151export default class EntryAbility extends UIAbility { 152 onCreate(want, launchParam) { 153 console.log('[Demo] EntryAbility onCreate'); 154 globalThis.abilityWant = want; 155 globalThis.context = this.context; 156 } 157 158 onDestroy() { 159 try { 160 if (listenerId !== -1) { 161 missionManager.off('mission', listenerId, (err) => { 162 console.log(err); 163 }); 164 } 165 } catch (paramError) { 166 console.error('error: ${paramError.code}, ${paramError.message}'); 167 } 168 console.log('[Demo] EntryAbility onDestroy'); 169 } 170 171 onWindowStageCreate(windowStage) { 172 // The main window is created. Set a main page for this ability. 173 console.log('[Demo] EntryAbility onWindowStageCreate'); 174 try { 175 listenerId = missionManager.on('mission', listener); 176 } catch (paramError) { 177 console.error('error: ${paramError.code}, ${paramError.message}'); 178 } 179 180 windowStage.loadContent('pages/index', (err, data) => { 181 if (err.code) { 182 console.error('Failed to load the content. Cause: ${JSON.stringify(err)}'); 183 return; 184 } 185 console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}'); 186 }); 187 188 if (globalThis.flag) { 189 return; 190 } 191 } 192}; 193``` 194 195 196## missionManager.off 197 198off(type: 'mission', listenerId: number): Promise<void>; 199 200Deregisters a mission status listener. This API uses a promise to return the result. 201 202**Required permissions**: ohos.permission.MANAGE_MISSIONS 203 204**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 205 206**System API**: This is a system API and cannot be called by third-party applications. 207 208**Parameters** 209 210 | Name| Type| Mandatory| Description| 211 | -------- | -------- | -------- | -------- | 212 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.| 213 214**Return value** 215 216 | Type| Description| 217 | -------- | -------- | 218 | Promise<void> | Promise used to return the result.| 219 220**Error codes** 221 222| ID| Error Message| 223| ------- | -------- | 224| 16300002 | Input error. The specified mission listener does not exist. | 225 226For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 227 228**Example** 229 230```ts 231import missionManager from '@ohos.app.ability.missionManager'; 232import UIAbility from '@ohos.app.ability.UIAbility'; 233 234let listener = { 235 onMissionCreated: function (mission) {console.log('--------onMissionCreated-------');}, 236 onMissionDestroyed: function (mission) {console.log('--------onMissionDestroyed-------');}, 237 onMissionSnapshotChanged: function (mission) {console.log('--------onMissionSnapshotChanged-------');}, 238 onMissionMovedToFront: function (mission) {console.log('--------onMissionMovedToFront-------');}, 239 onMissionIconUpdated: function (mission, icon) {console.log('--------onMissionIconUpdated-------');}, 240 onMissionClosed: function (mission) {console.log('--------onMissionClosed-------');}, 241 onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');} 242}; 243 244let listenerId = -1; 245 246export default class EntryAbility extends UIAbility { 247 onCreate(want, launchParam) { 248 console.log('[Demo] EntryAbility onCreate'); 249 globalThis.abilityWant = want; 250 globalThis.context = this.context; 251 } 252 253 onDestroy() { 254 try { 255 if (listenerId !== -1) { 256 missionManager.off('mission', listenerId).catch(function (err) { 257 console.log(err); 258 }); 259 } 260 } catch (paramError) { 261 console.error('error: ${paramError.code}, ${paramError.message}'); 262 } 263 console.log('[Demo] EntryAbility onDestroy'); 264 } 265 266 onWindowStageCreate(windowStage) { 267 // The main window is created. Set a main page for this ability. 268 console.log('[Demo] EntryAbility onWindowStageCreate'); 269 try { 270 listenerId = missionManager.on('mission', listener); 271 } catch (paramError) { 272 console.error('error: ${paramError.code}, ${paramError.message}'); 273 } 274 275 windowStage.loadContent('pages/index', (err, data) => { 276 if (err.code) { 277 console.error('Failed to load the content. Cause: ${JSON.stringify(err)}'); 278 return; 279 } 280 console.info('Succeeded in loading the content. Data: ${JSON.stringify(data)}'); 281 }); 282 283 if (globalThis.flag) { 284 return; 285 } 286 } 287}; 288``` 289 290 291## missionManager.getMissionInfo 292 293getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void; 294 295Obtains the information about a given mission. This API uses an asynchronous callback to return the result. 296 297**Required permissions**: ohos.permission.MANAGE_MISSIONS 298 299**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 300 301**System API**: This is a system API and cannot be called by third-party applications. 302 303**Parameters** 304 305 | Name| Type| Mandatory| Description| 306 | -------- | -------- | -------- | -------- | 307 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 308 | missionId | number | Yes| Mission ID.| 309 | callback | AsyncCallback<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.| 310 311**Example** 312 313 ```ts 314 import missionManager from '@ohos.app.ability.missionManager'; 315 316 try { 317 let allMissions=missionManager.getMissionInfos('',10).catch(function(err){console.log(err);}); 318 missionManager.getMissionInfo('', allMissions[0].missionId, (error, mission) => { 319 console.log('getMissionInfo is called, error.code = ' + error.code); 320 console.log('mission.missionId = ' + mission.missionId); 321 console.log('mission.runningState = ' + mission.runningState); 322 console.log('mission.lockedState = ' + mission.lockedState); 323 console.log('mission.timestamp = ' + mission.timestamp); 324 console.log('mission.label = ' + mission.label); 325 console.log('mission.iconPath = ' + mission.iconPath); 326 }); 327 } catch (paramError) { 328 console.log('error: ' + paramError.code + ', ' + paramError.message); 329 } 330 ``` 331 332 333## missionManager.getMissionInfo 334 335getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>; 336 337Obtains the information about a given mission. This API uses a promise to return the result. 338 339**Required permissions**: ohos.permission.MANAGE_MISSIONS 340 341**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 342 343**System API**: This is a system API and cannot be called by third-party applications. 344 345**Parameters** 346 347 | Name| Type| Mandatory| Description| 348 | -------- | -------- | -------- | -------- | 349 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 350 | missionId | number | Yes| Mission ID.| 351 352**Return value** 353 354 | Type| Description| 355 | -------- | -------- | 356 | Promise<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.| 357 358**Example** 359 360 ```ts 361 import missionManager from '@ohos.app.ability.missionManager'; 362 363 try { 364 let mission = missionManager.getMissionInfo('', 10).catch(function (err){ 365 console.log(err); 366 }); 367 } catch (paramError) { 368 console.log('error: ' + paramError.code + ', ' + paramError.message); 369 } 370 ``` 371 372 373## missionManager.getMissionInfos 374 375getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void; 376 377Obtains information about all missions. This API uses an asynchronous callback to return the result. 378 379**Required permissions**: ohos.permission.MANAGE_MISSIONS 380 381**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 382 383**System API**: This is a system API and cannot be called by third-party applications. 384 385**Parameters** 386 387 | Name| Type| Mandatory| Description| 388 | -------- | -------- | -------- | -------- | 389 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 390 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 391 | callback | AsyncCallback<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.| 392 393**Example** 394 395 ```ts 396 import missionManager from '@ohos.app.ability.missionManager'; 397 398 try { 399 missionManager.getMissionInfos('', 10, (error, missions) => { 400 console.log('getMissionInfos is called, error.code = ' + error.code); 401 console.log('size = ' + missions.length); 402 console.log('missions = ' + JSON.stringify(missions)); 403 }); 404 } catch (paramError) { 405 console.log('error: ' + paramError.code + ', ' + paramError.message); 406 } 407 ``` 408 409 410## missionManager.getMissionInfos 411 412getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>; 413 414Obtains information about all missions. This API uses a promise to return the result. 415 416**Required permissions**: ohos.permission.MANAGE_MISSIONS 417 418**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 419 420**System API**: This is a system API and cannot be called by third-party applications. 421 422**Parameters** 423 424 | Name| Type| Mandatory| Description| 425 | -------- | -------- | -------- | -------- | 426 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 427 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 428 429**Return value** 430 431 | Type| Description| 432 | -------- | -------- | 433 | Promise<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.| 434 435**Example** 436 437 ```ts 438 import missionManager from '@ohos.app.ability.missionManager'; 439 440 try { 441 let allMissions = missionManager.getMissionInfos('', 10).catch(function (err){ 442 console.log(err); 443 }); 444 } catch (paramError) { 445 console.log('error: ' + paramError.code + ', ' + paramError.message); 446 } 447 ``` 448 449 450## missionManager.getMissionSnapShot 451 452getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void; 453 454Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result. 455 456**Required permissions**: ohos.permission.MANAGE_MISSIONS 457 458**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 459 460**System API**: This is a system API and cannot be called by third-party applications. 461 462**Parameters** 463 464 | Name| Type| Mandatory| Description| 465 | -------- | -------- | -------- | -------- | 466 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 467 | missionId | number | Yes| Mission ID.| 468 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 469 470**Example** 471 472 ```ts 473 import missionManager from '@ohos.app.ability.missionManager'; 474 475 try { 476 missionManager.getMissionInfos('', 10, (error, missions) => { 477 console.log('getMissionInfos is called, error.code = ' + error.code); 478 console.log('size = ' + missions.length); 479 console.log('missions = ' + JSON.stringify(missions)); 480 let id = missions[0].missionId; 481 482 missionManager.getMissionSnapShot('', id, (error, snapshot) => { 483 console.log('getMissionSnapShot is called, error.code = ' + error.code); 484 console.log('bundleName = ' + snapshot.ability.bundleName); 485 }); 486 }); 487 } catch (paramError) { 488 console.log('error: ' + paramError.code + ', ' + paramError.message); 489 } 490 ``` 491 492 493## missionManager.getMissionSnapShot 494 495getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>; 496 497Obtains the snapshot of a given mission. This API uses a promise to return the result. 498 499**Required permissions**: ohos.permission.MANAGE_MISSIONS 500 501**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 502 503**System API**: This is a system API and cannot be called by third-party applications. 504 505**Parameters** 506 507 | Name| Type| Mandatory| Description| 508 | -------- | -------- | -------- | -------- | 509 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 510 | missionId | number | Yes| Mission ID.| 511 512**Return value** 513 514 | Type| Description| 515 | -------- | -------- | 516 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 517 518**Example** 519 520 ```ts 521 import missionManager from '@ohos.app.ability.missionManager'; 522 523 try { 524 let allMissions; 525 missionManager.getMissionInfos('',10).then(function(res){ 526 allMissions=res; 527 }).catch(function(err){console.log(err);}); 528 console.log('size = ' + allMissions.length); 529 console.log('missions = ' + JSON.stringify(allMissions)); 530 let id = allMissions[0].missionId; 531 532 let snapshot = missionManager.getMissionSnapShot('', id).catch(function (err){ 533 console.log(err); 534 }); 535 } catch (paramError) { 536 console.log('error: ' + paramError.code + ', ' + paramError.message); 537 } 538 ``` 539 540## missionManager.getLowResolutionMissionSnapShot 541 542getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void; 543 544Obtains the low-resolution snapshot of a given mission. This API uses an asynchronous callback to return the result. 545 546**Required permissions**: ohos.permission.MANAGE_MISSIONS 547 548**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 549 550**System API**: This is a system API and cannot be called by third-party applications. 551 552**Parameters** 553 554 | Name| Type| Mandatory| Description| 555 | -------- | -------- | -------- | -------- | 556 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 557 | missionId | number | Yes| Mission ID.| 558 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 559 560**Example** 561 562 ```ts 563 import missionManager from '@ohos.app.ability.missionManager'; 564 565 try { 566 missionManager.getMissionInfos('', 10, (error, missions) => { 567 console.log('getMissionInfos is called, error.code = ' + error.code); 568 console.log('size = ' + missions.length); 569 console.log('missions = ' + JSON.stringify(missions)); 570 let id = missions[0].missionId; 571 572 missionManager.getLowResolutionMissionSnapShot('', id, (error, snapshot) => { 573 console.log('getLowResolutionMissionSnapShot is called, error.code = ' + error.code); 574 console.log('bundleName = ' + snapshot.ability.bundleName); 575 }); 576 }); 577 } catch (paramError) { 578 console.log('error: ' + paramError.code + ', ' + paramError.message); 579 } 580 ``` 581 582 583## missionManager.getLowResolutionMissionSnapShot 584 585getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot>; 586 587Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result. 588 589**Required permissions**: ohos.permission.MANAGE_MISSIONS 590 591**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 592 593**System API**: This is a system API and cannot be called by third-party applications. 594 595**Parameters** 596 597 | Name| Type| Mandatory| Description| 598 | -------- | -------- | -------- | -------- | 599 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 600 | missionId | number | Yes| Mission ID.| 601 602**Return value** 603 604 | Type| Description| 605 | -------- | -------- | 606 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 607 608**Example** 609 610 ```ts 611 import missionManager from '@ohos.app.ability.missionManager'; 612 613 try { 614 let allMissions; 615 missionManager.getMissionInfos('',10).then(function(res){ 616 allMissions=res; 617 }).catch(function(err){console.log(err);}); 618 console.log('size = ' + allMissions.length); 619 console.log('missions = ' + JSON.stringify(allMissions)); 620 let id = allMissions[0].missionId; 621 622 let snapshot = missionManager.getLowResolutionMissionSnapShot('', id).catch(function (err){ 623 console.log(err); 624 }); 625 } catch (paramError) { 626 console.log('error: ' + paramError.code + ', ' + paramError.message); 627 } 628 ``` 629 630 631## missionManager.lockMission 632 633lockMission(missionId: number, callback: AsyncCallback<void>): void; 634 635Locks a given mission. This API uses an asynchronous callback to return the result. 636 637**Required permissions**: ohos.permission.MANAGE_MISSIONS 638 639**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 640 641**System API**: This is a system API and cannot be called by third-party applications. 642 643**Parameters** 644 645 | Name| Type| Mandatory| Description| 646 | -------- | -------- | -------- | -------- | 647 | missionId | number | Yes| Mission ID.| 648 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 649 650**Error codes** 651 652| ID| Error Message| 653| ------- | -------- | 654| 16300001 | Mission not found. | 655 656For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 657 658**Example** 659 660 ```ts 661 import missionManager from '@ohos.app.ability.missionManager'; 662 663 try { 664 missionManager.getMissionInfos('', 10, (error, missions) => { 665 console.log('getMissionInfos is called, error.code = ' + error.code); 666 console.log('size = ' + missions.length); 667 console.log('missions = ' + JSON.stringify(missions)); 668 let id = missions[0].missionId; 669 670 missionManager.lockMission(id).then(() => { 671 console.log('lockMission is called '); 672 }); 673 }); 674 } catch (paramError) { 675 console.log('error: ' + paramError.code + ', ' + paramError.message); 676 } 677 ``` 678 679 680## missionManager.lockMission 681 682lockMission(missionId: number): Promise<void>; 683 684Locks a given mission. This API uses a promise to return the result. 685 686**Required permissions**: ohos.permission.MANAGE_MISSIONS 687 688**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 689 690**System API**: This is a system API and cannot be called by third-party applications. 691 692**Parameters** 693 694 | Name| Type| Mandatory| Description| 695 | -------- | -------- | -------- | -------- | 696 | missionId | number | Yes| Mission ID.| 697 698**Return value** 699 700 | Type| Description| 701 | -------- | -------- | 702 | Promise<void> | Promise used to return the result.| 703 704**Error codes** 705 706| ID| Error Message| 707| ------- | -------- | 708| 16300001 | Mission not found. | 709 710For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 711 712**Example** 713 714 ```ts 715 import missionManager from '@ohos.app.ability.missionManager'; 716 717 try { 718 let allMissions; 719 missionManager.getMissionInfos('',10).then(function(res){ 720 allMissions=res; 721 }).catch(function(err){console.log(err);}); 722 console.log('size = ' + allMissions.length); 723 console.log('missions = ' + JSON.stringify(allMissions)); 724 let id = allMissions[0].missionId; 725 726 missionManager.lockMission(id).catch(function (err){ 727 console.log(err); 728 }); 729 } catch (paramError) { 730 console.log('error: ' + paramError.code + ', ' + paramError.message); 731 } 732 ``` 733 734 735## missionManager.unlockMission 736 737unlockMission(missionId: number, callback: AsyncCallback<void>): void; 738 739Unlocks a given mission. This API uses an asynchronous callback to return the result. 740 741**Required permissions**: ohos.permission.MANAGE_MISSIONS 742 743**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 744 745**System API**: This is a system API and cannot be called by third-party applications. 746 747**Parameters** 748 749| Name| Type| Mandatory| Description| 750| -------- | -------- | -------- | -------- | 751| missionId | number | Yes| Mission ID.| 752| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 753 754**Error codes** 755 756| ID| Error Message| 757| ------- | -------- | 758| 16300001 | Mission not found. | 759 760For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 761 762**Example** 763 764 ```ts 765 import missionManager from '@ohos.app.ability.missionManager'; 766 767 try { 768 missionManager.getMissionInfos('', 10, (error, missions) => { 769 console.log('getMissionInfos is called, error.code = ' + error.code); 770 console.log('size = ' + missions.length); 771 console.log('missions = ' + JSON.stringify(missions)); 772 let id = missions[0].missionId; 773 774 missionManager.unlockMission(id).then(() => { 775 console.log('unlockMission is called '); 776 }); 777 }); 778 } catch (paramError) { 779 console.log('error: ' + paramError.code + ', ' + paramError.message); 780 } 781 ``` 782 783 784## missionManager.unlockMission 785 786unlockMission(missionId: number): Promise<void>; 787 788Unlocks a given mission. This API uses a promise to return the result. 789 790**Required permissions**: ohos.permission.MANAGE_MISSIONS 791 792**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 793 794**System API**: This is a system API and cannot be called by third-party applications. 795 796**Parameters** 797 798 | Name| Type| Mandatory| Description| 799 | -------- | -------- | -------- | -------- | 800 | missionId | number | Yes| Mission ID.| 801 802**Return value** 803 804 | Type| Description| 805 | -------- | -------- | 806 | Promise<void> | Promise used to return the result.| 807 808**Error codes** 809 810| ID| Error Message| 811| ------- | -------- | 812| 16300001 | Mission not found. | 813 814For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 815 816**Example** 817 818 ```ts 819 import missionManager from '@ohos.app.ability.missionManager'; 820 821 try { 822 let allMissions; 823 missionManager.getMissionInfos('',10).then(function(res){ 824 allMissions=res; 825 }).catch(function(err){console.log(err);}); 826 console.log('size = ' + allMissions.length); 827 console.log('missions = ' + JSON.stringify(allMissions)); 828 let id = allMissions[0].missionId; 829 830 missionManager.lockMission(id).catch(function (err){ 831 console.log(err); 832 }); 833 missionManager.unlockMission(id).catch(function (err){ 834 console.log(err); 835 }); 836 } catch (paramError) { 837 console.log('error: ' + paramError.code + ', ' + paramError.message); 838 } 839 ``` 840 841 842## missionManager.clearMission 843 844clearMission(missionId: number, callback: AsyncCallback<void>): void; 845 846Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result. 847 848**Required permissions**: ohos.permission.MANAGE_MISSIONS 849 850**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 851 852**System API**: This is a system API and cannot be called by third-party applications. 853 854**Parameters** 855 856 | Name| Type| Mandatory| Description| 857 | -------- | -------- | -------- | -------- | 858 | missionId | number | Yes| Mission ID.| 859 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 860 861**Example** 862 863 ```ts 864 import missionManager from '@ohos.app.ability.missionManager'; 865 866 try { 867 missionManager.getMissionInfos('', 10, (error, missions) => { 868 console.log('getMissionInfos is called, error.code = ' + error.code); 869 console.log('size = ' + missions.length); 870 console.log('missions = ' + JSON.stringify(missions)); 871 let id = missions[0].missionId; 872 873 missionManager.clearMission(id).then(() => { 874 console.log('clearMission is called '); 875 }); 876 }); 877 } catch (paramError) { 878 console.log('error: ' + paramError.code + ', ' + paramError.message); 879 } 880 ``` 881 882 883## missionManager.clearMission 884 885clearMission(missionId: number): Promise<void>; 886 887Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result. 888 889**Required permissions**: ohos.permission.MANAGE_MISSIONS 890 891**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 892 893**System API**: This is a system API and cannot be called by third-party applications. 894 895**Parameters** 896 897 | Name| Type| Mandatory| Description| 898 | -------- | -------- | -------- | -------- | 899 | missionId | number | Yes| Mission ID.| 900 901**Return value** 902 903 | Type| Description| 904 | -------- | -------- | 905 | Promise<void> | Promise used to return the result.| 906 907**Example** 908 909 ```ts 910 import missionManager from '@ohos.app.ability.missionManager'; 911 912 try { 913 let allMissions; 914 missionManager.getMissionInfos('',10).then(function(res){ 915 allMissions=res; 916 }).catch(function(err){console.log(err);}); 917 console.log('size = ' + allMissions.length); 918 console.log('missions = ' + JSON.stringify(allMissions)); 919 let id = allMissions[0].missionId; 920 921 missionManager.clearMission(id).catch(function (err){ 922 console.log(err); 923 }); 924 } catch (paramError) { 925 console.log('error: ' + paramError.code + ', ' + paramError.message); 926 } 927 ``` 928 929 930## missionManager.clearAllMissions 931 932clearAllMissions(callback: AsyncCallback<void>): void; 933 934Clears all unlocked missions. This API uses an asynchronous callback to return the result. 935 936**Required permissions**: ohos.permission.MANAGE_MISSIONS 937 938**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 939 940**System API**: This is a system API and cannot be called by third-party applications. 941 942**Example** 943 944 ```ts 945 import missionManager from '@ohos.app.ability.missionManager'; 946 947 missionManager.clearAllMissions().then(() => { 948 console.log('clearAllMissions is called '); 949 }); 950 ``` 951 952 953## missionManager.clearAllMissions 954 955clearAllMissions(): Promise<void>; 956 957Clears all unlocked missions. This API uses a promise to return the result. 958 959**Required permissions**: ohos.permission.MANAGE_MISSIONS 960 961**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 962 963**System API**: This is a system API and cannot be called by third-party applications. 964 965**Return value** 966 967 | Type| Description| 968 | -------- | -------- | 969 | Promise<void> | Promise used to return the result.| 970 971**Example** 972 973 ```ts 974 import missionManager from '@ohos.app.ability.missionManager'; 975 missionManager.clearAllMissions().catch(function (err){ 976 console.log(err); 977 }); 978 ``` 979 980 981## missionManager.moveMissionToFront 982 983moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void; 984 985Switches a given mission to the foreground. This API uses an asynchronous callback to return the result. 986 987**Required permissions**: ohos.permission.MANAGE_MISSIONS 988 989**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 990 991**System API**: This is a system API and cannot be called by third-party applications. 992 993**Parameters** 994 995 | Name| Type| Mandatory| Description| 996 | -------- | -------- | -------- | -------- | 997 | missionId | number | Yes| Mission ID.| 998 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 999 1000**Error codes** 1001 1002| ID| Error Message| 1003| ------- | -------- | 1004| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1005 1006For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1007 1008**Example** 1009 1010 ```ts 1011 import missionManager from '@ohos.app.ability.missionManager'; 1012 1013 try { 1014 missionManager.getMissionInfos('', 10, (error, missions) => { 1015 console.log('getMissionInfos is called, error.code = ' + error.code); 1016 console.log('size = ' + missions.length); 1017 console.log('missions = ' + JSON.stringify(missions)); 1018 let id = missions[0].missionId; 1019 1020 missionManager.moveMissionToFront(id).then(() => { 1021 console.log('moveMissionToFront is called '); 1022 }); 1023 }); 1024 } catch (paramError) { 1025 console.log('error: ' + paramError.code + ', ' + paramError.message); 1026 } 1027 ``` 1028 1029 1030## missionManager.moveMissionToFront 1031 1032moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void; 1033 1034Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result. 1035 1036**Required permissions**: ohos.permission.MANAGE_MISSIONS 1037 1038**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1039 1040**System API**: This is a system API and cannot be called by third-party applications. 1041 1042**Parameters** 1043 1044 | Name| Type| Mandatory| Description| 1045 | -------- | -------- | -------- | -------- | 1046 | missionId | number | Yes| Mission ID.| 1047 | options | [StartOptions](js-apis-app-ability-startOptions.md) | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| 1048 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1049 1050**Error codes** 1051 1052| ID| Error Message| 1053| ------- | -------- | 1054| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1055 1056For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1057 1058**Example** 1059 1060 ```ts 1061 import missionManager from '@ohos.app.ability.missionManager'; 1062 1063 try { 1064 missionManager.getMissionInfos('', 10, (error, missions) => { 1065 console.log('getMissionInfos is called, error.code = ' + error.code); 1066 console.log('size = ' + missions.length); 1067 console.log('missions = ' + JSON.stringify(missions)); 1068 let id = missions[0].missionId; 1069 1070 missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => { 1071 console.log('moveMissionToFront is called '); 1072 }); 1073 }); 1074 } catch (paramError) { 1075 console.log('error: ' + paramError.code + ', ' + paramError.message); 1076 } 1077 ``` 1078 1079 1080## missionManager.moveMissionToFront 1081 1082moveMissionToFront(missionId: number, options?: StartOptions): Promise<void>; 1083 1084Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result. 1085 1086**Required permissions**: ohos.permission.MANAGE_MISSIONS 1087 1088**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1089 1090**System API**: This is a system API and cannot be called by third-party applications. 1091 1092**Parameters** 1093 1094 | Name| Type| Mandatory| Description| 1095 | -------- | -------- | -------- | -------- | 1096 | missionId | number | Yes| Mission ID.| 1097 | options | [StartOptions](js-apis-app-ability-startOptions.md) | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.| 1098 1099**Return value** 1100 1101 | Type| Description| 1102 | -------- | -------- | 1103 | Promise<void> | Promise used to return the result.| 1104 1105**Error codes** 1106 1107| ID| Error Message| 1108| ------- | -------- | 1109| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1110 1111For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1112 1113**Example** 1114 1115 ```ts 1116 import missionManager from '@ohos.app.ability.missionManager'; 1117 1118 try { 1119 let allMissions; 1120 missionManager.getMissionInfos('',10).then(function(res){ 1121 allMissions=res; 1122 }).catch(function(err){console.log(err);}); 1123 console.log('size = ' + allMissions.length); 1124 console.log('missions = ' + JSON.stringify(allMissions)); 1125 let id = allMissions[0].missionId; 1126 1127 missionManager.moveMissionToFront(id).catch(function (err){ 1128 console.log(err); 1129 }); 1130 } catch (paramError) { 1131 console.log('error: ' + paramError.code + ', ' + paramError.message); 1132 } 1133 ``` 1134