1

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • 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 Answers4

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.

Community
  • 1
  • 1
Nirali
  • 13,571
  • 6
  • 40
  • 53
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.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
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