harmony 鸿蒙@ohos.app.ability.appManager (appManager) (System API)
@ohos.app.ability.appManager (appManager) (System API)
The 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.
NOTE
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.
This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.app.ability.appManager (appManager).
Modules to Import
import { appManager } from '@kit.AbilityKit';
appManager.PreloadMode12+
Enumerates the modes used for preloading an application process.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
Name | Value | Description |
---|---|---|
PRESS_DOWN | 0 | The application process is preloaded when the application icon is pressed. |
KeepAliveAppType14+
Enumerates the types of applications to be kept alive.
System API: This is a system API.
System capability: SystemCapability.Ability.AbilityRuntime.Core
Name | Value | Description |
---|---|---|
ALL | 0 | Third-party and system applications. This value can be called only as an input parameter of getKeepAliveBundles. |
THIRD_PARTY | 1 | Third-party application. |
SYSTEM | 2 | System application. |
KeepAliveSetter14+
Enumerates the types of parties that set to keep applications alive.
System API: This is a system API.
System capability: SystemCapability.Ability.AbilityRuntime.Core
Name | Value | Description |
---|---|---|
SYSTEM | 0 | System, which means that the system sets to keep applications alive. |
USER | 1 | User, which means that a user sets to keep applications alive. |
KeepAliveBundleInfo14+
Describes the keep-alive application information, which can be obtained by calling getKeepAliveBundles.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Name | Type | Read-Only | Optional | Description |
---|---|---|---|---|
bundleName | string | Yes | No | Bundle name. |
userId | number | Yes | No | User ID. |
appType | KeepAliveAppType | Yes | No | Type of the application to be kept alive. |
setter | KeepAliveSetter | Yes | No | Type of the party that sets to keep the application alive. |
appManager.isSharedBundleRunning10+
isSharedBundleRunning(bundleName: string, versionCode: number): Promise<boolean>
Checks whether the shared library is in use. This API uses a promise to return the result.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of the shared library. |
versionCode | number | Yes | Version number of the shared library. |
Return value
Type | Description |
---|---|
Promise<boolean> | Promise used to return the result. The value true means that the shared library is in use, and false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
const bundleName = "this is a bundleName";
const versionCode = 1;
appManager.isSharedBundleRunning(bundleName, versionCode).then((data) => {
console.log(`The shared bundle running is: ${JSON.stringify(data)}`);
}).catch((error: BusinessError) => {
console.error(`error: ${JSON.stringify(error)}`);
});
appManager.isSharedBundleRunning10+
isSharedBundleRunning(bundleName: string, versionCode: number, callback: AsyncCallback<boolean>): void
Checks whether the shared library is in use. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of the shared library. |
versionCode | number | Yes | Version number of the shared library. |
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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
const bundleName = "this is a bundleName";
const versionCode = 1;
appManager.isSharedBundleRunning(bundleName, versionCode, (err, data) => {
if (err) {
console.error(`err: ${JSON.stringify(err)}`);
} else {
console.log(`The shared bundle running is: ${JSON.stringify(data)}`);
}
});
appManager.on(‘appForegroundState’)11+
on(type: ‘appForegroundState’, observer: AppForegroundStateObserver): void
Registers 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.
System API: This is a system API.
Required permissions: ohos.permission.RUNNING_STATE_OBSERVER
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. It is fixed at ‘appForegroundState’. |
observer | AppForegroundStateObserver | Yes | Observer used to listen for application start or exit events. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let observer: appManager.AppForegroundStateObserver = {
onAppStateChanged(appStateData) {
console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`);
},
};
try {
appManager.on('appForegroundState', observer);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.on(‘abilityFirstFrameState’)12+
on(type: ‘abilityFirstFrameState’, observer: AbilityFirstFrameStateObserver, bundleName?: string): void
Registers an observer to listen for the complete of the first frame rendering of a given ability.
System API: This is a system API.
Required permissions: ohos.permission.RUNNING_STATE_OBSERVER
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. It is fixed at ‘abilityFirstFrameState’. |
observer | AbilityFirstFrameStateObserver | Yes | Observer used to listen for the complete of the first frame rendering of the ability. |
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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = {
onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) {
console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData));
}
};
try {
appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
} catch (e) {
let code = (e as BusinessError).code;
let message = (e as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.off(‘appForegroundState’)11+
off(type: ‘appForegroundState’, observer?: AppForegroundStateObserver): void
Deregisters the observer used to listen for application start or exit events.
System API: This is a system API.
Required permissions: ohos.permission.RUNNING_STATE_OBSERVER
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. It is fixed at ‘appForegroundState’. |
observer | AppForegroundStateObserver | No | Observer used to listen for application start or exit events. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let observer_: appManager.AppForegroundStateObserver|undefined;
// 1. Register an observer to listen for application start or exit events.
let observer: appManager.AppForegroundStateObserver = {
onAppStateChanged(appStateData: appManager.AppStateData) {
console.log(`[appManager] onAppStateChanged: ${JSON.stringify(appStateData)}`);
},
};
try {
appManager.on('appForegroundState', observer);
// Save the observer object.
observer_ = observer;
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
// 2. Deregister the observer.
try {
appManager.off('appForegroundState', observer_);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.off(‘abilityFirstFrameState’)12+
off(type: ‘abilityFirstFrameState’, observer?: AbilityFirstFrameStateObserver): void
Deregisters the observer used to listen for the complete of the first frame rendering of a given ability.
System API: This is a system API.
Required permissions: ohos.permission.RUNNING_STATE_OBSERVER
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. It is fixed at ‘abilityFirstFrameState’. |
observer | AbilityFirstFrameStateObserver | No | Callback used for deregistration. If this parameter is left blank, all subscriptions to the specified event are canceled. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let abilityFirstFrameStateObserverForAll: appManager.AbilityFirstFrameStateObserver = {
onAbilityFirstFrameDrawn(abilityStateData: appManager.AbilityFirstFrameStateData) {
console.log("abilityFirstFrame: ", JSON.stringify(abilityStateData));
}
};
try {
appManager.on('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
} catch (e) {
let code = (e as BusinessError).code;
let message = (e as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
try {
appManager.off('abilityFirstFrameState', abilityFirstFrameStateObserverForAll);
} catch (e) {
let code = (e as BusinessError).code;
let message = (e as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getForegroundApplications
getForegroundApplications(callback: AsyncCallback<Array<AppStateData>>): void
Obtains applications that are running in the foreground. This API uses an asynchronous callback to return the result. The application information is defined by AppStateData.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<Array<AppStateData>> | 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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
function getForegroundApplicationsCallback(err: BusinessError, data: Array<appManager.AppStateData>) {
if (err) {
console.error(`getForegroundApplicationsCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log(`getForegroundApplicationsCallback success, data: ${JSON.stringify(data)}`);
}
}
try {
appManager.getForegroundApplications(getForegroundApplicationsCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getForegroundApplications
getForegroundApplications(): Promise<Array<AppStateData>>
Obtains applications that are running in the foreground. This API uses a promise to return the result. The application information is defined by AppStateData.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<Array<AppStateData>> | Promise used to return an array holding the application state data. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
appManager.getForegroundApplications().then((data) => {
console.log(`getForegroundApplications success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getForegroundApplications fail, err: ${JSON.stringify(err)}`);
});
appManager.killProcessWithAccount
killProcessWithAccount(bundleName: string, accountId: number): Promise<void>
Kills a process by bundle name and account ID. This API uses a promise to return the result.
NOTE
The ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission is not required when accountId specifies the current user.
Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
accountId | number | Yes | ID of a system account. For details, see getOsAccountLocalId. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
let accountId = 0;
try {
appManager.killProcessWithAccount(bundleName, accountId).then(() => {
console.log('killProcessWithAccount success');
}).catch((err: BusinessError) => {
console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.killProcessWithAccount14+
killProcessWithAccount(bundleName: string, accountId: number, clearPageStack: boolean, appIndex?: number): Promise<void>
Kills a process by bundle name and account ID. This API uses a promise to return the result.
NOTE
The ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission is not required when accountId specifies the current user.
Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
accountId | number | Yes | ID of a system account. For details, see getOsAccountLocalId. |
clearPageStack | boolean | Yes | Whether to clear the page stack. The value true means to clear the page stack, and false means the opposite. |
appIndex | number | No | Index of an application clone. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
let accountId = 0;
let isClearPageStack = false;
let appIndex = 1;
try {
appManager.killProcessWithAccount(bundleName, accountId, isClearPageStack, appIndex).then(() => {
console.log('killProcessWithAccount success');
}).catch((err: BusinessError) => {
console.error(`killProcessWithAccount fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.killProcessWithAccount
killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback<void>): void
Kills a process by bundle name and account ID. This API uses an asynchronous callback to return the result.
NOTE
The ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS permission is not required when accountId specifies the current user.
Required permissions: ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS, ohos.permission.KILL_APP_PROCESSES, or ohos.permission.CLEAN_BACKGROUND_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
accountId | number | Yes | ID of a system account. For details, see getOsAccountLocalId. |
callback | AsyncCallback<void> | Yes | Callback used to return the API call result. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
let accountId = 0;
function killProcessWithAccountCallback(err: BusinessError) {
if (err) {
console.error(`killProcessWithAccountCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('killProcessWithAccountCallback success.');
}
}
appManager.killProcessWithAccount(bundleName, accountId, killProcessWithAccountCallback);
appManager.killProcessesByBundleName
killProcessesByBundleName(bundleName: string, callback: AsyncCallback<void>)
Kills a process by bundle name. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
callback | AsyncCallback<void> | Yes | Callback used to return the API call result. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
function killProcessesByBundleNameCallback(err: BusinessError) {
if (err) {
console.error(`killProcessesByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('killProcessesByBundleNameCallback success.');
}
}
try {
appManager.killProcessesByBundleName(bundleName, killProcessesByBundleNameCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.killProcessesByBundleName
killProcessesByBundleName(bundleName: string): Promise<void>
Kills a process by bundle name. This API uses a promise to return the result.
Required permissions: ohos.permission.KILL_APP_PROCESSES or ohos.permission.CLEAN_BACKGROUND_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
try {
appManager.killProcessesByBundleName(bundleName).then((data) => {
console.log('killProcessesByBundleName success.');
}).catch((err: BusinessError) => {
console.error(`killProcessesByBundleName fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.clearUpApplicationData
clearUpApplicationData(bundleName: string, callback: AsyncCallback<void>)
Clears application data by bundle name. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.CLEAN_APPLICATION_DATA
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
callback | AsyncCallback<void> | Yes | Callback used to return the API call result. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
function clearUpApplicationDataCallback(err: BusinessError) {
if (err) {
console.error(`clearUpApplicationDataCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('clearUpApplicationDataCallback success.');
}
}
try {
appManager.clearUpApplicationData(bundleName, clearUpApplicationDataCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.clearUpApplicationData
clearUpApplicationData(bundleName: string): Promise<void>
Clears application data by bundle name. This API uses a promise to return the result.
Required permissions: ohos.permission.CLEAN_APPLICATION_DATA
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<void> | Promise used to return the API call result. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = 'bundleName';
try {
appManager.clearUpApplicationData(bundleName).then((data) => {
console.log('clearUpApplicationData success.');
}).catch((err: BusinessError) => {
console.error(`clearUpApplicationData fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getProcessMemoryByPid10+
getProcessMemoryByPid(pid: number, callback: AsyncCallback<number>): void
Obtains the memory size of a process. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
pid | number | Yes | Process ID. For details, see getRunningProcessInfoByBundleName. |
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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let pid = 0;
function getProcessMemoryByPidCallback(err: BusinessError, data: number) {
if (err) {
console.error(`getProcessMemoryByPidCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('getProcessMemoryByPidCallback success.');
}
}
try {
appManager.getProcessMemoryByPid(pid, getProcessMemoryByPidCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getProcessMemoryByPid10+
getProcessMemoryByPid(pid: number): Promise<number>
Obtains the memory size of a process. This API uses a promise to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
pid | number | Yes | Process ID. For details, see getRunningProcessInfoByBundleName. |
Return value
Type | Description |
---|---|
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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let pid = 0;
try {
appManager.getProcessMemoryByPid(pid).then((data) => {
console.log('getProcessMemoryByPid success.');
}).catch((err: BusinessError) => {
console.error(`getProcessMemoryByPid fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getRunningProcessInfoByBundleName10+
getRunningProcessInfoByBundleName(bundleName: string, callback: AsyncCallback<Array<ProcessInformation>>): void
Obtains information about the running processes by bundle name. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
callback | AsyncCallback<Array<ProcessInformation>> | 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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "bundleName";
function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) {
if (err) {
console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('getRunningProcessInfoByBundleNameCallback success.');
}
}
try {
appManager.getRunningProcessInfoByBundleName(bundleName, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getRunningProcessInfoByBundleName10+
getRunningProcessInfoByBundleName(bundleName: string): Promise<Array<ProcessInformation>>
Obtains information about the running processes by bundle name. This API uses a promise to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<Array<ProcessInformation>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "bundleName";
try {
appManager.getRunningProcessInfoByBundleName(bundleName).then((data) => {
console.log('getRunningProcessInfoByBundleName success.');
}).catch((err: BusinessError) => {
console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getRunningProcessInfoByBundleName10+
getRunningProcessInfoByBundleName(bundleName: string, userId: number, callback: AsyncCallback<Array<ProcessInformation>>): void
Obtains information about the running processes by bundle name and user ID. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
userId | number | Yes | User ID. |
callback | AsyncCallback<Array<ProcessInformation>> | 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. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "bundleName";
let userId = 0;
function getRunningProcessInfoByBundleNameCallback(err: BusinessError, data: Array<appManager.ProcessInformation>) {
if (err) {
console.error(`getRunningProcessInfoByBundleNameCallback fail, err: ${JSON.stringify(err)}`);
} else {
console.log('getRunningProcessInfoByBundleNameCallback success.');
}
}
try {
appManager.getRunningProcessInfoByBundleName(bundleName, userId, getRunningProcessInfoByBundleNameCallback);
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.getRunningProcessInfoByBundleName10+
getRunningProcessInfoByBundleName(bundleName: string, userId: number): Promise<Array<ProcessInformation>>
Obtains information about the running processes by bundle name and user ID. This API uses a promise to return the result.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
userId | number | Yes | User ID. |
Return value
Type | Description |
---|---|
Promise<Array<ProcessInformation>> | Promise used to return the API call result and the process running information. You can perform error handling or custom processing in this callback. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "bundleName";
let userId = 0;
try {
appManager.getRunningProcessInfoByBundleName(bundleName, userId).then((data) => {
console.log('getRunningProcessInfoByBundleName success.');
}).catch((err: BusinessError) => {
console.error(`getRunningProcessInfoByBundleName fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.isApplicationRunning11+
isApplicationRunning(bundleName: string): Promise<boolean>
Checks whether an application is running. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<boolean> | Promise used to return the result. The value true means that the application is running, and false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "com.example.myapplication";
appManager.isApplicationRunning(bundleName).then((data) => {
console.log(`The application running is: ${JSON.stringify(data)}`);
}).catch((error: BusinessError) => {
console.error(`error: ${JSON.stringify(error)}`);
});
appManager.isApplicationRunning11+
isApplicationRunning(bundleName: string, callback: AsyncCallback<boolean>): void
Checks whether an application is running. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of the shared library. |
callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value true means that the application is running, and false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName = "com.example.myapplication";
try {
appManager.isApplicationRunning(bundleName, (err, data) => {
if (err) {
console.error(`err: ${JSON.stringify(err)}`);
} else {
console.log(`The application running is: ${JSON.stringify(data)}`);
}
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
ApplicationState
Enumerates the application states. This enum can be used together with AbilityStateData to return the application state.
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Name | Value | Description |
---|---|---|
STATE_CREATE | 0 | The application is being created. |
STATE_FOREGROUND | 2 | The application is running in the foreground. |
STATE_ACTIVE | 3 | The application is active. |
STATE_BACKGROUND | 4 | The application is running in the background. |
STATE_DESTROY | 5 | The application is being destroyed. |
appManager.getRunningProcessInformationByBundleType12+
getRunningProcessInformationByBundleType(bundleType: bundleManager.BundleType): Promise<Array<ProcessInformation>>
Obtains the information about the running process based on the bundle type. This API uses a promise to return the result.
System API: This is a system API.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleType | bundleManager.BundleType | Yes | Bundle type. |
Return value
Type | Description |
---|---|
Promise<Array<ProcessInformation>> | Promise used to return the process information. |
Error codes For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not system application. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager, bundleManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
appManager.getRunningProcessInformationByBundleType(bundleManager.BundleType.ATOMIC_SERVICE)
.then((data) => {
console.log(`The running process information is: ${JSON.stringify(data)}`);
}).catch((error: BusinessError) => {
console.error(`error: ${JSON.stringify(error)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.preloadApplication12+
preloadApplication(bundleName: string, userId: number, mode: PreloadMode, appIndex?: number): Promise<void>
Preloads 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.
Required permissions: ohos.permission.PRELOAD_APPLICATION
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of the application to preload. |
userId | number | Yes | User ID. |
mode | PreloadMode | Yes | Mode used for preloading. |
appIndex | number | No | Application index of the twin application to be preloaded. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | The application does not have permission to call the interface. |
202 | Not system application. |
401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
16000050 | Internal error. |
16300005 | The target bundle does not exist. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
try {
let bundleName = "ohos.samples.etsclock";
let userId = 100;
let mode = appManager.PreloadMode.PRESS_DOWN;
let appIndex = 0;
appManager.preloadApplication(bundleName, userId, mode, appIndex)
.then(() => {
hilog.info(0x0000, 'testTag', `preloadApplication success`);
})
.catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${err.code}, msg:${err.message}`);
})
} catch (err) {
hilog.error(0x0000, 'testTag', `preloadApplication error, code: ${(err as BusinessError).code}, msg:${(err as BusinessError).message}`);
}
appManager.getRunningMultiAppInfo12+
getRunningMultiAppInfo(bundleName: string): Promise<RunningMultiAppInfo>
Obtains 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.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<RunningMultiAppInfo> | Promise used to return the information about running applications with multi-app mode. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | The application does not have permission to call the interface. |
202 | Not system application. |
401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. |
16000072 | App clone or multi-instance is not supported. |
18500001 | The bundle does not exist or no patch has been applied. |
Example
import { appManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
let bundleName = "ohos.samples.etsclock";
appManager.getRunningMultiAppInfo(bundleName).then((info: appManager.RunningMultiAppInfo) => {
hilog.info(0x0000, 'testTag', `getRunningMultiAppInfo success`);
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`);
})
} catch (err) {
hilog.error(0x0000, 'testTag', `getRunningMultiAppInfo error, code: ${err.code}, msg:${err.message}`);
}
appManager.terminateMission13+
terminateMission(missionId: number): Promise<void>
Terminates a mission. This API uses a promise to return the result.
Required permissions: ohos.permission.KILL_APP_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
missionId | number | Yes | Mission ID, which can be obtained by calling getMissionInfos. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
build() {
Button('start link', { type: ButtonType.Capsule, stateEffect: true })
.width('87%')
.height('5%')
.margin({ bottom: '12vp' })
.onClick(() => {
let missionId: number = 0;
try {
appManager.terminateMission(missionId).then(()=>{
console.log('terminateMission success.');
}).catch((err: BusinessError)=>{
console.error('terminateMission failed. err: ' + JSON.stringify(err));
})
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
})
}
}
appManager.getSupportedProcessCachePids14+
getSupportedProcessCachePids(bundleName : string): Promise<Array<number>>
Obtains the PIDs of processes that support quick startup after caching in a specified application.
NOTE
This API can only be used to obtain the PIDs of the system account to which the caller belongs.
Required permissions: ohos.permission.GET_RUNNING_INFO
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Model restriction: This API can be used only in the stage model.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
Return value
Type | Description |
---|---|
Promise<Array<number>> | Promise used to return an array containing the PIDs. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not system application. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
801 | Capability not supported. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
let bundleName = "ohos.samples.processcache";
appManager.getSupportedProcessCachePids(bundleName).then((pids: Array<number>) => {
hilog.info(0x0000, 'testTag', `pids: ${JSON.stringify(pids)}`);
}).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`);
})
} catch (err) {
hilog.error(0x0000, 'testTag', `get pids error, code: ${err.code}, msg:${err.message}`);
}
appManager.clearUpAppData13+
clearUpAppData(bundleName: string, appCloneIndex?: number): Promise<void>
Clears data of a specified application based on the bundle name and application clone index.
Required permissions: ohos.permission.CLEAN_APPLICATION_DATA
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
appCloneIndex | number | No | Index of the application clone. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
16000050 | Internal error. |
16000073 | The app clone index does not exist. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let bundleName: string = 'com.ohos.demo';
let appCloneIndex: number = 0;
try {
appManager.clearUpAppData(bundleName, appCloneIndex).then(() => {
console.log(`clearUpAppData success.`);
}).catch((err: BusinessError) => {
console.error(`clearUpAppData fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] error: ${code}, ${message}`);
}
appManager.setKeepAliveForBundle14+
setKeepAliveForBundle(bundleName: string, userId: number, enable: boolean): Promise<void>
Keeps an application of a specified user alive, or cancels its keep-alive status. This API uses a promise to return the result. Currently, this API takes effect only on 2-in-1 devices.
Permission required: ohos.permission.MANAGE_APP_KEEP_ALIVE
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name. |
userId | number | Yes | User ID. |
enable | boolean | Yes | Whether to keep the application alive or cancel its keep-alive status. The value true means to keep the application alive, and false means to cancel its keep-alive status. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not system application. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
801 | Capability not supported. |
16000050 | Internal error. |
16300005 | The target bundle does not exist. |
16300008 | The target bundle has no main ability. |
16300009 | The target bundle has no status-bar ability. |
16300010 | The target application is not attached to status bar. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
let bundleName = "ohos.samples.keepaliveapp";
let userId = 100;
appManager.setKeepAliveForBundle(bundleName, userId, true).then(() => {
console.log(`setKeepAliveForBundle success`);
}).catch((err: BusinessError) => {
console.error(`setKeepAliveForBundle fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] setKeepAliveForBundle error: ${code}, ${message}`);
}
appManager.getKeepAliveBundles14+
getKeepAliveBundles(type: KeepAliveAppType, userId?: number): Promise<Array<KeepAliveBundleInfo>>
Obtains information about a specified type of keep-alive application of a user. The application information is defined by KeepAliveBundleInfo. This API uses a promise to return the result. Currently, this API takes effect only on 2-in-1 devices.
Permission required: ohos.permission.MANAGE_APP_KEEP_ALIVE
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | KeepAliveAppType | Yes | Type of the application. |
userId | number | No | User ID. |
Return value
Type | Description |
---|---|
Promise<Array<KeepAliveBundleInfo>> | Promise used to return the array of keep-alive application information. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
801 | Capability not supported. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let userId = 100;
let type: appManager.KeepAliveAppType = appManager.KeepAliveAppType.THIRD_PARTY;
try {
appManager.getKeepAliveBundles(type, userId).then((data) => {
console.log(`getKeepAliveBundles success, data: ${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
console.error(`getKeepAliveBundles fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] getKeepAliveBundles error: ${code}, ${message}`);
}
appManager.killProcessesInBatch14+
killProcessesInBatch(pids: Array<number>): Promise<void>
Kill processes in batches. Currently, this API takes effect only on 2-in-1 devices.
Required permissions: ohos.permission.KILL_APP_PROCESSES
System capability: SystemCapability.Ability.AbilityRuntime.Core
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
pids | Array<number> | Yes | IDs of the processes to kill. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and Ability Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Not System App. Interface caller is not a system app. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
801 | Capability not supported. |
16000050 | Internal error. |
Example
import { appManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
let pids: Array<number> = [100, 101, 102];
appManager.killProcessesInBatch(pids).then(() => {
console.log(`killProcessesInBatch success`);
}).catch((err: BusinessError) => {
console.error(`killProcessesInBatch fail, err: ${JSON.stringify(err)}`);
});
} catch (paramError) {
let code = (paramError as BusinessError).code;
let message = (paramError as BusinessError).message;
console.error(`[appManager] killProcessesInBatch error: ${code}, ${message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙AbilityAccessControl
harmony 鸿蒙OH_NativeBundle_ApplicationInfo
harmony 鸿蒙OH_NativeBundle_ElementName
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦