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 | type | string | Yes | Name of the target mission.| 36 | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.| 37 38**Return value** 39 40 | Type| Description| 41 | -------- | -------- | 42 | number | Index of the mission status listener, which is created by the system and allocated when the listener is registered.| 43 44**Example** 45 46```ts 47import missionManager from '@ohos.app.ability.missionManager'; 48import UIAbility from '@ohos.app.ability.UIAbility'; 49import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 50import common from '@ohos.app.ability.common'; 51import Want from '@ohos.app.ability.Want'; 52import { BusinessError } from '@ohos.base'; 53import window from '@ohos.window'; 54import image from '@ohos.multimedia.image'; 55 56let listener: missionManager.MissionListener = { 57 onMissionCreated: (mission: number) => {console.log('--------onMissionCreated-------');}, 58 onMissionDestroyed: (mission: number) => {console.log('--------onMissionDestroyed-------');}, 59 onMissionSnapshotChanged: (mission: number) => {console.log('--------onMissionSnapshotChanged-------');}, 60 onMissionMovedToFront: (mission: number) => {console.log('--------onMissionMovedToFront-------');}, 61 onMissionIconUpdated: (mission: number, icon: image.PixelMap) => {console.log('--------onMissionIconUpdated-------');}, 62 onMissionClosed: (mission: number) => {console.log('--------onMissionClosed-------');}, 63 onMissionLabelUpdated: (mission: number) => {console.log('--------onMissionLabelUpdated-------');} 64}; 65 66let listenerId = -1; 67let abilityWant: Want; 68let context: common.UIAbilityContext; 69 70export default class EntryAbility extends UIAbility { 71 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 72 console.log('[Demo] EntryAbility onCreate'); 73 abilityWant = want; 74 context = this.context; 75 } 76 77 onDestroy() { 78 try { 79 if (listenerId !== -1) { 80 missionManager.off('mission', listenerId).catch((err: BusinessError) => { 81 console.log(JSON.stringify(err)); 82 }); 83 } 84 } catch (paramError) { 85 let code = (paramError as BusinessError).code; 86 let message = (paramError as BusinessError).message; 87 console.error(`error: ${code}, ${message} `); 88 } 89 console.log('[Demo] EntryAbility onDestroy'); 90 } 91 92 onWindowStageCreate(windowStage: window.WindowStage) { 93 // The main window is created. Set a main page for this ability. 94 console.log('[Demo] EntryAbility onWindowStageCreate'); 95 try { 96 listenerId = missionManager.on('mission', listener); 97 } catch (paramError) { 98 let code = (paramError as BusinessError).code; 99 let message = (paramError as BusinessError).message; 100 console.error(`error: ${code}, ${message} `); 101 } 102 103 windowStage.loadContent('pages/index', (err, data) => { 104 if (err.code) { 105 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 106 return; 107 } 108 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 109 }); 110 } 111}; 112``` 113 114 115## missionManager.off 116 117off(type: 'mission', listenerId: number, callback: AsyncCallback<void>): void 118 119Deregisters a mission status listener. 120 121**Required permissions**: ohos.permission.MANAGE_MISSIONS 122 123**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 124 125**System API**: This is a system API and cannot be called by third-party applications. 126 127**Parameters** 128 129 | Name| Type| Mandatory| Description| 130 | -------- | -------- | -------- | -------- | 131 | type | string | Yes | Name of the target mission.| 132 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.| 133 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 134 135**Error codes** 136 137| ID| Error Message| 138| ------- | -------- | 139| 16300002 | Input error. The specified mission listener does not exist. | 140 141For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 142 143**Example** 144 145```ts 146import missionManager from '@ohos.app.ability.missionManager'; 147import UIAbility from '@ohos.app.ability.UIAbility'; 148import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 149import common from '@ohos.app.ability.common'; 150import Want from '@ohos.app.ability.Want'; 151import { BusinessError } from '@ohos.base'; 152import window from '@ohos.window'; 153import image from '@ohos.multimedia.image'; 154 155let listener: missionManager.MissionListener = { 156 onMissionCreated: (mission: number) => {console.log('--------onMissionCreated-------');}, 157 onMissionDestroyed: (mission: number) => {console.log('--------onMissionDestroyed-------');}, 158 onMissionSnapshotChanged: (mission: number) => {console.log('--------onMissionSnapshotChanged-------');}, 159 onMissionMovedToFront: (mission: number) => {console.log('--------onMissionMovedToFront-------');}, 160 onMissionIconUpdated: (mission: number, icon: image.PixelMap) => {console.log('--------onMissionIconUpdated-------');}, 161 onMissionClosed: (mission: number) => {console.log('--------onMissionClosed-------');}, 162 onMissionLabelUpdated: (mission: number) => {console.log('--------onMissionLabelUpdated-------');} 163}; 164 165let listenerId = -1; 166let abilityWant: Want; 167let context: common.UIAbilityContext; 168 169export default class EntryAbility extends UIAbility { 170 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 171 console.log('[Demo] EntryAbility onCreate'); 172 abilityWant = want; 173 context = this.context; 174 } 175 176 onDestroy() { 177 try { 178 if (listenerId !== -1) { 179 missionManager.off('mission', listenerId, (err: BusinessError) => { 180 console.log(`${err.code}`); 181 }); 182 } 183 } catch (paramError) { 184 let code = (paramError as BusinessError).code; 185 let message = (paramError as BusinessError).message; 186 console.error(`error: ${code}, ${message} `); 187 } 188 console.log('[Demo] EntryAbility onDestroy'); 189 } 190 191 onWindowStageCreate(windowStage: window.WindowStage) { 192 // The main window is created. Set a main page for this ability. 193 console.log('[Demo] EntryAbility onWindowStageCreate'); 194 try { 195 listenerId = missionManager.on('mission', listener); 196 } catch (paramError) { 197 let code = (paramError as BusinessError).code; 198 let message = (paramError as BusinessError).message; 199 console.error(`error: ${code}, ${message} `); 200 } 201 202 windowStage.loadContent('pages/index', (err: BusinessError, data) => { 203 if (err.code) { 204 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 205 return; 206 } 207 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 208 }); 209 } 210}; 211``` 212 213 214## missionManager.off 215 216off(type: 'mission', listenerId: number): Promise<void> 217 218Deregisters a mission status listener. This API uses a promise to return the result. 219 220**Required permissions**: ohos.permission.MANAGE_MISSIONS 221 222**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 223 224**System API**: This is a system API and cannot be called by third-party applications. 225 226**Parameters** 227 228 | Name| Type| Mandatory| Description| 229 | -------- | -------- | -------- | -------- | 230 | type | string | Yes | Name of the target mission.| 231 | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **on()**.| 232 233**Return value** 234 235 | Type| Description| 236 | -------- | -------- | 237 | Promise<void> | Promise used to return the result.| 238 239**Error codes** 240 241| ID| Error Message| 242| ------- | -------- | 243| 16300002 | Input error. The specified mission listener does not exist. | 244 245For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 246 247**Example** 248 249```ts 250import missionManager from '@ohos.app.ability.missionManager'; 251import UIAbility from '@ohos.app.ability.UIAbility'; 252import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 253import common from '@ohos.app.ability.common'; 254import Want from '@ohos.app.ability.Want'; 255import { BusinessError } from '@ohos.base'; 256import window from '@ohos.window'; 257import image from '@ohos.multimedia.image'; 258 259let listener: missionManager.MissionListener = { 260 onMissionCreated: (mission: number) => {console.log('--------onMissionCreated-------');}, 261 onMissionDestroyed: (mission: number) => {console.log('--------onMissionDestroyed-------');}, 262 onMissionSnapshotChanged: (mission: number) => {console.log('--------onMissionSnapshotChanged-------');}, 263 onMissionMovedToFront: (mission: number) => {console.log('--------onMissionMovedToFront-------');}, 264 onMissionIconUpdated: (mission: number, icon: image.PixelMap) => {console.log('--------onMissionIconUpdated-------');}, 265 onMissionClosed: (mission: number) => {console.log('--------onMissionClosed-------');}, 266 onMissionLabelUpdated: (mission: number) => {console.log('--------onMissionLabelUpdated-------');} 267}; 268 269let listenerId = -1; 270let abilityWant: Want; 271let context: common.UIAbilityContext; 272 273export default class EntryAbility extends UIAbility { 274 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 275 console.log('[Demo] EntryAbility onCreate'); 276 abilityWant = want; 277 context = this.context; 278 } 279 280 onDestroy() { 281 try { 282 if (listenerId !== -1) { 283 missionManager.off('mission', listenerId).catch((err: BusinessError) => { 284 console.log(`${err.code}`); 285 }); 286 } 287 } catch (paramError) { 288 let code = (paramError as BusinessError).code; 289 let message = (paramError as BusinessError).message; 290 console.error(`error: ${code}, ${message} `); 291 } 292 console.log('[Demo] EntryAbility onDestroy'); 293 } 294 295 onWindowStageCreate(windowStage: window.WindowStage) { 296 // The main window is created. Set a main page for this ability. 297 console.log('[Demo] EntryAbility onWindowStageCreate'); 298 try { 299 listenerId = missionManager.on('mission', listener); 300 } catch (paramError) { 301 let code = (paramError as BusinessError).code; 302 let message = (paramError as BusinessError).message; 303 console.error(`error: ${code}, ${message} `); 304 } 305 306 windowStage.loadContent('pages/index', (err: BusinessError, data) => { 307 if (err.code) { 308 console.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); 309 return; 310 } 311 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 312 }); 313 } 314}; 315``` 316 317## missionManager.getMissionInfo 318 319getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void 320 321Obtains the information about a given mission. This API uses an asynchronous callback 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 | callback | AsyncCallback<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.| 336 337**Example** 338 339 ```ts 340 import missionManager from '@ohos.app.ability.missionManager'; 341 import { BusinessError } from '@ohos.base'; 342 343 let testMissionId = 1; 344 345 missionManager.getMissionInfos('',10) 346 .then((allMissions: Array<missionManager.MissionInfo>) => { 347 try { 348 if (allMissions && allMissions.length > 0) { 349 testMissionId = allMissions[0].missionId; 350 } 351 352 missionManager.getMissionInfo('', testMissionId, (error: BusinessError, mission: missionManager.MissionInfo) => { 353 if (error) { 354 console.error(`getMissionInfo failed, error.code: ${error.code}, error.message: ${error.message}`); 355 } else { 356 console.log(`mission.missionId = ${mission.missionId}`); 357 console.log(`mission.runningState = ${mission.runningState}`); 358 console.log(`mission.lockedState = ${mission.lockedState}`); 359 console.log(`mission.timestamp = ${mission.timestamp}`); 360 console.log(`mission.label = ${mission.label}`); 361 console.log(`mission.iconPath = ${mission.iconPath}`); 362 } 363 }); 364 } catch (paramError) { 365 let code = (paramError as BusinessError).code; 366 let message = (paramError as BusinessError).message; 367 console.error(`error: ${code}, ${message} `); 368 } 369 }) 370 .catch((err: BusinessError) => {console.log(`${err.code}`);}); 371 ``` 372 373## missionManager.getMissionInfo 374 375getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo> 376 377Obtains the information about a given mission. This API uses a promise 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 | missionId | number | Yes| Mission ID.| 391 392**Return value** 393 394 | Type| Description| 395 | -------- | -------- | 396 | Promise<[MissionInfo](./js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.| 397 398**Example** 399 400```ts 401import missionManager from '@ohos.app.ability.missionManager'; 402import { BusinessError } from '@ohos.base'; 403 404let testMissionId = 1; 405try { 406 missionManager.getMissionInfo('', testMissionId).then((data: missionManager.MissionInfo) => { 407 console.info(`getMissionInfo successfully. Data: ${JSON.stringify(data)}`); 408 }).catch((error: BusinessError) => { 409 console.error(`getMissionInfo failed. Cause: ${error.message}`); 410 }); 411} catch (error) { 412 let err: BusinessError = error as BusinessError; 413 console.error(`getMissionInfo failed. Cause: ${err.message}`); 414} 415``` 416 417## missionManager.getMissionInfos 418 419getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void 420 421Obtains information about all missions. This API uses an asynchronous callback to return the result. 422 423**Required permissions**: ohos.permission.MANAGE_MISSIONS 424 425**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 426 427**System API**: This is a system API and cannot be called by third-party applications. 428 429**Parameters** 430 431 | Name| Type| Mandatory| Description| 432 | -------- | -------- | -------- | -------- | 433 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 434 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 435 | callback | AsyncCallback<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.| 436 437**Example** 438 439 ```ts 440 import missionManager from '@ohos.app.ability.missionManager'; 441 import { BusinessError } from '@ohos.base'; 442 443 try { 444 missionManager.getMissionInfos('', 10, (error: BusinessError, missions: Array<missionManager.MissionInfo>) => { 445 if (error) { 446 console.error(`getMissionInfos failed, error.code: ${error.code}, error.message: ${error.message}`); 447 } else { 448 console.log(`size = ${missions.length}`); 449 console.log(`missions = ${JSON.stringify(missions)}`); 450 } 451 }); 452 } catch (paramError) { 453 let code = (paramError as BusinessError).code; 454 let message = (paramError as BusinessError).message; 455 console.error(`error: ${code}, ${message} `); 456 } 457 ``` 458 459 460## missionManager.getMissionInfos 461 462getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>> 463 464Obtains information about all missions. This API uses a promise to return the result. 465 466**Required permissions**: ohos.permission.MANAGE_MISSIONS 467 468**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 469 470**System API**: This is a system API and cannot be called by third-party applications. 471 472**Parameters** 473 474 | Name| Type| Mandatory| Description| 475 | -------- | -------- | -------- | -------- | 476 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 477 | numMax | number | Yes| Maximum number of missions whose information can be obtained.| 478 479**Return value** 480 481 | Type| Description| 482 | -------- | -------- | 483 | Promise<Array<[MissionInfo](./js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.| 484 485**Example** 486 487```ts 488import missionManager from '@ohos.app.ability.missionManager'; 489import { BusinessError } from '@ohos.base'; 490 491try { 492 missionManager.getMissionInfos('', 10).then((data: Array<missionManager.MissionInfo>) => { 493 console.info(`getMissionInfos successfully. Data: ${JSON.stringify(data)}`); 494 }).catch((error: BusinessError) => { 495 console.error(`getMissionInfos failed. Cause: ${error.message}`); 496 }); 497} catch (error) { 498 let err: BusinessError = error as BusinessError; 499 console.error(`getMissionInfos failed. Cause: ${err.message}`); 500} 501``` 502 503## missionManager.getMissionSnapShot 504 505getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void 506 507Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result. 508 509**Required permissions**: ohos.permission.MANAGE_MISSIONS 510 511**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 512 513**System API**: This is a system API and cannot be called by third-party applications. 514 515**Parameters** 516 517 | Name| Type| Mandatory| Description| 518 | -------- | -------- | -------- | -------- | 519 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 520 | missionId | number | Yes| Mission ID.| 521 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 522 523**Example** 524```ts 525import missionManager from '@ohos.app.ability.missionManager'; 526import { BusinessError } from '@ohos.base'; 527 528let testMissionId = 2; 529try { 530 missionManager.getMissionSnapShot('', testMissionId, (err: BusinessError, data: missionManager.MissionSnapshot ) => { 531 if (err) { 532 console.error(`getMissionSnapShot failed: ${err.message}`); 533 } else { 534 console.info(`getMissionSnapShot successfully: ${JSON.stringify(data)}`); 535 } 536 }); 537} catch (error) { 538 let err: BusinessError = error as BusinessError; 539 console.error(`getMissionSnapShot failed: ${err.message}`); 540} 541``` 542 543## missionManager.getMissionSnapShot 544 545getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot> 546 547Obtains the snapshot of a given mission. This API uses a promise to return the result. 548 549**Required permissions**: ohos.permission.MANAGE_MISSIONS 550 551**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 552 553**System API**: This is a system API and cannot be called by third-party applications. 554 555**Parameters** 556 557 | Name| Type| Mandatory| Description| 558 | -------- | -------- | -------- | -------- | 559 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 560 | missionId | number | Yes| Mission ID.| 561 562**Return value** 563 564 | Type| Description| 565 | -------- | -------- | 566 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 567 568**Example** 569```ts 570import missionManager from '@ohos.app.ability.missionManager'; 571import { BusinessError } from '@ohos.base'; 572 573let testMissionId = 2; 574try { 575 missionManager.getMissionSnapShot('', testMissionId).then((data: missionManager.MissionSnapshot) => { 576 console.info(`getMissionSnapShot successfully. Data: ${JSON.stringify(data)}`); 577 }).catch((error: BusinessError) => { 578 console.error(`getMissionSnapShot failed. Cause: ${error.message}`); 579 }); 580} catch (error) { 581 let err: BusinessError = error as BusinessError; 582 console.error(`getMissionSnapShot failed. Cause: ${err.message}`); 583} 584``` 585 586## missionManager.getLowResolutionMissionSnapShot 587 588getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void 589 590Obtains the low-resolution snapshot of a given mission. This API uses an asynchronous callback to return the result. 591 592**Required permissions**: ohos.permission.MANAGE_MISSIONS 593 594**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 595 596**System API**: This is a system API and cannot be called by third-party applications. 597 598**Parameters** 599 600 | Name| Type| Mandatory| Description| 601 | -------- | -------- | -------- | -------- | 602 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 603 | missionId | number | Yes| Mission ID.| 604 | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.| 605 606**Example** 607```ts 608import missionManager from '@ohos.app.ability.missionManager'; 609import { BusinessError } from '@ohos.base'; 610 611let testMissionId = 2; 612try { 613 missionManager.getLowResolutionMissionSnapShot('', testMissionId, (err: BusinessError, data: missionManager.MissionSnapshot) => { 614 if (err) { 615 console.error(`getLowResolutionMissionSnapShot failed: ${err.message}`); 616 } else { 617 console.info(`getLowResolutionMissionSnapShot successfully: ${JSON.stringify(data)}`); 618 } 619 }); 620} catch (error) { 621 let err: BusinessError = error as BusinessError; 622 console.error(`getLowResolutionMissionSnapShot failed: ${err.message}`); 623} 624``` 625 626## missionManager.getLowResolutionMissionSnapShot 627 628getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot> 629 630Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result. 631 632**Required permissions**: ohos.permission.MANAGE_MISSIONS 633 634**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 635 636**System API**: This is a system API and cannot be called by third-party applications. 637 638**Parameters** 639 640 | Name| Type| Mandatory| Description| 641 | -------- | -------- | -------- | -------- | 642 | deviceId | string | Yes| Device ID. It is a null string by default for the local device.| 643 | missionId | number | Yes| Mission ID.| 644 645**Return value** 646 647 | Type| Description| 648 | -------- | -------- | 649 | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.| 650 651**Example** 652 653```ts 654import missionManager from '@ohos.app.ability.missionManager'; 655import { BusinessError } from '@ohos.base'; 656 657let testMissionId = 2; 658try { 659 missionManager.getLowResolutionMissionSnapShot('', testMissionId).then((data: missionManager.MissionSnapshot) => { 660 console.info(`getLowResolutionMissionSnapShot successfully. Data: ${JSON.stringify(data)}`); 661 }).catch((error: BusinessError) => { 662 console.error(`getLowResolutionMissionSnapShot failed. Cause: ${error.message}`); 663 }); 664} catch (error) { 665 let err: BusinessError = error as BusinessError; 666 console.error(`getLowResolutionMissionSnapShot failed. Cause: ${err.message}`); 667} 668``` 669 670 671## missionManager.lockMission 672 673lockMission(missionId: number, callback: AsyncCallback<void>): void 674 675Locks a given mission. This API uses an asynchronous callback to return the result. 676 677**Required permissions**: ohos.permission.MANAGE_MISSIONS 678 679**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 680 681**System API**: This is a system API and cannot be called by third-party applications. 682 683**Parameters** 684 685 | Name| Type| Mandatory| Description| 686 | -------- | -------- | -------- | -------- | 687 | missionId | number | Yes| Mission ID.| 688 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 689 690**Error codes** 691 692| ID| Error Message| 693| ------- | -------- | 694| 16300001 | Mission not found. | 695 696For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 697 698**Example** 699 700```ts 701import missionManager from '@ohos.app.ability.missionManager'; 702import { BusinessError } from '@ohos.base'; 703 704let testMissionId = 2; 705try { 706 missionManager.lockMission(testMissionId, (err: BusinessError, data: void) => { 707 if (err) { 708 console.error(`lockMission failed: ${err.message}`); 709 } else { 710 console.info(`lockMission successfully: ${JSON.stringify(data)}`); 711 } 712 }); 713} catch (error) { 714 let err: BusinessError = error as BusinessError; 715 console.error(`lockMission failed: ${err.message}`); 716} 717``` 718 719## missionManager.lockMission 720 721lockMission(missionId: number): Promise<void> 722 723Locks a given mission. This API uses a promise to return the result. 724 725**Required permissions**: ohos.permission.MANAGE_MISSIONS 726 727**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 728 729**System API**: This is a system API and cannot be called by third-party applications. 730 731**Parameters** 732 733 | Name| Type| Mandatory| Description| 734 | -------- | -------- | -------- | -------- | 735 | missionId | number | Yes| Mission ID.| 736 737**Return value** 738 739 | Type| Description| 740 | -------- | -------- | 741 | Promise<void> | Promise used to return the result.| 742 743**Error codes** 744 745| ID| Error Message| 746| ------- | -------- | 747| 16300001 | Mission not found. | 748 749For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 750 751**Example** 752```ts 753import missionManager from '@ohos.app.ability.missionManager'; 754import { BusinessError } from '@ohos.base'; 755 756let testMissionId = 2; 757try { 758 missionManager.lockMission(testMissionId).then((data: void) => { 759 console.info(`lockMission successfully. Data: ${JSON.stringify(data)}`); 760 }).catch((error: BusinessError) => { 761 console.error(`lockMission failed. Cause: ${error.message}`); 762 }); 763} catch (error) { 764 let err: BusinessError = error as BusinessError; 765 console.error(`lockMission failed. Cause: ${err.message}`); 766} 767``` 768 769## missionManager.unlockMission 770 771unlockMission(missionId: number, callback: AsyncCallback<void>): void 772 773Unlocks a given mission. This API uses an asynchronous callback to return the result. 774 775**Required permissions**: ohos.permission.MANAGE_MISSIONS 776 777**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 778 779**System API**: This is a system API and cannot be called by third-party applications. 780 781**Parameters** 782 783| Name| Type| Mandatory| Description| 784| -------- | -------- | -------- | -------- | 785| missionId | number | Yes| Mission ID.| 786| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 787 788**Error codes** 789 790| ID| Error Message| 791| ------- | -------- | 792| 16300001 | Mission not found. | 793 794For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 795 796**Example** 797```ts 798import missionManager from '@ohos.app.ability.missionManager'; 799import { BusinessError } from '@ohos.base'; 800 801let testMissionId = 2; 802try { 803 missionManager.unlockMission(testMissionId, (err: BusinessError, data: void) => { 804 if (err) { 805 console.error(`unlockMission failed: ${err.message}`); 806 } else { 807 console.info(`unlockMission successfully: ${JSON.stringify(data)}`); 808 } 809 }); 810} catch (error) { 811 let err: BusinessError = error as BusinessError; 812 console.error(`unlockMission failed: ${err.message}`); 813} 814``` 815 816## missionManager.unlockMission 817 818unlockMission(missionId: number): Promise<void> 819 820Unlocks a given mission. This API uses a promise to return the result. 821 822**Required permissions**: ohos.permission.MANAGE_MISSIONS 823 824**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 825 826**System API**: This is a system API and cannot be called by third-party applications. 827 828**Parameters** 829 830 | Name| Type| Mandatory| Description| 831 | -------- | -------- | -------- | -------- | 832 | missionId | number | Yes| Mission ID.| 833 834**Return value** 835 836 | Type| Description| 837 | -------- | -------- | 838 | Promise<void> | Promise used to return the result.| 839 840**Error codes** 841 842| ID| Error Message| 843| ------- | -------- | 844| 16300001 | Mission not found. | 845 846For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 847 848**Example** 849 850```ts 851import missionManager from '@ohos.app.ability.missionManager'; 852import { BusinessError } from '@ohos.base'; 853 854let testMissionId = 2; 855try { 856 missionManager.unlockMission(testMissionId).then((data: void) => { 857 console.info(`unlockMission successfully. Data: ${JSON.stringify(data)}`); 858 }).catch((error: BusinessError) => { 859 console.error(`unlockMission failed. Cause: ${error.message}`); 860 }); 861} catch (error) { 862 let err: BusinessError = error as BusinessError; 863 console.error(`unlockMission failed. Cause: ${err.message}`); 864} 865``` 866 867## missionManager.clearMission 868 869clearMission(missionId: number, callback: AsyncCallback<void>): void 870 871Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result. 872 873**Required permissions**: ohos.permission.MANAGE_MISSIONS 874 875**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 876 877**System API**: This is a system API and cannot be called by third-party applications. 878 879**Parameters** 880 881 | Name| Type| Mandatory| Description| 882 | -------- | -------- | -------- | -------- | 883 | missionId | number | Yes| Mission ID.| 884 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 885 886**Example** 887 888```ts 889import missionManager from '@ohos.app.ability.missionManager'; 890import { BusinessError } from '@ohos.base'; 891 892let testMissionId = 2; 893try { 894 missionManager.clearMission(testMissionId, (err: BusinessError, data: void) => { 895 if (err) { 896 console.error(`clearMission failed: ${err.message}`); 897 } else { 898 console.info(`clearMission successfully: ${JSON.stringify(data)}`); 899 } 900 }); 901} catch (error) { 902 let err: BusinessError = error as BusinessError; 903 console.error(`clearMission failed: ${err.message}`); 904} 905``` 906 907 908## missionManager.clearMission 909 910clearMission(missionId: number): Promise<void> 911 912Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result. 913 914**Required permissions**: ohos.permission.MANAGE_MISSIONS 915 916**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 917 918**System API**: This is a system API and cannot be called by third-party applications. 919 920**Parameters** 921 922 | Name| Type| Mandatory| Description| 923 | -------- | -------- | -------- | -------- | 924 | missionId | number | Yes| Mission ID.| 925 926**Return value** 927 928 | Type| Description| 929 | -------- | -------- | 930 | Promise<void> | Promise used to return the result.| 931 932**Example** 933 934```ts 935import missionManager from '@ohos.app.ability.missionManager'; 936import { BusinessError } from '@ohos.base'; 937 938let testMissionId = 2; 939try { 940 missionManager.clearMission(testMissionId).then((data: void) => { 941 console.info(`clearMission successfully. Data: ${JSON.stringify(data)}`); 942 }).catch((error: BusinessError) => { 943 console.error(`clearMission failed. Cause: ${error.message}`); 944 }); 945} catch (error) { 946 let err: BusinessError = error as BusinessError; 947 console.error(`clearMission failed. Cause: ${err.message}`); 948} 949``` 950 951## missionManager.clearAllMissions 952 953clearAllMissions(callback: AsyncCallback<void>): void 954 955Clears all unlocked missions. This API uses an asynchronous callback to return the result. 956 957**Required permissions**: ohos.permission.MANAGE_MISSIONS 958 959**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 960 961**System API**: This is a system API and cannot be called by third-party applications. 962 963**Parameters** 964 965 | Name| Type| Mandatory| Description| 966 | -------- | -------- | -------- | -------- | 967 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 968 969**Example** 970 971```ts 972import missionManager from '@ohos.app.ability.missionManager'; 973import { BusinessError } from '@ohos.base'; 974 975try { 976 missionManager.clearAllMissions((err: BusinessError) => { 977 if (err) { 978 console.error(`clearAllMissions failed: ${err.message}`); 979 } else { 980 console.info('clearAllMissions successfully.'); 981 } 982 }); 983} catch (error) { 984 let err: BusinessError = error as BusinessError; 985 console.error(`clearAllMissions failed: ${err.message}`); 986} 987``` 988 989## missionManager.clearAllMissions 990 991clearAllMissions(): Promise<void> 992 993Clears all unlocked missions. This API uses a promise to return the result. 994 995**Required permissions**: ohos.permission.MANAGE_MISSIONS 996 997**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 998 999**System API**: This is a system API and cannot be called by third-party applications. 1000 1001**Return value** 1002 1003 | Type| Description| 1004 | -------- | -------- | 1005 | Promise<void> | Promise used to return the result.| 1006 1007**Example** 1008 1009```ts 1010import missionManager from '@ohos.app.ability.missionManager'; 1011import { BusinessError } from '@ohos.base'; 1012 1013try { 1014 missionManager.clearAllMissions().then((data: void) => { 1015 console.info(`clearAllMissions successfully. Data: ${JSON.stringify(data)}`); 1016 }).catch((err: BusinessError) => { 1017 console.error(`clearAllMissions failed: ${err.message}`); 1018 }); 1019} catch (error) { 1020 let err: BusinessError = error as BusinessError; 1021 console.error(`clearAllMissions failed: ${err.message}`); 1022} 1023``` 1024 1025## missionManager.moveMissionToFront 1026 1027moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void 1028 1029Switches a given mission to the foreground. This API uses an asynchronous callback to return the result. 1030 1031**Required permissions**: ohos.permission.MANAGE_MISSIONS 1032 1033**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1034 1035**System API**: This is a system API and cannot be called by third-party applications. 1036 1037**Parameters** 1038 1039 | Name| Type| Mandatory| Description| 1040 | -------- | -------- | -------- | -------- | 1041 | missionId | number | Yes| Mission ID.| 1042 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1043 1044**Error codes** 1045 1046| ID| Error Message| 1047| ------- | -------- | 1048| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1049 1050For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1051 1052**Example** 1053 1054```ts 1055import missionManager from '@ohos.app.ability.missionManager'; 1056import { BusinessError } from '@ohos.base'; 1057 1058let testMissionId = 2; 1059try { 1060 missionManager.moveMissionToFront(testMissionId, (err: BusinessError, data: void) => { 1061 if (err) { 1062 console.error(`moveMissionToFront failed: ${err.message}`); 1063 } else { 1064 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 1065 } 1066 }); 1067} catch (error) { 1068 let err: BusinessError = error as BusinessError; 1069 console.error(`moveMissionToFront failed: ${err.message}`); 1070} 1071``` 1072 1073## missionManager.moveMissionToFront 1074 1075moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void 1076 1077Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result. 1078 1079**Required permissions**: ohos.permission.MANAGE_MISSIONS 1080 1081**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1082 1083**System API**: This is a system API and cannot be called by third-party applications. 1084 1085**Parameters** 1086 1087 | Name| Type| Mandatory| Description| 1088 | -------- | -------- | -------- | -------- | 1089 | missionId | number | Yes| Mission ID.| 1090 | 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.| 1091 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1092 1093**Error codes** 1094 1095| ID| Error Message| 1096| ------- | -------- | 1097| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1098 1099For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1100 1101**Example** 1102 1103```ts 1104import missionManager from '@ohos.app.ability.missionManager'; 1105import { BusinessError } from '@ohos.base'; 1106 1107let testMissionId = 2; 1108try { 1109 missionManager.moveMissionToFront(testMissionId, {windowMode : 101}, (err: BusinessError, data: void) => { 1110 if (err) { 1111 console.error(`moveMissionToFront failed: ${err.message}`); 1112 } else { 1113 console.info(`moveMissionToFront successfully: ${JSON.stringify(data)}`); 1114 } 1115 }); 1116} catch (error) { 1117 let err: BusinessError = error as BusinessError; 1118 console.error(`moveMissionToFront failed: ${err.message}`); 1119} 1120``` 1121 1122## missionManager.moveMissionToFront 1123 1124moveMissionToFront(missionId: number, options?: StartOptions): Promise<void> 1125 1126Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result. 1127 1128**Required permissions**: ohos.permission.MANAGE_MISSIONS 1129 1130**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1131 1132**System API**: This is a system API and cannot be called by third-party applications. 1133 1134**Parameters** 1135 1136 | Name| Type| Mandatory| Description| 1137 | -------- | -------- | -------- | -------- | 1138 | missionId | number | Yes| Mission ID.| 1139 | 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. By default, no value is passed in, indicating that the default startup parameters are used.| 1140 1141**Return value** 1142 1143 | Type| Description| 1144 | -------- | -------- | 1145 | Promise<void> | Promise used to return the result.| 1146 1147**Error codes** 1148 1149| ID| Error Message| 1150| ------- | -------- | 1151| 16000009 | An ability cannot be started or stopped in Wukong mode. | 1152 1153For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1154 1155**Example** 1156 1157```ts 1158import missionManager from '@ohos.app.ability.missionManager'; 1159import { BusinessError } from '@ohos.base'; 1160 1161let testMissionId = 2; 1162try { 1163 missionManager.moveMissionToFront(testMissionId).then((data: void) => { 1164 console.info(`moveMissionToFront successfully. Data: ${JSON.stringify(data)}`); 1165 }).catch((error: BusinessError) => { 1166 console.error(`moveMissionToFront failed. Cause: ${error.message}`); 1167 }); 1168} catch (error) { 1169 let err: BusinessError = error as BusinessError; 1170 console.error(`moveMissionToFront failed. Cause: ${err.message}`); 1171} 1172``` 1173 1174## missionManager.moveMissionsToForeground<sup>10+</sup> 1175 1176moveMissionsToForeground(missionIds: Array<number>, callback: AsyncCallback<void>): void 1177 1178Switches a batch of missions to the foreground. This API uses an asynchronous callback to return the result. 1179 1180**Required permissions**: ohos.permission.MANAGE_MISSIONS 1181 1182**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1183 1184**System API**: This is a system API. 1185 1186**Parameters** 1187 1188 | Name| Type| Mandatory| Description| 1189 | -------- | -------- | -------- | -------- | 1190 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1191 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1192 1193**Error codes** 1194 1195For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1196 1197| ID| Error Message| 1198| ------- | -------- | 1199| 16000050 | Internal error. | 1200 1201**Example** 1202 1203```ts 1204import abilityManager from '@ohos.app.ability.abilityManager'; 1205import missionManager from '@ohos.app.ability.missionManager'; 1206import { BusinessError } from '@ohos.base'; 1207 1208try { 1209 missionManager.getMissionInfos("", 10, (error: BusinessError, missionInfos: Array<missionManager.MissionInfo>) => { 1210 if (error.code) { 1211 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1212 return; 1213 } 1214 if (missionInfos.length < 1) { 1215 return; 1216 } 1217 1218 let toShows = new Array<number>(); 1219 for (let missionInfo of missionInfos) { 1220 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1221 toShows.push(missionInfo.missionId); 1222 } 1223 } 1224 missionManager.moveMissionsToForeground(toShows, (err: BusinessError, data: void) => { 1225 if (err) { 1226 console.error(`moveMissionsToForeground failed: ${err.message}`); 1227 } else { 1228 console.info(`moveMissionsToForeground successfully: ${JSON.stringify(data)}`); 1229 } 1230 }); 1231 }); 1232} catch (paramError) { 1233 let code = (paramError as BusinessError).code; 1234 let message = (paramError as BusinessError).message; 1235 console.error(`error: ${code}, ${message} `); 1236} 1237 1238``` 1239 1240## missionManager.moveMissionsToForeground<sup>10+</sup> 1241 1242moveMissionsToForeground(missionIds: Array<number>, topMission: number, callback: AsyncCallback<void>): void 1243 1244Switches a batch of missions to the foreground, and moves the mission with the specified ID to the top. This API uses an asynchronous callback to return the result. 1245 1246**Required permissions**: ohos.permission.MANAGE_MISSIONS 1247 1248**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1249 1250**System API**: This is a system API. 1251 1252**Parameters** 1253 1254 | Name| Type| Mandatory| Description| 1255 | -------- | -------- | -------- | -------- | 1256 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1257 | topMission | number | Yes| ID of the mission to be moved to the top.| 1258 | callback | AsyncCallback<void> | Yes| Callback used to return the result.| 1259 1260**Error codes** 1261 1262For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1263 1264| ID| Error Message| 1265| ------- | -------- | 1266| 16000050 | Internal error. | 1267 1268**Example** 1269 1270```ts 1271import abilityManager from '@ohos.app.ability.abilityManager'; 1272import missionManager from '@ohos.app.ability.missionManager'; 1273import { BusinessError } from '@ohos.base'; 1274 1275try { 1276 missionManager.getMissionInfos("", 10, (error: BusinessError, missionInfos: Array<missionManager.MissionInfo>) => { 1277 if (error.code) { 1278 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1279 return; 1280 } 1281 if (missionInfos.length < 1) { 1282 return; 1283 } 1284 1285 let toShows = new Array<number>(); 1286 for (let missionInfo of missionInfos) { 1287 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1288 toShows.push(missionInfo.missionId); 1289 } 1290 } 1291 missionManager.moveMissionsToForeground(toShows, toShows[0], (err: BusinessError, data: void) => { 1292 if (err) { 1293 console.error(`moveMissionsToForeground failed: ${err.message}`); 1294 } else { 1295 console.info(`moveMissionsToForeground successfully: ${JSON.stringify(data)}`); 1296 } 1297 }); 1298 }); 1299} catch (paramError) { 1300 let code = (paramError as BusinessError).code; 1301 let message = (paramError as BusinessError).message; 1302 console.error(`error: ${code}, ${message} `); 1303} 1304 1305``` 1306 1307## missionManager.moveMissionsToForeground<sup>10+</sup> 1308 1309moveMissionsToForeground(missionIds: Array<number>, topMission?: number): Promise<void> 1310 1311Switches a batch of missions to the foreground, and moves the mission with the specified ID to the top. This API uses a promise to return the result. 1312 1313**Required permissions**: ohos.permission.MANAGE_MISSIONS 1314 1315**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1316 1317**System API**: This is a system API. 1318 1319**Parameters** 1320 1321 | Name| Type| Mandatory| Description| 1322 | -------- | -------- | -------- | -------- | 1323 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1324 | topMission | number | No| ID of the mission to be moved to the top. The default value is **-1**, indicating that the default mission is moved to the top.| 1325 1326**Return value** 1327 1328 | Type| Description| 1329 | -------- | -------- | 1330 | Promise<void> | Promise used to return the result.| 1331 1332**Error codes** 1333 1334For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1335 1336| ID| Error Message| 1337| ------- | -------- | 1338| 16000050 | Internal error. | 1339 1340**Example** 1341 1342```ts 1343import abilityManager from '@ohos.app.ability.abilityManager'; 1344import missionManager from '@ohos.app.ability.missionManager'; 1345import { BusinessError } from '@ohos.base'; 1346 1347try { 1348 missionManager.getMissionInfos("", 10, (error: BusinessError, missionInfos: Array<missionManager.MissionInfo>) => { 1349 if (error.code) { 1350 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1351 return; 1352 } 1353 if (missionInfos.length < 1) { 1354 return; 1355 } 1356 1357 let toShows = new Array<number>(); 1358 for (let missionInfo of missionInfos) { 1359 if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { 1360 toShows.push(missionInfo.missionId); 1361 } 1362 } 1363 missionManager.moveMissionsToForeground(toShows, toShows[0]).then(() => { 1364 console.log("moveMissionsToForeground is called" ); 1365 }); 1366 }); 1367} catch (paramError) { 1368 let code = (paramError as BusinessError).code; 1369 let message = (paramError as BusinessError).message; 1370 console.error(`error: ${code}, ${message} `); 1371} 1372 1373``` 1374 1375## missionManager.moveMissionsToBackground<sup>10+</sup> 1376 1377moveMissionsToBackground(missionIds: Array<number>, callback: AsyncCallback<Array<number>>): void 1378 1379Switches a batch of missions to the background. This API uses an asynchronous callback to return the result. The mission IDs in the callback are sorted by mission level when the missions are switched. 1380 1381**Required permissions**: ohos.permission.MANAGE_MISSIONS 1382 1383**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1384 1385**System API**: This is a system API. 1386 1387**Parameters** 1388 1389 | Name| Type| Mandatory| Description| 1390 | -------- | -------- | -------- | -------- | 1391 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1392 | callback | AsyncCallback<Array<number>> | Yes| Callback used to return the result.| 1393 1394**Error codes** 1395 1396For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1397 1398| ID| Error Message| 1399| ------- | -------- | 1400| 16000050 | Internal error. | 1401 1402**Example** 1403 1404```ts 1405import abilityManager from '@ohos.app.ability.abilityManager'; 1406import missionManager from '@ohos.app.ability.missionManager'; 1407import { BusinessError } from '@ohos.base'; 1408 1409try { 1410 missionManager.getMissionInfos("", 10, (error: BusinessError, missionInfos: Array<missionManager.MissionInfo>) => { 1411 if (error.code) { 1412 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1413 return; 1414 } 1415 1416 let toHides = new Array<number>(); 1417 for (let missionInfo of missionInfos) { 1418 if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { 1419 toHides.push(missionInfo.missionId); 1420 } 1421 } 1422 missionManager.moveMissionsToBackground(toHides, (err: BusinessError, data: Array<number>) => { 1423 if (err) { 1424 console.error(`moveMissionsToBackground failed: ${err.message}`); 1425 } else { 1426 console.info(`moveMissionsToBackground successfully: ${JSON.stringify(data)}`); 1427 } 1428 }); 1429 }); 1430} catch (paramError) { 1431 let code = (paramError as BusinessError).code; 1432 let message = (paramError as BusinessError).message; 1433 console.error(`error: ${code}, ${message} `); 1434} 1435``` 1436 1437## missionManager.moveMissionsToBackground<sup>10+</sup> 1438 1439moveMissionsToBackground(missionIds : Array<number>): Promise<Array<number>> 1440 1441Switches a batch of missions to the background. This API uses a promise to return the result. The mission IDs in the promise are sorted by mission level when the missions are switched. 1442 1443**Required permissions**: ohos.permission.MANAGE_MISSIONS 1444 1445**System capability**: SystemCapability.Ability.AbilityRuntime.Mission 1446 1447**System API**: This is a system API. 1448 1449**Parameters** 1450 1451 | Name| Type| Mandatory| Description| 1452 | -------- | -------- | -------- | -------- | 1453 | missionIds | Array<number> | Yes| Array holding the mission IDs.| 1454 1455**Return value** 1456 1457 | Type| Description| 1458 | -------- | -------- | 1459 | Promise<Array<number>> | Promise used to return the result.| 1460 1461**Error codes** 1462 1463For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). 1464 1465| ID| Error Message| 1466| ------- | -------- | 1467| 16000050 | Internal error. | 1468 1469**Example** 1470 1471```ts 1472import abilityManager from '@ohos.app.ability.abilityManager'; 1473import missionManager from '@ohos.app.ability.missionManager'; 1474import { BusinessError } from '@ohos.base'; 1475 1476try { 1477 missionManager.getMissionInfos("", 10, (error: BusinessError, missionInfos: Array<missionManager.MissionInfo>) => { 1478 if (error.code) { 1479 console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); 1480 return; 1481 } 1482 1483 let toHides = new Array<number>(); 1484 for (let missionInfo of missionInfos) { 1485 if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { 1486 toHides.push(missionInfo.missionId); 1487 } 1488 } 1489 missionManager.moveMissionsToBackground(toHides).then((hideRes: Array<number>) => { 1490 console.log("moveMissionsToBackground is called, res: "+ JSON.stringify(hideRes)); 1491 }); 1492 }); 1493} catch (paramError) { 1494 let code = (paramError as BusinessError).code; 1495 let message = (paramError as BusinessError).message; 1496 console.error(`error: ${code}, ${message} `); 1497} 1498 1499``` 1500