1e41f4b71Sopenharmony_ci# @ohos.app.ability.appManager (appManager) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **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. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 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. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.app.ability.appManager (appManager)](js-apis-app-ability-appManager.md). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## appManager.PreloadMode<sup>12+</sup> 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciEnumerates the modes used for preloading an application process. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System API**: This is a system API. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name | Value | Description | 28e41f4b71Sopenharmony_ci| ----------- | --- | --------------------------- | 29e41f4b71Sopenharmony_ci| PRESS_DOWN | 0 | The application process is preloaded when the application icon is pressed.| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci## appManager.isSharedBundleRunning<sup>10+</sup> 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciisSharedBundleRunning(bundleName: string, versionCode: number): Promise\<boolean> 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciChecks whether the shared library is in use. This API uses a promise to return the result. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**System API**: This is a system API. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**Parameters** 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 46e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- | 47e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the shared library.| 48e41f4b71Sopenharmony_ci| versionCode | number | Yes | Version number of the shared library. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**Return value** 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci| Type| Description| 53e41f4b71Sopenharmony_ci| -------- | -------- | 54e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Error codes** 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| ID| Error Message| 61e41f4b71Sopenharmony_ci| ------- | -------- | 62e41f4b71Sopenharmony_ci| 201 | Permission denied. | 63e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 64e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 65e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**Example** 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci```ts 70e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 71e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciconst bundleName = "this is a bundleName"; 74e41f4b71Sopenharmony_ciconst versionCode = 1; 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ciappManager.isSharedBundleRunning(bundleName, versionCode).then((data) => { 77e41f4b71Sopenharmony_ci console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 78e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 79e41f4b71Sopenharmony_ci console.error(`error: ${JSON.stringify(error)}`); 80e41f4b71Sopenharmony_ci}); 81e41f4b71Sopenharmony_ci``` 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci## appManager.isSharedBundleRunning<sup>10+</sup> 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciisSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback\<boolean>): void 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciChecks whether the shared library is in use. This API uses an asynchronous callback to return the result. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**System API**: This is a system API. 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**Parameters** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 98e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- | 99e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the shared library.| 100e41f4b71Sopenharmony_ci| versionCode | number | Yes | Version number of the shared library. | 101e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean>> | Yes | Callback used to return the result. The value **true** means that the shared library is in use, and **false** means the opposite.| 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Error codes** 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci| ID| Error Message| 108e41f4b71Sopenharmony_ci| ------- | -------- | 109e41f4b71Sopenharmony_ci| 201 | Permission denied. | 110e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 111e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 112e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**Example** 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci```ts 117e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ciconst bundleName = "this is a bundleName"; 120e41f4b71Sopenharmony_ciconst versionCode = 1; 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ciappManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => { 123e41f4b71Sopenharmony_ci if (err) { 124e41f4b71Sopenharmony_ci console.error(`err: ${JSON.stringify(err)}`); 125e41f4b71Sopenharmony_ci } else { 126e41f4b71Sopenharmony_ci console.log(`The shared bundle running is: ${JSON.stringify(data)}`); 127e41f4b71Sopenharmony_ci } 128e41f4b71Sopenharmony_ci}); 129e41f4b71Sopenharmony_ci``` 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci## appManager.on('applicationState') 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_cion(type: 'applicationState', observer: ApplicationStateObserver): number 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ciRegisters an observer to listen for the state changes of all applications. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**System API**: This is a system API. 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Parameters** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 146e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 147e41f4b71Sopenharmony_ci| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 148e41f4b71Sopenharmony_ci| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver-sys.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**Return value** 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci| Type| Description| 153e41f4b71Sopenharmony_ci| --- | --- | 154e41f4b71Sopenharmony_ci| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci**Error codes** 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci| ID| Error Message| 161e41f4b71Sopenharmony_ci| ------- | -------- | 162e41f4b71Sopenharmony_ci| 201 | Permission denied. | 163e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 164e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 165e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**Example** 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci```ts 170e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 171e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_cilet applicationStateObserver: appManager.ApplicationStateObserver = { 174e41f4b71Sopenharmony_ci onForegroundApplicationChanged(appStateData) { 175e41f4b71Sopenharmony_ci console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 176e41f4b71Sopenharmony_ci }, 177e41f4b71Sopenharmony_ci onAbilityStateChanged(abilityStateData) { 178e41f4b71Sopenharmony_ci console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 179e41f4b71Sopenharmony_ci }, 180e41f4b71Sopenharmony_ci onProcessCreated(processData) { 181e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 182e41f4b71Sopenharmony_ci }, 183e41f4b71Sopenharmony_ci onProcessDied(processData) { 184e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 185e41f4b71Sopenharmony_ci }, 186e41f4b71Sopenharmony_ci onProcessStateChanged(processData) { 187e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 188e41f4b71Sopenharmony_ci }, 189e41f4b71Sopenharmony_ci onAppStarted(appStateData) { 190e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 191e41f4b71Sopenharmony_ci }, 192e41f4b71Sopenharmony_ci onAppStopped(appStateData) { 193e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 194e41f4b71Sopenharmony_ci } 195e41f4b71Sopenharmony_ci}; 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_citry { 198e41f4b71Sopenharmony_ci const observerId = appManager.on('applicationState', applicationStateObserver); 199e41f4b71Sopenharmony_ci console.log(`[appManager] observerCode: ${observerId}`); 200e41f4b71Sopenharmony_ci} catch (paramError) { 201e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 202e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 203e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 204e41f4b71Sopenharmony_ci} 205e41f4b71Sopenharmony_ci``` 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci## appManager.on('applicationState') 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_cion(type: 'applicationState', observer: ApplicationStateObserver, bundleNameList: Array\<string>): number 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ciRegisters an observer to listen for the state changes of a specified application. 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**System API**: This is a system API. 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**Parameters** 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 222e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 223e41f4b71Sopenharmony_ci| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 224e41f4b71Sopenharmony_ci| observer | [ApplicationStateObserver](js-apis-inner-application-applicationStateObserver-sys.md) | Yes| Application state observer, which is used to observe the lifecycle change of an application.| 225e41f4b71Sopenharmony_ci| bundleNameList | `Array<string>` | Yes| **bundleName** array of the application. A maximum of 128 bundle names can be passed.| 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Return value** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| Type| Description| 230e41f4b71Sopenharmony_ci| --- | --- | 231e41f4b71Sopenharmony_ci| number | Digital code of the observer, which will be used in **off()** to deregister the observer.| 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**Error codes** 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci| ID| Error Message| 238e41f4b71Sopenharmony_ci| ------- | -------- | 239e41f4b71Sopenharmony_ci| 201 | Permission denied. | 240e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 241e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 242e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**Example** 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci```ts 247e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 248e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_cilet applicationStateObserver: appManager.ApplicationStateObserver = { 251e41f4b71Sopenharmony_ci onForegroundApplicationChanged(appStateData) { 252e41f4b71Sopenharmony_ci console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 253e41f4b71Sopenharmony_ci }, 254e41f4b71Sopenharmony_ci onAbilityStateChanged(abilityStateData) { 255e41f4b71Sopenharmony_ci console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 256e41f4b71Sopenharmony_ci }, 257e41f4b71Sopenharmony_ci onProcessCreated(processData) { 258e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 259e41f4b71Sopenharmony_ci }, 260e41f4b71Sopenharmony_ci onProcessDied(processData) { 261e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 262e41f4b71Sopenharmony_ci }, 263e41f4b71Sopenharmony_ci onProcessStateChanged(processData) { 264e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 265e41f4b71Sopenharmony_ci }, 266e41f4b71Sopenharmony_ci onAppStarted(appStateData) { 267e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 268e41f4b71Sopenharmony_ci }, 269e41f4b71Sopenharmony_ci onAppStopped(appStateData) { 270e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 271e41f4b71Sopenharmony_ci } 272e41f4b71Sopenharmony_ci}; 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_cilet bundleNameList = ['bundleName1', 'bundleName2']; 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_citry { 277e41f4b71Sopenharmony_ci const observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 278e41f4b71Sopenharmony_ci console.log(`[appManager] observerCode: ${observerId}`); 279e41f4b71Sopenharmony_ci} catch (paramError) { 280e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 281e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 282e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 283e41f4b71Sopenharmony_ci} 284e41f4b71Sopenharmony_ci``` 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci## appManager.on('appForegroundState')<sup>11+</sup> 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_cion(type: 'appForegroundState', observer: AppForegroundStateObserver): void 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ciRegisters an observer to listen for application start or exit events. The observer can be used by a system application to observe the start or event events of all applications. 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**System API**: This is a system API. 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**Parameters** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 301e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 302e41f4b71Sopenharmony_ci| type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| 303e41f4b71Sopenharmony_ci| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | Yes| Observer used to listen for application start or exit events.| 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**Error codes** 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci| ID| Error Message| 310e41f4b71Sopenharmony_ci| ------- | -------- | 311e41f4b71Sopenharmony_ci| 201 | Permission denied. | 312e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 313e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 314e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**Example** 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci```ts 319e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 320e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cilet observer: appManager.AppForegroundStateObserver = { 323e41f4b71Sopenharmony_ci onAppStateChanged(appStateData) { 324e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); 325e41f4b71Sopenharmony_ci }, 326e41f4b71Sopenharmony_ci}; 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_citry { 329e41f4b71Sopenharmony_ci appManager.on('appForegroundState', observer); 330e41f4b71Sopenharmony_ci} catch (paramError) { 331e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 332e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 333e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 334e41f4b71Sopenharmony_ci} 335e41f4b71Sopenharmony_ci``` 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci## appManager.on('abilityFirstFrameState')<sup>12+</sup> 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_cion(type: 'abilityFirstFrameState', observer: AbilityFirstFrameStateObserver, bundleName?: string): void 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ciRegisters an observer to listen for the complete of the first frame rendering of a given ability. 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci**System API**: This is a system API. 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**Parameters** 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 352e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 353e41f4b71Sopenharmony_ci| type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | 354e41f4b71Sopenharmony_ci| observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | Yes | Observer used to listen for the complete of the first frame rendering of the ability. | 355e41f4b71Sopenharmony_ci| bundleName | string | No | Bundle name of the ability to be listened for. If this parameter is left blank, the event is listened for all applications.| 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**Error codes** 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci| ID| Error Message| 362e41f4b71Sopenharmony_ci| ------- | -------- | 363e41f4b71Sopenharmony_ci| 201 | Permission denied. | 364e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 365e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 366e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**Example** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci```ts 371e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 372e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_cilet abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { 375e41f4b71Sopenharmony_ci onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { 376e41f4b71Sopenharmony_ci console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); 377e41f4b71Sopenharmony_ci } 378e41f4b71Sopenharmony_ci}; 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_citry { 381e41f4b71Sopenharmony_ci appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 382e41f4b71Sopenharmony_ci} catch (e) { 383e41f4b71Sopenharmony_ci let code = (e as BusinessError).code; 384e41f4b71Sopenharmony_ci let message = (e as BusinessError).message; 385e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 386e41f4b71Sopenharmony_ci} 387e41f4b71Sopenharmony_ci``` 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci## appManager.off('applicationState') 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_cioff(type: 'applicationState', observerId: number, callback: AsyncCallback\<void>): void 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ciDeregisters the application state observer. This API uses an asynchronous callback to return the result. 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**System API**: This is a system API. 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**Parameters** 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 404e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 405e41f4b71Sopenharmony_ci| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 406e41f4b71Sopenharmony_ci| observerId | number | Yes| Digital code of the observer.| 407e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**Error codes** 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci| ID| Error Message| 414e41f4b71Sopenharmony_ci| ------- | -------- | 415e41f4b71Sopenharmony_ci| 201 | Permission denied. | 416e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 417e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 418e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**Example** 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci```ts 423e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 424e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_cilet observerId = 0; 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_cilet applicationStateObserver: appManager.ApplicationStateObserver = { 429e41f4b71Sopenharmony_ci onForegroundApplicationChanged(appStateData) { 430e41f4b71Sopenharmony_ci console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 431e41f4b71Sopenharmony_ci }, 432e41f4b71Sopenharmony_ci onAbilityStateChanged(abilityStateData) { 433e41f4b71Sopenharmony_ci console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 434e41f4b71Sopenharmony_ci }, 435e41f4b71Sopenharmony_ci onProcessCreated(processData) { 436e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 437e41f4b71Sopenharmony_ci }, 438e41f4b71Sopenharmony_ci onProcessDied(processData) { 439e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 440e41f4b71Sopenharmony_ci }, 441e41f4b71Sopenharmony_ci onProcessStateChanged(processData) { 442e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 443e41f4b71Sopenharmony_ci }, 444e41f4b71Sopenharmony_ci onAppStarted(appStateData) { 445e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 446e41f4b71Sopenharmony_ci }, 447e41f4b71Sopenharmony_ci onAppStopped(appStateData) { 448e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 449e41f4b71Sopenharmony_ci } 450e41f4b71Sopenharmony_ci}; 451e41f4b71Sopenharmony_cilet bundleNameList = ['bundleName1', 'bundleName2']; 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_citry { 454e41f4b71Sopenharmony_ci observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 455e41f4b71Sopenharmony_ci console.log(`[appManager] observerCode: ${observerId}`); 456e41f4b71Sopenharmony_ci} catch (paramError) { 457e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 458e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 459e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message} `); 460e41f4b71Sopenharmony_ci} 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci// 2. Deregister the application state observer. 463e41f4b71Sopenharmony_cifunction unregisterApplicationStateObserverCallback(err: BusinessError) { 464e41f4b71Sopenharmony_ci if (err) { 465e41f4b71Sopenharmony_ci console.error(`unregisterApplicationStateObserverCallback fail, err: ${JSON.stringify(err)}`); 466e41f4b71Sopenharmony_ci } else { 467e41f4b71Sopenharmony_ci console.log('unregisterApplicationStateObserverCallback success.'); 468e41f4b71Sopenharmony_ci } 469e41f4b71Sopenharmony_ci} 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_citry { 472e41f4b71Sopenharmony_ci appManager.off('applicationState', observerId, unregisterApplicationStateObserverCallback); 473e41f4b71Sopenharmony_ci} catch (paramError) { 474e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 475e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 476e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 477e41f4b71Sopenharmony_ci} 478e41f4b71Sopenharmony_ci``` 479e41f4b71Sopenharmony_ci 480e41f4b71Sopenharmony_ci## appManager.off('applicationState') 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_cioff(type: 'applicationState', observerId: number): Promise\<void> 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ciDeregisters the application state observer. This API uses an asynchronous callback to return the result. 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**System API**: This is a system API. 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci**Parameters** 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 495e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 496e41f4b71Sopenharmony_ci| type | string | Yes| Type of the API to call. It is fixed at **'applicationState'**.| 497e41f4b71Sopenharmony_ci| observerId | number | Yes| Digital code of the observer.| 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**Return value** 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci| Type| Description| 502e41f4b71Sopenharmony_ci| -------- | -------- | 503e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**Error codes** 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci| ID| Error Message| 510e41f4b71Sopenharmony_ci| ------- | -------- | 511e41f4b71Sopenharmony_ci| 201 | Permission denied. | 512e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 513e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 514e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci**Example** 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci```ts 519e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 520e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_cilet observerId = 0; 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci// 1. Register an application state observer. 525e41f4b71Sopenharmony_cilet applicationStateObserver: appManager.ApplicationStateObserver = { 526e41f4b71Sopenharmony_ci onForegroundApplicationChanged(appStateData) { 527e41f4b71Sopenharmony_ci console.log(`[appManager] onForegroundApplicationChanged: ${JSON.stringify(appStateData)}`); 528e41f4b71Sopenharmony_ci }, 529e41f4b71Sopenharmony_ci onAbilityStateChanged(abilityStateData) { 530e41f4b71Sopenharmony_ci console.log(`[appManager] onAbilityStateChanged: ${JSON.stringify(abilityStateData)}`); 531e41f4b71Sopenharmony_ci }, 532e41f4b71Sopenharmony_ci onProcessCreated(processData) { 533e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessCreated: ${JSON.stringify(processData)}`); 534e41f4b71Sopenharmony_ci }, 535e41f4b71Sopenharmony_ci onProcessDied(processData) { 536e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessDied: ${JSON.stringify(processData)}`); 537e41f4b71Sopenharmony_ci }, 538e41f4b71Sopenharmony_ci onProcessStateChanged(processData) { 539e41f4b71Sopenharmony_ci console.log(`[appManager] onProcessStateChanged: ${JSON.stringify(processData)}`); 540e41f4b71Sopenharmony_ci }, 541e41f4b71Sopenharmony_ci onAppStarted(appStateData) { 542e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStarted: ${JSON.stringify(appStateData)}`); 543e41f4b71Sopenharmony_ci }, 544e41f4b71Sopenharmony_ci onAppStopped(appStateData) { 545e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStopped: ${JSON.stringify(appStateData)}`); 546e41f4b71Sopenharmony_ci } 547e41f4b71Sopenharmony_ci}; 548e41f4b71Sopenharmony_cilet bundleNameList = ['bundleName1', 'bundleName2']; 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_citry { 551e41f4b71Sopenharmony_ci observerId = appManager.on('applicationState', applicationStateObserver, bundleNameList); 552e41f4b71Sopenharmony_ci} catch (paramError) { 553e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 554e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 555e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 556e41f4b71Sopenharmony_ci} 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci// 2. Deregister the application state observer. 559e41f4b71Sopenharmony_citry { 560e41f4b71Sopenharmony_ci appManager.off('applicationState', observerId).then((data) => { 561e41f4b71Sopenharmony_ci console.log(`unregisterApplicationStateObserver success, data: ${JSON.stringify(data)}`); 562e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 563e41f4b71Sopenharmony_ci console.error(`unregisterApplicationStateObserver fail, err: ${JSON.stringify(err)}`); 564e41f4b71Sopenharmony_ci }); 565e41f4b71Sopenharmony_ci} catch (paramError) { 566e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 567e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 568e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 569e41f4b71Sopenharmony_ci} 570e41f4b71Sopenharmony_ci``` 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci## appManager.off('appForegroundState')<sup>11+</sup> 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_cioff(type: 'appForegroundState', observer?: AppForegroundStateObserver): void 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ciDeregisters the observer used to listen for application start or exit events. 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci**System API**: This is a system API. 579e41f4b71Sopenharmony_ci 580e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci**Parameters** 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 587e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 588e41f4b71Sopenharmony_ci| type | string | Yes| Event type. It is fixed at **'appForegroundState'**.| 589e41f4b71Sopenharmony_ci| observer | [AppForegroundStateObserver](js-apis-inner-application-appForegroundStateObserver-sys.md) | No| Observer used to listen for application start or exit events.| 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci**Error codes** 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci| ID| Error Message| 596e41f4b71Sopenharmony_ci| ------- | -------- | 597e41f4b71Sopenharmony_ci| 201 | Permission denied. | 598e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 599e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 600e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci**Example** 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci```ts 605e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 606e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_cilet observer_: appManager.AppForegroundStateObserver | undefined; 609e41f4b71Sopenharmony_ci// 1. Register an observer to listen for application start or exit events. 610e41f4b71Sopenharmony_cilet observer: appManager.AppForegroundStateObserver = { 611e41f4b71Sopenharmony_ci onAppStateChanged(appStateData: appManager.AppStateData) { 612e41f4b71Sopenharmony_ci console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`); 613e41f4b71Sopenharmony_ci }, 614e41f4b71Sopenharmony_ci}; 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_citry { 617e41f4b71Sopenharmony_ci appManager.on('appForegroundState', observer); 618e41f4b71Sopenharmony_ci // Save the observer object. 619e41f4b71Sopenharmony_ci observer_ = observer; 620e41f4b71Sopenharmony_ci} catch (paramError) { 621e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 622e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 623e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 624e41f4b71Sopenharmony_ci} 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci// 2. Deregister the observer. 627e41f4b71Sopenharmony_citry { 628e41f4b71Sopenharmony_ci appManager.off('appForegroundState', observer_); 629e41f4b71Sopenharmony_ci} catch (paramError) { 630e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 631e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 632e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 633e41f4b71Sopenharmony_ci} 634e41f4b71Sopenharmony_ci``` 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci## appManager.off('abilityFirstFrameState')<sup>12+</sup> 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_cioff(type: 'abilityFirstFrameState', observer?: AbilityFirstFrameStateObserver): void 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ciDeregisters the observer used to listen for the complete of the first frame rendering of a given ability. 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci**System API**: This is a system API. 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**Parameters** 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 651e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 652e41f4b71Sopenharmony_ci| type | string | Yes | Event type. It is fixed at **'abilityFirstFrameState'**. | 653e41f4b71Sopenharmony_ci| observer | [AbilityFirstFrameStateObserver](js-apis-inner-application-abilityFirstFrameStateObserver-sys.md) | No | Callback used for deregistration. If this parameter is left blank, all subscriptions to the specified event are canceled.| 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**Error codes** 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci| ID| Error Message| 660e41f4b71Sopenharmony_ci| ------- | -------- | 661e41f4b71Sopenharmony_ci| 201 | Permission denied. | 662e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 663e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 664e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 665e41f4b71Sopenharmony_ci 666e41f4b71Sopenharmony_ci**Example** 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci```ts 669e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 670e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_cilet abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = { 673e41f4b71Sopenharmony_ci onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) { 674e41f4b71Sopenharmony_ci console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData)); 675e41f4b71Sopenharmony_ci } 676e41f4b71Sopenharmony_ci}; 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_citry { 679e41f4b71Sopenharmony_ci appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 680e41f4b71Sopenharmony_ci} catch (e) { 681e41f4b71Sopenharmony_ci let code = (e as BusinessError).code; 682e41f4b71Sopenharmony_ci let message = (e as BusinessError).message; 683e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 684e41f4b71Sopenharmony_ci} 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_citry { 687e41f4b71Sopenharmony_ci appManager.off('abilityFirstFrameState', abilityFirstFrameStateObserverForAll); 688e41f4b71Sopenharmony_ci} catch (e) { 689e41f4b71Sopenharmony_ci let code = (e as BusinessError).code; 690e41f4b71Sopenharmony_ci let message = (e as BusinessError).message; 691e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 692e41f4b71Sopenharmony_ci} 693e41f4b71Sopenharmony_ci``` 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci## appManager.getForegroundApplications 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_cigetForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ciObtains applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData-sys.md). 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ci**System API**: This is a system API. 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci**Parameters** 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 710e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 711e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.md)>> | Yes| Callback used to return the API call result and an array holding the application state data. You can perform error handling or custom processing in this callback.| 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**Error codes** 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci| ID| Error Message| 718e41f4b71Sopenharmony_ci| ------- | -------- | 719e41f4b71Sopenharmony_ci| 201 | Permission denied. | 720e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 721e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 722e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci**Example** 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci```ts 727e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 728e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_cifunction getForegroundApplicationsCallback(err: BusinessError, data: Array<appManager.AppStateData>) { 731e41f4b71Sopenharmony_ci if (err) { 732e41f4b71Sopenharmony_ci console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`); 733e41f4b71Sopenharmony_ci } else { 734e41f4b71Sopenharmony_ci console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`); 735e41f4b71Sopenharmony_ci } 736e41f4b71Sopenharmony_ci} 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_citry { 739e41f4b71Sopenharmony_ci appManager.getForegroundApplications(getForegroundApplicationsCallback); 740e41f4b71Sopenharmony_ci} catch (paramError) { 741e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 742e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 743e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 744e41f4b71Sopenharmony_ci} 745e41f4b71Sopenharmony_ci``` 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci## appManager.getForegroundApplications 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_cigetForegroundApplications(): Promise\<Array\<AppStateData>> 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ciObtains applications that are running in the foreground. This API uses a promise to return the result. The application information is defined by [AppStateData](js-apis-inner-application-appStateData-sys.md). 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**System API**: This is a system API. 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci**Return value** 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci| Type| Description| 762e41f4b71Sopenharmony_ci| -------- | -------- | 763e41f4b71Sopenharmony_ci| Promise\<Array\<[AppStateData](js-apis-inner-application-appStateData-sys.md)>> | Promise used to return an array holding the application state data.| 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci**Error codes** 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci| ID| Error Message| 770e41f4b71Sopenharmony_ci| ------- | -------- | 771e41f4b71Sopenharmony_ci| 201 | Permission denied. | 772e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 773e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci**Example** 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci```ts 778e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 779e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ciappManager.getForegroundApplications().then((data) => { 782e41f4b71Sopenharmony_ci console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`); 783e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 784e41f4b71Sopenharmony_ci console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`); 785e41f4b71Sopenharmony_ci}); 786e41f4b71Sopenharmony_ci``` 787e41f4b71Sopenharmony_ci 788e41f4b71Sopenharmony_ci## appManager.killProcessWithAccount 789e41f4b71Sopenharmony_ci 790e41f4b71Sopenharmony_cikillProcessWithAccount(bundleName: string, accountId: number): Promise\<void\> 791e41f4b71Sopenharmony_ci 792e41f4b71Sopenharmony_ciKills a process by bundle name and account ID. This API uses a promise to return the result. 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_ci> **NOTE** 795e41f4b71Sopenharmony_ci> 796e41f4b71Sopenharmony_ci> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci**System API**: This is a system API. 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_ci**Parameters** 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 807e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 808e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 809e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci**Return value** 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci| Type | Description | 814e41f4b71Sopenharmony_ci| -------------- | --------------- | 815e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci**Error codes** 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci| ID| Error Message| 822e41f4b71Sopenharmony_ci| ------- | -------- | 823e41f4b71Sopenharmony_ci| 201 | Permission denied. | 824e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 825e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 826e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci**Example** 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci```ts 831e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 832e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 833e41f4b71Sopenharmony_ci 834e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 835e41f4b71Sopenharmony_cilet accountId = 0; 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_citry { 838e41f4b71Sopenharmony_ci appManager.killProcessWithAccount(bundleName, accountId).then(() => { 839e41f4b71Sopenharmony_ci console.log('killProcessWithAccount success'); 840e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 841e41f4b71Sopenharmony_ci console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); 842e41f4b71Sopenharmony_ci }); 843e41f4b71Sopenharmony_ci} catch (paramError) { 844e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 845e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 846e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 847e41f4b71Sopenharmony_ci} 848e41f4b71Sopenharmony_ci``` 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci## appManager.killProcessWithAccount<sup>13+</sup> 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_cikillProcessWithAccount(bundleName: string, accountId: number, clearPageStack: boolean, appIndex?: number): Promise\<void\> 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ciKills a process by bundle name and account ID. This API uses a promise to return the result. 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_ci> **NOTE** 857e41f4b71Sopenharmony_ci> 858e41f4b71Sopenharmony_ci> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci**System API**: This is a system API. 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci**Parameters** 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 869e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 870e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 871e41f4b71Sopenharmony_ci| accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 872e41f4b71Sopenharmony_ci| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| 873e41f4b71Sopenharmony_ci| appIndex | number | No| Index of an application clone.| 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**Return value** 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci| Type | Description | 878e41f4b71Sopenharmony_ci| -------------- | --------------- | 879e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci**Error codes** 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci| ID| Error Message| 886e41f4b71Sopenharmony_ci| ------- | -------- | 887e41f4b71Sopenharmony_ci| 201 | Permission denied. | 888e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 889e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 890e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci**Example** 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci```ts 895e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 896e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 899e41f4b71Sopenharmony_cilet accountId = 0; 900e41f4b71Sopenharmony_cilet isClearPageStack = false; 901e41f4b71Sopenharmony_cilet appIndex = 1; 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_citry { 904e41f4b71Sopenharmony_ci appManager.killProcessWithAccount(bundleName, accountId, isClearPageStack, appIndex).then(() => { 905e41f4b71Sopenharmony_ci console.log('killProcessWithAccount success'); 906e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 907e41f4b71Sopenharmony_ci console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`); 908e41f4b71Sopenharmony_ci }); 909e41f4b71Sopenharmony_ci} catch (paramError) { 910e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 911e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 912e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 913e41f4b71Sopenharmony_ci} 914e41f4b71Sopenharmony_ci``` 915e41f4b71Sopenharmony_ci 916e41f4b71Sopenharmony_ci## appManager.killProcessWithAccount 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_cikillProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback\<void\>): void 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ciKills a process by bundle name and account ID. This API uses an asynchronous callback to return the result. 921e41f4b71Sopenharmony_ci 922e41f4b71Sopenharmony_ci> **NOTE** 923e41f4b71Sopenharmony_ci> 924e41f4b71Sopenharmony_ci> The **ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS** permission is not required when **accountId** specifies the current user. 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci**System API**: This is a system API. 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci**Parameters** 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci | Name| Type| Mandatory| Description| 935e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 936e41f4b71Sopenharmony_ci | bundleName | string | Yes| Bundle name.| 937e41f4b71Sopenharmony_ci | accountId | number | Yes| ID of a system account. For details, see [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9).| 938e41f4b71Sopenharmony_ci | callback | AsyncCallback\<void\> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**Error codes** 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| ID| Error Message| 945e41f4b71Sopenharmony_ci| ------- | -------- | 946e41f4b71Sopenharmony_ci| 201 | Permission denied. | 947e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 948e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 949e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**Example** 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci```ts 954e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 955e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 956e41f4b71Sopenharmony_ci 957e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 958e41f4b71Sopenharmony_cilet accountId = 0; 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_cifunction killProcessWithAccountCallback(err: BusinessError) { 961e41f4b71Sopenharmony_ci if (err) { 962e41f4b71Sopenharmony_ci console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`); 963e41f4b71Sopenharmony_ci } else { 964e41f4b71Sopenharmony_ci console.log('killProcessWithAccountCallback success.'); 965e41f4b71Sopenharmony_ci } 966e41f4b71Sopenharmony_ci} 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_ciappManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback); 969e41f4b71Sopenharmony_ci``` 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci## appManager.killProcessesByBundleName 972e41f4b71Sopenharmony_ci 973e41f4b71Sopenharmony_cikillProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>) 974e41f4b71Sopenharmony_ci 975e41f4b71Sopenharmony_ciKills a process by bundle name. This API uses an asynchronous callback to return the result. 976e41f4b71Sopenharmony_ci 977e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES 978e41f4b71Sopenharmony_ci 979e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_ci**System API**: This is a system API. 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_ci**Parameters** 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 986e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 987e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 988e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci**Error codes** 991e41f4b71Sopenharmony_ci 992e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ci| ID| Error Message| 995e41f4b71Sopenharmony_ci| ------- | -------- | 996e41f4b71Sopenharmony_ci| 201 | Permission denied. | 997e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 998e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 999e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ci**Example** 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ci```ts 1004e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1005e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_cifunction killProcessesByBundleNameCallback(err: BusinessError) { 1010e41f4b71Sopenharmony_ci if (err) { 1011e41f4b71Sopenharmony_ci console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1012e41f4b71Sopenharmony_ci } else { 1013e41f4b71Sopenharmony_ci console.log('killProcessesByBundleNameCallback success.'); 1014e41f4b71Sopenharmony_ci } 1015e41f4b71Sopenharmony_ci} 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_citry { 1018e41f4b71Sopenharmony_ci appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback); 1019e41f4b71Sopenharmony_ci} catch (paramError) { 1020e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1021e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1022e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1023e41f4b71Sopenharmony_ci} 1024e41f4b71Sopenharmony_ci``` 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ci## appManager.killProcessesByBundleName 1027e41f4b71Sopenharmony_ci 1028e41f4b71Sopenharmony_cikillProcessesByBundleName(bundleName: string): Promise\<void> 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ciKills a process by bundle name. This API uses a promise to return the result. 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1035e41f4b71Sopenharmony_ci 1036e41f4b71Sopenharmony_ci**System API**: This is a system API. 1037e41f4b71Sopenharmony_ci 1038e41f4b71Sopenharmony_ci**Parameters** 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1041e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1042e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ci**Return value** 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci| Type| Description| 1047e41f4b71Sopenharmony_ci| -------- | -------- | 1048e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_ci**Error codes** 1051e41f4b71Sopenharmony_ci 1052e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1053e41f4b71Sopenharmony_ci 1054e41f4b71Sopenharmony_ci| ID| Error Message| 1055e41f4b71Sopenharmony_ci| ------- | -------- | 1056e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1057e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1058e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1059e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci**Example** 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci```ts 1064e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1065e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_citry { 1070e41f4b71Sopenharmony_ci appManager.killProcessesByBundleName(bundleName).then((data) => { 1071e41f4b71Sopenharmony_ci console.log('killProcessesByBundleName success.'); 1072e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1073e41f4b71Sopenharmony_ci console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 1074e41f4b71Sopenharmony_ci }); 1075e41f4b71Sopenharmony_ci} catch (paramError) { 1076e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1077e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1078e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1079e41f4b71Sopenharmony_ci} 1080e41f4b71Sopenharmony_ci``` 1081e41f4b71Sopenharmony_ci 1082e41f4b71Sopenharmony_ci## appManager.killProcessesByBundleName<sup>13+</sup> 1083e41f4b71Sopenharmony_ci 1084e41f4b71Sopenharmony_cikillProcessesByBundleName(bundleName: string, clearPageStack: boolean, appIndex?: number): Promise\<void> 1085e41f4b71Sopenharmony_ci 1086e41f4b71Sopenharmony_ciKills a process by bundle name. This API uses a promise to return the result. 1087e41f4b71Sopenharmony_ci 1088e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_BACKGROUND_PROCESSES 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci**System API**: This is a system API. 1093e41f4b71Sopenharmony_ci 1094e41f4b71Sopenharmony_ci**Parameters** 1095e41f4b71Sopenharmony_ci 1096e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1097e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1098e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1099e41f4b71Sopenharmony_ci| clearPageStack | boolean | Yes| Whether to clear the page stack. The value **true** means to clear the page stack, and **false** means the opposite.| 1100e41f4b71Sopenharmony_ci| appIndex | number | No| Index of an application clone.| 1101e41f4b71Sopenharmony_ci 1102e41f4b71Sopenharmony_ci**Return value** 1103e41f4b71Sopenharmony_ci 1104e41f4b71Sopenharmony_ci| Type| Description| 1105e41f4b71Sopenharmony_ci| -------- | -------- | 1106e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 1107e41f4b71Sopenharmony_ci 1108e41f4b71Sopenharmony_ci**Error codes** 1109e41f4b71Sopenharmony_ci 1110e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1111e41f4b71Sopenharmony_ci 1112e41f4b71Sopenharmony_ci| ID| Error Message| 1113e41f4b71Sopenharmony_ci| ------- | -------- | 1114e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1115e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1116e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1117e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci**Example** 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ci```ts 1122e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1123e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 1126e41f4b71Sopenharmony_cilet isClearPageStack = false; 1127e41f4b71Sopenharmony_cilet appIndex = 1; 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_citry { 1130e41f4b71Sopenharmony_ci appManager.killProcessesByBundleName(bundleName, isClearPageStack, appIndex).then((data) => { 1131e41f4b71Sopenharmony_ci console.log('killProcessesByBundleName success.'); 1132e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1133e41f4b71Sopenharmony_ci console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`); 1134e41f4b71Sopenharmony_ci }); 1135e41f4b71Sopenharmony_ci} catch (paramError) { 1136e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1137e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1138e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1139e41f4b71Sopenharmony_ci} 1140e41f4b71Sopenharmony_ci``` 1141e41f4b71Sopenharmony_ci 1142e41f4b71Sopenharmony_ci## appManager.clearUpApplicationData 1143e41f4b71Sopenharmony_ci 1144e41f4b71Sopenharmony_ciclearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>) 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ciClears application data by bundle name. This API uses an asynchronous callback to return the result. 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1151e41f4b71Sopenharmony_ci 1152e41f4b71Sopenharmony_ci**System API**: This is a system API. 1153e41f4b71Sopenharmony_ci 1154e41f4b71Sopenharmony_ci**Parameters** 1155e41f4b71Sopenharmony_ci 1156e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1157e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1158e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1159e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes| Callback used to return the API call result. You can perform error handling or custom processing in this callback.| 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci**Error codes** 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci| ID| Error Message| 1166e41f4b71Sopenharmony_ci| ------- | -------- | 1167e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1168e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1169e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1170e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci**Example** 1173e41f4b71Sopenharmony_ci 1174e41f4b71Sopenharmony_ci```ts 1175e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1176e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_cifunction clearUpApplicationDataCallback(err: BusinessError) { 1181e41f4b71Sopenharmony_ci if (err) { 1182e41f4b71Sopenharmony_ci console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`); 1183e41f4b71Sopenharmony_ci } else { 1184e41f4b71Sopenharmony_ci console.log('clearUpApplicationDataCallback success.'); 1185e41f4b71Sopenharmony_ci } 1186e41f4b71Sopenharmony_ci} 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_citry { 1189e41f4b71Sopenharmony_ci appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback); 1190e41f4b71Sopenharmony_ci} catch (paramError) { 1191e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1192e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1193e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1194e41f4b71Sopenharmony_ci} 1195e41f4b71Sopenharmony_ci``` 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci## appManager.clearUpApplicationData 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ciclearUpApplicationData(bundleName: string): Promise\<void> 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ciClears application data by bundle name. This API uses a promise to return the result. 1202e41f4b71Sopenharmony_ci 1203e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CLEAN_APPLICATION_DATA 1204e41f4b71Sopenharmony_ci 1205e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci**System API**: This is a system API. 1208e41f4b71Sopenharmony_ci 1209e41f4b71Sopenharmony_ci**Parameters** 1210e41f4b71Sopenharmony_ci 1211e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1212e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1213e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_ci**Return value** 1216e41f4b71Sopenharmony_ci 1217e41f4b71Sopenharmony_ci| Type| Description| 1218e41f4b71Sopenharmony_ci| -------- | -------- | 1219e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback.| 1220e41f4b71Sopenharmony_ci 1221e41f4b71Sopenharmony_ci**Error codes** 1222e41f4b71Sopenharmony_ci 1223e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_ci| ID| Error Message| 1226e41f4b71Sopenharmony_ci| ------- | -------- | 1227e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1228e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1229e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1230e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1231e41f4b71Sopenharmony_ci 1232e41f4b71Sopenharmony_ci**Example** 1233e41f4b71Sopenharmony_ci 1234e41f4b71Sopenharmony_ci```ts 1235e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1236e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1237e41f4b71Sopenharmony_ci 1238e41f4b71Sopenharmony_cilet bundleName = 'bundleName'; 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_citry { 1241e41f4b71Sopenharmony_ci appManager.clearUpApplicationData(bundleName).then((data) => { 1242e41f4b71Sopenharmony_ci console.log('clearUpApplicationData success.'); 1243e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1244e41f4b71Sopenharmony_ci console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`); 1245e41f4b71Sopenharmony_ci }); 1246e41f4b71Sopenharmony_ci} catch (paramError) { 1247e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1248e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1249e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1250e41f4b71Sopenharmony_ci} 1251e41f4b71Sopenharmony_ci``` 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ci## appManager.getProcessMemoryByPid<sup>10+</sup> 1254e41f4b71Sopenharmony_ci 1255e41f4b71Sopenharmony_cigetProcessMemoryByPid(pid: number, callback: AsyncCallback\<number>): void 1256e41f4b71Sopenharmony_ci 1257e41f4b71Sopenharmony_ciObtains the memory size of a process. This API uses an asynchronous callback to return the result. 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci**System API**: This is a system API. 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ci**Parameters** 1264e41f4b71Sopenharmony_ci 1265e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1266e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1267e41f4b71Sopenharmony_ci| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10).| 1268e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes| Callback used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.| 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci**Error codes** 1271e41f4b71Sopenharmony_ci 1272e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1273e41f4b71Sopenharmony_ci 1274e41f4b71Sopenharmony_ci| ID| Error Message| 1275e41f4b71Sopenharmony_ci| ------- | -------- | 1276e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1277e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1278e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1279e41f4b71Sopenharmony_ci 1280e41f4b71Sopenharmony_ci**Example** 1281e41f4b71Sopenharmony_ci 1282e41f4b71Sopenharmony_ci```ts 1283e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1284e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1285e41f4b71Sopenharmony_ci 1286e41f4b71Sopenharmony_cilet pid = 0; 1287e41f4b71Sopenharmony_cifunction getProcessMemoryByPidCallback(err: BusinessError, data: number) { 1288e41f4b71Sopenharmony_ci if (err) { 1289e41f4b71Sopenharmony_ci console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`); 1290e41f4b71Sopenharmony_ci } else { 1291e41f4b71Sopenharmony_ci console.log('getProcessMemoryByPidCallback success.'); 1292e41f4b71Sopenharmony_ci } 1293e41f4b71Sopenharmony_ci} 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_citry { 1296e41f4b71Sopenharmony_ci appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback); 1297e41f4b71Sopenharmony_ci} catch (paramError) { 1298e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1299e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1300e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1301e41f4b71Sopenharmony_ci} 1302e41f4b71Sopenharmony_ci``` 1303e41f4b71Sopenharmony_ci 1304e41f4b71Sopenharmony_ci## appManager.getProcessMemoryByPid<sup>10+</sup> 1305e41f4b71Sopenharmony_ci 1306e41f4b71Sopenharmony_cigetProcessMemoryByPid(pid: number): Promise\<number> 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_ciObtains the memory size of a process. This API uses a promise to return the result. 1309e41f4b71Sopenharmony_ci 1310e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1311e41f4b71Sopenharmony_ci 1312e41f4b71Sopenharmony_ci**System API**: This is a system API. 1313e41f4b71Sopenharmony_ci 1314e41f4b71Sopenharmony_ci**Parameters** 1315e41f4b71Sopenharmony_ci 1316e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1317e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1318e41f4b71Sopenharmony_ci| pid | number | Yes| Process ID. For details, see [getRunningProcessInfoByBundleName](#appmanagergetrunningprocessinfobybundlename10). | 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_ci**Return value** 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci| Type| Description| 1323e41f4b71Sopenharmony_ci| -------- | -------- | 1324e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the API call result and the memory size (in KB). You can perform error handling or custom processing in this callback.| 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ci**Error codes** 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci| ID| Error Message| 1331e41f4b71Sopenharmony_ci| ------- | -------- | 1332e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1333e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1334e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci**Example** 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci```ts 1339e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1340e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1341e41f4b71Sopenharmony_ci 1342e41f4b71Sopenharmony_cilet pid = 0; 1343e41f4b71Sopenharmony_ci 1344e41f4b71Sopenharmony_citry { 1345e41f4b71Sopenharmony_ci appManager.getProcessMemoryByPid(pid).then((data) => { 1346e41f4b71Sopenharmony_ci console.log('getProcessMemoryByPid success.'); 1347e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1348e41f4b71Sopenharmony_ci console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`); 1349e41f4b71Sopenharmony_ci }); 1350e41f4b71Sopenharmony_ci} catch (paramError) { 1351e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1352e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1353e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1354e41f4b71Sopenharmony_ci} 1355e41f4b71Sopenharmony_ci``` 1356e41f4b71Sopenharmony_ci 1357e41f4b71Sopenharmony_ci## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_cigetRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback\<Array\<ProcessInformation>>): void 1360e41f4b71Sopenharmony_ci 1361e41f4b71Sopenharmony_ciObtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result. 1362e41f4b71Sopenharmony_ci 1363e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1364e41f4b71Sopenharmony_ci 1365e41f4b71Sopenharmony_ci**System API**: This is a system API. 1366e41f4b71Sopenharmony_ci 1367e41f4b71Sopenharmony_ci**Parameters** 1368e41f4b71Sopenharmony_ci 1369e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1370e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1371e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1372e41f4b71Sopenharmony_ci| 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.| 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci**Error codes** 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_ci| ID| Error Message| 1379e41f4b71Sopenharmony_ci| ------- | -------- | 1380e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1381e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1382e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ci**Example** 1385e41f4b71Sopenharmony_ci 1386e41f4b71Sopenharmony_ci```ts 1387e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1388e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_cilet bundleName = "bundleName"; 1391e41f4b71Sopenharmony_cifunction getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) { 1392e41f4b71Sopenharmony_ci if (err) { 1393e41f4b71Sopenharmony_ci console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1394e41f4b71Sopenharmony_ci } else { 1395e41f4b71Sopenharmony_ci console.log('getRunningProcessInfoByBundleNameCallback success.'); 1396e41f4b71Sopenharmony_ci } 1397e41f4b71Sopenharmony_ci} 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_citry { 1400e41f4b71Sopenharmony_ci appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback); 1401e41f4b71Sopenharmony_ci} catch (paramError) { 1402e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1403e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1404e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1405e41f4b71Sopenharmony_ci} 1406e41f4b71Sopenharmony_ci``` 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_ci## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_cigetRunningProcessInfoByBundleName(bundleName: string): Promise\<Array\<ProcessInformation>> 1411e41f4b71Sopenharmony_ci 1412e41f4b71Sopenharmony_ciObtains information about the running processes by bundle name. This API uses a promise to return the result. 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1415e41f4b71Sopenharmony_ci 1416e41f4b71Sopenharmony_ci**System API**: This is a system API. 1417e41f4b71Sopenharmony_ci 1418e41f4b71Sopenharmony_ci**Parameters** 1419e41f4b71Sopenharmony_ci 1420e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1421e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1422e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1423e41f4b71Sopenharmony_ci 1424e41f4b71Sopenharmony_ci**Return value** 1425e41f4b71Sopenharmony_ci 1426e41f4b71Sopenharmony_ci| Type| Description| 1427e41f4b71Sopenharmony_ci| -------- | -------- | 1428e41f4b71Sopenharmony_ci| 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.| 1429e41f4b71Sopenharmony_ci 1430e41f4b71Sopenharmony_ci**Error codes** 1431e41f4b71Sopenharmony_ci 1432e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1433e41f4b71Sopenharmony_ci 1434e41f4b71Sopenharmony_ci| ID| Error Message| 1435e41f4b71Sopenharmony_ci| ------- | -------- | 1436e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1437e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1438e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1439e41f4b71Sopenharmony_ci 1440e41f4b71Sopenharmony_ci**Example** 1441e41f4b71Sopenharmony_ci 1442e41f4b71Sopenharmony_ci```ts 1443e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1444e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_cilet bundleName = "bundleName"; 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_citry { 1449e41f4b71Sopenharmony_ci appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => { 1450e41f4b71Sopenharmony_ci console.log('getRunningProcessInfoByBundleName success.'); 1451e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1452e41f4b71Sopenharmony_ci console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1453e41f4b71Sopenharmony_ci }); 1454e41f4b71Sopenharmony_ci} catch (paramError) { 1455e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1456e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1457e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1458e41f4b71Sopenharmony_ci} 1459e41f4b71Sopenharmony_ci``` 1460e41f4b71Sopenharmony_ci 1461e41f4b71Sopenharmony_ci## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1462e41f4b71Sopenharmony_ci 1463e41f4b71Sopenharmony_cigetRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback\<Array\<ProcessInformation>>): void 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ciObtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result. 1466e41f4b71Sopenharmony_ci 1467e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1468e41f4b71Sopenharmony_ci 1469e41f4b71Sopenharmony_ci**System API**: This is a system API. 1470e41f4b71Sopenharmony_ci 1471e41f4b71Sopenharmony_ci**Parameters** 1472e41f4b71Sopenharmony_ci 1473e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1474e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1475e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1476e41f4b71Sopenharmony_ci| userId | number | Yes| User ID.| 1477e41f4b71Sopenharmony_ci| 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.| 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci**Error codes** 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1482e41f4b71Sopenharmony_ci 1483e41f4b71Sopenharmony_ci| ID| Error Message| 1484e41f4b71Sopenharmony_ci| ------- | -------- | 1485e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1486e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1487e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1488e41f4b71Sopenharmony_ci 1489e41f4b71Sopenharmony_ci**Example** 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci```ts 1492e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1493e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_cilet bundleName = "bundleName"; 1496e41f4b71Sopenharmony_cilet userId = 0; 1497e41f4b71Sopenharmony_cifunction getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) { 1498e41f4b71Sopenharmony_ci if (err) { 1499e41f4b71Sopenharmony_ci console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`); 1500e41f4b71Sopenharmony_ci } else { 1501e41f4b71Sopenharmony_ci console.log('getRunningProcessInfoByBundleNameCallback success.'); 1502e41f4b71Sopenharmony_ci } 1503e41f4b71Sopenharmony_ci} 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_citry { 1506e41f4b71Sopenharmony_ci appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback); 1507e41f4b71Sopenharmony_ci} catch (paramError) { 1508e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1509e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1510e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1511e41f4b71Sopenharmony_ci} 1512e41f4b71Sopenharmony_ci``` 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ci## appManager.getRunningProcessInfoByBundleName<sup>10+</sup> 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_cigetRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise\<Array\<ProcessInformation>> 1517e41f4b71Sopenharmony_ci 1518e41f4b71Sopenharmony_ciObtains information about the running processes by bundle name and user ID. This API uses a promise to return the result. 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_ci**System API**: This is a system API. 1523e41f4b71Sopenharmony_ci 1524e41f4b71Sopenharmony_ci**Parameters** 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1527e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1528e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1529e41f4b71Sopenharmony_ci| userId | number | Yes| User ID.| 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci**Return value** 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ci| Type| Description| 1534e41f4b71Sopenharmony_ci| -------- | -------- | 1535e41f4b71Sopenharmony_ci| 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.| 1536e41f4b71Sopenharmony_ci 1537e41f4b71Sopenharmony_ci**Error codes** 1538e41f4b71Sopenharmony_ci 1539e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1540e41f4b71Sopenharmony_ci 1541e41f4b71Sopenharmony_ci| ID| Error Message| 1542e41f4b71Sopenharmony_ci| ------- | -------- | 1543e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1544e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1545e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1546e41f4b71Sopenharmony_ci 1547e41f4b71Sopenharmony_ci**Example** 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci```ts 1550e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1551e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1552e41f4b71Sopenharmony_ci 1553e41f4b71Sopenharmony_cilet bundleName = "bundleName"; 1554e41f4b71Sopenharmony_cilet userId = 0; 1555e41f4b71Sopenharmony_ci 1556e41f4b71Sopenharmony_citry { 1557e41f4b71Sopenharmony_ci appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => { 1558e41f4b71Sopenharmony_ci console.log('getRunningProcessInfoByBundleName success.'); 1559e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1560e41f4b71Sopenharmony_ci console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`); 1561e41f4b71Sopenharmony_ci }); 1562e41f4b71Sopenharmony_ci} catch (paramError) { 1563e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1564e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1565e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1566e41f4b71Sopenharmony_ci} 1567e41f4b71Sopenharmony_ci``` 1568e41f4b71Sopenharmony_ci 1569e41f4b71Sopenharmony_ci## appManager.isApplicationRunning<sup>11+</sup> 1570e41f4b71Sopenharmony_ci 1571e41f4b71Sopenharmony_ciisApplicationRunning(bundleName: string): Promise\<boolean> 1572e41f4b71Sopenharmony_ci 1573e41f4b71Sopenharmony_ciChecks whether an application is running. This API uses a promise to return the result. 1574e41f4b71Sopenharmony_ci 1575e41f4b71Sopenharmony_ci**System API**: This is a system API. 1576e41f4b71Sopenharmony_ci 1577e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1580e41f4b71Sopenharmony_ci 1581e41f4b71Sopenharmony_ci**Parameters** 1582e41f4b71Sopenharmony_ci 1583e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1584e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- | 1585e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name.| 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci**Return value** 1588e41f4b71Sopenharmony_ci 1589e41f4b71Sopenharmony_ci| Type| Description| 1590e41f4b71Sopenharmony_ci| -------- | -------- | 1591e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1592e41f4b71Sopenharmony_ci 1593e41f4b71Sopenharmony_ci**Error codes** 1594e41f4b71Sopenharmony_ci 1595e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1596e41f4b71Sopenharmony_ci 1597e41f4b71Sopenharmony_ci| ID| Error Message| 1598e41f4b71Sopenharmony_ci| ------- | -------- | 1599e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1600e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1601e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1602e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1603e41f4b71Sopenharmony_ci 1604e41f4b71Sopenharmony_ci**Example** 1605e41f4b71Sopenharmony_ci 1606e41f4b71Sopenharmony_ci```ts 1607e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1608e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_cilet bundleName = "com.example.myapplication"; 1611e41f4b71Sopenharmony_ci 1612e41f4b71Sopenharmony_ciappManager.isApplicationRunning(bundleName).then((data) => { 1613e41f4b71Sopenharmony_ci console.log(`The application running is: ${JSON.stringify(data)}`); 1614e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 1615e41f4b71Sopenharmony_ci console.error(`error: ${JSON.stringify(error)}`); 1616e41f4b71Sopenharmony_ci}); 1617e41f4b71Sopenharmony_ci``` 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci## appManager.isApplicationRunning<sup>11+</sup> 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ciisApplicationRunning(bundleName: string, callback: AsyncCallback\<boolean>): void 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ciChecks whether an application is running. This API uses an asynchronous callback to return the result. 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ci**System API**: This is a system API. 1626e41f4b71Sopenharmony_ci 1627e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1628e41f4b71Sopenharmony_ci 1629e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1630e41f4b71Sopenharmony_ci 1631e41f4b71Sopenharmony_ci**Parameters** 1632e41f4b71Sopenharmony_ci 1633e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1634e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- | 1635e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the shared library.| 1636e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1637e41f4b71Sopenharmony_ci 1638e41f4b71Sopenharmony_ci**Error codes** 1639e41f4b71Sopenharmony_ci 1640e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1641e41f4b71Sopenharmony_ci 1642e41f4b71Sopenharmony_ci| ID| Error Message| 1643e41f4b71Sopenharmony_ci| ------- | -------- | 1644e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1645e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1646e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1647e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1648e41f4b71Sopenharmony_ci 1649e41f4b71Sopenharmony_ci**Example** 1650e41f4b71Sopenharmony_ci 1651e41f4b71Sopenharmony_ci```ts 1652e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1653e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1654e41f4b71Sopenharmony_ci 1655e41f4b71Sopenharmony_cilet bundleName = "com.example.myapplication"; 1656e41f4b71Sopenharmony_ci 1657e41f4b71Sopenharmony_citry { 1658e41f4b71Sopenharmony_ci appManager.isApplicationRunning(bundleName, (err, data) => { 1659e41f4b71Sopenharmony_ci if (err) { 1660e41f4b71Sopenharmony_ci console.error(`err: ${JSON.stringify(err)}`); 1661e41f4b71Sopenharmony_ci } else { 1662e41f4b71Sopenharmony_ci console.log(`The application running is: ${JSON.stringify(data)}`); 1663e41f4b71Sopenharmony_ci } 1664e41f4b71Sopenharmony_ci }); 1665e41f4b71Sopenharmony_ci} catch (paramError) { 1666e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1667e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1668e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1669e41f4b71Sopenharmony_ci} 1670e41f4b71Sopenharmony_ci``` 1671e41f4b71Sopenharmony_ci 1672e41f4b71Sopenharmony_ci## ApplicationState 1673e41f4b71Sopenharmony_ci 1674e41f4b71Sopenharmony_ciEnumerates the application states. This enum can be used together with [AbilityStateData](js-apis-inner-application-appStateData-sys.md) to return the application state. 1675e41f4b71Sopenharmony_ci 1676e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1677e41f4b71Sopenharmony_ci 1678e41f4b71Sopenharmony_ci**System API**: This is a system API. 1679e41f4b71Sopenharmony_ci 1680e41f4b71Sopenharmony_ci| Name | Value | Description | 1681e41f4b71Sopenharmony_ci| -------------------- | --- | --------------------------------- | 1682e41f4b71Sopenharmony_ci| STATE_CREATE | 0 | The application is being created. | 1683e41f4b71Sopenharmony_ci| STATE_FOREGROUND | 2 | The application is running in the foreground. | 1684e41f4b71Sopenharmony_ci| STATE_ACTIVE | 3 | The application is active. | 1685e41f4b71Sopenharmony_ci| STATE_BACKGROUND | 4 | The application is running in the background. | 1686e41f4b71Sopenharmony_ci| STATE_DESTROY | 5 | The application is being destroyed. | 1687e41f4b71Sopenharmony_ci 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci## appManager.getRunningProcessInformationByBundleType<sup>12+</sup> 1690e41f4b71Sopenharmony_ci 1691e41f4b71Sopenharmony_cigetRunningProcessInformationByBundleType(bundleType: bundleManager.BundleType): Promise\<Array\<ProcessInformation>> 1692e41f4b71Sopenharmony_ci 1693e41f4b71Sopenharmony_ciObtains the information about the running process based on the bundle type. This API uses a promise to return the result. 1694e41f4b71Sopenharmony_ci 1695e41f4b71Sopenharmony_ci**System API**: This is a system API. 1696e41f4b71Sopenharmony_ci 1697e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1698e41f4b71Sopenharmony_ci 1699e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1700e41f4b71Sopenharmony_ci 1701e41f4b71Sopenharmony_ci**Parameters** 1702e41f4b71Sopenharmony_ci 1703e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1704e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | -------------- | 1705e41f4b71Sopenharmony_ci| bundleType | [bundleManager.BundleType](js-apis-bundleManager.md#bundletype) | Yes | Bundle type.| 1706e41f4b71Sopenharmony_ci 1707e41f4b71Sopenharmony_ci**Return value** 1708e41f4b71Sopenharmony_ci 1709e41f4b71Sopenharmony_ci| Type| Description| 1710e41f4b71Sopenharmony_ci| -------- | -------- | 1711e41f4b71Sopenharmony_ci| Promise\<Array\<[ProcessInformation](js-apis-inner-application-processInformation.md)>> | Promise used to return the process information.| 1712e41f4b71Sopenharmony_ci 1713e41f4b71Sopenharmony_ci**Error codes** 1714e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1715e41f4b71Sopenharmony_ci 1716e41f4b71Sopenharmony_ci| ID| Error Message| 1717e41f4b71Sopenharmony_ci| ------- | -------- | 1718e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1719e41f4b71Sopenharmony_ci| 202 | Not system application. | 1720e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1721e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1722e41f4b71Sopenharmony_ci 1723e41f4b71Sopenharmony_ci 1724e41f4b71Sopenharmony_ci**Example** 1725e41f4b71Sopenharmony_ci 1726e41f4b71Sopenharmony_ci```ts 1727e41f4b71Sopenharmony_ciimport { appManager, bundleManager } from '@kit.AbilityKit'; 1728e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1729e41f4b71Sopenharmony_ci 1730e41f4b71Sopenharmony_citry { 1731e41f4b71Sopenharmony_ci appManager.getRunningProcessInformationByBundleType(bundleManager.BundleType.ATOMIC_SERVICE) 1732e41f4b71Sopenharmony_ci .then((data) => { 1733e41f4b71Sopenharmony_ci console.log(`The running process information is: ${JSON.stringify(data)}`); 1734e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1735e41f4b71Sopenharmony_ci console.error(`error: ${JSON.stringify(error)}`); 1736e41f4b71Sopenharmony_ci }); 1737e41f4b71Sopenharmony_ci} catch (paramError) { 1738e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1739e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1740e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1741e41f4b71Sopenharmony_ci} 1742e41f4b71Sopenharmony_ci``` 1743e41f4b71Sopenharmony_ci 1744e41f4b71Sopenharmony_ci## appManager.preloadApplication<sup>12+</sup> 1745e41f4b71Sopenharmony_ci 1746e41f4b71Sopenharmony_cipreloadApplication(bundleName: string, userId: number, mode: PreloadMode, appIndex?: number): Promise\<void> 1747e41f4b71Sopenharmony_ci 1748e41f4b71Sopenharmony_ciPreloads an application process. A successful call does not always mean that the preloading is successful. In other words, the target application process may not be created even if the API is successfully called. This API uses a promise to return the result. 1749e41f4b71Sopenharmony_ci 1750e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PRELOAD_APPLICATION 1751e41f4b71Sopenharmony_ci 1752e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1753e41f4b71Sopenharmony_ci 1754e41f4b71Sopenharmony_ci**System API**: This is a system API. 1755e41f4b71Sopenharmony_ci 1756e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 1757e41f4b71Sopenharmony_ci 1758e41f4b71Sopenharmony_ci**Parameters** 1759e41f4b71Sopenharmony_ci 1760e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1761e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1762e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name of the application to preload.| 1763e41f4b71Sopenharmony_ci| userId | number | Yes| User ID.| 1764e41f4b71Sopenharmony_ci| mode | [PreloadMode](#appmanagerpreloadmode12) | Yes| Mode used for preloading.| 1765e41f4b71Sopenharmony_ci| appIndex | number | No| Application index of the twin application to be preloaded.| 1766e41f4b71Sopenharmony_ci 1767e41f4b71Sopenharmony_ci**Return value** 1768e41f4b71Sopenharmony_ci 1769e41f4b71Sopenharmony_ci| Type | Description | 1770e41f4b71Sopenharmony_ci| -------------- | ---------------- | 1771e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 1772e41f4b71Sopenharmony_ci 1773e41f4b71Sopenharmony_ci**Error codes** 1774e41f4b71Sopenharmony_ci 1775e41f4b71Sopenharmony_ci For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1776e41f4b71Sopenharmony_ci 1777e41f4b71Sopenharmony_ci| ID| Error Message| 1778e41f4b71Sopenharmony_ci| ------- | -------- | 1779e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1780e41f4b71Sopenharmony_ci| 202 | Not system application. | 1781e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1782e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1783e41f4b71Sopenharmony_ci| 16300005 | The target bundle does not exist. | 1784e41f4b71Sopenharmony_ci 1785e41f4b71Sopenharmony_ci**Example** 1786e41f4b71Sopenharmony_ci 1787e41f4b71Sopenharmony_ci```ts 1788e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1789e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1790e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1791e41f4b71Sopenharmony_ci 1792e41f4b71Sopenharmony_citry { 1793e41f4b71Sopenharmony_ci let bundleName = "ohos.samples.etsclock"; 1794e41f4b71Sopenharmony_ci let userId = 100; 1795e41f4b71Sopenharmony_ci let mode = appManager.PreloadMode.PRESS_DOWN; 1796e41f4b71Sopenharmony_ci let appIndex = 0; 1797e41f4b71Sopenharmony_ci appManager.preloadApplication(bundleName, userId, mode, appIndex) 1798e41f4b71Sopenharmony_ci .then(() => { 1799e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `preloadApplication success`); 1800e41f4b71Sopenharmony_ci }) 1801e41f4b71Sopenharmony_ci .catch((err: BusinessError) => { 1802e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${err.code}, msg:${err.message}`); 1803e41f4b71Sopenharmony_ci }) 1804e41f4b71Sopenharmony_ci} catch (err) { 1805e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${(err as BusinessError).code}, msg:${(err as BusinessError).message}`); 1806e41f4b71Sopenharmony_ci} 1807e41f4b71Sopenharmony_ci``` 1808e41f4b71Sopenharmony_ci 1809e41f4b71Sopenharmony_ci## appManager.getRunningMultiAppInfo<sup>12+</sup> 1810e41f4b71Sopenharmony_ci 1811e41f4b71Sopenharmony_cigetRunningMultiAppInfo(bundleName: string): Promise\<RunningMultiAppInfo> 1812e41f4b71Sopenharmony_ci 1813e41f4b71Sopenharmony_ciObtains the information about running applications in multi-app mode. This API uses a promise to return the result. The multi-app mode means that an application can be simultaneously logged in with different accounts on the same device. 1814e41f4b71Sopenharmony_ci 1815e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1816e41f4b71Sopenharmony_ci 1817e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1818e41f4b71Sopenharmony_ci 1819e41f4b71Sopenharmony_ci**System API**: This is a system API. 1820e41f4b71Sopenharmony_ci 1821e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 1822e41f4b71Sopenharmony_ci 1823e41f4b71Sopenharmony_ci**Parameters** 1824e41f4b71Sopenharmony_ci 1825e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1826e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1827e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1828e41f4b71Sopenharmony_ci 1829e41f4b71Sopenharmony_ci**Return value** 1830e41f4b71Sopenharmony_ci 1831e41f4b71Sopenharmony_ci| Type | Description | 1832e41f4b71Sopenharmony_ci| -------------- | ---------------- | 1833e41f4b71Sopenharmony_ci| Promise\<[RunningMultiAppInfo](js-apis-inner-application-runningMultiAppInfo-sys.md)> | Promise used to return the information about running applications with multi-app mode.| 1834e41f4b71Sopenharmony_ci 1835e41f4b71Sopenharmony_ci**Error codes** 1836e41f4b71Sopenharmony_ci 1837e41f4b71Sopenharmony_ci For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1838e41f4b71Sopenharmony_ci 1839e41f4b71Sopenharmony_ci| ID| Error Message| 1840e41f4b71Sopenharmony_ci| ------- | -------- | 1841e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1842e41f4b71Sopenharmony_ci| 202 | Not system application. | 1843e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1844e41f4b71Sopenharmony_ci| 16000072 | App clone or multi-instance is not supported. | 1845e41f4b71Sopenharmony_ci| 18500001 | The bundle does not exist or no patch has been applied. | 1846e41f4b71Sopenharmony_ci 1847e41f4b71Sopenharmony_ci**Example** 1848e41f4b71Sopenharmony_ci 1849e41f4b71Sopenharmony_ci```ts 1850e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1851e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1852e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1853e41f4b71Sopenharmony_ci 1854e41f4b71Sopenharmony_citry { 1855e41f4b71Sopenharmony_ci let bundleName = "ohos.samples.etsclock"; 1856e41f4b71Sopenharmony_ci appManager.getRunningMultiAppInfo(bundleName).then((info: appManager.RunningMultiAppInfo) => { 1857e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `getRunningMultiAppInfo success`); 1858e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1859e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); 1860e41f4b71Sopenharmony_ci }) 1861e41f4b71Sopenharmony_ci} catch (err) { 1862e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`); 1863e41f4b71Sopenharmony_ci} 1864e41f4b71Sopenharmony_ci``` 1865e41f4b71Sopenharmony_ci 1866e41f4b71Sopenharmony_ci## appManager.isAppRunning<sup>12+</sup> 1867e41f4b71Sopenharmony_ci 1868e41f4b71Sopenharmony_ciisAppRunning(bundleName: string, appCloneIndex?: number): Promise\<boolean> 1869e41f4b71Sopenharmony_ci 1870e41f4b71Sopenharmony_ciChecks whether an application is running. This API uses a promise to return the result. 1871e41f4b71Sopenharmony_ci 1872e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1873e41f4b71Sopenharmony_ci 1874e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1875e41f4b71Sopenharmony_ci 1876e41f4b71Sopenharmony_ci**System API**: This is a system API. 1877e41f4b71Sopenharmony_ci 1878e41f4b71Sopenharmony_ci**Parameters** 1879e41f4b71Sopenharmony_ci 1880e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1881e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1882e41f4b71Sopenharmony_ci| bundleName | string | Yes| Bundle name.| 1883e41f4b71Sopenharmony_ci| appCloneIndex | number | No| Index of the app clone.| 1884e41f4b71Sopenharmony_ci 1885e41f4b71Sopenharmony_ci**Return value** 1886e41f4b71Sopenharmony_ci 1887e41f4b71Sopenharmony_ci| Type | Description | 1888e41f4b71Sopenharmony_ci| -------------- | ---------------- | 1889e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is running, and **false** means the opposite.| 1890e41f4b71Sopenharmony_ci 1891e41f4b71Sopenharmony_ci**Error codes** 1892e41f4b71Sopenharmony_ci 1893e41f4b71Sopenharmony_ci For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1894e41f4b71Sopenharmony_ci 1895e41f4b71Sopenharmony_ci| ID| Error Message| 1896e41f4b71Sopenharmony_ci| ------- | -------- | 1897e41f4b71Sopenharmony_ci| 201 | The application does not have permission to call the interface. | 1898e41f4b71Sopenharmony_ci| 202 | Not system application. | 1899e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 1900e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1901e41f4b71Sopenharmony_ci| 16000073 | The app clone index is invalid. | 1902e41f4b71Sopenharmony_ci 1903e41f4b71Sopenharmony_ci**Example** 1904e41f4b71Sopenharmony_ci 1905e41f4b71Sopenharmony_ci```ts 1906e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1907e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 1908e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1909e41f4b71Sopenharmony_ci 1910e41f4b71Sopenharmony_citry { 1911e41f4b71Sopenharmony_ci let bundleName = "ohos.samples.etsclock"; 1912e41f4b71Sopenharmony_ci appManager.isAppRunning(bundleName).then((data: boolean) => { 1913e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `data: ${JSON.stringify(data)}`); 1914e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1915e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 1916e41f4b71Sopenharmony_ci }) 1917e41f4b71Sopenharmony_ci} catch (err) { 1918e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `isAppRunning error, code: ${err.code}, msg:${err.message}`); 1919e41f4b71Sopenharmony_ci} 1920e41f4b71Sopenharmony_ci``` 1921e41f4b71Sopenharmony_ci 1922e41f4b71Sopenharmony_ci## appManager.terminateMission<sup>12+</sup> 1923e41f4b71Sopenharmony_ci 1924e41f4b71Sopenharmony_citerminateMission(missionId: number): Promise\<void> 1925e41f4b71Sopenharmony_ci 1926e41f4b71Sopenharmony_ciTerminates a mission. This API uses a promise to return the result. 1927e41f4b71Sopenharmony_ci 1928e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.KILL_APP_PROCESSES 1929e41f4b71Sopenharmony_ci 1930e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 1931e41f4b71Sopenharmony_ci 1932e41f4b71Sopenharmony_ci**System API**: This is a system API. 1933e41f4b71Sopenharmony_ci 1934e41f4b71Sopenharmony_ci**Parameters** 1935e41f4b71Sopenharmony_ci 1936e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 1937e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1938e41f4b71Sopenharmony_ci| missionId | number | Yes| Mission ID, which can be obtained by calling [getMissionInfos](js-apis-app-ability-missionManager-sys.md#missionmanagergetmissioninfos).| 1939e41f4b71Sopenharmony_ci 1940e41f4b71Sopenharmony_ci**Return value** 1941e41f4b71Sopenharmony_ci 1942e41f4b71Sopenharmony_ci| Type| Description| 1943e41f4b71Sopenharmony_ci| -------- | -------- | 1944e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value.| 1945e41f4b71Sopenharmony_ci 1946e41f4b71Sopenharmony_ci**Error codes** 1947e41f4b71Sopenharmony_ci 1948e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 1949e41f4b71Sopenharmony_ci 1950e41f4b71Sopenharmony_ci| ID| Error Message| 1951e41f4b71Sopenharmony_ci| ------- | -------- | 1952e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1953e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 1954e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1955e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 1956e41f4b71Sopenharmony_ci 1957e41f4b71Sopenharmony_ci**Example** 1958e41f4b71Sopenharmony_ci```ts 1959e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 1960e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1961e41f4b71Sopenharmony_ci 1962e41f4b71Sopenharmony_ci@Entry 1963e41f4b71Sopenharmony_ci@Component 1964e41f4b71Sopenharmony_cistruct Index { 1965e41f4b71Sopenharmony_ci build() { 1966e41f4b71Sopenharmony_ci Button('start link', { type: ButtonType.Capsule, stateEffect: true }) 1967e41f4b71Sopenharmony_ci .width('87%') 1968e41f4b71Sopenharmony_ci .height('5%') 1969e41f4b71Sopenharmony_ci .margin({ bottom: '12vp' }) 1970e41f4b71Sopenharmony_ci .onClick(() => { 1971e41f4b71Sopenharmony_ci let missionId: number = 0; 1972e41f4b71Sopenharmony_ci try { 1973e41f4b71Sopenharmony_ci appManager.terminateMission(missionId).then(()=>{ 1974e41f4b71Sopenharmony_ci console.log('terminateMission success.'); 1975e41f4b71Sopenharmony_ci }).catch((err: BusinessError)=>{ 1976e41f4b71Sopenharmony_ci console.error('terminateMission failed. err: ' + JSON.stringify(err)); 1977e41f4b71Sopenharmony_ci }) 1978e41f4b71Sopenharmony_ci } catch (paramError) { 1979e41f4b71Sopenharmony_ci let code = (paramError as BusinessError).code; 1980e41f4b71Sopenharmony_ci let message = (paramError as BusinessError).message; 1981e41f4b71Sopenharmony_ci console.error(`[appManager] error: ${code}, ${message}`); 1982e41f4b71Sopenharmony_ci } 1983e41f4b71Sopenharmony_ci }) 1984e41f4b71Sopenharmony_ci } 1985e41f4b71Sopenharmony_ci} 1986e41f4b71Sopenharmony_ci``` 1987e41f4b71Sopenharmony_ci 1988e41f4b71Sopenharmony_ci## appManager.getSupportedProcessCachePids<sup>13+</sup> 1989e41f4b71Sopenharmony_ci 1990e41f4b71Sopenharmony_cigetSupportedProcessCachePids(bundleName : string): Promise\<Array\<number>> 1991e41f4b71Sopenharmony_ci 1992e41f4b71Sopenharmony_ciObtains the PIDs of processes that support quick startup after caching in a specified application. 1993e41f4b71Sopenharmony_ci 1994e41f4b71Sopenharmony_ci> **NOTE** 1995e41f4b71Sopenharmony_ci> 1996e41f4b71Sopenharmony_ci> This API can only be used to obtain the PIDs of the system account to which the caller belongs. 1997e41f4b71Sopenharmony_ci 1998e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_RUNNING_INFO 1999e41f4b71Sopenharmony_ci 2000e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Ability.AbilityRuntime.Core 2001e41f4b71Sopenharmony_ci 2002e41f4b71Sopenharmony_ci**System API**: This is a system API. 2003e41f4b71Sopenharmony_ci 2004e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 2005e41f4b71Sopenharmony_ci 2006e41f4b71Sopenharmony_ci**Parameters** 2007e41f4b71Sopenharmony_ci 2008e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 2009e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2010e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name.| 2011e41f4b71Sopenharmony_ci 2012e41f4b71Sopenharmony_ci**Return value** 2013e41f4b71Sopenharmony_ci 2014e41f4b71Sopenharmony_ci| Type| Description| 2015e41f4b71Sopenharmony_ci| -------- | -------- | 2016e41f4b71Sopenharmony_ci| Promise\<Array\<number>> | Promise used to return an array containing the PIDs.| 2017e41f4b71Sopenharmony_ci 2018e41f4b71Sopenharmony_ci**Error codes** 2019e41f4b71Sopenharmony_ci 2020e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md). 2021e41f4b71Sopenharmony_ci 2022e41f4b71Sopenharmony_ci| ID| Error Message| 2023e41f4b71Sopenharmony_ci| ------- | -------- | 2024e41f4b71Sopenharmony_ci| 201 | Permission denied. | 2025e41f4b71Sopenharmony_ci| 202 | Not system application. | 2026e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2027e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 2028e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 2029e41f4b71Sopenharmony_ci 2030e41f4b71Sopenharmony_ci**Example** 2031e41f4b71Sopenharmony_ci 2032e41f4b71Sopenharmony_ci```ts 2033e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 2034e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit'; 2035e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 2036e41f4b71Sopenharmony_ci 2037e41f4b71Sopenharmony_citry { 2038e41f4b71Sopenharmony_ci let bundleName = "ohos.samples.processcache"; 2039e41f4b71Sopenharmony_ci appManager.getSupportedProcessCachePids(bundleName).then((pids: Array<number>) => { 2040e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', `pids: ${JSON.stringify(pids)}`); 2041e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 2042e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); 2043e41f4b71Sopenharmony_ci }) 2044e41f4b71Sopenharmony_ci} catch (err) { 2045e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`); 2046e41f4b71Sopenharmony_ci} 2047e41f4b71Sopenharmony_ci``` 2048