• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.abilityManager (AbilityManager)
2
3The AbilityManager module provides APIs for obtaining ability information and running status information.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 14. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { abilityManager } from '@kit.AbilityKit';
13```
14
15
16## AbilityState
17
18Enumerates the ability states. This enum can be used together with [AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md) to return the ability state.
19
20**System capability**: SystemCapability.Ability.AbilityRuntime.Core
21
22| Name| Value| Description|
23| -------- | -------- | -------- |
24| INITIAL | 0 | The ability is in the initial state.|
25| FOCUS | 2 | The ability has the focus.|
26| FOREGROUND | 9 | The ability is in the foreground state. |
27| BACKGROUND | 10 | The ability is in the background state. |
28| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. |
29| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. |
30
31
32## abilityManager.getAbilityRunningInfos
33
34getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
35
36Obtains the UIAbility running information. This API uses a promise to return the result.
37
38**Required permissions**: ohos.permission.GET_RUNNING_INFO
39
40**System capability**: SystemCapability.Ability.AbilityRuntime.Core
41
42**Return value**
43
44| Type                                      | Description     |
45| ---------------------------------------- | ------- |
46| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in it.|
47
48**Error codes**
49
50For details about the error codes, see [Ability Error Codes](errorcode-ability.md).
51
52| ID| Error Message|
53| ------- | -------- |
54| 16000050 | Internal error. |
55
56**Example**
57
58```ts
59import { abilityManager } from '@kit.AbilityKit';
60import { BusinessError } from '@kit.BasicServicesKit';
61
62try {
63  abilityManager.getAbilityRunningInfos()
64    .then((data: abilityManager.AbilityRunningInfo[]) => {
65      console.log(`getAbilityRunningInfos success, data: ${JSON.stringify(data)}`);
66    })
67    .catch((error: BusinessError) => {
68      console.error(`getAbilityRunningInfos fail, error code: ${JSON.stringify(error.code)}, error msg: ${JSON.stringify(error.message)}`);
69    })
70} catch (e) {
71  let code = (e as BusinessError).code;
72  let msg = (e as BusinessError).message;
73  console.error(`getAbilityRunningInfos fail, error code: ${JSON.stringify(code)}, error msg: ${JSON.stringify(msg)}`);
74}
75```
76