I need for my Application the exact inch of a display. My current solution is:
double inch;
double x = Math.pow(widthPix/dm.xdpi,2);
double y = Math.p
Try this.... This will give you the exact size of the display..
static String getDisplaySize(Activity activity) {
double x = 0, y = 0;
int mWidthPixels, mHeightPixels;
try {
WindowManager windowManager = activity.getWindowManager();
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
Point realSize = new Point();
Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
mWidthPixels = realSize.x;
mHeightPixels = realSize.y;
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
x = Math.pow(mWidthPixels / dm.xdpi, 2);
y = Math.pow(mHeightPixels / dm.ydpi, 2);
} catch (Exception ex) {
ex.printStackTrace();
}
return String.format(Locale.US, "%.2f", Math.sqrt(x + y));
}