3

I have 7 drawable folders with (7 qualifiers that is) all with the same named images, so I need to know how can I programmatically or otherwise find out which drawable folder the application is taking the images from: drawable-xhdpi, drawable-mdpi, etc?

Edit to question: There are precedence of qualifiers and situations where both drawable folders are possible candidates. For example drawable-large-mdpi and drawable-mdpi, or even the third candidate can be drawable-sw600dp if I have all three folders. I know there is a documentation on precedence of qualifiers, but I want to be sure on my conclusions

Nazerke
  • 2,098
  • 7
  • 37
  • 57
  • Based on the device screen sizes the android will choose the drawable folder... – Subburaj Dec 31 '13 at 13:29
  • I know that. The question is how can I know. I have a specific situation where I need to be assured in it myself. – Nazerke Dec 31 '13 at 13:31
  • one way is u have to take screen sizes and from that you have to conclude from which folder it will load. – Subburaj Dec 31 '13 at 13:33
  • 1
    Of course I conclude, but that doesn't make me feel sure about where is it coming from. There are precedence of qualifiers and situations where both drawable folders are possible candidates. For example drawable-large-mdpi and drawable-mdpi, or even the third candidate can be drawable-sw600dp if I have all three folders. I know there is a documentation on precedence of qualifiers, but I want to be sure on my conclusions – Nazerke Dec 31 '13 at 13:36
  • Did you ever figure this out? I'm having the same issue. I have the appropriate icons in their respective folders, and I know that android *should* be picking the right ones, but it's incredibly frustrating not to be able to see a filepath or anything confirming that – BThompson Sep 08 '16 at 22:50
  • 1
    @BThompson unfortunately I don't remember solving it, was a long time ago. But if I had the same issue today, I would write on actual imgs – Nazerke Sep 09 '16 at 03:09

1 Answers1

2

try this code

switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
    // handle your code here for ldpi
    break;
case DisplayMetrics.DENSITY_MEDIUM:
    // handle your code here for mdpi
    break;
case DisplayMetrics.DENSITY_HIGH:
   // handle your code here for hdpi
    break;
case DisplayMetrics.DENSITY_XHIGH:
    // handle your code here for xhdpi
    break;
}
Shahjahan Khan
  • 189
  • 1
  • 8
  • first we can check the screen size (http://stackoverflow.com/questions/11252067/how-do-i-get-the-screensize-programmatically-in-android) and then checked for density – Shahjahan Khan Dec 31 '13 at 13:46