Currently we have a project that instead of using the res/drawable folder to store images, we have to store them in the assets folder. However we still want to leverage on Android’s automatic picking of images (through qualifiers eg. drawable-hdpi, drawable-mdpi, etc. )depending on the device’s resolution/density etc.
My question is, do you know if it is possible to use qualifiers in the assets folder and use the Android mechanism to choose the best image resource? If not, do you know other approaches I can use as a workaround?
Thanks.
The qualifiers work only for resource folders. However, you can make use of the qualifiers for getting the file name to be used from assets.
For example, you can have different strings.xml in values-ldpi, values-hdpi, etc. Each of these strings.xml contain the name of the file to be used.
values-ldpi/strings.xml:
values-mdpi/strings.xml:
You can then get the name of the logo_file using
getResources().getString(R.string.logo_file)and use it to retrieve from the assets.