我在从我的应用程序中杀死第三方应用程序时遇到问题。这是代码:
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", "----------------------------------");
在 AndroidManifest 我添加了权限android.permission.KILL_BACKGROUND_PROCESSES
和android.permission.RESTART_PACKAGES
.
在日志中,当 com.adobe.air 包正在运行时,我可以正确读取消息,但是killBackgroundProcesses
,restartPackage
并且KillProcess
没有成功强制关闭应用程序本身。怎么了?