How to get qualifiers for this resource (when using it)?

I have a very simple question:

Given a specific resource (id, string, drawable, ...) from the R.java file, is it possible to find out which ones in his folder that correspond to it? If so, how?

For example, if my device has a screen with hdpi density and I have the same file name "x.png" with "res / drawable-hdpi" and "res / drawable-mdpi", and I'm going to decode this file what I would like to get is that he got the file from res / drawable-hdpi, and knowing that it has hdpi density.

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

The same applies to other qualifiers (locale, screenSize, ...).

+6
source share
3 answers

This problem arises a lot if your targeting is for a large number of devices, so I decided to create my own application to find out which one is used. Here is a link.

Hope this helps.

0
source

I do not think that the Android infrastructure provides a mechanism for your application to find out which resource was used.

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

However, I do not quite understand what is your requirement? Do you want your application to recognize which resource is being used? Or you need it only during development / assembly.

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

0
source

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
source

Source: https://habr.com/ru/post/946011/


All Articles