Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Tablet or Phone in Android , Programmatically?

My case is that the logic is same for both Phone and Tablet. But there is slight difference in the layout. And I tried with the following code

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

Samsung Tab 10" has the resolution of 1280 * 800 and S3 has the resolution of 1270 * 720. And this code returns the Size as XLarge for both the Tab and Phone as its criteria for checking is > 960 * 720.

I have tested inserting the respective UI in the layout folder in Res as Layout, Layout-Large and Layout-xLarge . But this didn't effect in anyway. while checking it took the UI from the Layout folder.

Anyway even though I place the UI in the different layout folders, I have to check them in the class file to set the respective ContentView.

Is there any other way to find it?

like image 553
VIGNESH Avatar asked May 28 '13 04:05

VIGNESH


People also ask

How do I know what Android tablet I have?

Open 'Settings' and then 'About tablet' on the bottom left side. Then you will find 'Device name' (e.g. “Galaxy Tab A (2016)”) and 'Model number' (e.g. “SM-T585”) below. After choosing 'Software information', you'll see the 'Android version' (e.g. “7.0”).

How do I find device info on Android?

Go into the Settings menu of your device and check for an option that details the Android system info. This can vary depending on your brand of device and whether it's a phone or a tablet. As you can see from this screenshot, all we can really glean from this information screen is the model name and Android version.

Is a tablet an Android?

An Android tablet is a tablet-sized PC that runs on Google's Android operating system (OS). Android tablets include almost all the key features found in a regular tablet PC, including office applications, games, Web browsers and many other programs.


1 Answers

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> 
like image 147
edwin Avatar answered Sep 20 '22 09:09

edwin