在 AndroidManifest.xml 中,我有这个权限:
<user-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
但我仍然收到错误消息:
Permission Denial: killBackgroundProcesses() from ... requires android.permission.KILL_BACKGROUND_PROCESSES
此方法是从以下位置调用的:
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for(RunningAppProcessInfo runningProcess : runningProcesses) {
if(runningProcess.processName.equals("com.example.nihao")) {
Log.v("Hello", "kill process "+runningProcess.pid);
//android.os.Process.killProcess(runningProcess.pid);
am.killBackgroundProcesses("com.example.nihao");
}
}
有什么线索吗?