js-apis-inner-application-missionSnapshot.md 2.1 KB
Newer Older
W
wusongqing 已提交
1 2
# MissionSnapshot

3
The **MissionSnapshot** module defines the snapshot of a mission. The snapshot can be obtained through [getMissionSnapShot](js-apis-app-ability-missionManager.md#missionmanagergetmissionsnapshot).
W
wusongqing 已提交
4

W
wusongqing 已提交
5
> **NOTE**
W
wusongqing 已提交
6
> 
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
> The APIs of this module are system APIs and cannot be called by third-party applications.
W
wusongqing 已提交
9

10 11 12 13 14 15
## Modules to Import

```ts
import missionManager from '@ohos.app.ability.missionManager';
```

16 17 18 19
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
20
| ability | ElementName | Yes| Yes| Ability information of the mission.|
21 22 23
| snapshot | [image.PixelMap](js-apis-image.md) | Yes| Yes| Snapshot of the mission.|

## How to Use
W
wusongqing 已提交
24

W
wusongqing 已提交
25
The mission snapshot information can be obtained by using **getMissionSnapShot** in **missionManager**.
W
wusongqing 已提交
26

27 28
**Example**
```ts
29 30 31 32 33
  import ElementName from '@ohos.bundle';
  import image from '@ohos.multimedia.image';
  import missionManager from '@ohos.app.ability.missionManager';

  try {
34
    missionManager.getMissionInfos('', 10, (error, missions) => {
35 36
      if (error) {
          console.error('getMissionInfos failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
37 38
          return;
      }
39 40 41
      console.log('size = ${missions.length}');
      console.log('missions = ${JSON.stringify(missions)}');
      let id = missions[0].missionId;
42

43
      missionManager.getMissionSnapShot('', id, (err, snapshot) => {
44 45
        if (err) {
          console.error('getMissionInfos failed, err.code: ${JSON.stringify(err.code)}, err.message: ${JSON.stringify(err.message)}');
46 47 48 49
          return;
        }

        // Carry out normal service processing.
50 51 52
        console.log('bundleName = ${snapshot.ability.bundleName}');
      });
    });
53
  } catch (paramError) {
54
    console.error('error: ${paramError.code}, ${paramError.message}');
55
  }
W
wusongqing 已提交
56
```