Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the exact dpi value of android device?

Tags:

android

dpi

we can use DisplayMetrics.densityDpi to obtain a approximate dpi value of the device,but i eager to know how to obtain the exact dpi value?

like image 782
Leo Avatar asked Nov 24 '25 09:11

Leo


1 Answers

Use DisplayMatrics.xdpi and DisplayMatrics.ydpi

xdpi    The exact physical pixels per inch of the screen in the X dimension.
ydpi    The exact physical pixels per inch of the screen in the Y dimension.

getResources().getDisplayMetrics().xdpi
getResources().getDisplayMetrics().ydpi
like image 50
retromuz Avatar answered Nov 26 '25 22:11

retromuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!