• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AbilityManager
2
3> **NOTE**
4>
5> 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.
6>
7> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
8
9# Modules to Import
10
11```js
12import AbilityManager from '@ohos.application.abilityManager'
13```
14
15## AbilityState
16
17Enumerates the ability states.
18
19**System capability**: SystemCapability.Ability.AbilityRuntime.Core
20
21| Name| Value| Description|
22| -------- | -------- | -------- |
23| INITIAL | 0 | The ability is in the initial state.|
24| FOREGROUND | 9 | The ability is in the foreground state. |
25| BACKGROUND | 10 | The ability is in the background state. |
26| FOREGROUNDING | 11 | The ability is in the foregrounding state. |
27| BACKGROUNDING | 12 | The ability is in the backgrounding state. |
28
29
30## updateConfiguration
31
32updateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
33
34Updates the configuration. This API uses an asynchronous callback to return the result.
35
36**System capability**: SystemCapability.Ability.AbilityRuntime.Core
37
38**Parameters**
39
40| Name       | Type                                      | Mandatory  | Description            |
41| --------- | ---------------------------------------- | ---- | -------------- |
42| config    | Configuration                            | Yes   | New configuration.|
43| callback  | AsyncCallback\<void>                   | Yes   | Callback used to return the result.     |
44
45**Example**
46
47```js
48import abilitymanager from '@ohos.application.abilityManager';
49
50var config = {
51  language: 'chinese'
52}
53
54abilitymanager.updateConfiguration(config, () => {
55    console.log('------------ updateConfiguration -----------');
56})
57```
58
59## updateConfiguration
60
61updateConfiguration(config: Configuration): Promise\<void>
62
63Updates the configuration. This API uses a promise to return the result.
64
65**System capability**: SystemCapability.Ability.AbilityRuntime.Core
66
67**Parameters**
68
69| Name       | Type                                      | Mandatory  | Description            |
70| --------- | ---------------------------------------- | ---- | -------------- |
71| config    | Configuration                            | Yes   | New configuration.|
72
73**Return value**
74
75| Type                                      | Description     |
76| ---------------------------------------- | ------- |
77| Promise\<void> | Promised used to return the result.|
78
79**Example**
80
81```js
82import abilitymanager from '@ohos.application.abilityManager';
83
84var config = {
85  language: 'chinese'
86}
87
88abilitymanager.updateConfiguration(config).then(() => {
89  console.log('updateConfiguration success');
90}).catch((err) => {
91  console.log('updateConfiguration fail');
92})
93```
94
95## getAbilityRunningInfos
96
97getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
98
99Obtains the ability running information. This API uses an asynchronous callback to return the result.
100
101**System capability**: SystemCapability.Ability.AbilityRuntime.Core
102
103**Parameters**
104
105| Name       | Type                                      | Mandatory  | Description            |
106| --------- | ---------------------------------------- | ---- | -------------- |
107| callback  | AsyncCallback\<Array\<AbilityRunningInfo>>  | Yes   | Callback used to return the result.     |
108
109**Example**
110
111```js
112import abilitymanager from '@ohos.application.abilityManager';
113
114abilitymanager.getAbilityRunningInfos((err,data) => {
115    console.log("getAbilityRunningInfos err: "  + err + " data: " + JSON.stringify(data));
116});
117```
118
119## getAbilityRunningInfos
120
121getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
122
123Obtains the ability running information. This API uses a promise to return the result.
124
125**System capability**: SystemCapability.Ability.AbilityRuntime.Core
126
127**Return value**
128
129| Type                                      | Description     |
130| ---------------------------------------- | ------- |
131| Promise\<Array\<AbilityRunningInfo>> | Promised used to return the result.|
132
133**Example**
134
135```js
136import abilitymanager from '@ohos.application.abilityManager';
137
138abilitymanager.getAbilityRunningInfos().then((data) => {
139    console.log("getAbilityRunningInfos  data: " + JSON.stringify(data))
140}).catch((err) => {
141  console.log("getAbilityRunningInfos err: "  + err)
142});
143```
144
145## getExtensionRunningInfos<sup>9+</sup>
146
147getExtensionRunningInfos(upperLimit: number, callback: AsyncCallback\<Array\<ExtensionRunningInfo>>): void
148
149Obtains the extension running information. This API uses an asynchronous callback to return the result.
150
151**System capability**: SystemCapability.Ability.AbilityRuntime.Core
152
153**Parameters**
154
155| Name       | Type                                      | Mandatory  | Description            |
156| --------- | ---------------------------------------- | ---- | -------------- |
157| upperLimit | number                                   | Yes| Maximum number of messages that can be obtained.|
158| callback  | AsyncCallback\<Array\<AbilityRunningInfo>>  | Yes   | Callback used to return the result.     |
159
160**Example**
161
162```js
163import abilitymanager from '@ohos.application.abilityManager';
164
165var upperLimit = 0;
166
167abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
168    console.log("getExtensionRunningInfos err: "  + err + " data: " + JSON.stringify(data));
169});
170```
171
172## getExtensionRunningInfos<sup>9+</sup>
173
174getExtensionRunningInfos(upperLimit: number): Promise\<Array\<ExtensionRunningInfo>>
175
176Obtains the extension running information. This API uses a promise to return the result.
177
178**System capability**: SystemCapability.Ability.AbilityRuntime.Core
179
180**Parameters**
181
182| Name       | Type                                      | Mandatory  | Description            |
183| --------- | ---------------------------------------- | ---- | -------------- |
184| upperLimit | number                                   | Yes| Maximum number of messages that can be obtained.|
185
186**Return value**
187
188| Type                                      | Description     |
189| ---------------------------------------- | ------- |
190| Promise\<Array\<AbilityRunningInfo>> | Promised used to return the result.|
191
192**Example**
193
194```js
195import abilitymanager from '@ohos.application.abilityManager';
196
197var upperLimit = 0;
198
199abilitymanager.getExtensionRunningInfos(upperLimit).then((data) => {
200  console.log("getAbilityRunningInfos data: " + JSON.stringify(data));
201}).catch((err) => {
202  console.log("getAbilityRunningInfos err: "  + err);
203})
204```
205