1e41f4b71Sopenharmony_ci# @ohos.application.abilityManager (AbilityManager)(系统接口)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciAbilityManager模块提供对Ability相关信息和状态信息进行获取、新增、修改等能力。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8开始支持,从API version 9废弃,替换模块为[@ohos.app.ability.abilityManager](js-apis-app-ability-abilityManager-sys.md)。后续版本的新增接口,采用上角标单独标记接口的起始版本。  
8e41f4b71Sopenharmony_ci> 本模块接口均为系统接口,三方应用不支持调用。
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport abilityManager from '@ohos.application.abilityManager';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## AbilityState
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciAbility的状态信息。
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 
25e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
26e41f4b71Sopenharmony_ci| INITIAL | 0 | 表示Ability为初始化状态。| 
27e41f4b71Sopenharmony_ci| FOREGROUND | 9 | 表示Ability处于前台。  | 
28e41f4b71Sopenharmony_ci| BACKGROUND | 10 | 表示Ability处于后台。  | 
29e41f4b71Sopenharmony_ci| FOREGROUNDING | 11 | 表示Ability处于前台调度中。  | 
30e41f4b71Sopenharmony_ci| BACKGROUNDING | 12 | 表示Ability处于后台调度中。  | 
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci## updateConfiguration
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciupdateConfiguration(config: Configuration, callback: AsyncCallback\<void>): void
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci通过修改配置来更新配置。使用callback异步回调。
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**需要权限**: ohos.permission.UPDATE_CONFIGURATION
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**参数**:
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| 参数名        | 类型                                       | 必填   | 说明             |
45e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- |
46e41f4b71Sopenharmony_ci| config    | [Configuration](js-apis-application-configuration.md)   | 是    | 新的配置项。 |
47e41f4b71Sopenharmony_ci| callback  | AsyncCallback\<void>                   | 是    | 回调函数,当通过修改配置来更新配置成功,err为undefined,否则为错误对象。      |
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**示例**:
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci```ts
52e41f4b71Sopenharmony_ciimport abilityManager from '@ohos.application.abilityManager';
53e41f4b71Sopenharmony_ciimport { Configuration } from '@ohos.application.Configuration';
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_cilet config: Configuration = {
56e41f4b71Sopenharmony_ci  language: 'chinese' 
57e41f4b71Sopenharmony_ci};
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ciabilityManager.updateConfiguration(config, () => {
60e41f4b71Sopenharmony_ci    console.log('------------ updateConfiguration -----------');
61e41f4b71Sopenharmony_ci});
62e41f4b71Sopenharmony_ci```
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci## updateConfiguration
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciupdateConfiguration(config: Configuration): Promise\<void>
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci通过修改配置来更新配置。使用Promise异步回调。
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**需要权限**: ohos.permission.UPDATE_CONFIGURATION
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**参数**:
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci| 参数名        | 类型                                       | 必填   | 说明             |
79e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- |
80e41f4b71Sopenharmony_ci| config    | [Configuration](js-apis-application-configuration.md)   | 是    | 新的配置项。 |
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**返回值:**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| 类型                                       | 说明      |
85e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
86e41f4b71Sopenharmony_ci| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**示例**:
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci```ts
91e41f4b71Sopenharmony_ciimport abilityManager from '@ohos.application.abilityManager';
92e41f4b71Sopenharmony_ciimport { Configuration } from '@ohos.application.Configuration';
93e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_cilet config: Configuration = {
96e41f4b71Sopenharmony_ci  language: 'chinese' 
97e41f4b71Sopenharmony_ci};
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ciabilityManager.updateConfiguration(config).then(() => {
100e41f4b71Sopenharmony_ci  console.log('updateConfiguration success');
101e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
102e41f4b71Sopenharmony_ci  console.error('updateConfiguration fail');
103e41f4b71Sopenharmony_ci});
104e41f4b71Sopenharmony_ci```
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci## getAbilityRunningInfos
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_cigetAbilityRunningInfos(callback: AsyncCallback\<Array\<AbilityRunningInfo>>): void
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci获取Ability运行相关信息。使用callback异步回调。
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**需要权限**: ohos.permission.GET_RUNNING_INFO
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**参数**:
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| 参数名        | 类型                                       | 必填   | 说明             |
121e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- |
122e41f4b71Sopenharmony_ci| callback  | AsyncCallback\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo-sys.md)>>  | 是    | 回调函数,返回Ability运行相关信息      |
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**示例**:
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci```ts
127e41f4b71Sopenharmony_ciimport abilityManager from '@ohos.application.abilityManager';
128e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ciabilityManager.getAbilityRunningInfos((err: BusinessError, data) => { 
131e41f4b71Sopenharmony_ci    console.log(`getAbilityRunningInfos err: ${err}, data: ${JSON.stringify(data)}`);
132e41f4b71Sopenharmony_ci});
133e41f4b71Sopenharmony_ci```
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci## getAbilityRunningInfos
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_cigetAbilityRunningInfos(): Promise\<Array\<AbilityRunningInfo>>
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci获取Ability运行相关信息。使用Promise异步回调。
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**需要权限**: ohos.permission.GET_RUNNING_INFO
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**返回值:**
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci| 类型                                       | 说明      |
150e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
151e41f4b71Sopenharmony_ci| Promise\<Array\<[AbilityRunningInfo](js-apis-inner-application-abilityRunningInfo-sys.md)>> | Promise对象,返回Ability运行相关信息。 |
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**示例**:
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci```ts
156e41f4b71Sopenharmony_ciimport abilityManager from '@ohos.application.abilityManager';
157e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ciabilityManager.getAbilityRunningInfos().then((data) => {
160e41f4b71Sopenharmony_ci    console.log(`getAbilityRunningInfos  data: ${JSON.stringify(data)}`);
161e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
162e41f4b71Sopenharmony_ci  console.error(`getAbilityRunningInfos err: ${JSON.stringify(err)}`);
163e41f4b71Sopenharmony_ci});
164e41f4b71Sopenharmony_ci```