我试图使用以下代码终止正在运行的应用程序,但它不起作用请提出任何建议。
使用restartPackage()
,KillingBackgroundProcess()
,android.os.processes.killprocess(pid)
,但没有任何工作。安卓或Android内核不支持我们没有给予我们很多权限来杀死其他应用程序。
Intent ints = new Intent(Intent.ACTION_MAIN, null);
ints.addCategory(Intent.CATEGORY_LAUNCHER);
checkedapp = name.get(position);
Log.w("Checked app name", checkedapp);
PackageManager pm = getApplicationContext().getPackageManager();
List<ResolveInfo> intentlist = pm.queryIntentActivities(ints,
PackageManager.PERMISSION_GRANTED);
ActivityManager am1 = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> processes = am1.getRunningTasks(Integer.MAX_VALUE);
if (processes != null)
{
for (int i = 0; i < processes.size(); i++)
{
String packageName = processes.get(i).topActivity.getPackageName();
Log.w("packagename", packageName);
RunningTaskInfo temp = processes.get(i);
try
{
pName = (String) pm.getApplicationLabel(pm.getApplicationInfo(packageName,
PackageManager.GET_META_DATA));
}
catch (NameNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
if (checkedapp.equals(pName))
{
am1.killBackgroundProcesses(packageName);
//String pid = Integer.toString(temp.id);
int pid=temp.id;
android.os.Process.killProcess(pid);
//Log.w("processid", pid);
icons.remove(position);
name.remove(position);
}
Is it really not possible to force stop any running application in android programmatically.
Please help.
答案 0 :(得分:2)
这不可能从你的程序中杀死另一个应用程序的进程,从ICS这个限制意味着。您编写的代码可能适用于早期版本,但我从未尝试过。