Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate PPI of Android Device

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.

like image 579
Sagar Patil Avatar asked May 27 '14 12:05

Sagar Patil


1 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.

like image 132
Lex Hobbit Avatar answered Oct 18 '22 09:10

Lex Hobbit