• 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> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.app.ability.appManager (appManager)](js-apis-app-ability-appManager.md)。
10
11## 导入模块
12
13```ts
14import { appManager } from '@kit.AbilityKit';
15```
16
17## appManager.PreloadMode<sup>12+</sup>
18
19表示预加载应用进程模式的枚举。
20
21**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
22
23**系统接口**:此接口为系统接口。
24
25**模型约束**:此接口仅可在Stage模型下使用。
26
27| 名称        | 值  | 说明                         |
28| ----------- | --- | --------------------------- |
29| PRESS_DOWN  | 0 | 按下应用图标时进行应用进程预加载。 |
30
31## KeepAliveAppType<sup>14+</sup>
32
33表示被保活应用的应用类型。
34
35**系统接口**:此接口为系统接口。
36
37**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
38
39| 名称        | 值  | 说明 |
40| -------- | ---------- | -------- |
41| ALL  | 0 | 三方应用和系统应用。此选项只能作为[getKeepAliveBundles](#appmanagergetkeepalivebundles14)接口的入参被调用。  |
42| THIRD_PARTY | 1  | 三方应用。  |
43| SYSTEM | 2 | 系统应用。 |
44
45## KeepAliveSetter<sup>14+</sup>
46
47表示应用保活的设置方类型。
48
49**系统接口**:此接口为系统接口。
50
51**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
52
53| 名称        | 值  | 说明 |
54| -------- | ---------- | -------- |
55| SYSTEM | 0 | 应用保活设置方为系统。 |
56| USER  | 1 | 应用保活设置方为用户。  |
57
58## KeepAliveBundleInfo<sup>14+</sup>
59
60定义应用保活信息,可以通过[getKeepAliveBundles](#appmanagergetkeepalivebundles14)获取当前应用的相关信息。
61
62**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
63
64**系统接口**:此接口为系统接口。
65
66| 名称 | 类型 | 只读 | 可选 | 说明 |
67| ------------------------- | ------ | ---- | ---- | --------- |
68| bundleName   | string | 是 | 否  | Bundle名称。 |
69| userId   | number | 是 | 否  | 用户ID。 |
70| appType       | [KeepAliveAppType](#keepaliveapptype14) | 是 | 否 | 表示被保活应用的应用类型。   |
71| setter       | [KeepAliveSetter](#keepalivesetter14) | 是 | 否 | 表示应用保活设置者类型。   |
72
73## appManager.isSharedBundleRunning<sup>10+</sup>
74
75isSharedBundleRunning(bundleName: string, versionCode: number): Promise\<boolean>
76
77检查共享库是否正在使用。使用Promise异步回调。
78
79**需要权限**:ohos.permission.GET_RUNNING_INFO
80
81**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
82
83**系统接口**:此接口为系统接口。
84
85**参数**:
86
87| 参数名        | 类型                                       | 必填   | 说明             |
88| --------- | ---------------------------------------- | ---- | -------------- |
89| bundleName    | string   | 是    | 表示要查询的共享库包名。 |
90| versionCode   | number   | 是    | 表示要查询的共享库版本号。      |
91
92**返回值:**
93
94| 类型 | 说明 |
95| -------- | -------- |
96| Promise\<boolean> | Promise对象。返回true表示共享库正在使用,返回false表示共享库不在使用。 |
97
98**错误码**:
99
100以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
101
102| 错误码ID | 错误信息 |
103| ------- | -------- |
104| 201 | Permission denied. |
105| 202 | Not System App. Interface caller is not a system app. |
106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
107| 16000050 | Internal error. |
108
109**示例:**
110
111```ts
112import { appManager } from '@kit.AbilityKit';
113import { BusinessError } from '@kit.BasicServicesKit';
114
115const bundleName = "this is a bundleName";
116const versionCode = 1;
117
118appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => {
119  console.log(`The shared bundle running is: ${JSON.stringify(data)}`);
120}).catch((error: BusinessError) => {
121  console.error(`error: ${JSON.stringify(error)}`);
122});
123```
124
125## appManager.isSharedBundleRunning<sup>10+</sup>
126
127isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\<boolean>): void
128
129检查共享库是否正在使用。使用callback异步回调。
130
131**需要权限**:ohos.permission.GET_RUNNING_INFO
132
133**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
134
135**系统接口**:此接口为系统接口。
136
137**参数**:
138
139| 参数名        | 类型                                       | 必填   | 说明             |
140| --------- | ---------------------------------------- | ---- | -------------- |
141| bundleName    | string   | 是    | 表示要查询的共享库包名。 |
142| versionCode   | number   | 是    | 表示要查询的共享库版本号。      |
143| callback    | AsyncCallback\<boolean>> | 是    | 回调函数。返回true表示共享库正在使用,返回false表示共享库不在使用。 |
144
145**错误码**:
146
147以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
148
149| 错误码ID | 错误信息 |
150| ------- | -------- |
151| 201 | Permission denied. |
152| 202 | Not System App. Interface caller is not a system app. |
153| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
154| 16000050 | Internal error. |
155
156**示例:**
157
158```ts
159import { appManager } from '@kit.AbilityKit';
160
161const bundleName = "this is a bundleName";
162const versionCode = 1;
163
164appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => {
165  if (err) {
166    console.error(`err: ${JSON.stringify(err)}`);
167  } else {
168    console.log(`The shared bundle running is: ${JSON.stringify(data)}`);
169  }
170});
171```
172
173## appManager.on('appForegroundState')<sup>11+</sup>
174
175on(type: 'appForegroundState', observer: AppForegroundStateObserver): void
176
177注册应用启动和退出的观测器,可用于系统应用观测所有应用的启动和退出。
178
179**系统接口**:此接口为系统接口。
180
181**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
182
183**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
184
185**参数:**
186
187| 参数名 | 类型 | 必填 | 说明 |
188| -------- | -------- | -------- | -------- |
189| type | string | 是 | 调用接口类型,固定填'appForegroundState'字符串。 |
190| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | 是 | 应用状态观测器,用于观测应用的启动和退出。 |
191
192**错误码**:
193
194以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
195
196| 错误码ID | 错误信息 |
197| ------- | -------- |
198| 201 | Permission denied. |
199| 202 | Not System App. Interface caller is not a system app. |
200| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
201| 16000050 | Internal error. |
202
203**示例:**
204
205```ts
206import { appManager } from '@kit.AbilityKit';
207import { BusinessError } from '@kit.BasicServicesKit';
208
209let observer: appManager.AppForegroundStateObserver = {
210  onAppStateChanged(appStateData) {
211    console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`);
212  },
213};
214
215try {
216  appManager.on('appForegroundState', observer);
217} catch (paramError) {
218  let code = (paramError as BusinessError).code;
219  let message = (paramError as BusinessError).message;
220  console.error(`[appManager] error: ${code}, ${message}`);
221}
222```
223
224## appManager.on('abilityFirstFrameState')<sup>12+</sup>
225
226on(type: 'abilityFirstFrameState', observer: AbilityFirstFrameStateObserver, bundleName?: string): void
227
228注册监听Ability首帧绘制完成事件观察者对象,可用于系统应用监听Ability首帧绘制事件。
229
230**系统接口**:此接口为系统接口。
231
232**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
233
234**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
235
236**参数:**
237
238| 参数名     | 类型                                                         | 必填 | 说明                                                         |
239| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
240| type       | string                                                       | 是   | 调用接口类型,固定填'abilityFirstFrameState'字符串。         |
241| observer   | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | 是   | 表示待注册的Ability首帧绘制完成事件观察者对象。              |
242| bundleName | string                                                       | 否   | 表示待监听的Ability的应用bundleName,不填表示注册监听所有应用ability首帧绘制完成事件。 |
243
244**错误码**:
245
246以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
247
248| 错误码ID | 错误信息 |
249| ------- | -------- |
250| 201 | Permission denied. |
251| 202 | Not System App. Interface caller is not a system app. |
252| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
253| 16000050 | Internal error. |
254
255**示例:**
256
257```ts
258import { appManager } from '@kit.AbilityKit';
259import { BusinessError } from '@kit.BasicServicesKit';
260
261let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = {
262  onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) {
263    console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData));
264  }
265};
266
267try {
268  appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
269} catch (e) {
270  let code = (e as BusinessError).code;
271  let message = (e as BusinessError).message;
272  console.error(`[appManager] error: ${code}, ${message}`);
273}
274```
275
276## appManager.off('appForegroundState')<sup>11+</sup>
277
278off(type: 'appForegroundState', observer?: AppForegroundStateObserver): void
279
280取消注册应用启动和退出的观测器。
281
282**系统接口**:此接口为系统接口。
283
284**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
285
286**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
287
288**参数:**
289
290| 参数名 | 类型 | 必填 | 说明 |
291| -------- | -------- | -------- | -------- |
292| type | string | 是 | 调用接口类型,固定填'appForegroundState'字符串。|
293| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | 否 | 取消注册的应用启动和退出观测器。|
294
295**错误码**:
296
297以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
298
299| 错误码ID | 错误信息 |
300| ------- | -------- |
301| 201 | Permission denied. |
302| 202 | Not System App. Interface caller is not a system app. |
303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
304| 16000050 | Internal error. |
305
306**示例:**
307
308```ts
309import { appManager } from '@kit.AbilityKit';
310import { BusinessError } from '@kit.BasicServicesKit';
311
312let observer_: appManager.AppForegroundStateObserver | undefined;
313// 1.注册应用启动和退出的监听器
314let observer: appManager.AppForegroundStateObserver = {
315  onAppStateChanged(appStateData: appManager.AppStateData) {
316    console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`);
317  },
318};
319
320try {
321  appManager.on('appForegroundState', observer);
322  // 保存observer对象,用于注销
323  observer_ = observer;
324} catch (paramError) {
325  let code = (paramError as BusinessError).code;
326  let message = (paramError as BusinessError).message;
327  console.error(`[appManager] error: ${code}, ${message}`);
328}
329
330// 2.注销监听器
331try {
332  appManager.off('appForegroundState',  observer_);
333} catch (paramError) {
334  let code = (paramError as BusinessError).code;
335  let message = (paramError as BusinessError).message;
336  console.error(`[appManager] error: ${code}, ${message}`);
337}
338```
339
340## appManager.off('abilityFirstFrameState')<sup>12+</sup>
341
342off(type: 'abilityFirstFrameState', observer?: AbilityFirstFrameStateObserver): void
343
344取消注册监听Ability首帧绘制完成事件观察者对象。
345
346**系统接口**:此接口为系统接口。
347
348**需要权限**:ohos.permission.RUNNING_STATE_OBSERVER
349
350**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
351
352**参数:**
353
354| 参数名   | 类型                                                         | 必填 | 说明                                                         |
355| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
356| type     | string                                                       | 是   | 调用接口类型,固定填'abilityFirstFrameState'字符串。         |
357| observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | 否   | 表示待取消的Ability首帧绘制完成事件观察者对象,不填表示取消所有监听对象。 |
358
359**错误码**:
360
361以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
362
363| 错误码ID | 错误信息 |
364| ------- | -------- |
365| 201 | Permission denied. |
366| 202 | Not System App. Interface caller is not a system app. |
367| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
368| 16000050 | Internal error. |
369
370**示例:**
371
372```ts
373import { appManager } from '@kit.AbilityKit';
374import { BusinessError } from '@kit.BasicServicesKit';
375
376let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = {
377  onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) {
378    console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData));
379  }
380};
381
382try {
383  appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
384} catch (e) {
385  let code = (e as BusinessError).code;
386  let message = (e as BusinessError).message;
387  console.error(`[appManager] error: ${code}, ${message}`);
388}
389
390try {
391  appManager.off('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
392} catch (e) {
393  let code = (e as BusinessError).code;
394  let message = (e as BusinessError).message;
395  console.error(`[appManager] error: ${code}, ${message}`);
396}
397```
398
399## appManager.getForegroundApplications
400
401getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void
402
403获取当前所有前台应用的信息。该应用信息由[AppStateData](js-apis-inner-application-appStateData.md)定义。
404
405**需要权限**:ohos.permission.GET_RUNNING_INFO
406
407**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
408
409**系统接口**:此接口为系统接口。
410
411**参数:**
412
413| 参数名 | 类型 | 必填 | 说明 |
414| -------- | -------- | -------- | -------- |
415| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 是 | 以回调方式方式返回接口运行结果及应用状态数据数组,可进行错误处理或其他自定义处理。 |
416
417**错误码**:
418
419以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
420
421| 错误码ID | 错误信息 |
422| ------- | -------- |
423| 201 | Permission denied. |
424| 202 | Not System App. Interface caller is not a system app. |
425| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
426| 16000050 | Internal error. |
427
428**示例:**
429
430```ts
431import { appManager } from '@kit.AbilityKit';
432import { BusinessError } from '@kit.BasicServicesKit';
433
434function getForegroundApplicationsCallback(err: BusinessError, data: Array<appManager.AppStateData>) {
435  if (err) {
436    console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`);
437  } else {
438    console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`);
439  }
440}
441
442try {
443  appManager.getForegroundApplications(getForegroundApplicationsCallback);
444} catch (paramError) {
445  let code = (paramError as BusinessError).code;
446  let message = (paramError as BusinessError).message;
447  console.error(`[appManager] error: ${code}, ${message}`);
448}
449```
450
451## appManager.getForegroundApplications
452
453getForegroundApplications(): Promise\<Array\<AppStateData>>
454
455获取当前所有前台应用的信息。该应用信息由[AppStateData](js-apis-inner-application-appStateData.md)定义。
456
457**需要权限**:ohos.permission.GET_RUNNING_INFO
458
459**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
460
461**系统接口**:此接口为系统接口。
462
463**返回值:**
464
465| 类型 | 说明 |
466| -------- | -------- |
467| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData.md)>> | 返回前台进程应用程序的数组。 |
468
469**错误码**:
470
471以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
472
473| 错误码ID | 错误信息 |
474| ------- | -------- |
475| 201 | Permission denied. |
476| 202 | Not System App. Interface caller is not a system app. |
477| 16000050 | Internal error. |
478
479**示例:**
480
481```ts
482import { appManager } from '@kit.AbilityKit';
483import { BusinessError } from '@kit.BasicServicesKit';
484
485appManager.getForegroundApplications().then((data) => {
486  console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`);
487}).catch((err: BusinessError) => {
488  console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`);
489});
490```
491
492## appManager.killProcessWithAccount
493
494killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
495
496终止account进程。使用Promise异步回调。
497
498> **说明:**
499>
500> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
501
502**需要权限**:ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
503
504**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
505
506**系统接口**:此接口为系统接口。
507
508**参数:**
509
510| 参数名 | 类型 | 必填 | 说明 |
511| -------- | -------- | -------- | -------- |
512| bundleName | string | 是 | Bundle名称。 |
513| accountId | number | 是 | 系统账号的账号ID,详情参考[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)。 |
514
515**返回值:**
516
517| 类型             | 说明              |
518| -------------- | --------------- |
519| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
520
521**错误码**:
522
523以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
524
525| 错误码ID | 错误信息 |
526| ------- | -------- |
527| 201 | Permission denied. |
528| 202 | Not System App. Interface caller is not a system app. |
529| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
530| 16000050 | Internal error. |
531
532**示例:**
533
534```ts
535import { appManager } from '@kit.AbilityKit';
536import { BusinessError } from '@kit.BasicServicesKit';
537
538let bundleName = 'bundleName';
539let accountId = 0;
540
541try {
542  appManager.killProcessWithAccount(bundleName, accountId).then(() => {
543    console.log('killProcessWithAccount success');
544  }).catch((err: BusinessError) => {
545    console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`);
546  });
547} catch (paramError) {
548  let code = (paramError as BusinessError).code;
549  let message = (paramError as BusinessError).message;
550  console.error(`[appManager] error: ${code}, ${message}`);
551}
552```
553
554## appManager.killProcessWithAccount<sup>14+</sup>
555
556killProcessWithAccount(bundleName: string, accountId: number, clearPageStack: boolean, appIndex?: number): Promise\<void\>
557
558终止account进程。使用Promise异步回调。
559
560> **说明:**
561>
562> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
563
564**需要权限**:ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.CLEAN_BACKGROUND_PROCESSES
565
566**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
567
568**系统接口**:此接口为系统接口。
569
570**参数:**
571
572| 参数名 | 类型 | 必填 | 说明 |
573| -------- | -------- | -------- | -------- |
574| bundleName | string | 是 | Bundle名称。 |
575| accountId | number | 是 | 系统账号的账号ID,详情参考[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)。 |
576| clearPageStack | boolean | 是 | 表示是否清除页面堆栈。true表示清除,false表示不清除。 |
577| appIndex | number | 否 | 应用分身ID。 |
578
579**返回值:**
580
581| 类型             | 说明              |
582| -------------- | --------------- |
583| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
584
585**错误码**:
586
587以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
588
589| 错误码ID | 错误信息 |
590| ------- | -------- |
591| 201 | Permission denied. |
592| 202 | Not System App. Interface caller is not a system app. |
593| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
594| 16000050 | Internal error. |
595
596**示例:**
597
598```ts
599import { appManager } from '@kit.AbilityKit';
600import { BusinessError } from '@kit.BasicServicesKit';
601
602let bundleName = 'bundleName';
603let accountId = 0;
604let isClearPageStack = false;
605let appIndex = 1;
606
607try {
608  appManager.killProcessWithAccount(bundleName, accountId, isClearPageStack, appIndex).then(() => {
609    console.log('killProcessWithAccount success');
610  }).catch((err: BusinessError) => {
611    console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`);
612  });
613} catch (paramError) {
614  let code = (paramError as BusinessError).code;
615  let message = (paramError as BusinessError).message;
616  console.error(`[appManager] error: ${code}, ${message}`);
617}
618```
619
620## appManager.killProcessWithAccount
621
622killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void
623
624终止account进程。使用callback异步回调。
625
626> **说明:**
627>
628> 当accountId为当前用户时,不需要校验ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS权限。
629
630**需要权限**:ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
631
632**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
633
634**系统接口**:此接口为系统接口。
635
636**参数:**
637
638  | 参数名 | 类型 | 必填 | 说明 |
639  | -------- | -------- | -------- | -------- |
640  | bundleName | string | 是 | 应用Bundle名称。 |
641  | accountId | number | 是 | 系统账号的账号ID,详情参考[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)。 |
642  | callback | AsyncCallback\<void\> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
643
644**错误码**:
645
646以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
647
648| 错误码ID | 错误信息 |
649| ------- | -------- |
650| 201 | Permission denied. |
651| 202 | Not System App. Interface caller is not a system app. |
652| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
653| 16000050 | Internal error. |
654
655**示例:**
656
657```ts
658import { appManager } from '@kit.AbilityKit';
659import { BusinessError } from '@kit.BasicServicesKit';
660
661let bundleName = 'bundleName';
662let accountId = 0;
663
664function killProcessWithAccountCallback(err: BusinessError) {
665  if (err) {
666    console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`);
667  } else {
668    console.log('killProcessWithAccountCallback success.');
669  }
670}
671
672appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
673```
674
675## appManager.killProcessesByBundleName
676
677killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>)
678
679通过Bundle名称终止进程。
680
681**需要权限**:ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
682
683**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
684
685**系统接口**:此接口为系统接口。
686
687**参数:**
688
689| 参数名 | 类型 | 必填 | 说明 |
690| -------- | -------- | -------- | -------- |
691| bundleName | string | 是 | 表示Bundle名称。 |
692| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
693
694**错误码**:
695
696以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
697
698| 错误码ID | 错误信息 |
699| ------- | -------- |
700| 201 | Permission denied. |
701| 202 | Not System App. Interface caller is not a system app. |
702| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
703| 16000050 | Internal error. |
704
705**示例:**
706
707```ts
708import { appManager } from '@kit.AbilityKit';
709import { BusinessError } from '@kit.BasicServicesKit';
710
711let bundleName = 'bundleName';
712
713function killProcessesByBundleNameCallback(err: BusinessError) {
714  if (err) {
715    console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
716  } else {
717    console.log('killProcessesByBundleNameCallback success.');
718  }
719}
720
721try {
722  appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
723} catch (paramError) {
724  let code = (paramError as BusinessError).code;
725  let message = (paramError as BusinessError).message;
726  console.error(`[appManager] error: ${code}, ${message}`);
727}
728```
729
730## appManager.killProcessesByBundleName
731
732killProcessesByBundleName(bundleName: string): Promise\<void>
733
734通过Bundle名称终止进程。
735
736**需要权限**:ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
737
738**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
739
740**系统接口**:此接口为系统接口。
741
742**参数:**
743
744| 参数名 | 类型 | 必填 | 说明 |
745| -------- | -------- | -------- | -------- |
746| bundleName | string | 是 | 表示Bundle名称。 |
747
748**返回值:**
749
750| 类型 | 说明 |
751| -------- | -------- |
752| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
753
754**错误码**:
755
756以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
757
758| 错误码ID | 错误信息 |
759| ------- | -------- |
760| 201 | Permission denied. |
761| 202 | Not System App. Interface caller is not a system app. |
762| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
763| 16000050 | Internal error. |
764
765**示例:**
766
767```ts
768import { appManager } from '@kit.AbilityKit';
769import { BusinessError } from '@kit.BasicServicesKit';
770
771let bundleName = 'bundleName';
772
773try {
774  appManager.killProcessesByBundleName(bundleName).then((data) => {
775    console.log('killProcessesByBundleName success.');
776  }).catch((err: BusinessError) => {
777    console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`);
778  });
779} catch (paramError) {
780  let code = (paramError as BusinessError).code;
781  let message = (paramError as BusinessError).message;
782  console.error(`[appManager] error: ${code}, ${message}`);
783}
784```
785
786## appManager.clearUpApplicationData
787
788clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>)
789
790通过Bundle名称清除应用数据。
791
792**需要权限**:ohos.permission.CLEAN_APPLICATION_DATA
793
794**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
795
796**系统接口**:此接口为系统接口。
797
798**参数:**
799
800| 参数名 | 类型 | 必填 | 说明 |
801| -------- | -------- | -------- | -------- |
802| bundleName | string | 是 | Bundle名称。 |
803| callback | AsyncCallback\<void> | 是 | 以回调方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
804
805**错误码**:
806
807以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
808
809| 错误码ID | 错误信息 |
810| ------- | -------- |
811| 201 | Permission denied. |
812| 202 | Not System App. Interface caller is not a system app. |
813| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
814| 16000050 | Internal error. |
815
816**示例:**
817
818```ts
819import { appManager } from '@kit.AbilityKit';
820import { BusinessError } from '@kit.BasicServicesKit';
821
822let bundleName = 'bundleName';
823
824function clearUpApplicationDataCallback(err: BusinessError) {
825  if (err) {
826    console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`);
827  } else {
828    console.log('clearUpApplicationDataCallback success.');
829  }
830}
831
832try {
833  appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
834} catch (paramError) {
835  let code = (paramError as BusinessError).code;
836  let message = (paramError as BusinessError).message;
837  console.error(`[appManager] error: ${code}, ${message}`);
838}
839```
840
841## appManager.clearUpApplicationData
842
843clearUpApplicationData(bundleName: string): Promise\<void>
844
845通过Bundle名称清除应用数据。
846
847**需要权限**:ohos.permission.CLEAN_APPLICATION_DATA
848
849**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
850
851**系统接口**:此接口为系统接口。
852
853**参数:**
854
855| 参数名 | 类型 | 必填 | 说明 |
856| -------- | -------- | -------- | -------- |
857| bundleName | string | 是 | 表示Bundle名称。 |
858
859**返回值:**
860
861| 类型 | 说明 |
862| -------- | -------- |
863| Promise\<void> | 以Promise方式返回接口运行结果,可进行错误处理或其他自定义处理。 |
864
865**错误码**:
866
867以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
868
869| 错误码ID | 错误信息 |
870| ------- | -------- |
871| 201 | Permission denied. |
872| 202 | Not System App. Interface caller is not a system app. |
873| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
874| 16000050 | Internal error. |
875
876**示例:**
877
878```ts
879import { appManager } from '@kit.AbilityKit';
880import { BusinessError } from '@kit.BasicServicesKit';
881
882let bundleName = 'bundleName';
883
884try {
885  appManager.clearUpApplicationData(bundleName).then((data) => {
886    console.log('clearUpApplicationData success.');
887  }).catch((err: BusinessError) => {
888    console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`);
889  });
890} catch (paramError) {
891  let code = (paramError as BusinessError).code;
892  let message = (paramError as BusinessError).message;
893  console.error(`[appManager] error: ${code}, ${message}`);
894}
895```
896
897## appManager.getProcessMemoryByPid<sup>10+</sup>
898
899getProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void
900
901通过pid查询对应进程占用的内存大小。
902
903**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
904
905**系统接口**:此接口为系统接口。
906
907**参数:**
908
909| 参数名 | 类型 | 必填 | 说明 |
910| -------- | -------- | -------- | -------- |
911| pid | number | 是 | 表示进程id,详情参考[getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10)。 |
912| callback | AsyncCallback\<number> | 是 | 以回调方式返回接口运行结果及进程占用的内存大小(单位KB),可进行错误处理或其他自定义处理。 |
913
914**错误码**:
915
916以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
917
918| 错误码ID | 错误信息 |
919| ------- | -------- |
920| 202 | Not System App. Interface caller is not a system app. |
921| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
922| 16000050 | Internal error. |
923
924**示例:**
925
926```ts
927import { appManager } from '@kit.AbilityKit';
928import { BusinessError } from '@kit.BasicServicesKit';
929
930let pid = 0;
931function getProcessMemoryByPidCallback(err: BusinessError, data: number) {
932  if (err) {
933    console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`);
934  } else {
935    console.log('getProcessMemoryByPidCallback success.');
936  }
937}
938
939try {
940  appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback);
941} catch (paramError) {
942  let code = (paramError as BusinessError).code;
943  let message = (paramError as BusinessError).message;
944  console.error(`[appManager] error: ${code}, ${message}`);
945}
946```
947
948## appManager.getProcessMemoryByPid<sup>10+</sup>
949
950getProcessMemoryByPid(pid: number): Promise\<number>
951
952通过pid查询对应进程占用的内存大小。
953
954**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
955
956**系统接口**:此接口为系统接口。
957
958**参数:**
959
960| 参数名 | 类型 | 必填 | 说明 |
961| -------- | -------- | -------- | -------- |
962| pid | number | 是 | 表示进程id,详情参考[getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10)。  |
963
964**返回值:**
965
966| 类型 | 说明 |
967| -------- | -------- |
968| Promise\<number> | 以Promise方式返回接口运行结果及进程占用的内存大小(单位KB),可进行错误处理或其他自定义处理。 |
969
970**错误码**:
971
972以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
973
974| 错误码ID | 错误信息 |
975| ------- | -------- |
976| 202 | Not System App. Interface caller is not a system app. |
977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
978| 16000050 | Internal error. |
979
980**示例:**
981
982```ts
983import { appManager } from '@kit.AbilityKit';
984import { BusinessError } from '@kit.BasicServicesKit';
985
986let pid = 0;
987
988try {
989  appManager.getProcessMemoryByPid(pid).then((data) => {
990    console.log('getProcessMemoryByPid success.');
991  }).catch((err: BusinessError) => {
992    console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`);
993  });
994} catch (paramError) {
995  let code = (paramError as BusinessError).code;
996  let message = (paramError as BusinessError).message;
997  console.error(`[appManager] error: ${code}, ${message}`);
998}
999```
1000
1001## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
1002
1003getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void
1004
1005通过bundleName获取有关运行进程的信息。
1006
1007**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1008
1009**系统接口**:此接口为系统接口。
1010
1011**参数:**
1012
1013| 参数名 | 类型 | 必填 | 说明 |
1014| -------- | -------- | -------- | -------- |
1015| bundleName | string | 是 | 表示Bundle名称。 |
1016| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 是 | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
1017
1018**错误码**:
1019
1020以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1021
1022| 错误码ID | 错误信息 |
1023| ------- | -------- |
1024| 202 | Not System App. Interface caller is not a system app. |
1025| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1026| 16000050 | Internal error. |
1027
1028**示例:**
1029
1030```ts
1031import { appManager } from '@kit.AbilityKit';
1032import { BusinessError } from '@kit.BasicServicesKit';
1033
1034let bundleName = "bundleName";
1035function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) {
1036  if (err) {
1037    console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
1038  } else {
1039    console.log('getRunningProcessInfoByBundleNameCallback success.');
1040  }
1041}
1042
1043try {
1044  appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback);
1045} catch (paramError) {
1046  let code = (paramError as BusinessError).code;
1047  let message = (paramError as BusinessError).message;
1048  console.error(`[appManager] error: ${code}, ${message}`);
1049}
1050```
1051
1052## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
1053
1054getRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>>
1055
1056通过bundleName获取有关运行进程的信息。
1057
1058**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1059
1060**系统接口**:此接口为系统接口。
1061
1062**参数:**
1063
1064| 参数名 | 类型 | 必填 | 说明 |
1065| -------- | -------- | -------- | -------- |
1066| bundleName | string | 是 | 表示Bundle名称。 |
1067
1068**返回值:**
1069
1070| 类型 | 说明 |
1071| -------- | -------- |
1072| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 以Promise方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
1073
1074**错误码**:
1075
1076以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1077
1078| 错误码ID | 错误信息 |
1079| ------- | -------- |
1080| 202 | Not System App. Interface caller is not a system app. |
1081| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1082| 16000050 | Internal error. |
1083
1084**示例:**
1085
1086```ts
1087import { appManager } from '@kit.AbilityKit';
1088import { BusinessError } from '@kit.BasicServicesKit';
1089
1090let bundleName = "bundleName";
1091
1092try {
1093  appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => {
1094    console.log('getRunningProcessInfoByBundleName success.');
1095  }).catch((err: BusinessError) => {
1096    console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`);
1097  });
1098} catch (paramError) {
1099  let code = (paramError as BusinessError).code;
1100  let message = (paramError as BusinessError).message;
1101  console.error(`[appManager] error: ${code}, ${message}`);
1102}
1103```
1104
1105## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
1106
1107getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void
1108
1109通过bundleName和userId获取有关运行进程的信息。
1110
1111**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1112
1113**系统接口**:此接口为系统接口。
1114
1115**参数:**
1116
1117| 参数名 | 类型 | 必填 | 说明 |
1118| -------- | -------- | -------- | -------- |
1119| bundleName | string | 是 | 表示Bundle名称。 |
1120| userId | number | 是 | 表示用户Id。 |
1121| callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 是 | 以回调方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
1122
1123**错误码**:
1124
1125以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1126
1127| 错误码ID | 错误信息 |
1128| ------- | -------- |
1129| 202 | Not System App. Interface caller is not a system app. |
1130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1131| 16000050 | Internal error. |
1132
1133**示例:**
1134
1135```ts
1136import { appManager } from '@kit.AbilityKit';
1137import { BusinessError } from '@kit.BasicServicesKit';
1138
1139let bundleName = "bundleName";
1140let userId = 0;
1141function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) {
1142  if (err) {
1143    console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
1144  } else {
1145    console.log('getRunningProcessInfoByBundleNameCallback success.');
1146  }
1147}
1148
1149try {
1150  appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback);
1151} catch (paramError) {
1152  let code = (paramError as BusinessError).code;
1153  let message = (paramError as BusinessError).message;
1154  console.error(`[appManager] error: ${code}, ${message}`);
1155}
1156```
1157
1158## appManager.getRunningProcessInfoByBundleName<sup>10+</sup>
1159
1160getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>>
1161
1162通过bundleName和userId获取有关运行进程的信息。
1163
1164**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1165
1166**系统接口**:此接口为系统接口。
1167
1168**参数:**
1169
1170| 参数名 | 类型 | 必填 | 说明 |
1171| -------- | -------- | -------- | -------- |
1172| bundleName | string | 是 | 表示Bundle名称。 |
1173| userId | number | 是 | 表示用户Id。 |
1174
1175**返回值:**
1176
1177| 类型 | 说明 |
1178| -------- | -------- |
1179| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | 以Promise方式返回接口运行结果及有关运行进程的信息,可进行错误处理或其他自定义处理。 |
1180
1181**错误码**:
1182
1183以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1184
1185| 错误码ID | 错误信息 |
1186| ------- | -------- |
1187| 202 | Not System App. Interface caller is not a system app. |
1188| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1189| 16000050 | Internal error. |
1190
1191**示例:**
1192
1193```ts
1194import { appManager } from '@kit.AbilityKit';
1195import { BusinessError } from '@kit.BasicServicesKit';
1196
1197let bundleName = "bundleName";
1198let userId = 0;
1199
1200try {
1201  appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => {
1202    console.log('getRunningProcessInfoByBundleName success.');
1203  }).catch((err: BusinessError) => {
1204    console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`);
1205  });
1206} catch (paramError) {
1207  let code = (paramError as BusinessError).code;
1208  let message = (paramError as BusinessError).message;
1209  console.error(`[appManager] error: ${code}, ${message}`);
1210}
1211```
1212
1213## appManager.isApplicationRunning<sup>11+</sup>
1214
1215isApplicationRunning(bundleName: string): Promise\<boolean>
1216
1217查询单个应用是否正在运行。使用Promise异步回调。
1218
1219**系统接口**:此接口为系统接口。
1220
1221**需要权限**:ohos.permission.GET_RUNNING_INFO
1222
1223**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1224
1225**参数**:
1226
1227| 参数名        | 类型                                       | 必填   | 说明             |
1228| --------- | ---------------------------------------- | ---- | -------------- |
1229| bundleName    | string   | 是    | 表示要查询的应用的包名。 |
1230
1231**返回值:**
1232
1233| 类型 | 说明 |
1234| -------- | -------- |
1235| Promise\<boolean> | Promise对象。返回true表示查询的应用正在运行,返回false表示查询的应用没有运行。 |
1236
1237**错误码**:
1238
1239以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1240
1241| 错误码ID | 错误信息 |
1242| ------- | -------- |
1243| 201 | Permission denied. |
1244| 202 | Not System App. Interface caller is not a system app. |
1245| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1246| 16000050 | Internal error. |
1247
1248**示例:**
1249
1250```ts
1251import { appManager } from '@kit.AbilityKit';
1252import { BusinessError } from '@kit.BasicServicesKit';
1253
1254let bundleName = "com.example.myapplication";
1255
1256appManager.isApplicationRunning(bundleName).then((data) => {
1257  console.log(`The application running is: ${JSON.stringify(data)}`);
1258}).catch((error: BusinessError) => {
1259  console.error(`error: ${JSON.stringify(error)}`);
1260});
1261```
1262
1263## appManager.isApplicationRunning<sup>11+</sup>
1264
1265isApplicationRunning(bundleName: string, callback: AsyncCallback\<boolean>): void
1266
1267查询单个应用是否正在运行。使用callback异步回调。
1268
1269**系统接口**:此接口为系统接口。
1270
1271**需要权限**:ohos.permission.GET_RUNNING_INFO
1272
1273**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1274
1275**参数**:
1276
1277| 参数名        | 类型                                       | 必填   | 说明             |
1278| --------- | ---------------------------------------- | ---- | -------------- |
1279| bundleName    | string   | 是    | 表示要查询的共享库包名。 |
1280| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。返回true表示查询的应用正在运行,返回false表示查询的应用没有运行。 |
1281
1282**错误码**:
1283
1284以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1285
1286| 错误码ID | 错误信息 |
1287| ------- | -------- |
1288| 201 | Permission denied. |
1289| 202 | Not System App. Interface caller is not a system app. |
1290| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1291| 16000050 | Internal error. |
1292
1293**示例:**
1294
1295```ts
1296import { appManager } from '@kit.AbilityKit';
1297import { BusinessError } from '@kit.BasicServicesKit';
1298
1299let bundleName = "com.example.myapplication";
1300
1301try {
1302  appManager.isApplicationRunning(bundleName, (err, data) => {
1303    if (err) {
1304      console.error(`err: ${JSON.stringify(err)}`);
1305    } else {
1306      console.log(`The application running is: ${JSON.stringify(data)}`);
1307    }
1308  });
1309} catch (paramError) {
1310  let code = (paramError as BusinessError).code;
1311  let message = (paramError as BusinessError).message;
1312  console.error(`[appManager] error: ${code}, ${message}`);
1313}
1314```
1315
1316## ApplicationState
1317
1318应用状态,该类型为枚举,可配合[AbilityStateData](js-apis-inner-application-abilityStateData.md)返回相应的应用状态。
1319
1320**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1321
1322**系统接口**:此接口为系统接口。
1323
1324| 名称                 | 值  | 说明                               |
1325| -------------------- | --- | --------------------------------- |
1326| STATE_CREATE    | 0   |   应用处于创建状态。         |
1327| STATE_FOREGROUND          | 2   |      应用处于前台状态。            |
1328| STATE_ACTIVE  | 3   |     应用处于获焦状态。     |
1329| STATE_BACKGROUND        | 4   |    应用处于后台不可见状态。           |
1330| STATE_DESTROY        | 5   |    应用处于销毁状态。       |
1331
1332
1333## appManager.getRunningProcessInformationByBundleType<sup>12+</sup>
1334
1335getRunningProcessInformationByBundleType(bundleType: bundleManager.BundleType): Promise\<Array\<ProcessInformation>>
1336
1337根据包类型获取当前运行进程的有关信息。使用Promise异步回调。
1338
1339**系统接口**:此接口为系统接口。
1340
1341**需要权限**:ohos.permission.GET_RUNNING_INFO
1342
1343**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1344
1345**参数**:
1346
1347| 参数名        | 类型                                       | 必填   | 说明             |
1348| --------- | ---------------------------------------- | ---- | -------------- |
1349| bundleType    | [bundleManager.BundleType](js-apis-bundleManager.md#bundletype)  | 是    | 表示要查询的包类型。 |
1350
1351**返回值:**
1352
1353| 类型 | 说明 |
1354| -------- | -------- |
1355| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise对象,返回特定包类型的运行进程的信息。 |
1356
1357**错误码**:
1358以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1359
1360| 错误码ID | 错误信息 |
1361| ------- | -------- |
1362| 201 | Permission denied. |
1363| 202 | Not system application. |
1364| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1365| 16000050 | Internal error. |
1366
1367
1368**示例:**
1369
1370```ts
1371import { appManager, bundleManager } from '@kit.AbilityKit';
1372import { BusinessError } from '@kit.BasicServicesKit';
1373
1374try {
1375  appManager.getRunningProcessInformationByBundleType(bundleManager.BundleType.ATOMIC_SERVICE)
1376    .then((data) => {
1377      console.log(`The running process information is: ${JSON.stringify(data)}`);
1378    }).catch((error: BusinessError) => {
1379    console.error(`error: ${JSON.stringify(error)}`);
1380  });
1381} catch (paramError) {
1382  let code = (paramError as BusinessError).code;
1383  let message = (paramError as BusinessError).message;
1384  console.error(`[appManager] error: ${code}, ${message}`);
1385}
1386```
1387
1388## appManager.preloadApplication<sup>12+</sup>
1389
1390preloadApplication(bundleName: string, userId: number, mode: PreloadMode, appIndex?: number): Promise\<void>
1391
1392预加载应用进程。接口返回成功并不代表预加载成功,具体结果以目标应用进程是否创建成功为准。使用Promise异步回调。
1393
1394**需要权限**:ohos.permission.PRELOAD_APPLICATION
1395
1396**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1397
1398**系统接口**:此接口为系统接口。
1399
1400**模型约束**:此接口仅可在Stage模型下使用。
1401
1402**参数:**
1403
1404| 参数名 | 类型 | 必填 | 说明 |
1405| -------- | -------- | -------- | -------- |
1406| bundleName | string | 是 | 预加载的应用包名。 |
1407| userId | number | 是 | 预加载的用户Id。 |
1408| mode | [PreloadMode](#appmanagerpreloadmode12) | 是 | 预加载模式。 |
1409| appIndex | number | 否 | 预加载应用分身的appIndex。 |
1410
1411**返回值:**
1412
1413| 类型           | 说明              |
1414| -------------- | ---------------- |
1415| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
1416
1417**错误码**:
1418
1419  以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1420
1421| 错误码ID | 错误信息 |
1422| ------- | -------- |
1423| 201 | The application does not have permission to call the interface. |
1424| 202 | Not system application. |
1425| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
1426| 16000050 | Internal error. |
1427| 16300005 | The target bundle does not exist. |
1428
1429**示例:**
1430
1431```ts
1432import { appManager } from '@kit.AbilityKit';
1433import { BusinessError } from '@kit.BasicServicesKit';
1434import { hilog } from '@kit.PerformanceAnalysisKit';
1435
1436try {
1437  let bundleName = "ohos.samples.etsclock";
1438  let userId = 100;
1439  let mode = appManager.PreloadMode.PRESS_DOWN;
1440  let appIndex = 0;
1441  appManager.preloadApplication(bundleName, userId, mode, appIndex)
1442    .then(() => {
1443      hilog.info(0x0000, 'testTag', `preloadApplication success`);
1444    })
1445    .catch((err: BusinessError) => {
1446      hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${err.code}, msg:${err.message}`);
1447    })
1448} catch (err) {
1449  hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${(err as BusinessError).code}, msg:${(err as BusinessError).message}`);
1450}
1451```
1452
1453## appManager.getRunningMultiAppInfo<sup>12+</sup>
1454
1455getRunningMultiAppInfo(bundleName: string): Promise\<RunningMultiAppInfo>
1456
1457根据应用包名获取系统中运行态的应用多开(即在一个设备上运行多个相同的应用)的相关信息,使用Promise异步回调。
1458
1459**需要权限**:ohos.permission.GET_RUNNING_INFO
1460
1461**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1462
1463**系统接口**:此接口为系统接口。
1464
1465**模型约束**:此接口仅可在Stage模型下使用。
1466
1467**参数:**
1468
1469| 参数名 | 类型 | 必填 | 说明 |
1470| -------- | -------- | -------- | -------- |
1471| bundleName | string | 是 | 查询的应用包名。 |
1472
1473**返回值:**
1474
1475| 类型           | 说明              |
1476| -------------- | ---------------- |
1477| Promise\<[RunningMultiAppInfo](js-apis-inner-application-runningMultiAppInfo-sys.md)> | Promise对象。返回特定包名的运行态应用多开信息。 |
1478
1479**错误码**:
1480
1481  以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1482
1483| 错误码ID | 错误信息 |
1484| ------- | -------- |
1485| 201 | The application does not have permission to call the interface. |
1486| 202 | Not system application. |
1487| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
1488| 16000072 | App clone or multi-instance is not supported. |
1489| 18500001 | The bundle does not exist or no patch has been applied. |
1490
1491**示例:**
1492
1493```ts
1494import { appManager } from '@kit.AbilityKit';
1495import { hilog } from '@kit.PerformanceAnalysisKit';
1496import { BusinessError } from '@kit.BasicServicesKit';
1497
1498try {
1499  let bundleName = "ohos.samples.etsclock";
1500  appManager.getRunningMultiAppInfo(bundleName).then((info: appManager.RunningMultiAppInfo) => {
1501      hilog.info(0x0000, 'testTag', `getRunningMultiAppInfo success`);
1502    }).catch((err: BusinessError) => {
1503      hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`);
1504    })
1505} catch (err) {
1506  hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`);
1507}
1508```
1509
1510## appManager.terminateMission<sup>13+</sup>
1511
1512terminateMission(missionId: number): Promise\<void>
1513
1514关闭指定的任务。使用Promise异步回调。
1515
1516**需要权限**:ohos.permission.KILL_APP_PROCESSES
1517
1518**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1519
1520**系统接口**:此接口为系统接口。
1521
1522**参数:**
1523
1524| 参数名 | 类型 | 必填 | 说明 |
1525| -------- | -------- | -------- | -------- |
1526| missionId | number | 是 | 任务ID,可通过[getMissionInfos](js-apis-app-ability-missionManager-sys.md#missionmanagergetmissioninfos)获取。 |
1527
1528**返回值:**
1529
1530| 类型 | 说明 |
1531| -------- | -------- |
1532| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
1533
1534**错误码**:
1535
1536以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1537
1538| 错误码ID | 错误信息 |
1539| ------- | -------- |
1540| 201 | Permission denied. |
1541| 202 | Not System App. Interface caller is not a system app. |
1542| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1543| 16000050 | Internal error. |
1544
1545**示例:**
1546```ts
1547import { appManager } from '@kit.AbilityKit';
1548import { BusinessError } from '@kit.BasicServicesKit';
1549
1550@Entry
1551@Component
1552struct Index {
1553  build() {
1554    Button('start link', { type: ButtonType.Capsule, stateEffect: true })
1555      .width('87%')
1556      .height('5%')
1557      .margin({ bottom: '12vp' })
1558      .onClick(() => {
1559        let missionId: number = 0;
1560        try {
1561          appManager.terminateMission(missionId).then(()=>{
1562              console.log('terminateMission success.');
1563            }).catch((err: BusinessError)=>{
1564              console.error('terminateMission failed. err: ' + JSON.stringify(err));
1565            })
1566        } catch (paramError) {
1567          let code = (paramError as BusinessError).code;
1568          let message = (paramError as BusinessError).message;
1569          console.error(`[appManager] error: ${code}, ${message}`);
1570        }
1571      })
1572  }
1573}
1574```
1575
1576## appManager.getSupportedProcessCachePids<sup>14+</sup>
1577
1578getSupportedProcessCachePids(bundleName : string): Promise\<Array\<number>>
1579
1580查询当前应用中支持缓存后快速启动的进程PID。
1581
1582> **说明:**
1583>
1584> 本接口仅支持获取调用者所在系统账号下的进程PID。
1585
1586**需要权限**:ohos.permission.GET_RUNNING_INFO
1587
1588**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1589
1590**系统接口**:此接口为系统接口。
1591
1592**模型约束**:此接口仅可在Stage模型下使用。
1593
1594**参数:**
1595
1596| 参数名 | 类型 | 必填 | 说明 |
1597| -------- | -------- | -------- | -------- |
1598| bundleName    | string   | 是    | 表示要查询的应用包名。 |
1599
1600**返回值:**
1601
1602| 类型 | 说明 |
1603| -------- | -------- |
1604| Promise\<Array\<number>> | Promise对象。返回一个数组,包含当前应用中支持缓存后快速启动的所有进程PID。 |
1605
1606**错误码**:
1607
1608以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1609
1610| 错误码ID | 错误信息 |
1611| ------- | -------- |
1612| 201 | Permission denied. |
1613| 202 | Not system application. |
1614| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1615| 801 | Capability not supported. |
1616| 16000050 | Internal error. |
1617
1618**示例:**
1619
1620```ts
1621import { appManager } from '@kit.AbilityKit';
1622import { hilog } from '@kit.PerformanceAnalysisKit';
1623import { BusinessError } from '@kit.BasicServicesKit';
1624
1625try {
1626  let bundleName = "ohos.samples.processcache";
1627  appManager.getSupportedProcessCachePids(bundleName).then((pids: Array<number>) => {
1628      hilog.info(0x0000, 'testTag', `pids: ${JSON.stringify(pids)}`);
1629    }).catch((err: BusinessError) => {
1630      hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`);
1631    })
1632} catch (err) {
1633  hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`);
1634}
1635```
1636
1637## appManager.clearUpAppData<sup>13+</sup>
1638
1639clearUpAppData(bundleName: string, appCloneIndex?: number): Promise\<void>
1640
1641根据Bundle名称和应用分身索引,清除指定应用的数据。
1642
1643**需要权限**:ohos.permission.CLEAN_APPLICATION_DATA
1644
1645**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1646
1647**系统接口**:此接口为系统接口。
1648
1649**参数:**
1650
1651| 参数名 | 类型 | 必填 | 说明 |
1652| -------- | -------- | -------- | -------- |
1653| bundleName | string | 是 | 表示Bundle名称。 |
1654| appCloneIndex | number | 否 | 表示应用分身索引。 |
1655
1656**返回值:**
1657
1658| 类型 | 说明 |
1659| -------- | -------- |
1660| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
1661
1662**错误码**:
1663
1664以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1665
1666| 错误码ID | 错误信息 |
1667| ------- | -------- |
1668| 201 | Permission denied. |
1669| 202 | Not System App. Interface caller is not a system app. |
1670| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1671| 16000050 | Internal error. |
1672| 16000073 | The app clone index does not exist. |
1673
1674**示例:**
1675
1676```ts
1677import { appManager } from '@kit.AbilityKit';
1678import { BusinessError } from '@kit.BasicServicesKit';
1679
1680let bundleName: string = 'com.ohos.demo';
1681let appCloneIndex: number = 0;
1682
1683try {
1684  appManager.clearUpAppData(bundleName, appCloneIndex).then(() => {
1685    console.log(`clearUpAppData success.`);
1686  }).catch((err: BusinessError) => {
1687    console.error(`clearUpAppData fail, err: ${JSON.stringify(err)}`);
1688  });
1689} catch (paramError) {
1690  let code = (paramError as BusinessError).code;
1691  let message = (paramError as BusinessError).message;
1692  console.error(`[appManager] error: ${code}, ${message}`);
1693}
1694```
1695
1696## appManager.setKeepAliveForBundle<sup>14+</sup>
1697
1698setKeepAliveForBundle(bundleName: string, userId: number, enable: boolean): Promise\<void>
1699
1700为指定用户下的应用设置或取消保活。使用Promise异步回调。本接口当前仅支持2in1设备。
1701
1702**需要权限**:ohos.permission.MANAGE_APP_KEEP_ALIVE
1703
1704**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1705
1706**系统接口**:此接口为系统接口。
1707
1708**参数:**
1709
1710| 参数名 | 类型 | 必填 | 说明 |
1711| -------- | -------- | -------- | -------- |
1712| bundleName    | string   | 是    | 表示要设置保活的应用包名。 |
1713| userId    | number   | 是    | 表示要设置保活应用所属的用户ID。 |
1714| enable    | boolean   | 是    | 表示对应用保活或者取消保活。 |
1715
1716**返回值:**
1717
1718| 类型 | 说明 |
1719| -------- | -------- |
1720| Promise\<void> | Promise对象。无返回结果的Promise对象。|
1721
1722**错误码**:
1723
1724以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1725
1726| 错误码ID | 错误信息 |
1727| ------- | -------- |
1728| 201 | Permission denied. |
1729| 202 | Not system application. |
1730| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1731| 801 | Capability not supported. |
1732| 16000050 | Internal error. |
1733| 16300005 | The target bundle does not exist. |
1734| 16300008 | The target bundle has no main ability. |
1735| 16300009 | The target bundle has no status-bar ability. |
1736| 16300010 | The target application is not attached to status bar. |
1737
1738**示例:**
1739
1740```ts
1741import { appManager } from '@kit.AbilityKit';
1742import { BusinessError } from '@kit.BasicServicesKit';
1743
1744try {
1745  let bundleName = "ohos.samples.keepaliveapp";
1746  let userId = 100;
1747  appManager.setKeepAliveForBundle(bundleName, userId, true).then(() => {
1748    console.log(`setKeepAliveForBundle success`);
1749  }).catch((err: BusinessError) => {
1750    console.error(`setKeepAliveForBundle fail, err: ${JSON.stringify(err)}`);
1751  });
1752} catch (paramError) {
1753  let code = (paramError as BusinessError).code;
1754  let message = (paramError as BusinessError).message;
1755  console.error(`[appManager] setKeepAliveForBundle error: ${code}, ${message}`);
1756}
1757```
1758
1759## appManager.getKeepAliveBundles<sup>14+</sup>
1760
1761getKeepAliveBundles(type: KeepAliveAppType, userId?: number): Promise\<Array\<KeepAliveBundleInfo>>
1762
1763获取指定用户下指定类型的保活应用信息。该应用信息由[KeepAliveBundleInfo](#keepalivebundleinfo14)定义。
1764使用Promise异步回调。本接口当前仅支持2in1设备。
1765
1766**需要权限**:ohos.permission.MANAGE_APP_KEEP_ALIVE
1767
1768**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1769
1770**系统接口**:此接口为系统接口。
1771
1772**参数:**
1773
1774| 参数名 | 类型 | 必填 | 说明 |
1775| -------- | -------- | -------- | -------- |
1776| type    | [KeepAliveAppType](#keepaliveapptype14)   | 是    | 表示要查询的保活应用类型。 |
1777| userId    | number   | 否    | 表示要设置保活应用所属的用户ID。 |
1778
1779**返回值:**
1780
1781| 类型 | 说明 |
1782| -------- | -------- |
1783| Promise\<Array\<[KeepAliveBundleInfo](#keepalivebundleinfo14)>> | Promise对象,返回用户保活应用信息的数组。|
1784
1785**错误码**:
1786
1787以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1788
1789| 错误码ID | 错误信息 |
1790| ------- | -------- |
1791| 201 | Permission denied. |
1792| 202 | Not System App. Interface caller is not a system app. |
1793| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1794| 801 | Capability not supported. |
1795| 16000050 | Internal error. |
1796
1797**示例:**
1798
1799```ts
1800import { appManager } from '@kit.AbilityKit';
1801import { BusinessError } from '@kit.BasicServicesKit';
1802
1803let userId = 100;
1804let type: appManager.KeepAliveAppType = appManager.KeepAliveAppType.THIRD_PARTY;
1805try {
1806  appManager.getKeepAliveBundles(type, userId).then((data) => {
1807    console.log(`getKeepAliveBundles success, data: ${JSON.stringify(data)}`);
1808  }).catch((err: BusinessError) => {
1809    console.error(`getKeepAliveBundles fail, err: ${JSON.stringify(err)}`);
1810  });
1811} catch (paramError) {
1812  let code = (paramError as BusinessError).code;
1813  let message = (paramError as BusinessError).message;
1814  console.error(`[appManager] getKeepAliveBundles error: ${code}, ${message}`);
1815}
1816```
1817
1818
1819## appManager.killProcessesInBatch<sup>14+</sup>
1820
1821killProcessesInBatch(pids: Array\<number>): Promise\<void>
1822
1823批量查杀进程。本接口当前仅支持2in1设备。
1824
1825**需要权限**:ohos.permission.KILL_APP_PROCESSES
1826
1827**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
1828
1829**系统接口**:此接口为系统接口。
1830
1831**参数:**
1832
1833| 参数名 | 类型 | 必填 | 说明 |
1834| -------- | -------- | -------- | -------- |
1835| pids    | Array\<number>   | 是    | 要查杀的进程ID。 |
1836
1837**返回值:**
1838
1839| 类型 | 说明 |
1840| -------- | -------- |
1841| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
1842
1843**错误码**:
1844
1845以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。
1846
1847| 错误码ID | 错误信息 |
1848| ------- | -------- |
1849| 201 | Permission denied. |
1850| 202 | Not System App. Interface caller is not a system app. |
1851| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1852| 801 | Capability not supported. |
1853| 16000050 | Internal error. |
1854
1855**示例:**
1856
1857```ts
1858import { appManager } from '@kit.AbilityKit';
1859import { BusinessError } from '@kit.BasicServicesKit';
1860
1861try {
1862  let pids: Array<number> = [100, 101, 102];
1863  appManager.killProcessesInBatch(pids).then(() => {
1864    console.log(`killProcessesInBatch success`);
1865  }).catch((err: BusinessError) => {
1866    console.error(`killProcessesInBatch fail, err: ${JSON.stringify(err)}`);
1867  });
1868} catch (paramError) {
1869  let code = (paramError as BusinessError).code;
1870  let message = (paramError as BusinessError).message;
1871  console.error(`[appManager] killProcessesInBatch error: ${code}, ${message}`);
1872}
1873```
1874