Header Ads

Determine if the device is a smartphone or tablet?

This subject is discussed in the Android Training:
If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/):
<resources>
    <bool name="isTablet">true</bool>
</resources>
Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure this technique works on all platforms (before 3.2), create the same file in res/values-xlarge folder:

<resources>
    <bool name="isTablet">true</bool>
</resources>
Then, in the "standard" value file (as res/values/), you set the boolean to false:
<resources>
    <bool name="isTablet">false</bool>
</resources>
Then in you activity, you can get this value and check if you are running in a tablet size device:
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    // do something
} else {
    // do something else
}
from : http://stackoverflow.com/a/9308284

No comments:

Powered by Blogger.