Reputation: 4405
If I have any device at hand, how can I know which resources will be used by my apk?
e.g. drawable-hdpi
or drawable-xhdpi
or drawable-xxhdpi
I am not asking in theory which of these folders is loaded when but specifically if I have a random device at hand how do I know which will be used?
Upvotes: 1
Views: 775
Reputation:
One diagnostic method which is simple is to add a strings.xml
(or resource type of your choice) to a qualified res/values- directory with a string value corresponding to the density such as in:
res/values-xxhdpi
strings.xml (containing)
<string name="selected_density">xxhdpi</string>
You can do this with other resources types as well such as integer. This lets the system do the work for you. Do this for each density of interest and also supply a default in values/ version.
Then in code simply:
String densityStr = context.getString(R.string.selected_density);
See Configuration qualifier names
table here: https://developer.android.com/guide/topics/resources/providing-resources
Upvotes: 1
Reputation: 4442
You have to understand the idea of Density Buckets. Take a look at this image(collected from here)
So, Below 160 dpi is called ldpi
and found inside folder drawable-ldpi
and below 320 and upto 480 dpi is called xhdpi
and found inside folder drawable-xhdpi
etc.
So, which variation will be used solely depends on your phone's screen density. For better understanding take a look at this article, specially on the Table-1.
To get your phone's density, you can use this code
final float scale = getResources().getDisplayMetrics().density;
So,If your phone falled under xhdpi category, which is between 320 and 480 dpi, drawable-xhdpi
variation will be used and so on.
Upvotes: 2
Reputation: 6967
You can take a look at some Google results like: generator or explanation if you want to know the 'magic' behind it.
And on the Android development site you can find an overview of the density buckets: Density buckets
If that still doesn't answer your question, you can also take per example a couple of different images per density folder (hdpi, ldpi, mdpi...) and just see which shows on your device or emulator.
Upvotes: 2