How to find Tablet or Phone in Android , Programmatically?

For example, you could set some res-values folder:

res/values-xlarge res/values-large res/values-sw600dp

etc. Then You could declare a boolean for each one:

    <resources>
<bool name="isXLarge">true</bool>
    </resources>

or

    <resources>
<bool name="isLarge">true</bool>
    </resources>

you can get the value by

   boolean xlargeValue = getResources().getBoolean(R.bool.isXlarge);
   boolean largevalue = getResources().getBoolean(R.bool.isLarge);
   boolean tabletValue = getResources().getBoolean(R.bool.sw620dp):

Try this

    public boolean isTablet(Context context) {
        boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
        boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
        return (xlarge || large);
    }

It will return true if you are using a tablet. It has been checked on Samsung Galaxy Tab 7" and Samsung Galaxy S3.


This subject is discussed in the Android Training:

http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali

Here is implementation,

Credit goes to ol_v_er for this simple and easy approach.

Some additional Information

You have now flag indicate whether your application is running on phone or tablet.

I have created two packages to handle UI and it's functionality,

com.phone
com.tablet

And you redirect control to your needed package

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    // do something
    //Start activity for tablet
} else {
    // do something else
    //Start activity for phone     
}

Refer

Note :I think for both 10 inch and 7 inch screen app take resources from res/values-sw600dp/ . But To be more specific I think for 10 inch tablet screen we can use res/values-sw720dp/

<resources>
    <bool name="isTablet">true</bool>
</resources>