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