Search code examples
androidimageresolutiondpi

Android: Requesting external images based on DPI


When you've got bundled graphical assets you place them in drawable-hdpi, drawable-xhdpi etc. so the right image is loaded based on the device's DPI.

What's the norm when dealing with external images requested from the web?

The solution I have in mind is to define the URL in resource folders using configuration qualifiers. Eg.

values-ldpi
-- http://website.com/logo24x24.jpg
values-mdpi
-- http://website.com/logo32x32.jpg
values-hdpi
-- http://website.com/logo48x48.jpg
values-xhdpi
-- http://website.com/logo64x64.jpg

Then in the layout XML define the image as being 32x32dp.

What's the common way of doing this? Doing it programmatically rather than using config qualifiers?


Solution

  • If you have the ability to run a servlet (or any server side logic) it would be best to send the DPI as a parameter and make the decisions on the filenames on the server. This will allow for easier changes without the need of updating the client and also will ease the process of writing a long list of values in the client.