AndreiBogdan
AndreiBogdan

Reputation: 11164

Determine any Android device's screen type

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

Answers (2)

Ahmed Hegazy
Ahmed Hegazy

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:

  1. Calculate diagonal resolution in pixels using the Pythagorean theorem:

    enter image description here

  2. Calculate PPI:

    enter image description here

where

enter image description here is diagonal resolution in pixels

enter image description here is width resolution in pixels

enter image description here is height resolution in pixels

enter image description here is diagonal size in inches (this is the number advertised as the size of the display).

Upvotes: 1

Anupam
Anupam

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

Related Questions