Sunil Kumar Sahoo
Sunil Kumar Sahoo

Reputation: 53647

How detect the device type programmatically whether tablet or mobile

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.

Upvotes: 1

Views: 5053

Answers (4)

Yogesh Rathi
Yogesh Rathi

Reputation: 6499

protected String getDeviceType() {
boolean status = (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
if (status)
        return "Mobile";
    else
        return "Tablet";
}

Upvotes: 0

Nirali
Nirali

Reputation: 13805

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.

Upvotes: 2

Rajdeep Dua
Rajdeep Dua

Reputation: 11230

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

Upvotes: 0

Warpzit
Warpzit

Reputation: 28152

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.

Upvotes: 1

Related Questions