Get system 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 getSystemProperty() {
buffer = new StringBuffer();
initProperty("java.vendor.url", "java.vendor.url");
initProperty("java.class.path", "java.class.path");
initProperty("user.home", "user.home");
initProperty("java.class.version", "java.class.version");
initProperty("os.version", "os.version");
initProperty("java.vendor", "java.vendor");
initProperty("user.dir", "user.dir");
initProperty("user.timezone", "user.timezone");
initProperty("path.separator", "path.separator");
initProperty(" os.name", " os.name");
initProperty("os.arch", "os.arch");
initProperty("line.separator", "line.separator");
initProperty("file.separator", "file.separator");
initProperty("user.name", "user.name");
initProperty("java.version", "java.version");
initProperty("java.home", "java.home");
return buffer.toString();
}
private static String initProperty(String description, String propertyStr) {
if (buffer == null) {
buffer = new StringBuffer();
}
buffer.append(description).append(":");
buffer.append(System.getProperty(propertyStr)).append("\n");
return buffer.toString();
}
}
Related examples in the same category