2014-01-19 86 views

回答

0

這可能會幫助你...

public static HashSet<String> getRunningApps(Context context) { 
    final HashSet<String> hashSet = new HashSet<String>(); 
    final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 
    final PackageManager packageManager = context.getPackageManager(); 
    List<RunningTaskInfo> runningTasks = activityManager.getRunningTasks(Integer.MAX_VALUE); 
    for (RunningTaskInfo runningTaskInfo : runningTasks) { 
     String packageName = runningTaskInfo.baseActivity.getPackageName(); 
     try { 
      String appName = packageManager.getApplicationInfo(packageName, 0).loadLabel(packageManager).toString(); 
      hashSet.add(appName); 
     } catch (NameNotFoundException exception) { 
      // handle Exception 
     } 
    } 
    return hashSet; 
} 
0

可以列出所有進程與以下行:

ActivityManager localActivityManager = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE); 

List RunningServiceInfo services = localActivityManager .getRunningServices(100); 

而且從RunningServiceInfo你可以得到詳細信息的過程。 另一種方法是使用getRunningAppProcesses

相關問題