• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.appManager (appManager)
2
3appManager模块提供App管理的能力,包括查询当前是否处于稳定性测试场景、查询是否为ram受限设备、获取应用程序的内存大小、获取有关运行进程的信息等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import appManager from '@ohos.app.ability.appManager';
13```
14
15## appManager.isRunningInStabilityTest
16
17isRunningInStabilityTest(callback: AsyncCallback<boolean>): void
18
19查询当前是否处于稳定性测试场景。
20
21**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
22
23**参数:**
24
25  | 参数名 | 类型 | 必填 | 说明 |
26  | -------- | -------- | -------- | -------- |
27  | callback | AsyncCallback<boolean> | 是 |以回调方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。  |
28
29**错误码**:
30
31| 错误码ID | 错误信息 |
32| ------- | -------- |
33| 16000050 | Internal error. |
34
35以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
36
37**示例:**
38
39```ts
40import appManager from '@ohos.app.ability.appManager';
41
42appManager.isRunningInStabilityTest((err, flag) => {
43    if (err) {
44        console.error(`isRunningInStabilityTest fail, err: ${JSON.stringify(err)}`);
45    } else {
46        console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`);
47    }
48});
49```
50
51
52## appManager.isRunningInStabilityTest
53
54isRunningInStabilityTest(): Promise<boolean>
55
56查询当前是否处于稳定性测试场景。
57
58**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
59
60**返回值:**
61
62  | 类型 | 说明 |
63  | -------- | -------- |
64  | Promise<boolean> | 以Promise方式返回接口运行结果及当前是否处于稳定性测试场景,可进行错误处理或其他自定义处理。true: 处于稳定性测试场景,false:处于非稳定性测试场景。 |
65
66**错误码**:
67
68| 错误码ID | 错误信息 |
69| ------- | -------- |
70| 16000050 | Internal error. |
71
72以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
73
74**示例:**
75
76```ts
77import appManager from '@ohos.app.ability.appManager';
78import { BusinessError } from '@ohos.base';
79
80appManager.isRunningInStabilityTest().then((flag) => {
81    console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`);
82}).catch((error: BusinessError) => {
83    console.error(`error: ${JSON.stringify(error)}`);
84});
85```
86
87
88## appManager.isRamConstrainedDevice
89
90isRamConstrainedDevice(): Promise\<boolean>
91
92查询是否为ram受限设备。
93
94**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
95
96**返回值:**
97
98  | 类型 | 说明 |
99  | -------- | -------- |
100  | Promise&lt;boolean&gt; | 以Promise方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。 |
101
102**错误码**:
103
104| 错误码ID | 错误信息 |
105| ------- | -------- |
106| 16000050 | Internal error. |
107
108以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
109
110**示例:**
111
112```ts
113import appManager from '@ohos.app.ability.appManager';
114import { BusinessError } from '@ohos.base';
115
116appManager.isRamConstrainedDevice().then((data) => {
117    console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
118}).catch((error: BusinessError) => {
119    console.error(`error: ${JSON.stringify(error)}`);
120});
121```
122
123## appManager.isRamConstrainedDevice
124
125isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void
126
127查询是否为ram受限设备。
128
129**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
130
131**参数:**
132
133  | 参数名 | 类型 | 必填 | 说明 |
134  | -------- | -------- | -------- | -------- |
135  | callback | AsyncCallback&lt;boolean&gt; | 是 |以回调方式返回接口运行结果及当前设备是否为ram受限设备,可进行错误处理或其他自定义处理。true:当前设备为ram受限设备,false:当前设备为非ram受限设备。  |
136
137**错误码**:
138
139| 错误码ID | 错误信息 |
140| ------- | -------- |
141| 16000050 | Internal error. |
142
143以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
144
145**示例:**
146
147```ts
148import appManager from '@ohos.app.ability.appManager';
149
150appManager.isRamConstrainedDevice((err, data) => {
151    if (err) {
152        console.error(`isRamConstrainedDevice fail, err: ${JSON.stringify(err)}`);
153    } else {
154        console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`);
155    }
156});
157```
158
159## appManager.getAppMemorySize
160
161getAppMemorySize(): Promise\<number>
162
163获取当前应用程序可以使用的内存的值。
164
165**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
166
167**返回值:**
168
169  | 类型 | 说明 |
170  | -------- | -------- |
171  | Promise&lt;number&gt; | 获取当前应用程序可以使用的内存的值,可根据此值进行错误处理或其他自定义处理,单位是M。使用Promise异步回调。|
172
173**错误码**:
174
175| 错误码ID | 错误信息 |
176| ------- | -------- |
177| 16000050 | Internal error. |
178
179以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
180
181**示例:**
182
183```ts
184import appManager from '@ohos.app.ability.appManager';
185import { BusinessError } from '@ohos.base';
186
187appManager.getAppMemorySize().then((data) => {
188    console.log(`The size of app memory is: ${JSON.stringify(data)}`);
189}).catch((error: BusinessError) => {
190    console.error(`error: ${JSON.stringify(error)}`);
191});
192```
193
194## appManager.getAppMemorySize
195
196getAppMemorySize(callback: AsyncCallback\<number>): void
197
198获取当前应用程序可以使用的内存的值。
199
200**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
201
202**参数:**
203
204  | 参数名 | 类型 | 必填 | 说明 |
205  | -------- | -------- | -------- | -------- |
206  | callback | AsyncCallback&lt;number&gt; | 是 |获取当前应用程序可以使用的内存的值,可根据此值进行错误处理或其他自定义处理,单位是M。使用callback异步回调。|
207
208**错误码**:
209
210| 错误码ID | 错误信息 |
211| ------- | -------- |
212| 16000050 | Internal error. |
213
214以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
215
216**示例:**
217
218```ts
219import appManager from '@ohos.app.ability.appManager';
220
221appManager.getAppMemorySize((err, data) => {
222    if (err) {
223        console.error(`getAppMemorySize fail, err: ${JSON.stringify(err)}`);
224    } else {
225        console.log(`The size of app memory is: ${JSON.stringify(data)}`);
226    }
227});
228```
229
230## appManager.getRunningProcessInformation
231
232getRunningProcessInformation(): Promise\<Array\<ProcessInformation>>
233
234获取当前运行进程的有关信息。使用Promise异步回调。
235
236**需要权限**:ohos.permission.GET_RUNNING_INFO
237
238> **说明:**
239>
240> 从API version 11开始,该接口不再需要ohos.permission.GET_RUNNING_INFO权限。
241
242**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
243
244**返回值:**
245
246| 类型 | 说明 |
247| -------- | -------- |
248| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 以Promise方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
249
250**错误码**:
251
252| 错误码ID | 错误信息 |
253| ------- | -------- |
254| 16000050 | Internal error. |
255
256以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
257
258**示例:**
259
260```ts
261import appManager from '@ohos.app.ability.appManager';
262import { BusinessError } from '@ohos.base';
263
264appManager.getRunningProcessInformation().then((data) => {
265    console.log(`The running process information is: ${JSON.stringify(data)}`);
266}).catch((error: BusinessError) => {
267    console.error(`error: ${JSON.stringify(error)}`);
268});
269```
270
271## appManager.getRunningProcessInformation
272
273getRunningProcessInformation(callback: AsyncCallback<Array\<ProcessInformation>>): void
274
275获取当前运行进程的有关信息。使用callback异步回调。
276
277**需要权限**:ohos.permission.GET_RUNNING_INFO
278
279> **说明:**
280>
281> 从API version 11开始,该接口不再需要ohos.permission.GET_RUNNING_INFO权限。
282
283**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
284
285**参数:**
286
287| 参数名 | 类型 | 必填 | 说明 |
288| -------- | -------- | -------- | -------- |
289| callback | AsyncCallback&lt;Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>&gt; | 是 | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
290
291**错误码**:
292
293| 错误码ID | 错误信息 |
294| ------- | -------- |
295| 16000050 | Internal error. |
296
297以上错误码详细介绍请参考[元能力子系统错误码](errorcode-ability.md)。
298
299**示例:**
300
301```ts
302import appManager from '@ohos.app.ability.appManager';
303import { BusinessError } from '@ohos.base';
304
305appManager.getRunningProcessInformation((err, data) => {
306    if (err) {
307        console.error(`getRunningProcessInformation fail, err: ${JSON.stringify(err)}`);
308    } else {
309        console.log(`ProcessInformation: ${JSON.stringify(data)}`);
310    }
311});
312```
313
314## ProcessState<sup>10+</sup>
315
316进程状态,该类型为枚举,可配合[ProcessData](js-apis-inner-application-processData-sys.md)返回相应的进程状态。
317
318**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
319
320| 名称                 | 值  | 说明                               |
321| -------------------- | --- | --------------------------------- |
322| STATE_CREATE    | 0   |      当进程在创建中的时候处于的状态。       |
323| STATE_FOREGROUND          | 1   |            当进程切换到前台的时候处于的状态。      |
324| STATE_ACTIVE  | 2   |          当进程在获焦的时候处于的状态。   |
325| STATE_BACKGROUND        | 3   |       当进程处于后台不可见时处于的状态。           |
326| STATE_DESTROY        | 4   |         当进程在销毁的时候处于的状态。         |
327