Get running task information : System Information « Hardware « Android






Get running task information

   

package app.test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;

class CMDExecute {

  public synchronized String run(String[] cmd, String workdirectory)
      throws IOException {
    String result = "";

    try {
      ProcessBuilder builder = new ProcessBuilder(cmd);
      // set working directory
      if (workdirectory != null)
        builder.directory(new File(workdirectory));
      builder.redirectErrorStream(true);
      Process process = builder.start();
      InputStream in = process.getInputStream();
      byte[] re = new byte[1024];
      while (in.read(re) != -1) {
        System.out.println(new String(re));
        result = result + new String(re);
      }
      in.close();

    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return result;
  }

}

public class Main {
  private static StringBuffer buffer;
  public static String getRunningTasksInfo(Context context) {
    StringBuffer sInfo = new StringBuffer();
    final ActivityManager activityManager = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = activityManager.getRunningTasks(100);
    Iterator<RunningTaskInfo> l = tasks.iterator();
    while (l.hasNext()) {
      RunningTaskInfo ti = (RunningTaskInfo) l.next();
      sInfo.append("id: ").append(ti.id);
      sInfo.append("\nbaseActivity: ").append(
          ti.baseActivity.flattenToString());
      sInfo.append("\nnumActivities: ").append(ti.numActivities);
      sInfo.append("\nnumRunning: ").append(ti.numRunning);
      sInfo.append("\ndescription: ").append(ti.description);
      sInfo.append("\n\n");
    }
    return sInfo.toString();
  }
}

   
    
    
  








Related examples in the same category

1.Get Disk information
2.Get Net stat information
3.Get dmesg information
4.Get Process information
5.Get net conf information
6.Get mount information
7.Get telephone information
8.Get system information