How do I calculate PPI of Android device. Most specifically Android Tablets. Take a Note that I want to calculate PPI of the device and not DPI.
3 Answers
It's easy like one-two-three =) Let's caculate PPI to Nexus 5, for example.
float LCD_Diagonal = 4.95f;
int screenHeightPx = 1920;
int screenWidthPx = 1080;
float PPI = (float)Math.sqrt((double)(screenWidthPx*screenWidthPx + screenHeightPx*screenHeightPx))/LCD_Diagonal;
Log.e(TAG, "display_page_screen_ppi: " + String.format(Locale.getDefault(),"%d %s", Math.round(PPI), "ppi"));
In result we have 445 ppi
that's true according with specs.

- 504
- 1
- 9
- 21
-
@SagarPatil check the answer, please =) – Lex Hobbit Aug 26 '17 at 16:02
-
Here what is diagonal_density? – Rajakumar Mar 12 '18 at 09:43
-
Interesting that given this formula for Nexus 6 (6.0 in, 1440x2560) the result is 489.5 when it is actually 493 for the phone. Do you know why that can be the case? – krossovochkin Aug 08 '22 at 10:32
-
@krossovochkin possibly you should check LCD Diagonal in inches. you may use wrong value – Lex Hobbit Aug 27 '22 at 11:39
-
1@krossovochkin its may be 5.96f actual value https://www.knowsize.com/phone-motorola-nexus-6-size – Lex Hobbit Aug 27 '22 at 11:43
PPI
The screen density is quoted as Pixels Per Inch, PPI, and is the number of pixels that fit into an inch. The higher the number then the sharper images look on the display, therefore consumers consider a high PPI figure an advantage when buying a device. Sometimes the figure is quoted as Dots Per Inch, DPI, though the use of DPI is confusing as it comes from printing terminology, and it can refer to a the sensitivity of the sensors in digital scanners and digital cameras. For Android screens when it comes to PPI vs. DPI use PPI and leave DPI to refer to printers, where it is really a different measurement (because the dots needed to produce high quality images on paper are of greater density).
The PPI figure for a screen can be calculated given the resolution (number of x and y pixels) and size (diagonal measurement of the visible area) of a screen. Use the Pythagorean theorem to calculate the number of pixels in the diagonal then divide the result by the screen size. i.e. PPI=(square root of x^2 + y^2)/screen size
Second Option
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
// Display device width and height in pixels
screenHeightpx = dm.heightPixels;
screenWidthpx = dm.widthPixels;

- 1
- 1

- 10,224
- 2
- 37
- 59
-
3-1 **DO NOT PLAGIARIZE EXTERNAL WEBSITES by copying their content verbatim without credit** – Chris Stratton May 27 '14 at 18:21
-
For that you need to take the diaplaymatrix.
DisplayMetrics dm = getResources().getDisplayMetrics();
int height = dm.heightPixels;
int width = dm.widthPixels;

- 867
- 1
- 8
- 22