Friday, June 7, 2013

Way to Identify Mobile and Tablet Devices with simple flag condition

You can identify Mobile and Tablet Devices with simple flag condition.

Set a boolean value in a specific value file like say (res/values-xlarge/):

<resources>
    <bool name="isTabletDevice">true</bool>
</resources>

Then, in the "standard" value file like say (res/values/):

<resources>
    <bool name="isTabletDevice">false</bool>
</resources>

Then from your activity, fetch this flag value to check device type :

boolean tabletDeviceSize = getResources().getBoolean(R.bool.isTabletDevice);
if (tabletDeviceSize) {
    //use tablet code
} else {
    //use mobile code
}

Thanks.

No comments:

Post a Comment