AndroDev
AndroDev

Reputation: 3304

How to know screen uses 320-hdpi or 320-mdpi in Android

I want to know in my code whether my device uses 320-hdpi or 320-mdpi resources. Is it possible?

I gone through some examples like this but it gives me generic density pixels (like mdpi, ldpi and hdpi). But I want to know exactly which resource data is used by my device. Whether it is 320-hdpi, 320-mdpi or 320-ldpi.

Thank you in advance.

Upvotes: 1

Views: 713

Answers (3)

Ravi Bhatt
Ravi Bhatt

Reputation: 1948

I think you can use DisplayMetrics class for this.

Use following code to get display metrics.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

Then you can obtain desity by metrics.desity

If the density is 1 than mdpi resources will be use. If its less than 1 then ldpi resources will be used. If its 1.5 than hdpi resources will be used. If its 2 than xhdpi resources will be used.

Upvotes: 2

Squonk
Squonk

Reputation: 48871

From your Activity try...

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

You can then look at the various fields of metrics to find out physical and dpi characteristics of the display.

See DisplayMetrics documentation.

Upvotes: 1

Ethan
Ethan

Reputation: 1616

You can install this app on your device

https://play.google.com/store/apps/details?id=com.roysolberg.android.developertools

Go to "Resource Qualifiers", it will give you all information such as your device screen size (normal, large, xlarge) and screen density (ldpi, mdpi, hdpi,...)

Upvotes: 0

Related Questions