8

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

android developer
  • 114,585
  • 152
  • 739
  • 1,270

3 Answers3

1

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));
Novikov
  • 504
  • 6
  • 12
  • Where's the part that I give you the resource ID? Currently, all I see is that you've identified the density of the device. It has nothing to do with a given resource. – android developer Oct 07 '15 at 19:57
  • this, u can view dpi in numbers. http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android check dpi with Configuration and known Density Bucket for your phone. – Novikov Oct 08 '15 at 11:08
  • You do not understand the question. I don't ask for density. I ask how to get the origin folder of the resource that I choose. For example, if I have a drawable inside multiple folders ("drawable-ldpi", "drawable-port", "drawable-iw",... ) , I want to find which of the files it chose when I try to get it. – android developer Oct 08 '15 at 16:53
  • okey sorry, but if you use qualifer only of density (hdpi, xhdpi etc...) for drawable folder, my method is must go with – Novikov Oct 09 '15 at 09:09
  • No, because it won't know which file it used, only which file fits best in case it's available. – android developer Oct 09 '15 at 10:40
0

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.

u.jegan
  • 833
  • 6
  • 15
0

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.

Sam
  • 3,413
  • 1
  • 18
  • 20
  • suppose the code doesn't know anything about which resources files exist, what i want is to have a function that will tell which qualifiers are used for the given resource . it's for runtime (because otherwise i can see myself where the files are...) . – android developer May 28 '13 at 14:36
  • that in my opinion is not possible... best thing you can do is you know which resources you have put in each folder with the qualifiers provided by you. Depending on the device metrics i mentioned, you can guess which resource is being picked up by your app. I don't think you can find out what qualifiers are present for a particular resource, that would be done by the android system, and not your application. – Sam May 29 '13 at 02:53