1# @ohos.app.ability.appManager (appManager) 2 3The **appManager** module implements application management. You can use the APIs of this module to query whether the application is undergoing a stability test, whether the application is running on a RAM constrained device, the memory size of the application, and information about the running process. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { appManager } from '@kit.AbilityKit'; 13``` 14 15## ProcessState<sup>10+</sup> 16 17Enumerates the processes states. 18 19**Atomic service API**: This API can be used in atomic services since API version 11. 20 21**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22 23| Name | Value | Description | 24| -------------------- | --- | --------------------------------- | 25| STATE_CREATE | 0 | The process is being created. | 26| STATE_FOREGROUND | 1 | The process is running in the foreground. | 27| STATE_ACTIVE | 2 | The process is active. | 28| STATE_BACKGROUND | 3 | The process is running in the background. | 29| STATE_DESTROY | 4 | The process is being destroyed. | 30 31## appManager.isRunningInStabilityTest 32 33isRunningInStabilityTest(callback: AsyncCallback<boolean>): void 34 35Checks whether this application is undergoing a stability test. This API uses an asynchronous callback to return the result. 36 37**Atomic service API**: This API can be used in atomic services since API version 11. 38 39**System capability**: SystemCapability.Ability.AbilityRuntime.Core 40 41**Parameters** 42 43 | Name| Type| Mandatory| Description| 44 | -------- | -------- | -------- | -------- | 45 | callback | AsyncCallback<boolean> | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite. | 46 47**Error codes** 48 49For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 50 51| ID| Error Message| 52| ------- | -------- | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 54| 16000050 | Internal error. | 55 56**Example** 57 58```ts 59import { appManager } from '@kit.AbilityKit'; 60 61appManager.isRunningInStabilityTest((err, flag) => { 62 if (err) { 63 console.error(`isRunningInStabilityTest fail, err: ${JSON.stringify(err)}`); 64 } else { 65 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 66 } 67}); 68``` 69 70 71## appManager.isRunningInStabilityTest 72 73isRunningInStabilityTest(): Promise<boolean> 74 75Checks whether this application is undergoing a stability test. This API uses a promise to return the result. 76 77**Atomic service API**: This API can be used in atomic services since API version 11. 78 79**System capability**: SystemCapability.Ability.AbilityRuntime.Core 80 81**Return value** 82 83 | Type| Description| 84 | -------- | -------- | 85 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is undergoing a stability test, and **false** means the opposite.| 86 87**Error codes** 88 89For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 90 91| ID| Error Message| 92| ------- | -------- | 93| 16000050 | Internal error. | 94 95**Example** 96 97```ts 98import { appManager } from '@kit.AbilityKit'; 99import { BusinessError } from '@kit.BasicServicesKit'; 100 101appManager.isRunningInStabilityTest().then((flag) => { 102 console.log(`The result of isRunningInStabilityTest is: ${JSON.stringify(flag)}`); 103}).catch((error: BusinessError) => { 104 console.error(`error: ${JSON.stringify(error)}`); 105}); 106``` 107 108 109## appManager.isRamConstrainedDevice 110 111isRamConstrainedDevice(): Promise\<boolean> 112 113Checks whether this application is running on a RAM constrained device. This API uses a promise to return the result. 114 115**Atomic service API**: This API can be used in atomic services since API version 11. 116 117**System capability**: SystemCapability.Ability.AbilityRuntime.Core 118 119**Return value** 120 121 | Type| Description| 122 | -------- | -------- | 123 | Promise<boolean> | Promise used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite.| 124 125**Error codes** 126 127For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 128 129| ID| Error Message| 130| ------- | -------- | 131| 16000050 | Internal error. | 132 133**Example** 134 135```ts 136import { appManager } from '@kit.AbilityKit'; 137import { BusinessError } from '@kit.BasicServicesKit'; 138 139appManager.isRamConstrainedDevice().then((data) => { 140 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 141}).catch((error: BusinessError) => { 142 console.error(`error: ${JSON.stringify(error)}`); 143}); 144``` 145 146## appManager.isRamConstrainedDevice 147 148isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void 149 150Checks whether this application is running on a RAM constrained device. This API uses an asynchronous callback to return the result. 151 152**Atomic service API**: This API can be used in atomic services since API version 11. 153 154**System capability**: SystemCapability.Ability.AbilityRuntime.Core 155 156**Parameters** 157 158 | Name| Type| Mandatory| Description| 159 | -------- | -------- | -------- | -------- | 160 | callback | AsyncCallback<boolean> | Yes|Callback used to return the API call result and the result **true** or **false**. You can perform error handling or custom processing in this callback. The value **true** means that the application is running on a RAM constrained device, and **false** means the opposite. | 161 162**Error codes** 163 164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 165 166| ID| Error Message| 167| ------- | -------- | 168| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 169| 16000050 | Internal error. | 170 171**Example** 172 173```ts 174import { appManager } from '@kit.AbilityKit'; 175 176appManager.isRamConstrainedDevice((err, data) => { 177 if (err) { 178 console.error(`isRamConstrainedDevice fail, err: ${JSON.stringify(err)}`); 179 } else { 180 console.log(`The result of isRamConstrainedDevice is: ${JSON.stringify(data)}`); 181 } 182}); 183``` 184 185## appManager.getAppMemorySize 186 187getAppMemorySize(): Promise\<number> 188 189Obtains the memory size of this application. This API uses a promise to return the result. 190 191**Atomic service API**: This API can be used in atomic services since API version 11. 192 193**System capability**: SystemCapability.Ability.AbilityRuntime.Core 194 195**Return value** 196 197 | Type| Description| 198 | -------- | -------- | 199 | Promise<number> | Promise used to return the memory size, in MB. You can perform error processing or other custom processing based on the size. | 200 201**Error codes** 202 203For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 204 205| ID| Error Message| 206| ------- | -------- | 207| 16000050 | Internal error. | 208 209**Example** 210 211```ts 212import { appManager } from '@kit.AbilityKit'; 213import { BusinessError } from '@kit.BasicServicesKit'; 214 215appManager.getAppMemorySize().then((data) => { 216 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 217}).catch((error: BusinessError) => { 218 console.error(`error: ${JSON.stringify(error)}`); 219}); 220``` 221 222## appManager.getAppMemorySize 223 224getAppMemorySize(callback: AsyncCallback\<number>): void 225 226Obtains the memory size of this application. This API uses an asynchronous callback to return the result. 227 228**Atomic service API**: This API can be used in atomic services since API version 11. 229 230**System capability**: SystemCapability.Ability.AbilityRuntime.Core 231 232**Parameters** 233 234 | Name| Type| Mandatory| Description| 235 | -------- | -------- | -------- | -------- | 236 | callback | AsyncCallback<number> | Yes|Callback used to return the memory size, in MB. You can perform error processing or other custom processing based on the size. | 237 238**Error codes** 239 240For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 241 242| ID| Error Message| 243| ------- | -------- | 244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 245| 16000050 | Internal error. | 246 247**Example** 248 249```ts 250import { appManager } from '@kit.AbilityKit'; 251 252appManager.getAppMemorySize((err, data) => { 253 if (err) { 254 console.error(`getAppMemorySize fail, err: ${JSON.stringify(err)}`); 255 } else { 256 console.log(`The size of app memory is: ${JSON.stringify(data)}`); 257 } 258}); 259``` 260 261## appManager.getRunningProcessInformation 262 263getRunningProcessInformation(): Promise\<Array\<ProcessInformation>> 264 265Obtains information about the running processes. This API uses a promise to return the result. 266 267> **NOTE** 268> 269> In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications. Since API version 11, no permission is required for calling this API. 270 271**Atomic service API**: This API can be used in atomic services since API version 11. 272 273**System capability**: SystemCapability.Ability.AbilityRuntime.Core 274 275**Return value** 276 277| Type| Description| 278| -------- | -------- | 279| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 280 281**Error codes** 282 283For details about the error codes, see [Ability Error Codes](errorcode-ability.md). 284 285| ID| Error Message| 286| ------- | -------- | 287| 16000050 | Internal error. | 288 289**Example** 290 291```ts 292import { appManager } from '@kit.AbilityKit'; 293import { BusinessError } from '@kit.BasicServicesKit'; 294 295appManager.getRunningProcessInformation().then((data) => { 296 console.log(`The running process information is: ${JSON.stringify(data)}`); 297}).catch((error: BusinessError) => { 298 console.error(`error: ${JSON.stringify(error)}`); 299}); 300``` 301 302## appManager.getRunningProcessInformation 303 304getRunningProcessInformation(callback: AsyncCallback\<Array\<ProcessInformation>>): void 305 306Obtains information about the running processes. This API uses an asynchronous callback to return the result. 307 308> **NOTE** 309> 310> In versions earlier than API version 11, this API requires the **ohos.permission.GET_RUNNING_INFO** permission, which is available only for system applications. Since API version 11, no permission is required for calling this API. 311 312**Atomic service API**: This API can be used in atomic services since API version 11. 313 314**System capability**: SystemCapability.Ability.AbilityRuntime.Core 315 316**Parameters** 317 318 | Name| Type| Mandatory| Description| 319 | -------- | -------- | -------- | -------- | 320 | callback | AsyncCallback\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Yes|Callback used to return the API call result and the process running information. You can perform error handling or custom processing in this callback.| 321 322**Error codes** 323 324For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 325 326| ID| Error Message| 327| ------- | -------- | 328| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 329| 16000050 | Internal error. | 330 331**Example** 332 333```ts 334import { appManager } from '@kit.AbilityKit'; 335 336appManager.getRunningProcessInformation((err, data) => { 337 if (err) { 338 console.error(`getRunningProcessInformation fail, err: ${JSON.stringify(err)}`); 339 } else { 340 console.log(`The running process information is: ${JSON.stringify(data)}`); 341 } 342}); 343``` 344 345## appManager.on('applicationState')<sup>14+</sup> 346 347on(type: 'applicationState', observer: ApplicationStateObserver): number 348 349Registers an observer to listen for the state changes of all applications. 350 351**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 352 353**System capability**: SystemCapability.Ability.AbilityRuntime.Core 354 355**Parameters** 356 357| Name| Type| Mandatory| Description| 358| -------- | -------- | -------- | -------- | 359| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 360| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 361 362**Return value** 363 364| Type| Description| 365| --- | --- | 366| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 367 368**Error codes** 369 370For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 371 372| ID| Error Message| 373| ------- | -------- | 374| 201 | Permission denied. | 375| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 376| 16000050 | Internal error. | 377 378**Example** 379 380```ts 381import { appManager } from '@kit.AbilityKit'; 382import { BusinessError } from '@kit.BasicServicesKit'; 383 384let applicationStateObserver: appManager.ApplicationStateObserver = { 385 onForegroundApplicationChanged(appStateData) { 386 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 387 }, 388 onAbilityStateChanged(abilityStateData) { 389 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 390 }, 391 onProcessCreated(processData) { 392 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 393 }, 394 onProcessDied(processData) { 395 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 396 }, 397 onProcessStateChanged(processData) { 398 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 399 }, 400 onAppStarted(appStateData) { 401 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 402 }, 403 onAppStopped(appStateData) { 404 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 405 } 406}; 407 408try { 409 const observerId = appManager.on('applicationState', applicationStateObserver); 410 console.log(`[appManager] observerCode: ${observerId}`); 411} catch (paramError) { 412 let code = (paramError as BusinessError).code; 413 let message = (paramError as BusinessError).message; 414 console.error(`[appManager] error: ${code}, ${message}`); 415} 416``` 417 418## appManager.on('applicationState')<sup>14+</sup> 419 420on(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number 421 422Registers an observer to listen for the state changes of a specified application. 423 424**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 425 426**System capability**: SystemCapability.Ability.AbilityRuntime.Core 427 428**Parameters** 429 430| Name| Type| Mandatory| Description| 431| -------- | -------- | -------- | -------- | 432| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 433| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 434| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| 435 436**Return value** 437 438| Type| Description| 439| --- | --- | 440| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 441 442**Error codes** 443 444For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 445 446| ID| Error Message| 447| ------- | -------- | 448| 201 | Permission denied. | 449| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 450| 16000050 | Internal error. | 451 452**Example** 453 454```ts 455import { appManager } from '@kit.AbilityKit'; 456import { BusinessError } from '@kit.BasicServicesKit'; 457 458let applicationStateObserver: appManager.ApplicationStateObserver = { 459 onForegroundApplicationChanged(appStateData) { 460 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 461 }, 462 onAbilityStateChanged(abilityStateData) { 463 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 464 }, 465 onProcessCreated(processData) { 466 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 467 }, 468 onProcessDied(processData) { 469 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 470 }, 471 onProcessStateChanged(processData) { 472 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 473 }, 474 onAppStarted(appStateData) { 475 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 476 }, 477 onAppStopped(appStateData) { 478 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 479 } 480}; 481 482let bundleNameList = ['bundleName1', 'bundleName2']; 483 484try { 485 const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 486 console.log(`[appManager] observerCode: ${observerId}`); 487} catch (paramError) { 488 let code = (paramError as BusinessError).code; 489 let message = (paramError as BusinessError).message; 490 console.error(`[appManager] error: ${code}, ${message}`); 491} 492``` 493 494## appManager.off('applicationState')<sup>14+</sup> 495 496off(type: 'applicationState', observerId: number): Promise\<void> 497 498Deregisters the application state observer. 499 500**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 501 502**System capability**: SystemCapability.Ability.AbilityRuntime.Core 503 504**Parameters** 505 506| Name| Type| Mandatory| Description| 507| -------- | -------- | -------- | -------- | 508| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 509| observerId | number | Yes| Digital code of the observer.| 510 511**Return value** 512 513| Type| Description| 514| -------- | -------- | 515| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 516 517**Error codes** 518 519For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 520 521| ID| Error Message| 522| ------- | -------- | 523| 201 | Permission denied. | 524| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 525| 16000050 | Internal error. | 526 527**Example** 528 529```ts 530import { appManager } from '@kit.AbilityKit'; 531import { BusinessError } from '@kit.BasicServicesKit'; 532 533let observerId = 0; 534 535// 1. Register an application state observer. 536let applicationStateObserver: appManager.ApplicationStateObserver = { 537 onForegroundApplicationChanged(appStateData) { 538 console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 539 }, 540 onAbilityStateChanged(abilityStateData) { 541 console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 542 }, 543 onProcessCreated(processData) { 544 console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 545 }, 546 onProcessDied(processData) { 547 console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 548 }, 549 onProcessStateChanged(processData) { 550 console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 551 }, 552 onAppStarted(appStateData) { 553 console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 554 }, 555 onAppStopped(appStateData) { 556 console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 557 } 558}; 559let bundleNameList = ['bundleName1', 'bundleName2']; 560 561try { 562 observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 563} catch (paramError) { 564 let code = (paramError as BusinessError).code; 565 let message = (paramError as BusinessError).message; 566 console.error(`[appManager] error: ${code}, ${message}`); 567} 568 569// 2. Deregister the application state observer. 570try { 571 appManager.off('applicationState', observerId).then((data) => { 572 console.log(`unregisterApplicationStateObserver success, data: ${JSON.stringify(data)}`); 573 }).catch((err: BusinessError) => { 574 console.error(`unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}`); 575 }); 576} catch (paramError) { 577 let code = (paramError as BusinessError).code; 578 let message = (paramError as BusinessError).message; 579 console.error(`[appManager] error: ${code}, ${message}`); 580} 581``` 582 583## appManager.killProcessesByBundleName<sup>14+</sup> 584 585killProcessesByBundleName(bundleName: string, clearPageStack: boolean, appIndex?: number): Promise\<void> 586 587Kills a process by bundle name. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. 588 589**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 590 591**System capability**: SystemCapability.Ability.AbilityRuntime.Core 592 593**Parameters** 594 595| Name| Type| Mandatory| Description| 596| -------- | -------- | -------- | -------- | 597| bundleName | string | Yes| Bundle name.| 598| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| 599| appIndex | number | No| Index of an application clone.| 600 601**Return value** 602 603| Type| Description| 604| -------- | -------- | 605| Promise\<void> | Promise that returns no value.| 606 607**Error codes** 608 609For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 610 611| ID| Error Message| 612| ------- | -------- | 613| 201 | Permission denied. | 614| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 615| 16000050 | Internal error. | 616 617**Example** 618 619```ts 620import { appManager } from '@kit.AbilityKit'; 621import { BusinessError } from '@kit.BasicServicesKit'; 622 623let bundleName = 'bundleName'; 624let isClearPageStack = false; 625let appIndex = 1; 626 627try { 628 appManager.killProcessesByBundleName(bundleName, isClearPageStack, appIndex).then((data) => { 629 console.log('killProcessesByBundleName success.'); 630 }).catch((err: BusinessError) => { 631 console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 632 }); 633} catch (paramError) { 634 let code = (paramError as BusinessError).code; 635 let message = (paramError as BusinessError).message; 636 console.error(`[appManager] error: ${code}, ${message}`); 637} 638``` 639 640## appManager.isAppRunning<sup>14+</sup> 641 642isAppRunning(bundleName: string, appCloneIndex?: number): Promise\<boolean> 643 644Checks whether an application is running. This API uses a promise to return the result. 645 646**Required permissions**: ohos.permission.GET_RUNNING_INFO 647 648**System capability**: SystemCapability.Ability.AbilityRuntime.Core 649 650**Parameters** 651 652| Name| Type| Mandatory| Description| 653| -------- | -------- | -------- | -------- | 654| bundleName | string | Yes| Bundle name.| 655| appCloneIndex | number | No| Index of an application clone.| 656 657**Return value** 658 659| Type | Description | 660| -------------- | ---------------- | 661| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 662 663**Error codes** 664 665 For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 666 667| ID| Error Message| 668| ------- | -------- | 669| 201 | The application does not have permission to call the interface. | 670| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 671| 16000050 | Internal error. | 672| 16000073 | The app clone index is invalid. | 673 674**Example** 675 676```ts 677import { appManager } from '@kit.AbilityKit'; 678import { hilog } from '@kit.PerformanceAnalysisKit'; 679import { BusinessError } from '@kit.BasicServicesKit'; 680 681try { 682 let bundleName = "ohos.samples.etsclock"; 683 appManager.isAppRunning(bundleName).then((data: boolean) => { 684 hilog.info(0x0000, 'testTag', `data: ${JSON.stringify(data)}`); 685 }).catch((err: BusinessError) => { 686 hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 687 }) 688} catch (err) { 689 hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 690} 691``` 692