I've a problem with killing third party apps from my application. Here's the code:
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> appProcesses = activityManager
.getRunningAppProcesses();
for (RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (appProcess.pkgList[0].equalsIgnoreCase("com.adobe.air")) {
Log.v("ACTIVITY FOUND", "" + appProcess.pkgList[0]
+ " - " + appProcess.pid);
activityManager.killBackgroundProcesses("com.adobe.air");
activityManager.restartPackage("com.adobe.air");
android.os.Process.killProcess(appProcess.pid);
}
}
}
Log.v("RUN", "----------------------------------");
And in AndroidManifest I added the permissions android.permission.KILL_BACKGROUND_PROCESSES
and android.permission.RESTART_PACKAGES
.
In Log I can correctly read the message when the package com.adobe.air is running, but killBackgroundProcesses
, restartPackage
and KillProcess
have no success force closing the app itself. What's wrong?