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