js-apis-application-missionManager.md 27.2 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
      console.error('unregisterMissionListener fail, error: ${error}');
96
  });
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
  missionManager.unregisterMissionListener(listenerid).catch(function (error) {
      console.error('unregisterMissionListener fail, error: ${error}');
G
Gloria 已提交
141 142
  });
```
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.error('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 218
  let mission = missionManager.getMissionInfo('', 10).catch(function (error){
      console.error('getMissionInfo fail, error: ${error}');
W
wusongqing 已提交
219 220 221 222 223 224
  });
  ```


## 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.error('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 290
  let allMissions = missionManager.getMissionInfos('', 10).catch(function (error){
      console.error('getMissionInfos fail, error: ${error}');
W
wusongqing 已提交
291 292 293 294 295 296
  });
  ```


## 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.error('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.error('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
    allMissions=res;
373 374 375
    }).catch(function(error) {
        console.error('getMissionInfos fail, error: ${error}');
    });
376 377 378
    console.log('size = ${allMissions.length}');
    console.log('missions = ${JSON.stringify(allMissions)}');
    let id = allMissions[0].missionId;
W
wusongqing 已提交
379

380 381
    let snapshot = missionManager.getMissionSnapShot('', id).catch(function (error){
        console.error('getMissionSnapShot fail, error: ${error}');
W
wusongqing 已提交
382
    });
W
wusongqing 已提交
383 384 385 386
  ```

## missionManager.lockMission

W
wusongqing 已提交
387
lockMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
388 389 390

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

391
**Required permissions**: ohos.permission.MANAGE_MISSIONS
392

W
wusongqing 已提交
393 394
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
397 398
**Parameters**

W
wusongqing 已提交
399 400 401 402
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
403 404 405

**Example**

406
  ```ts
407
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
408

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

    missionManager.lockMission(id).then(() => {
419 420
  	  console.log('lockMission is called ');
    });
W
wusongqing 已提交
421 422 423 424 425 426
  });
  ```


## missionManager.lockMission

W
wusongqing 已提交
427
lockMission(missionId: number): Promise<void>;
W
wusongqing 已提交
428 429 430

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

431
**Required permissions**: ohos.permission.MANAGE_MISSIONS
432

W
wusongqing 已提交
433 434
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
437 438
**Parameters**

W
wusongqing 已提交
439 440 441
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
442

W
wusongqing 已提交
443 444
**Return value**

W
wusongqing 已提交
445 446 447
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
448

W
wusongqing 已提交
449 450
**Example**

451
  ```ts
452 453 454
  import missionManager from '@ohos.application.missionManager';
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
455
    allMissions=res;
456 457 458
  }).catch(function(error) {
      console.error('getMissionInfos fail, error: ${error}');
  });
459 460 461
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
462

463 464
  missionManager.lockMission(id).catch(function (error){
      console.error('lockMission fail, error: ${error}');
W
wusongqing 已提交
465 466 467 468 469 470
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
471
unlockMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
472 473 474

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

475
**Required permissions**: ohos.permission.MANAGE_MISSIONS
476

W
wusongqing 已提交
477 478
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
481 482
**Parameters**

W
wusongqing 已提交
483 484 485 486
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| missionId | number | Yes| Mission ID.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
487 488 489

**Example**

490
  ```ts
491
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
492

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

    missionManager.unlockMission(id).then(() => {
503 504
  	  console.log('unlockMission is called ');
    });
W
wusongqing 已提交
505 506 507 508 509 510
  });
  ```


## missionManager.unlockMission

W
wusongqing 已提交
511
unlockMission(missionId: number): Promise<void>;
W
wusongqing 已提交
512 513 514

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

515
**Required permissions**: ohos.permission.MANAGE_MISSIONS
516

W
wusongqing 已提交
517 518
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
521 522
**Parameters**

W
wusongqing 已提交
523 524 525
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
W
wusongqing 已提交
526

W
wusongqing 已提交
527 528
**Return value**

W
wusongqing 已提交
529 530 531
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
532

W
wusongqing 已提交
533 534
**Example**

535
  ```ts
536
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
537

538 539
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
540
    allMissions=res;
541 542 543
  }).catch(function(error) {
      console.error('getMissionInfos fail, error: ${error}');
  });
544 545 546
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
547

548 549
  missionManager.lockMission(id).catch(function (error){
      console.error('lockMission fail, error: ${error}');
W
wusongqing 已提交
550
  });
551 552
  missionManager.unlockMission(id).catch(function (error){
      console.error('unlockMission fail, error: ${error}');
W
wusongqing 已提交
553 554 555 556 557 558
  });
  ```


## missionManager.clearMission

W
wusongqing 已提交
559
clearMission(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
560 561 562

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

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

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

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

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

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

**Example**

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

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

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


## missionManager.clearMission

W
wusongqing 已提交
599
clearMission(missionId: number): Promise<void>;
W
wusongqing 已提交
600 601 602

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

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

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

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

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

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

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

W
wusongqing 已提交
617 618 619
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
620

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

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

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

636 637
  missionManager.clearMission(id).catch(function (error){
    console.error('clearMission fail, error: ${error}');
W
wusongqing 已提交
638 639 640 641 642 643
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
644
clearAllMissions(callback: AsyncCallback<void>): void;
W
wusongqing 已提交
645 646 647

Clears all unlocked missions. 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
**Example**

656
  ```ts
W
wusongqing 已提交
657 658 659
  import missionManager from '@ohos.application.missionManager'

  missionManager.clearAllMissions().then(() => {
660
    console.log('clearAllMissions is called ');
W
wusongqing 已提交
661 662 663 664 665 666
  });
  ```


## missionManager.clearAllMissions

W
wusongqing 已提交
667
clearAllMissions(): Promise<void>;
W
wusongqing 已提交
668 669 670

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

671
**Required permissions**: ohos.permission.MANAGE_MISSIONS
672

W
wusongqing 已提交
673 674
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
677 678
**Return value**

W
wusongqing 已提交
679 680 681
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
682

W
wusongqing 已提交
683 684
**Example**

685
  ```ts
686
  import missionManager from '@ohos.application.missionManager';
687 688
  missionManager.clearAllMissions().catch(function (error){
      console.error('clearAllMissions fail, error: ${error}');
W
wusongqing 已提交
689 690 691 692 693 694
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
695
moveMissionToFront(missionId: number, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
696 697 698

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

699
**Required permissions**: ohos.permission.MANAGE_MISSIONS
700

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

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

W
wusongqing 已提交
705 706
**Parameters**

W
wusongqing 已提交
707 708 709 710
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
  | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
711 712 713

**Example**

714
  ```ts
715
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
716

717
  missionManager.getMissionInfos('', 10, (error, missions) => {
718
    if (error.code) {
719
        console.error('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
720 721
        return;
    }
722 723 724
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
725 726

    missionManager.moveMissionToFront(id).then(() => {
727 728
  	  console.log('moveMissionToFront is called ');
    });
W
wusongqing 已提交
729 730 731 732 733 734
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
735
moveMissionToFront(missionId: number, options: StartOptions, callback: AsyncCallback<void>): void;
W
wusongqing 已提交
736

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

739
**Required permissions**: ohos.permission.MANAGE_MISSIONS
740

W
wusongqing 已提交
741 742
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
745 746
**Parameters**

W
wusongqing 已提交
747 748 749
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
750
  | 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 已提交
751
  | callback | AsyncCallback<void> | Yes| Callback used to return the result.|
W
wusongqing 已提交
752 753 754

**Example**

755
  ```ts
756
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
757

758
  missionManager.getMissionInfos('', 10, (error, missions) => {
759
    if (error.code) {
760
        console.error('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
761 762
        return;
    }
763 764 765
    console.log('size = ${missions.length}');
    console.log('missions = ${JSON.stringify(missions)}');
    let id = missions[0].missionId;
W
wusongqing 已提交
766 767

    missionManager.moveMissionToFront(id,{windowMode : 101}).then(() => {
768
  	  console.log('moveMissionToFront is called ');
W
wusongqing 已提交
769 770 771 772 773 774 775
    });
  });
  ```


## missionManager.moveMissionToFront

W
wusongqing 已提交
776
moveMissionToFront(missionId: number, options?: StartOptions): Promise<void>;
W
wusongqing 已提交
777

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

780
**Required permissions**: ohos.permission.MANAGE_MISSIONS
781

W
wusongqing 已提交
782 783
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

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

W
wusongqing 已提交
786 787
**Parameters**

W
wusongqing 已提交
788 789 790
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | missionId | number | Yes| Mission ID.|
791
  | 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 已提交
792

W
wusongqing 已提交
793 794
**Return value**

W
wusongqing 已提交
795 796 797
  | Type| Description| 
  | -------- | -------- |
  | Promise<void> | Promise used to return the result.| 
W
wusongqing 已提交
798

W
wusongqing 已提交
799 800
**Example**

801
  ```ts
802
  import missionManager from '@ohos.application.missionManager';
W
wusongqing 已提交
803

804 805
  let allMissions;
  missionManager.getMissionInfos('',10).then(function(res){
W
wusongqing 已提交
806
    allMissions=res;
807 808 809
  }).catch(function(error) {
      console.error('getMissionInfos fail, error: ${error}');
  });
810 811 812
  console.log('size = ${allMissions.length}');
  console.log('missions = ${JSON.stringify(allMissions)}');
  let id = allMissions[0].missionId;
W
wusongqing 已提交
813

814 815
  missionManager.moveMissionToFront(id).catch(function (error){
    console.error('moveMissionToFront fail, error: ${error}');
W
wusongqing 已提交
816 817
  });
  ```