2011-08-09 61 views

回答

3

你可以做這樣的事情,但不建議:

List<ApplicationInfo> packages; 
    PackageManager pm; 
    pm = getPackageManager(); 
    //get a list of installed apps. 
    packages = pm.getInstalledApplications(0); 

    ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 

    for (ApplicationInfo packageInfo : packages) { 
     if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue; 
     if(packageInfo.packageName.equals("mypackage")) continue; 
     mActivityManager.killBackgroundProcesses(packageInfo.packageName); 
    } 
0

你可以這樣做:

int p = android.os.Process.myPid(); 
android.os.Process.killProcess(p); 
+0

,我的工作在同一個,如果你有工作代碼,然後分享。因爲你所說的不管用。 – Custadian

+0

@ user2204790查看上面的答案已更新 –

0

避免查殺系統應用你可以做這個,我包括像華爲的particlur品牌代碼有自己的應用程序(其中經常包含華爲)和三星有自己的,所以這個代碼避免殺死sy幹Apps,並會關閉所有其他應用程式apps.System往往含有的Android阿迪爾是我的包裏面我不想殺

ActivityManager actvityManager = (ActivityManager) 
     getApplicationContext().getSystemService(getApplicationContext().ACTIVITY_SERVICE); 
    List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses(); 

for(int pnum = 0; pnum < procInfos.size(); pnum++) 
{ 
    if((procInfos.get(pnum)).processName.contains("android")||(procInfos.get(pnum)).processName.contains("system")||(procInfos.get(pnum)).processName.contains("huawei")||(procInfos.get(pnum)).processName.contains("adil")) 
    { 
      //Toast.makeText(getApplicationContext(), "system apps", Toast.LENGTH_SHORT).show(); 
    } 
    else 
    { 
     actvityManager.killBackgroundProcesses(procInfos.get(pnum).processName); 
     Toast.makeText(getApplicationContext(), "killed "+procInfos.get(pnum).processName, Toast.LENGTH_SHORT).show(); 

    } 
} 
相關問題