• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.abilityManager (AbilityManager)
2
3The **AbilityManager** module provides APIs for obtaining, adding, and modifying ability running information and state information.
4
5> **NOTE**
6>
7> The 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.
8> The APIs of this module are system APIs and cannot be called by third-party applications.
9
10## Modules to Import
11
12```ts
13import AbilityManager from '@ohos.application.abilityManager';
14```
15
16## AbilityState
17
18Enumerates the ability states.
19
20**System capability**: SystemCapability.Ability.AbilityRuntime.Core
21
22**System API**: This is a system API and cannot be called by third-party applications.
23
24| Name| Value| Description|
25| -------- | -------- | -------- |
26| INITIAL | 0 | The ability is in the initial state.|
27| FOREGROUND | 9 | The ability is in the foreground state. |
28| BACKGROUND | 10 | The ability is in the background state. |
29| FOREGROUNDING | 11 | The ability is in the state of being switched to the foreground. |
30| BACKGROUNDING | 12 | The ability is in the state of being switched to the background. |
31
32## updateConfiguration
33
34updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
35
36Updates the configuration. This API uses an asynchronous callback to return the result.
37
38**Permission required**: ohos.permission.UPDATE_CONFIGURATION
39
40**System capability**: SystemCapability.Ability.AbilityRuntime.Core
41
42**Parameters**
43
44| Name       | Type                                      | Mandatory  | Description            |
45| --------- | ---------------------------------------- | ---- | -------------- |
46| config    | [Configuration](js-apis-application-configuration.md)   | Yes   | New configuration.|
47| callback  | AsyncCallback\<void>                   | Yes   | Callback used to return the result.     |
48
49**Example**
50
51```ts
52import abilitymanager from '@ohos.application.abilityManager';
53
54let config = {
55  language: 'chinese'
56};
57
58abilitymanager.updateConfiguration(config, () => {
59    console.log('------------ updateConfiguration -----------');
60})
61```
62
63## updateConfiguration
64
65updateConfiguration(config: Configuration): Promise\<void>
66
67Updates the configuration. This API uses a promise to return the result.
68
69**Permission required**: ohos.permission.UPDATE_CONFIGURATION
70
71**System capability**: SystemCapability.Ability.AbilityRuntime.Core
72
73**Parameters**
74
75| Name       | Type                                      | Mandatory  | Description            |
76| --------- | ---------------------------------------- | ---- | -------------- |
77| config    | [Configuration](js-apis-application-configuration.md)   | Yes   | New configuration.|
78
79**Return value**
80
81| Type                                      | Description     |
82| ---------------------------------------- | ------- |
83| Promise\<void> | Promise used to return the result.|
84
85**Example**
86
87```ts
88import abilitymanager from '@ohos.application.abilityManager';
89
90let config = {
91  language: 'chinese'
92};
93
94abilitymanager.updateConfiguration(config).then(() => {
95  console.log('updateConfiguration success');
96}).catch((err) => {
97  console.log('updateConfiguration fail');
98})
99```
100
101## getAbilityRunningInfos
102
103getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
104
105Obtains the ability running information. This API uses an asynchronous callback to return the result.
106
107**Required permissions**: ohos.permission.GET_RUNNING_INFO
108
109**System capability**: SystemCapability.Ability.AbilityRuntime.Core
110
111**Parameters**
112
113| Name       | Type                                      | Mandatory  | Description            |
114| --------- | ---------------------------------------- | ---- | -------------- |
115| callback  | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>>  | Yes   | Callback used to return the result.     |
116
117**Example**
118
119```ts
120import abilitymanager from '@ohos.application.abilityManager';
121
122abilitymanager.getAbilityRunningInfos((err,data) => {
123    console.log("getAbilityRunningInfos err: "  + err + " data: " + JSON.stringify(data));
124});
125```
126
127## getAbilityRunningInfos
128
129getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
130
131Obtains the ability running information. This API uses a promise to return the result.
132
133**Required permissions**: ohos.permission.GET_RUNNING_INFO
134
135**System capability**: SystemCapability.Ability.AbilityRuntime.Core
136
137**Return value**
138
139| Type                                      | Description     |
140| ---------------------------------------- | ------- |
141| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the result.|
142
143**Example**
144
145```ts
146import abilitymanager from '@ohos.application.abilityManager';
147
148abilitymanager.getAbilityRunningInfos().then((data) => {
149    console.log("getAbilityRunningInfos  data: " + JSON.stringify(data));
150}).catch((err) => {
151  console.log("getAbilityRunningInfos err: "  + err);
152});
153```
154