• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.application.appManager (appManager)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @SKY2001-->
5<!--Designer: @yzkp-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8<!--deprecated_code_no_check-->
9
10The appManager module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process.
11
12> **NOTE**
13>
14> 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.appManager](js-apis-app-ability-appManager.md) instead. Newly added APIs will be marked with a superscript to indicate their earliest API version.
15
16## Modules to Import
17
18```ts
19import appManager from '@ohos.application.appManager';
20```
21
22## appManager.isRunningInStabilityTest
23
24isRunningInStabilityTest(callback: AsyncCallback&lt;boolean&gt;): void
25
26Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result.
27
28**System capability**: SystemCapability.Ability.AbilityRuntime.Core
29
30**Parameters**
31
32  | Name| Type| Mandatory| Description|
33  | -------- | -------- | -------- | -------- |
34  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. **true** if undergoing a stability test, **false** otherwise.|
35
36**Example**
37
38  ```ts
39  import appManager from '@ohos.application.appManager';
40
41  appManager.isRunningInStabilityTest((error, flag) => {
42    if (error && error.code !== 0) {
43        console.error(`isRunningInStabilityTest fail, error: ${JSON.stringify(error)}`);
44    } else {
45        console.log(`isRunningInStabilityTest success, the result is: ${JSON.stringify(flag)}`);
46    }
47  });
48  ```
49
50
51## appManager.isRunningInStabilityTest
52
53isRunningInStabilityTest(): Promise&lt;boolean&gt;
54
55Checks whether this application is undergoing a stability test. This API uses a promise to return the result.
56
57**System capability**: SystemCapability.Ability.AbilityRuntime.Core
58
59**Return value**
60
61  | Type| Description|
62  | -------- | -------- |
63  | Promise&lt;boolean&gt; | Promise used to return the result. **true** if undergoing a stability test, **false** otherwise.|
64
65**Example**
66
67  ```ts
68  import appManager from '@ohos.application.appManager';
69  import { BusinessError } from '@ohos.base';
70
71  appManager.isRunningInStabilityTest().then((flag) => {
72      console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`);
73  }).catch((error: BusinessError) => {
74      console.error(`error: ${JSON.stringify(error)}`);
75  });
76  ```
77
78
79## appManager.isRamConstrainedDevice<sup>7+<sup>
80
81isRamConstrainedDevice(): Promise\<boolean>
82
83Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result.
84
85**System capability**: SystemCapability.Ability.AbilityRuntime.Core
86
87**Return value**
88
89  | Type| Description|
90  | -------- | -------- |
91  | Promise&lt;boolean&gt; | Promise used to return the result. **true** if running on a RAM constrained device, **false** otherwise.|
92
93**Example**
94
95  ```ts
96  import appManager from '@ohos.application.appManager';
97  import { BusinessError } from '@ohos.base';
98
99  appManager.isRamConstrainedDevice().then((data) => {
100      console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
101  }).catch((error: BusinessError) => {
102      console.error(`error: ${JSON.stringify(error)}`);
103  });
104  ```
105
106## appManager.isRamConstrainedDevice<sup>7+<sup>
107
108isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void
109
110Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result.
111
112**System capability**: SystemCapability.Ability.AbilityRuntime.Core
113
114**Parameters**
115
116  | Name| Type| Mandatory| Description|
117  | -------- | -------- | -------- | -------- |
118  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. **true** if running on a RAM constrained device, **false** otherwise.|
119
120**Example**
121
122  ```ts
123  import appManager from '@ohos.application.appManager';
124
125  appManager.isRamConstrainedDevice((error, data) => {
126      if (error && error.code !== 0) {
127          console.error(`isRamConstrainedDevice fail, error: ${JSON.stringify(error)}`);
128      } else {
129          console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
130      }
131  });
132  ```
133
134## appManager.getAppMemorySize<sup>7+<sup>
135
136getAppMemorySize(): Promise\<number>
137
138Obtains the memory size of this application. This API uses a promise to return the result.
139
140**System capability**: SystemCapability.Ability.AbilityRuntime.Core
141
142**Return value**
143
144  | Type| Description|
145  | -------- | -------- |
146  | Promise&lt;number&gt; | Promise used to return the memory size, in MB. You can perform error processing or other custom processing based on the size.  |
147
148**Example**
149
150  ```ts
151  import appManager from '@ohos.application.appManager';
152  import { BusinessError } from '@ohos.base';
153
154  appManager.getAppMemorySize().then((data) => {
155      console.log(`The size of app memory is: ${JSON.stringify(data)}`);
156  }).catch((error: BusinessError) => {
157      console.error(`error: ${JSON.stringify(error)}`);
158  });
159  ```
160
161## appManager.getAppMemorySize<sup>7+<sup>
162
163getAppMemorySize(callback: AsyncCallback\<number>): void
164
165Obtains the memory size of this application. This API uses an asynchronous callback to return the result.
166
167**System capability**: SystemCapability.Ability.AbilityRuntime.Core
168
169**Parameters**
170
171  | Name| Type| Mandatory| Description|
172  | -------- | -------- | -------- | -------- |
173  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the memory size, in MB. You can perform error processing or other custom processing based on the size.  |
174
175**Example**
176
177  ```ts
178  import appManager from '@ohos.application.appManager';
179
180  appManager.getAppMemorySize((error, data) => {
181      if (error && error.code !== 0) {
182          console.error(`getAppMemorySize fail, error: ${JSON.stringify(error)}`);
183      } else {
184          console.log(`The size of app memory is: ${JSON.stringify(data)}`);
185      }
186  });
187  ```
188## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
189
190getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>
191
192Obtains information about the running processes. This API uses a promise to return the result.
193
194> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation) instead.
195
196**Required permissions**: ohos.permission.GET_RUNNING_INFO (available only for system applications)
197
198**System capability**: SystemCapability.Ability.AbilityRuntime.Core
199
200**Return value**
201
202| Type| Description|
203| -------- | -------- |
204| Promise\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Promise used to return the information about the running processes.|
205
206**Example**
207
208  ```ts
209  import appManager from '@ohos.application.appManager';
210  import { BusinessError } from '@ohos.base';
211
212  appManager.getProcessRunningInfos().then((data) => {
213      console.log(`The process running infos is: ${JSON.stringify(data)}`);
214  }).catch((error: BusinessError) => {
215      console.error(`error: ${JSON.stringify(error)}`);
216  });
217  ```
218
219## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
220
221getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void
222
223Obtains information about the running processes. This API uses an asynchronous callback to return the result.
224
225> This API is deprecated since API version 9. You are advised to use [appManager.getRunningProcessInformation](js-apis-app-ability-appManager.md#appmanagergetrunningprocessinformation) instead.
226
227**Required permissions**: ohos.permission.GET_RUNNING_INFO (available only for system applications)
228
229**System capability**: SystemCapability.Ability.AbilityRuntime.Core
230
231**Parameters**
232
233| Name| Type| Mandatory| Description|
234| -------- | -------- | -------- | -------- |
235| callback | AsyncCallback\<Array\<[ProcessRunningInfo](js-apis-inner-application-processRunningInfo.md)>> | Yes| Callback used to return the information about the running processes.|
236
237**Example**
238
239  ```ts
240  import appManager from '@ohos.application.appManager';
241
242  appManager.getProcessRunningInfos((error, data) => {
243      if (error && error.code !== 0) {
244          console.error(`getProcessRunningInfos fail, error: ${JSON.stringify(error)}`);
245      } else {
246          console.log(`getProcessRunningInfos success, data: ${JSON.stringify(data)}`);
247      }
248  });
249  ```
250