user2581628
user2581628

Reputation: 31

how to find the ppi of an android screen

I have a very simple question.

All I'm looking for is the code to find the PPI of an android screen, i know how to find the height and width in pixels but not the amount of pixels per inch. I need this to help me find the diagonal of the screen. I tried but it doesn't seem to work

DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); 

int  ppi = (int) displayMetrics.density;

Upvotes: 2

Views: 4740

Answers (1)

Benjamin Schwalb
Benjamin Schwalb

Reputation: 1134

Maybe like this?

   DisplayMetrics metrics = getResources().getDisplayMetrics();

See here

Upvotes: 2

Related Questions