How to get screen density on Android via code?

1

I'm developing an application where images and layouts adapt to the logical density of the device.

Is it possible to get screen dpi of the device through Java?

    
asked by anonymous 25.08.2015 / 14:15

1 answer

0

It is possible to obtain the logical density through the code

 getResources().getDisplayMetrics().density;

It will return you:

0.75 - ldpi (low resolution)

1.0 - mdpi (medium resolution)

1.5 - hdpi (high resolution)

2.0 - xhdpi (great resolution)

3.0 - xxhdpi (+ optimal resolution)

4.0 - xxxhdpi (excellent)

reference: density

    
25.08.2015 / 14:17