如何杀死android中的应用程序?
killPackageProcesses(services.get(i).baseActivity.getPackageName());
这是函数 killPackageProcesses
public void killPackageProcesses(String packagename) {
int pid = 0;
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> pids = am
.getRunningAppProcesses();
for (int i = 0; i < pids.size(); i++) {
ActivityManager.RunningAppProcessInfo info = pids.get(i);
if (info.processName.equalsIgnoreCase(packagename)) {
pid = info.pid;
}
}
android.os.Process.killProcess(pid);
}
它不起作用。它如何适用于其他应用程序?许可是书面的。
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />