How to determine device screen size category (small, normal, large, xlarge) using code?

vieux picture vieux · Feb 16, 2011 · Viewed 109.5k times · Source

Is there any way to determine the category of screen size of the current device, such as small, normal, large, xlarge?

Not the density, but the screen size.

Answer

Jeff Gilfelt picture Jeff Gilfelt · Feb 16, 2011

You can use the Configuration.screenLayout bitmask.

Example:

if ((getResources().getConfiguration().screenLayout & 
    Configuration.SCREENLAYOUT_SIZE_MASK) == 
        Configuration.SCREENLAYOUT_SIZE_LARGE) {
    // on a large screen device ...

}