1

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.

Community
  • 1
  • 1
AndroDev
  • 3,236
  • 8
  • 35
  • 49

3 Answers3

2

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.

Ravi Bhatt
  • 1,930
  • 1
  • 14
  • 27
  • I already gone through this link and added in question too: http://stackoverflow.com/questions/10536701/call-a-function-based-on-the-devices-screen-size-hdpi-ldpi-mdpi . this does not solve my problem. It only gives you whether device is hdpi or ldpi. I want which resources folder it pickes while building. – AndroDev Nov 02 '12 at 05:39
  • okay. Besides that you can do a simple check by putting different image with same name in hdpi and mdpi folder. So by running it while testing, you can get whether it uses hdpi or mdpi. :) – Ravi Bhatt Nov 02 '12 at 06:12
1

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.

Squonk
  • 48,735
  • 19
  • 103
  • 135
  • I already gone through this link and added in question too: stackoverflow.com/questions/10536701/… . this does not solve my problem. It only gives you whether device is hdpi or ldpi. I want which resources folder it pickes while building. – AndroDev Nov 02 '12 at 06:03
  • 1
    @AndroDev : There's no API to discover the actual folder programatically. Android uses various parameters of the display to determine which folder to use and the `DisplayMetrics` fields give you logical and actual dpi information as well as physical pixels for both width and height. Using these you can calculate the screen size and consequentially work things out for yourself. In saying that though, I don't understand *why* you would want to do this - the point of Android doing this is meant to abstract things and means the code shouldn't need to know what kind of screen is being used. – Squonk Nov 03 '12 at 02:38
0

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,...)

Ethan
  • 1,616
  • 14
  • 8
  • Thank for answer but this is not what I am looking for. I want to know in my code what resolution resources it uses. – AndroDev Nov 02 '12 at 03:34