I need to be able to provide a different UI for phones than tablets on Android. But I've been having a heck of a time figuring out a simple, straightforward way to do a runtime check of the screen size/resolution. I've searched quite a bit, and all the answers I get either tell me the screen density, which isn't what I want, or fall in the category of "use dp" or "put different images in the drawable folders." None of those quite cover what I need. All the answers I've seen searching StackOverflow have either fallen into the above categories, or have given answers with deprecated solutions.
I thought I had a workable solution:
Configuration configuration = getResources().getConfiguration();
boolean bigScreen = configuration.screenLayout == configuration.SCREENLAYOUT_SIZE_LARGE
|| configuration.screenLayout == configuration.SCREENLAYOUT_SIZE_XLARGE;
if(bigScreen)
{
Intent userCreationIntent = new Intent(getApplicationContext(), AboutUs.class);
startActivityForResult(userCreationIntent, 0);
}
else
{
Intent userCreationIntent = new Intent(getApplicationContext(),AboutUsSmall.class);
startActivityForResult(userCreationIntent,0);
}
The problem is that this code is also sending my Nexus 7, a 7-inch tablet, to the AboutUsSmall layout/class.
What am I doing wrong? More to the point, how can I do this right?