简体   繁体   中英

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;

Maybe like this?

   DisplayMetrics metrics = getResources().getDisplayMetrics();

See here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM