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
The following gave me a a result quite close to the specs:
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
log.info("inches: {}", screenInches);
Output: inches: 4.589389937671455
Specs: Samsung Galaxy Nexus (720 x 1280 px, ~320 dpi, 4.65")
Please note, that dm.heightPixels
(or dm.widthPixels
depending on your orientatation) does not necessarily provide accurate information, since soft keys (as used in the Galaxy Nexus) are not added to the height (or width).