Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the qualifiers for a given resource (when using it)?

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

like image 647
android developer Avatar asked May 28 '13 13:05

android developer


People also ask

What is qualifier in resource selection?

You can use this qualifier to ensure that your app has at least <N> dps of width available for its UI. For example, if your layout requires that its smallest dimension of screen area be at least 600 dp at all times, then you can use this qualifier to create the layout resources, res/layout-sw600dp/ .

What are available qualifiers in Android Studio?

What is a qualifier? It is a constraint, indicating that the directory's worth of resources is targeting a particular certain devices and configurations. So, for example: res/layout/ is good for anything, but res/layout-land/ is for landscape orientations.

What is resource value in Android studio?

In Android, almost everything is a resource. Defining resources that you can then access in your app is an essential part of Android development. Resources are used for anything from defining colors, images, layouts, menus, and string values. The value of this is that nothing is hardcoded.

What is Android resource directory?

In Android, a resource is a localized text string, bitmap, layout, or other small piece of noncode information that your app needs. At build time, all resources get compiled into your application. The resources locates inside res directory of your app.


1 Answers

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));
like image 158
Novikov Avatar answered Nov 08 '22 19:11

Novikov