I need to show different notification to the user if he/she is using tablet against that of mobile. So is there any way to detect whether the device is tablet or mobile.
Asked
Active
Viewed 4,978 times
1
-
You can look at the screen size and or the api version. Would recommend screen size as api 4.0 works for both phones and tablets. – Warpzit Dec 16 '11 at 14:32
4 Answers
2
You can see below post
https://stackoverflow.com/a/11330947/1441666
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
which will return true if the device is operating on a large screen.
-
This will not work if the device is a smartphone but has a large screen. – user210504 Oct 18 '12 at 20:44
1
Here is a link to how you get the screen densities: Get screen dimensions in pixels
You'll then do something like this if(screen > comparevalue) then we have tablet, else phone.
0
protected String getDeviceType() {
boolean status = (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
if (status)
return "Mobile";
else
return "Tablet";
}

Yogesh Rathi
- 6,331
- 4
- 51
- 81
0
Another way to detect is to detect the Android version Check the variable android.os.Build.VERSION, honeycomb devices are tablets 2.x devices are phones or tablets.
http://developer.android.com/reference/android/os/Build.VERSION.html

Rajdeep Dua
- 11,190
- 2
- 32
- 22
-
Yes but this will be flawed in the long run as 4.0 works for tablets as well. Screen size would be the right way to go :) – Warpzit Dec 16 '11 at 19:01
-