0
我遇到了從我的應用程序中殺死第三方應用程序的問題。下面的代碼:Android:殺死第三個應用程序
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
沒有成功強制關閉應用程序本身。怎麼了?
您必須是root用戶或系統應用才能殺死其他應用。 – Simon