0
I want the application to just download the images that are adaptable to the user screen, such as: if the user device supports xxhdpi images, it will not be necessary to store the images of xxxhdpi, mdpi, hdpi, and so on...
0
I want the application to just download the images that are adaptable to the user screen, such as: if the user device supports xxhdpi images, it will not be necessary to store the images of xxxhdpi, mdpi, hdpi, and so on...
5
The qualifiers cited are densities, where mdpi
is the baseline. And the rest are proportional to mdpi
.
That is:
Programmatically it is possible to identify which screen density of the device, just use:
DisplayMetrics metrics = new DisplayMetrics();
Activity activity = <Sua Activity>;
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int density = metrics.densityDpi; // Densidade (ldpi, mdpi e etc...)
The result of density
is one of the values below:
DisplayMetrics.DENSITY_LOW (ldpi)
DisplayMetrics.DENSITY_MEDIUM (mdpi)
DisplayMetrics.DENSITY_HIGH (hdpi)
DisplayMetrics.DENSITY_XHIGH (xhdpi)
DisplayMetrics.DENSITY_XXHIGH (xxhpi)
DisplayMetrics.DENSITY_XXXHIGH (xxxhdpi)
A simple download approach would be to combine the density to mount or select an image url (from a collection of urls) for each density and search as the result of the device.
Obs: Remember that density is not equal to screen size. In theory, we can have devices with 640dpi density (xxxhdpi) with 320x240 resolution and another device with 120dpi and 1920x1080 resolution.
But density is a cool metric for filtering images. A more real metric, but much more complicated, would be to combine the screen demensions with the density.
1
It is possible to obtain the logical density through the code
getResources().getDisplayMetrics().density;
He will return you:
0.75 - ldpi (low resolution)
1.0 - mdpi (average resolution)
1.5 - hdpi (high resolution)
2.0 - xhdpi (great resolution)
3.0 - xxhdpi (+optimal resolution)
4.0 - xxxhdpi (excellent)
0
You can find out what the density category is (Density Bucket) to which the device belongs through of this question or by the @Wakim response, then pass this information as parameter for the request to the webservice that will bring the appropriate image (also informed as parameter).
Browser other questions tagged java android android-studio
You are not signed in. Login or sign up in order to post.
Thank you so much @Wakim!!
– Everton Luis