• 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 and deprecated since API version 9. You are advised to use [@ohos.app.ability.abilityManager](js-apis-app-ability-abilityManager.md) instead. 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';
53import { Configuration } from '@ohos.application.Configuration';
54
55let config: Configuration = {
56  language: 'chinese'
57};
58
59abilityManager.updateConfiguration(config, () => {
60    console.log('------------ updateConfiguration -----------');
61});
62```
63
64## updateConfiguration
65
66updateConfiguration(config: Configuration): Promise\<void>
67
68Updates the configuration. This API uses a promise to return the result.
69
70**Permission required**: ohos.permission.UPDATE_CONFIGURATION
71
72**System capability**: SystemCapability.Ability.AbilityRuntime.Core
73
74**Parameters**
75
76| Name       | Type                                      | Mandatory  | Description            |
77| --------- | ---------------------------------------- | ---- | -------------- |
78| config    | [Configuration](js-apis-application-configuration.md)   | Yes   | New configuration.|
79
80**Return value**
81
82| Type                                      | Description     |
83| ---------------------------------------- | ------- |
84| Promise\<void> | Promise used to return the result.|
85
86**Example**
87
88```ts
89import abilityManager from '@ohos.application.abilityManager';
90import { Configuration } from '@ohos.application.Configuration';
91import { BusinessError } from '@ohos.base';
92
93let config: Configuration = {
94  language: 'chinese'
95};
96
97abilityManager.updateConfiguration(config).then(() => {
98  console.log('updateConfiguration success');
99}).catch((err: BusinessError) => {
100  console.error('updateConfiguration fail');
101});
102```
103
104## getAbilityRunningInfos
105
106getAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
107
108Obtains the ability running information. This API uses an asynchronous callback to return the result.
109
110**Required permissions**: ohos.permission.GET_RUNNING_INFO
111
112**System capability**: SystemCapability.Ability.AbilityRuntime.Core
113
114**Parameters**
115
116| Name       | Type                                      | Mandatory  | Description            |
117| --------- | ---------------------------------------- | ---- | -------------- |
118| callback  | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>>  | Yes   | Callback used to return the result.     |
119
120**Example**
121
122```ts
123import abilityManager from '@ohos.application.abilityManager';
124
125abilityManager.getAbilityRunningInfos((err,data) => {
126    console.log(`getAbilityRunningInfos err: ${err}, data: ${JSON.stringify(data)}`);
127});
128```
129
130## getAbilityRunningInfos
131
132getAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
133
134Obtains the ability running information. This API uses a promise to return the result.
135
136**Required permissions**: ohos.permission.GET_RUNNING_INFO
137
138**System capability**: SystemCapability.Ability.AbilityRuntime.Core
139
140**Return value**
141
142| Type                                      | Description     |
143| ---------------------------------------- | ------- |
144| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo.md)>> | Promise used to return the result.|
145
146**Example**
147
148```ts
149import abilityManager from '@ohos.application.abilityManager';
150import { BusinessError } from '@ohos.base';
151
152abilityManager.getAbilityRunningInfos().then((data) => {
153    console.log(`getAbilityRunningInfos  data: ${JSON.stringify(data)}`);
154}).catch((err: BusinessError) => {
155  console.error(`getAbilityRunningInfos err: ${JSON.stringify(err)}`);
156});
157```
158