Software Archive
Read-only legacy content
17061 Discussions

How to distinguish phone vs. tablet

Lance_A_Intel
Employee
951 Views

Hello,

I'm trying to find the best known methods for distinguishing a tablet from a phone.

We recently discovered that a Tablet device (Thundersoft Bamboo) was getting a phone version of an App in the Google Play store instead of an alternate version more suited for tablets. After contacting the ISV we learned that the reason was that they distinguish a phone from a tablet based on screen properties. Specifically for the Bamboo:

getResources().getConfiguration().screenLayout  =  Configuration.SCREENLAYOUT_SIZE_NORMAL

Which they equate to being a phone.

Are there other methods that we can recommend to distinguish between a phone and a tablet that are not based on screen checks?

0 Kudos
3 Replies
Jorgesys
Beginner
951 Views

 

This is my method: 

    public static boolean isTablet(Context ctx){
            return (ctx.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; 
    }

 

0 Kudos
Jorgesys
Beginner
951 Views

Another method that I do not consider it necessary to implement on my apps but is good to use is using "Size Qualifiers", it works only in Android 3.2 and later

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

for example:

defining a variable type bool in default layout.xml

res/values-large/layout.xml:

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

and in  res/values-sw600dp/layout.xml  and res/values-xlarge/layout.xml

<resources>
    <bool name="isTablet">true</bool>
</resources>
So, from your app you will check if your mobile device is a Tablet:

 

 boolean isTablet = getResources().getBoolean(R.bool.isTablet);

if isTablet {

    //  true
} else {
    // false
}
 

 

0 Kudos
Lance_A_Intel
Employee
951 Views

Thanks Jorge, I will look into your suggestions and see how they work on the Bamboo device.

0 Kudos
Reply