8
votes

I have a very simple question:

Given a specific resource (id,string,drawable,...) from R.java file, is it possible to know which qualifiers it had on its folder that matched it? If so, how ?

For example, if my device has a screen with hdpi density , and i have the same filename "x.png" on "res/drawable-hdpi" and "res/drawable-mdpi" , and i'm about to decode this file, what i would want to get is that it got the file from res/drawable-hdpi , and by doing it know that it has the hdpi density .

Of course, in this example , if the file exists on other folders , but not on the hdpi folder, I would want it to tell me which one will be used when I decode the file.

Same goes for the rest of the qualifiers (locale, screenSize,...) .

3
I'm interested in that question. I'm in the same problem. Did you resolved it? Did you found out a function to guess the qualifer used by device in any situation?GmloMalo
@GmloMalo No. I don't even remember why I wanted this...android developer
@GmloMalo Sorry for that. If you found out about it, please write it here. It might be useful in the future, or just nice to know.android developer

3 Answers

1
votes

use http://developer.android.com/reference/android/content/res/Configuration.html

example for dpi:

    Configuration config = getResources().getConfiguration();
    Log.d("DPI ", Integer.toString(config.densityDpi));
0
votes

This problem occur a lot if your targeting for large number of device so i decided to create my own simple application to find out which drawable is being used.Here is the link.

Hope this will help.

0
votes

I do not think that the android framework provides a mechanism fro your application to figure out which resource was used.

But you can always formulate the rules based on the rules specified in the android resource qualifiers documentation.

However i am not clear what exactly your requirement is? Do you want your application to be able to recognize which resource is used? Or do you only want this during design/ build.

As for figuring out which resource is being used, you can easily formulate a logic based on screen density, screen size, current phone locale, and current orientation, all of which are available through various apis present in android.