How to check Whether a device is tablet or handset for all devices and OS(2.2-latest) programmatically.
-
check [this link](http://stackoverflow.com/q/5832368) – CRUSADER Jun 02 '13 at 13:02
3 Answers
There is no way. You can set a boolean inside res/values
<bool name="isHandest">false</bool>
inside values-sw600dp
, values-sw720dp
and values-xlarge
and
<bool name="isHandest">true</bool>
in res/values

- 156,034
- 29
- 297
- 305
-
-
It should be on values-large. Imho a 7" with android lower.than 3.2 it is not a tablet – Blackbelt Jun 02 '13 at 15:41
Use the Smallest-width Qualifier:
The Smallest-width qualifier allows you to target screens that have a certain minimum width given in dp. For example, the typical 7" tablet has a minimum width of 600 dp, so if you want your UI to have two panes on those screens (but a single list on smaller screens), you can use the same two layouts from the previous section for single and two-pane layouts, but instead of the large size qualifier, use sw600dp to indicate the two-pane layout is for screens on which the smallest-width is 600 dp
You can use different layouts or set a boolean in these folders:
<resources>
<bool name="is_tablet">true</bool>
</resources>
From official doc: http://developer.android.com/training/multiscreen/screensizes.html

- 39,407
- 49
- 186
- 260
If you define tablet as device with screen bigger than 7"
public static boolean isTablet() {
return screenSize >= 7;
}
public static double getScreenSize(Activity activity){
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
screenSize = Math.sqrt(x+y);
return screenSize;
}

- 1,616
- 14
- 8
-
1I believe "smallest width" resources qualifier like sw600dp does not work for Android version below 3.2? I cannot use layout-large as devices with screen size 5.4, 5.8, 6.3 fall into that category as well (while the first Samsung Galaxy Tab thinks it has normal layout). This is the problem I face in my project, beside calculating the screen size, no other way works for me. – Ethan Jun 02 '13 at 13:27