js-apis-missionManager.md 28.6 KB
Newer Older
W
wusongqing 已提交
1 2
# missionManager

3
The **missionManager** module provides APIs to lock, unlock, and clear missions, and switch a mission to the foreground.
W
wusongqing 已提交
4

W
wusongqing 已提交
5 6
> **NOTE**
> 
W
wusongqing 已提交
7
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
8 9 10 11 12 13 14

## Modules to Import

```
import missionManager from '@ohos.application.missionManager'
```

W
wusongqing 已提交
15 16 17
## Required Permissions

ohos.permission.MANAGE_MISSIONS
W
wusongqing 已提交
18 19 20

## missionManager.registerMissionListener

W
wusongqing 已提交
21
registerMissionListener(listener: MissionListener): number;
W
wusongqing 已提交
22 23 24

Registers a listener to observe the mission status.

25 26
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
27 28
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

29 30
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
31 32
**Parameters**

W
wusongqing 已提交
33 34 35
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | listener | MissionListener | Yes| Listener to register.|
W
wusongqing 已提交
36 37 38

**Return value**

W
wusongqing 已提交
39 40 41
  | Type| Description|
  | -------- | -------- |
  | number | Returns the unique index of the mission status listener, which is created by the system and allocated when the listener is registered.|
W
wusongqing 已提交
42 43 44

**Example**

G
Gloria 已提交
45 46 47 48 49 50 51 52
```js
  var listener = {
      onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
      onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
      onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
      onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
      onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
      onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
W
wusongqing 已提交
53 54 55
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);
G
Gloria 已提交
56
```
W
wusongqing 已提交
57 58 59 60


## missionManager.unregisterMissionListener

W
wusongqing 已提交
61
unregisterMissionListener(listenerId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
62

W
wusongqing 已提交
63
Deregisters a mission status listener. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
64

65 66
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
67 68
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

69 70
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
71 72
**Parameters**

W
wusongqing 已提交
73 74 75 76
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
  | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
77 78 79

**Example**

G
Gloria 已提交
80 81 82 83 84 85 86 87
```js
  var listener = {
      onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
      onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
      onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
      onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
      onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
      onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
W
wusongqing 已提交
88 89 90 91 92
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

  missionManager.unregisterMissionListener(listenerid, (error) => {
G
Gloria 已提交
93
      console.log("unregisterMissionListener");
W
wusongqing 已提交
94
  })
G
Gloria 已提交
95
```
W
wusongqing 已提交
96 97 98 99


## missionManager.unregisterMissionListener

W
wusongqing 已提交
100
unregisterMissionListener(listenerId: number): Promise<void>;
W
wusongqing 已提交
101

W
wusongqing 已提交
102
Deregisters a mission status listener. This API uses a promise to return the result.
W
wusongqing 已提交
103

104 105
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
106 107
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

108 109
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
110 111
**Parameters**

W
wusongqing 已提交
112 113 114
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | listenerId | number | Yes| Unique index of the mission status listener to unregister. It is returned by **registerMissionListener**.|
W
wusongqing 已提交
115

W
wusongqing 已提交
116 117
**Return value**

W
wusongqing 已提交
118 119 120
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
121

W
wusongqing 已提交
122 123
**Example**

G
Gloria 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
```js
  var listener = {
      onMissionCreated: function (mission) {console.log("--------onMissionCreated-------")},
      onMissionDestroyed: function (mission) {console.log("--------onMissionDestroyed-------")},
      onMissionSnapshotChanged: function (mission) {console.log("--------onMissionSnapshotChanged-------")},
      onMissionMovedToFront: function (mission) {console.log("--------onMissionMovedToFront-------")},
      onMissionIconUpdated: function (mission, icon) {console.log("--------onMissionIconUpdated-------")},
      onMissionClosed: function (mission) {console.log("--------onMissionClosed-------")}
  };
  console.log("registerMissionListener")
  var listenerid = missionManager.registerMissionListener(listener);

  missionManager.unregisterMissionListener(listenerid).catch(function (err) {
      console.log(err);
  });
```
W
wusongqing 已提交
140 141 142 143


## missionManager.getMissionInfo

W
wusongqing 已提交
144
getMissionInfo(deviceId: string, missionId: number, callback: AsyncCallback<MissionInfo>): void;
W
wusongqing 已提交
145

W
wusongqing 已提交
146
Obtains the information about a given mission. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
147

148 149
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
150 151
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

152 153
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
154 155
**Parameters**

W
wusongqing 已提交
156 157 158 159 160
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback<[MissionInfo](#missioninfo)> | Yes| Callback used to return the mission information obtained.|
W
wusongqing 已提交
161 162 163 164 165 166

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
167 168 169 170 171 172 173 174 175 176
  var allMissions=missionManager.getMissionInfos("",10).catch(function(err){console.log(err);});
      missionManager.getMissionInfo("", allMissions[0].missionId, (error, mission) => {
        console.log("getMissionInfo is called, error.code = " + error.code)
        console.log("mission.missionId = " + mission.missionId);
        console.log("mission.runningState = " + mission.runningState);
        console.log("mission.lockedState = " + mission.lockedState);
        console.log("mission.timestamp = " + mission.timestamp);
        console.log("mission.label = " + mission.label);
        console.log("mission.iconPath = " + mission.iconPath);
      });
W
wusongqing 已提交
177 178 179 180 181
  ```


## missionManager.getMissionInfo

W
wusongqing 已提交
182
getMissionInfo(deviceId: string, missionId: number): Promise<MissionInfo>;
W
wusongqing 已提交
183

W
wusongqing 已提交
184
Obtains the information about a given mission. This API uses a promise to return the result.
W
wusongqing 已提交
185

186 187
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
188 189
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

190 191
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
192 193
**Parameters**

W
wusongqing 已提交
194 195 196 197
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
198 199 200

**Return value**

W
wusongqing 已提交
201 202 203
  | Type| Description|
  | -------- | -------- |
  | Promise<[MissionInfo](#missioninfo)> | Promise used to return the mission information obtained.|
W
wusongqing 已提交
204 205 206 207 208 209

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
210
  var mission = missionManager.getMissionInfo("", 10).catch(function (err){
W
wusongqing 已提交
211 212 213 214 215 216 217
      console.log(err);
  });
  ```


## missionManager.getMissionInfos

W
wusongqing 已提交
218
getMissionInfos(deviceId: string, numMax: number, callback: AsyncCallback<Array<MissionInfo>>): void;
W
wusongqing 已提交
219

W
wusongqing 已提交
220
Obtains information about all missions. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
221

222 223
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
224 225
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

226 227
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
228 229
**Parameters**

W
wusongqing 已提交
230 231 232 233 234
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
  | callback | AsyncCallback<Array<[MissionInfo](#missioninfo)>> | Yes| Callback used to return the array of mission information obtained.|
W
wusongqing 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
      console.log("getMissionInfos is called, error.code = " + error.code);
      console.log("size = " + missions.length);
      console.log("missions = " + JSON.stringify(missions));
  })
  ```


## missionManager.getMissionInfos

W
wusongqing 已提交
251
getMissionInfos(deviceId: string, numMax: number): Promise<Array<MissionInfo>>;
W
wusongqing 已提交
252

W
wusongqing 已提交
253
Obtains information about all missions. This API uses a promise to return the result.
W
wusongqing 已提交
254

255 256
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
257 258
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

259 260
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
261 262
**Parameters**

W
wusongqing 已提交
263 264 265 266
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | numMax | number | Yes| Maximum number of missions whose information can be obtained.|
W
wusongqing 已提交
267 268 269

**Return value**

W
wusongqing 已提交
270 271 272
  | Type| Description|
  | -------- | -------- |
  | Promise<Array<[MissionInfo](#missioninfo)>> | Promise used to return the array of mission information obtained.|
W
wusongqing 已提交
273 274 275 276 277 278

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
279
  var allMissions = missionManager.getMissionInfos("", 10).catch(function (err){
W
wusongqing 已提交
280 281 282 283 284 285 286
      console.log(err);
  });
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
287
getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void;
W
wusongqing 已提交
288 289 290

Obtains the snapshot of a given mission. This API uses an asynchronous callback to return the result.

291 292
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
293 294
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

295 296
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
297 298
**Parameters**

W
wusongqing 已提交
299 300 301 302 303
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback<[MissionSnapshot](js-apis-application-MissionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
W
wusongqing 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.getMissionSnapShot("", id, (error, snapshot) => {
  	console.log("getMissionSnapShot is called, error.code = " + error.code);
  	console.log("bundleName = " + snapshot.ability.bundleName);
  })
  })
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
326
getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>;
W
wusongqing 已提交
327 328 329

Obtains the snapshot of a given mission. This API uses a promise to return the result.

330 331
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
332 333
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

334 335
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
336 337
**Parameters**

W
wusongqing 已提交
338 339 340 341
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
342 343 344

**Return value**

W
wusongqing 已提交
345 346 347
  | Type| Description|
  | -------- | -------- |
  | Promise<[MissionSnapshot](js-apis-application-MissionSnapshot.md)> | Promise used to return the snapshot information obtained.|
W
wusongqing 已提交
348 349 350 351 352 353

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
354 355 356 357 358 359 360 361 362 363 364
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
    }).catch(function(err){console.log(err);});
    console.log("size = " + allMissions.length);
    console.log("missions = " + JSON.stringify(allMissions));
    var id = allMissions[0].missionId;

    var snapshot = missionManager.getMissionSnapShot("", id).catch(function (err){
        console.log(err);
    });
W
wusongqing 已提交
365 366
  ```

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
## missionManager.getLowResolutionMissionSnapShot<sup>9+</sup>

getLowResolutionMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback\<MissionSnapshot>): void;

Obtains the low-resolution snapshot of a given mission. This API uses an asynchronous callback to return the result.

**Required permission**: ohos.permission.MANAGE_MISSIONS

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.getLowResolutionMissionSnapShot("", id, (error, snapshot) => {
  	console.log("getLowResolutionMissionSnapShot is called, error.code = " + error.code);
  	console.log("bundleName = " + snapshot.ability.bundleName);
  })
  })
  ```


## missionManager.getLowResolutionMissionSnapShot<sup>9+</sup>

getLowResolutionMissionSnapShot(deviceId: string, missionId: number): Promise\<MissionSnapshot>;

Obtains the low-resolution snapshot of a given mission. This API uses a promise to return the result.

**Required permission**: ohos.permission.MANAGE_MISSIONS

**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | deviceId | string | Yes| Device ID. It is a null string by default for the local device.|
  | missionId | number | Yes| Mission ID.|

**Return value**

  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[MissionSnapshot](js-apis-application-MissionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
    }).catch(function(err){console.log(err);});
    console.log("size = " + allMissions.length);
    console.log("missions = " + JSON.stringify(allMissions));
    var id = allMissions[0].missionId;

    var snapshot = missionManager.getLowResolutionMissionSnapShot("", id).catch(function (err){
        console.log(err);
    });
  ```

W
wusongqing 已提交
449 450 451

## missionManager.lockMission

W
wusongqing 已提交
452
lockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
453 454 455

Locks a given mission. This API uses an asynchronous callback to return the result.

456 457
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
458 459
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

460 461
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
462 463
**Parameters**

W
wusongqing 已提交
464 465 466 467
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.lockMission(id).then(() => {
  	console.log("lockMission is called ");
  });
  });
  ```


## missionManager.lockMission

W
wusongqing 已提交
489
lockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
490 491 492

Locks a given mission. This API uses a promise to return the result.

493 494
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
495 496
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

497 498
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
499 500
**Parameters**

W
wusongqing 已提交
501 502 503
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
504

W
wusongqing 已提交
505 506
**Return value**

W
wusongqing 已提交
507 508 509
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
510

W
wusongqing 已提交
511 512 513 514
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'
W
wusongqing 已提交
515 516 517 518
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
519 520 521 522
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
523
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
524 525 526 527 528 529 530
      console.log(err);
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
531
unlockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
532 533 534

Unlocks a given mission. This API uses an asynchronous callback to return the result.

535 536
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
537 538
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

539 540
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
541 542
**Parameters**

W
wusongqing 已提交
543 544 545 546
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.unlockMission(id).then(() => {
  	console.log("unlockMission is called ");
  });
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
568
unlockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
569 570 571

Unlocks a given mission. This API uses a promise to return the result.

572 573
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
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.

W
wusongqing 已提交
578 579
**Parameters**

W
wusongqing 已提交
580 581 582
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
583

W
wusongqing 已提交
584 585
**Return value**

W
wusongqing 已提交
586 587 588
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
589

W
wusongqing 已提交
590 591 592 593 594
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
595 596 597 598
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
599 600 601 602
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
603
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
604 605
      console.log(err);
  });
W
wusongqing 已提交
606
  missionManager.unlockMission(id).catch(function (err){
W
wusongqing 已提交
607 608 609 610 611 612 613
      console.log(err);
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
614
clearMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
615 616 617

Clears a given mission, regardless of whether it is locked. This API uses an asynchronous callback to return the result.

618 619
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
620 621
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

622 623
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
624 625
**Parameters**

W
wusongqing 已提交
626 627 628 629
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.clearMission(id).then(() => {
  	console.log("clearMission is called ");
  });
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
651
clearMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
652 653 654

Clears a given mission, regardless of whether it is locked. This API uses a promise to return the result.

655 656
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
657 658
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

659 660
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
661 662
**Parameters**

W
wusongqing 已提交
663 664 665
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
666

W
wusongqing 已提交
667 668
**Return value**

W
wusongqing 已提交
669 670 671
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
672

W
wusongqing 已提交
673 674 675 676 677
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
678 679 680 681
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
682 683 684 685
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
686
  missionManager.clearMission(id).catch(function (err){
W
wusongqing 已提交
687 688 689 690 691 692 693
    console.log(err);
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
694
clearAllMissions(callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
695 696 697

Clears all unlocked missions. This API uses an asynchronous callback to return the result.

698 699
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
700 701
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

702 703
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
704 705 706 707 708 709 710 711 712 713 714 715 716
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.clearAllMissions().then(() => {
    console.log("clearAllMissions is called ");
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
717
clearAllMissions(): Promise&lt;void&gt;;
W
wusongqing 已提交
718 719 720

Clears all unlocked missions. This API uses a promise to return the result.

721 722
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
723 724
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

725 726
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
727 728
**Return value**

W
wusongqing 已提交
729 730 731
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
732

W
wusongqing 已提交
733 734 735 736
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'
W
wusongqing 已提交
737
  missionManager.clearAllMissions().catch(function (err){
W
wusongqing 已提交
738 739 740 741 742 743 744
    console.log(err);
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
745
moveMissionToFront(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
746 747 748

Switches a given mission to the foreground. This API uses an asynchronous callback to return the result.

749 750
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
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.

W
wusongqing 已提交
755 756
**Parameters**

W
wusongqing 已提交
757 758 759 760
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.moveMissionToFront(id).then(() => {
  	console.log("moveMissionToFront is called ");
  });
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
782
moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
783

W
wusongqing 已提交
784
Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
785

786 787
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
788 789
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

790 791
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
792 793
**Parameters**

W
wusongqing 已提交
794 795 796
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
797
  | options | [StartOptions](js-apis-application-StartOptions.md) | Yes| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
W
wusongqing 已提交
798
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819

**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

  missionManager.getMissionInfos("", 10, (error, missions) => {
    console.log("getMissionInfos is called, error.code = " + error.code);
    console.log("size = " + missions.length);
    console.log("missions = " + JSON.stringify(missions));
    var id = missions[0].missionId;

    missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
  	console.log("moveMissionToFront is called ");
    });
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
820
moveMissionToFront(missionId: number, options?: StartOptions): Promise&lt;void&gt;;
W
wusongqing 已提交
821

W
wusongqing 已提交
822
Switches a given mission to the foreground, with the startup parameters for the switching specified. This API uses a promise to return the result.
W
wusongqing 已提交
823

824 825
**Required permission**: ohos.permission.MANAGE_MISSIONS

W
wusongqing 已提交
826 827
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

828 829
**System API**: This is a system API and cannot be called by third-party applications.

W
wusongqing 已提交
830 831
**Parameters**

W
wusongqing 已提交
832 833 834
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
835
  | options | [StartOptions](js-apis-application-StartOptions.md) | No| Startup parameters, which are used to specify the window mode and device ID for switching the mission to the foreground.|
W
wusongqing 已提交
836

W
wusongqing 已提交
837 838
**Return value**

W
wusongqing 已提交
839 840 841
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
842

W
wusongqing 已提交
843 844 845 846 847
**Example**

  ```js
  import missionManager from '@ohos.application.missionManager'

W
wusongqing 已提交
848 849 850 851
  var allMissions;
  missionManager.getMissionInfos("",10).then(function(res){
    allMissions=res;
  }).catch(function(err){console.log(err);});
W
wusongqing 已提交
852 853 854 855
  console.log("size = " + allMissions.length);
  console.log("missions = " + JSON.stringify(allMissions));
  var id = allMissions[0].missionId;

W
wusongqing 已提交
856
  missionManager.moveMissionToFront(id).catch(function (err){
W
wusongqing 已提交
857 858 859
    console.log(err);
  });
  ```
W
wusongqing 已提交
860 861 862 863 864

## MissionInfo

Describes the mission information.

865 866 867
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

**System API**: This is a system API and cannot be called by third-party applications.
W
wusongqing 已提交
868

W
wusongqing 已提交
869
| Name| Type| Readable| Writable| Description| 
W
wusongqing 已提交
870
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
871 872 873 874 875 876 877
| missionId | number | Yes| Yes| Mission ID.| 
| runningState | number | Yes| Yes| Running state of the mission.| 
| lockedState | boolean | Yes| Yes| Locked state of the mission.| 
| timestamp | string | Yes| Yes| Latest time when the mission was created or updated.| 
| want | [Want](js-apis-application-Want.md) | Yes| Yes| **Want** information of the mission.| 
| label | string | Yes| Yes| Label of the mission.| 
| iconPath | string | Yes| Yes| Path of the mission icon.| 
878
| continuable | boolean | Yes| Yes| Whether the mission can be continued on another device.|