js-apis-application-missionManager.md 29.7 KB
Newer Older
1
# @ohos.application.missionManager (missionManager)
W
wusongqing 已提交
2

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**
> 
7
> The APIs of this module are supported since API version 8 and deprecated since API version 9. You are advised to use [@ohos.app.ability.missionManager](js-apis-app-ability-missionManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
8 9 10

## Modules to Import

11
```ts
12
import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
13 14
```

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
**Required permissions**: ohos.permission.MANAGE_MISSIONS
26

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
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
35
  | listener | [MissionListener](js-apis-inner-application-missionListener.md) | Yes| Mission status listener to register.|
W
wusongqing 已提交
36 37 38

**Return value**

W
wusongqing 已提交
39 40
  | Type| Description|
  | -------- | -------- |
41
  | number | 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**

45
```ts
46 47 48 49 50 51 52 53
let 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-------');},
    onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
54
};
55 56
console.log('registerMissionListener');
let listenerid = missionManager.registerMissionListener(listener);
G
Gloria 已提交
57
```
W
wusongqing 已提交
58 59 60 61


## missionManager.unregisterMissionListener

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

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

66
**Required permissions**: ohos.permission.MANAGE_MISSIONS
67

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

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

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

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

**Example**

81
```ts
82 83 84 85 86 87 88 89
  let 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-------');},
      onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
W
wusongqing 已提交
90
  };
91 92
  console.log('registerMissionListener');
  let listenerid = missionManager.registerMissionListener(listener);
W
wusongqing 已提交
93 94

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


## missionManager.unregisterMissionListener

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

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

106
**Required permissions**: ohos.permission.MANAGE_MISSIONS
107

W
wusongqing 已提交
108 109
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
112 113
**Parameters**

W
wusongqing 已提交
114 115
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
116
  | listenerId | number | Yes| Index of the mission status listener to deregister. It is returned by **registerMissionListener()**.|
W
wusongqing 已提交
117

W
wusongqing 已提交
118 119
**Return value**

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

W
wusongqing 已提交
124 125
**Example**

126
```ts
127 128 129 130 131 132 133 134
  let 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-------');},
      onMissionLabelUpdated: function (mission) {console.log('--------onMissionLabelUpdated-------');}
G
Gloria 已提交
135
  };
136 137
  console.log('registerMissionListener');
  let listenerid = missionManager.registerMissionListener(listener);
G
Gloria 已提交
138 139 140 141 142

  missionManager.unregisterMissionListener(listenerid).catch(function (err) {
      console.log(err);
  });
```
W
wusongqing 已提交
143 144 145 146


## missionManager.getMissionInfo

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

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

151
**Required permissions**: ohos.permission.MANAGE_MISSIONS
152

W
wusongqing 已提交
153 154
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
157 158
**Parameters**

W
wusongqing 已提交
159 160 161 162
  | 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.|
163
  | callback | AsyncCallback<[MissionInfo](js-apis-inner-application-missionInfo.md)> | Yes| Callback used to return the mission information obtained.|
W
wusongqing 已提交
164 165 166

**Example**

167
  ```ts
168
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
169

170 171
  let allMissions=missionManager.getMissionInfos('',10).catch(function(err){console.log(err);});
      missionManager.getMissionInfo('', allMissions[0].missionId, (error, mission) => {
172
        if (error.code) {
173
          console.log('getMissionInfo failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
174 175 176
          return;
        }

177 178 179 180 181 182
        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 已提交
183
      });
W
wusongqing 已提交
184 185 186 187 188
  ```


## missionManager.getMissionInfo

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

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

193
**Required permissions**: ohos.permission.MANAGE_MISSIONS
194

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

W
wusongqing 已提交
199 200
**Parameters**

W
wusongqing 已提交
201 202 203 204
  | 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 已提交
205 206 207

**Return value**

W
wusongqing 已提交
208 209
  | Type| Description|
  | -------- | -------- |
210
  | Promise<[MissionInfo](js-apis-inner-application-missionInfo.md)> | Promise used to return the mission information obtained.|
W
wusongqing 已提交
211 212 213

**Example**

214
  ```ts
215
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
216

217
  let mission = missionManager.getMissionInfo('', 10).catch(function (err){
W
wusongqing 已提交
218 219 220 221 222 223 224
      console.log(err);
  });
  ```


## missionManager.getMissionInfos

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

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

229
**Required permissions**: ohos.permission.MANAGE_MISSIONS
230

W
wusongqing 已提交
231 232
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
235 236
**Parameters**

W
wusongqing 已提交
237 238 239 240
  | 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.|
241
  | callback | AsyncCallback<Array<[MissionInfo](js-apis-inner-application-missionInfo.md)>> | Yes| Callback used to return the array of mission information obtained.|
W
wusongqing 已提交
242 243 244

**Example**

245
  ```ts
246
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
247

248
  missionManager.getMissionInfos('', 10, (error, missions) => {
249
      if (error.code) {
250
          console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
251 252
          return;
      }
253 254 255
      console.log('size = ${missions.length}');
      console.log('missions = ${JSON.stringify(missions)}');
  });
W
wusongqing 已提交
256 257 258 259 260
  ```


## missionManager.getMissionInfos

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

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

265
**Required permissions**: ohos.permission.MANAGE_MISSIONS
266

W
wusongqing 已提交
267 268
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
271 272
**Parameters**

W
wusongqing 已提交
273 274 275 276
  | 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 已提交
277 278 279

**Return value**

W
wusongqing 已提交
280 281
  | Type| Description|
  | -------- | -------- |
282
  | Promise<Array<[MissionInfo](js-apis-inner-application-missionInfo.md)>> | Promise used to return the array of mission information obtained.|
W
wusongqing 已提交
283 284 285

**Example**

286
  ```ts
287
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
288

289
  let allMissions = missionManager.getMissionInfos('', 10).catch(function (err){
W
wusongqing 已提交
290 291 292 293 294 295 296
      console.log(err);
  });
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
297
getMissionSnapShot(deviceId: string, missionId: number, callback: AsyncCallback<MissionSnapshot>): void;
W
wusongqing 已提交
298 299 300

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

301
**Required permissions**: ohos.permission.MANAGE_MISSIONS
302

W
wusongqing 已提交
303 304
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
307 308
**Parameters**

W
wusongqing 已提交
309 310 311 312
  | 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.|
313
  | callback | AsyncCallback<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Yes| Callback used to return the snapshot information obtained.|
W
wusongqing 已提交
314 315 316

**Example**

317
  ```ts
318
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
319

320
  missionManager.getMissionInfos('', 10, (error, missions) => {
321
    if (error.code) {
322
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
323 324
        return;
    }
325 326 327
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
328

329
    missionManager.getMissionSnapShot('', id, (error, snapshot) => {
330
      if (error.code) {
331
          console.log('getMissionSnapShot failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
332 333
          return;
      }
334 335 336
      console.log('bundleName = ${snapshot.ability.bundleName}');
    });
  });
W
wusongqing 已提交
337 338 339 340 341
  ```


## missionManager.getMissionSnapShot

W
wusongqing 已提交
342
getMissionSnapShot(deviceId: string, missionId: number): Promise<MissionSnapshot>;
W
wusongqing 已提交
343 344 345

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

346
**Required permissions**: ohos.permission.MANAGE_MISSIONS
347

W
wusongqing 已提交
348 349
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
352 353
**Parameters**

W
wusongqing 已提交
354 355 356 357
  | 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 已提交
358 359 360

**Return value**

W
wusongqing 已提交
361 362
  | Type| Description|
  | -------- | -------- |
363
  | Promise<[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)> | Promise used to return the snapshot information obtained.|
W
wusongqing 已提交
364 365 366

**Example**

367
  ```ts
368
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
369

370 371
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
372 373
    allMissions=res;
    }).catch(function(err){console.log(err);});
374 375 376
    console.log('size = ${allMissions.length}');
    console.log('missions = ${JSON.stringify(allMissions)}');
    let id = allMissions[0].missionId;
W
wusongqing 已提交
377

378
    let snapshot = missionManager.getMissionSnapShot('', id).catch(function (err){
W
wusongqing 已提交
379 380
        console.log(err);
    });
W
wusongqing 已提交
381 382
  ```

383 384 385 386 387 388
## 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.

389
**Required permissions**: ohos.permission.MANAGE_MISSIONS
390 391 392 393 394 395 396 397 398 399 400

**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.|
401
  | callback | AsyncCallback&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Yes| Callback used to return the snapshot information obtained.|
402 403 404

**Example**

405
  ```ts
406
  import missionManager from '@ohos.application.missionManager';
407

408
  missionManager.getMissionInfos('', 10, (error, missions) => {
409
    if (error.code) {
410
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
411 412
        return;
    }
413 414 415
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
416

417
    missionManager.getLowResolutionMissionSnapShot('', id, (error, snapshot) => {
418
      if (error.code) {
419 420
          console.log('getLowResolutionMissionSnapShot failed, error.code: ${JSON.stringify(error.code)}
            'error.message: ${JSON.stringify(error.message)}');
421 422
          return;
      }
423 424 425
  	  console.log('bundleName = ${snapshot.ability.bundleName}');
    });
  });
426 427 428 429 430 431 432 433 434
  ```


## 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.

435
**Required permissions**: ohos.permission.MANAGE_MISSIONS
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451

**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|
  | -------- | -------- |
452
  | Promise&lt;[MissionSnapshot](js-apis-inner-application-missionSnapshot.md)&gt; | Promise used to return the snapshot information obtained.|
453 454 455

**Example**

456
  ```ts
457
  import missionManager from '@ohos.application.missionManager';
458

459 460
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
461 462
    allMissions=res;
    }).catch(function(err){console.log(err);});
463 464 465
    console.log('size = ${allMissions.length}');
    console.log('missions = ${JSON.stringify(allMissions)}');
    let id = allMissions[0].missionId;
466

467
    let snapshot = missionManager.getLowResolutionMissionSnapShot('', id).catch(function (err){
468 469 470 471
        console.log(err);
    });
  ```

W
wusongqing 已提交
472 473 474

## missionManager.lockMission

W
wusongqing 已提交
475
lockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
476 477 478

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

479
**Required permissions**: ohos.permission.MANAGE_MISSIONS
480

W
wusongqing 已提交
481 482
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
485 486
**Parameters**

W
wusongqing 已提交
487 488 489 490
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
491 492 493

**Example**

494
  ```ts
495
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
496

497
  missionManager.getMissionInfos('', 10, (error, missions) => {
498
    if (error.code) {
499 500
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}
            'error.message: ${JSON.stringify(error.message)}');
501 502
        return;
    }
503 504 505
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
506 507

    missionManager.lockMission(id).then(() => {
508 509
  	  console.log('lockMission is called ');
    });
W
wusongqing 已提交
510 511 512 513 514 515
  });
  ```


## missionManager.lockMission

W
wusongqing 已提交
516
lockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
517 518 519

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

520
**Required permissions**: ohos.permission.MANAGE_MISSIONS
521

W
wusongqing 已提交
522 523
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
526 527
**Parameters**

W
wusongqing 已提交
528 529 530
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
531

W
wusongqing 已提交
532 533
**Return value**

W
wusongqing 已提交
534 535 536
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
537

W
wusongqing 已提交
538 539
**Example**

540
  ```ts
541 542 543
  import missionManager from '@ohos.application.missionManager';
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
544 545
    allMissions=res;
  }).catch(function(err){console.log(err);});
546 547 548
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
549

W
wusongqing 已提交
550
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
551 552 553 554 555 556 557
      console.log(err);
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
558
unlockMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
559 560 561

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

562
**Required permissions**: ohos.permission.MANAGE_MISSIONS
563

W
wusongqing 已提交
564 565
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
568 569
**Parameters**

W
wusongqing 已提交
570 571 572 573
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
574 575 576

**Example**

577
  ```ts
578
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
579

580
  missionManager.getMissionInfos('', 10, (error, missions) => {
581
    if (error.code) {
582
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
583 584
        return;
    }
585 586 587
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
588 589

    missionManager.unlockMission(id).then(() => {
590 591
  	  console.log('unlockMission is called ');
    });
W
wusongqing 已提交
592 593 594 595 596 597
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
598
unlockMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
599 600 601

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

602
**Required permissions**: ohos.permission.MANAGE_MISSIONS
603

W
wusongqing 已提交
604 605
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
608 609
**Parameters**

W
wusongqing 已提交
610 611 612
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
613

W
wusongqing 已提交
614 615
**Return value**

W
wusongqing 已提交
616 617 618
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
619

W
wusongqing 已提交
620 621
**Example**

622
  ```ts
623
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
624

625 626
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
627 628
    allMissions=res;
  }).catch(function(err){console.log(err);});
629 630 631
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
632

W
wusongqing 已提交
633
  missionManager.lockMission(id).catch(function (err){
W
wusongqing 已提交
634 635
      console.log(err);
  });
W
wusongqing 已提交
636
  missionManager.unlockMission(id).catch(function (err){
W
wusongqing 已提交
637 638 639 640 641 642 643
      console.log(err);
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
644
clearMission(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
645 646 647

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

648
**Required permissions**: ohos.permission.MANAGE_MISSIONS
649

W
wusongqing 已提交
650 651
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
654 655
**Parameters**

W
wusongqing 已提交
656 657 658 659
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
660 661 662

**Example**

663
  ```ts
664
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
665

666
  missionManager.getMissionInfos('', 10, (error, missions) => {
667
    if (error.code) {
668
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
669 670
        return;
    }
671 672 673
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
674 675

    missionManager.clearMission(id).then(() => {
676 677
  	  console.log('clearMission is called ');
    });
W
wusongqing 已提交
678 679 680 681 682 683
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
684
clearMission(missionId: number): Promise&lt;void&gt;;
W
wusongqing 已提交
685 686 687

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

688
**Required permissions**: ohos.permission.MANAGE_MISSIONS
689

W
wusongqing 已提交
690 691
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
694 695
**Parameters**

W
wusongqing 已提交
696 697 698
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
699

W
wusongqing 已提交
700 701
**Return value**

W
wusongqing 已提交
702 703 704
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
705

W
wusongqing 已提交
706 707
**Example**

708
  ```ts
709
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
710

711 712
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
713 714
    allMissions=res;
  }).catch(function(err){console.log(err);});
715 716 717
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
718

W
wusongqing 已提交
719
  missionManager.clearMission(id).catch(function (err){
W
wusongqing 已提交
720 721 722 723 724 725 726
    console.log(err);
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
727
clearAllMissions(callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
728 729 730

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

731
**Required permissions**: ohos.permission.MANAGE_MISSIONS
732

W
wusongqing 已提交
733 734
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
737 738
**Example**

739
  ```ts
W
wusongqing 已提交
740 741 742
  import missionManager from '@ohos.application.missionManager'

  missionManager.clearAllMissions().then(() => {
743
    console.log('clearAllMissions is called ');
W
wusongqing 已提交
744 745 746 747 748 749
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
750
clearAllMissions(): Promise&lt;void&gt;;
W
wusongqing 已提交
751 752 753

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

754
**Required permissions**: ohos.permission.MANAGE_MISSIONS
755

W
wusongqing 已提交
756 757
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
760 761
**Return value**

W
wusongqing 已提交
762 763 764
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
765

W
wusongqing 已提交
766 767
**Example**

768
  ```ts
769
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
770
  missionManager.clearAllMissions().catch(function (err){
W
wusongqing 已提交
771 772 773 774 775 776 777
    console.log(err);
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
778
moveMissionToFront(missionId: number, callback: AsyncCallback&lt;void&gt;): void;
W
wusongqing 已提交
779 780 781

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

782
**Required permissions**: ohos.permission.MANAGE_MISSIONS
783

W
wusongqing 已提交
784 785
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
788 789
**Parameters**

W
wusongqing 已提交
790 791 792 793
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
794 795 796

**Example**

797
  ```ts
798
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
799

800
  missionManager.getMissionInfos('', 10, (error, missions) => {
801
    if (error.code) {
802
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
803 804
        return;
    }
805 806 807
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
808 809

    missionManager.moveMissionToFront(id).then(() => {
810 811
  	  console.log('moveMissionToFront is called ');
    });
W
wusongqing 已提交
812 813 814 815 816 817
  });
  ```


## missionManager.moveMissionToFront

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

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

822
**Required permissions**: ohos.permission.MANAGE_MISSIONS
823

W
wusongqing 已提交
824 825
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
828 829
**Parameters**

W
wusongqing 已提交
830 831 832
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
833
  | 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.|
W
wusongqing 已提交
834
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
835 836 837

**Example**

838
  ```ts
839
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
840

841
  missionManager.getMissionInfos('', 10, (error, missions) => {
842
    if (error.code) {
843
        console.log('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
844 845
        return;
    }
846 847 848
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
849 850

    missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
851
  	  console.log('moveMissionToFront is called ');
W
wusongqing 已提交
852 853 854 855 856 857 858
    });
  });
  ```


## missionManager.moveMissionToFront

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

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

863
**Required permissions**: ohos.permission.MANAGE_MISSIONS
864

W
wusongqing 已提交
865 866
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
869 870
**Parameters**

W
wusongqing 已提交
871 872 873
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
874
  | 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.|
W
wusongqing 已提交
875

W
wusongqing 已提交
876 877
**Return value**

W
wusongqing 已提交
878 879 880
  | Type| Description| 
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
881

W
wusongqing 已提交
882 883
**Example**

884
  ```ts
885
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
886

887 888
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
889 890
    allMissions=res;
  }).catch(function(err){console.log(err);});
891 892 893
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
894

W
wusongqing 已提交
895
  missionManager.moveMissionToFront(id).catch(function (err){
W
wusongqing 已提交
896 897 898
    console.log(err);
  });
  ```