Reputation: 11164
I'd like to figure out if a device has a hdpi
screen, ldpi
, mdpi
, large-hdpi
, etc, but I'm not talking about programatically doing this, instead I'd like to figure it out based on the device's specs.
For instance I'd like to look at gsmarena
over the device's specs and determine which resources get loaded by that specific device.
Can this be done? Or ... is there a list of such a thing, for all possible devices out there, somewhere on the web ?
Upvotes: 0
Views: 121
Reputation: 12605
You can look at the device's PPI and determine its category.
LDPI: Low density, ~120 dots per inch
MDPI: Medium density, ~120-160 dots per inch
TVDPI: Medium High density, ~160-213 dots per inch
HDPI: High density, ~213-240 dots per inch
XHDPI: eXtra High density, ~240-320 dots per inch
XXHDPI: eXtra eXtra High density, ~320-480 dots per inch[15]
XXXHDPI: eXtra eXtra eXtra High density, ~480-640 dots per inch[16]
If the website doesn't provide the PPI of the display then you can calculate it from knowing the diagonal size of the screen in inches and the resolution in pixels (width and height). This can be done in two steps:
Calculate diagonal resolution in pixels using the Pythagorean theorem:
Calculate PPI:
where
is diagonal resolution in pixels
is width resolution in pixels
is height resolution in pixels
is diagonal size in inches (this is the number advertised as the size of the display).
Upvotes: 1
Reputation: 887
I have written whole function for you. Enjoy!! Hope it Helps.
public String getScreenDensityDPI() {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
display.getRealMetrics(metrics);
switch (metrics.densityDpi) {
case DisplayMetrics.DENSITY_LOW:
return "ldpi";
case DisplayMetrics.DENSITY_MEDIUM:
return "mdpi";
case DisplayMetrics.DENSITY_TV:
return "tvdpi";
case DisplayMetrics.DENSITY_HIGH:
return "hdpi";
case DisplayMetrics.DENSITY_XHIGH:
return "xhdpi";
case DisplayMetrics.DENSITY_XXHIGH:
return "xxhdpi";
case DisplayMetrics.DENSITY_XXXHIGH:
return "xxxhdpi";
default:
return "" + mDisplayMetrics.densityDpi;
}
}
Upvotes: 1