I was searching for the same thing! I found 2 similar questons/answers:
Getting ScreenLayout
Using ScreenLayout Bitmask
While all three questions are essentially the same, you really need both answers to get your result.
I used this code to get the layout size inside my Activity:
int layoutSize = getResources().getConfiguration().screenLayout;
layoutSize = layoutSize & Configuration.SCREENLAYOUT_SIZE_MASK;
The first line will return the layout size, but it will be a number that is almost the maximum size of an int
.
The second line will AND the layout size with the given mask. The mask has a value of 15 in decimal, or F in hex.
The value returned is between 0 and 3. The values corresponding to screen sizes, as well as the value of the size mask, are defined as constants in the android.content.res.Configuration
class: Android Configruation Documentation.
All you need to do after the previous 2 lines is to have some kind of a switch statement comparing the returned layoutSize
with Configuration
's pre-defined values for SCREENLAYOUT_SIZE_XXX
.
Hope this is not too late for you to use it. My problem was that I did not know how to ask the question in exact Android language. That is probably why the same question was, and probably should be, asked so many different ways.