Get Display Metrics
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 getDisplayMetrics(Context cx) { String str = ""; DisplayMetrics dm = new DisplayMetrics(); dm = cx.getApplicationContext().getResources().getDisplayMetrics(); int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels; float density = dm.density; float xdpi = dm.xdpi; float ydpi = dm.ydpi; str += "The absolute width:" + String.valueOf(screenWidth) + "pixels\n"; str += "The absolute heightin:" + String.valueOf(screenHeight) + "pixels\n"; str += "The logical density of the display.:" + String.valueOf(density) + "\n"; str += "X dimension :" + String.valueOf(xdpi) + "pixels per inch\n"; str += "Y dimension :" + String.valueOf(ydpi) + "pixels per inch\n"; return str; } }