2
我試圖用以下代碼殺死正在運行的應用程序,但它不起作用,請給出任何建議。 使用restartPackage()
,KillingBackgroundProcess()
,android.os.processes.killprocess(pid)
但沒有任何工作。它不支持android或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.
您是否在Manifest文件中添加了權限? <使用權限android:name =「android.permission.KILL_BACKGROUND_PROCESSES」/> –
yes.I在我的androidmanifest.xml中添加了這些權限 –
This不是你應該能夠做的;它可能會在一些舊版本的Android上基本上是一個設計錯誤。 –