Check whether device is phone or tablet(7" or 10")?
Sometimes we have requirements to check whether device is phone or tablet & even for tablet whether device is 7" or 10". Following method will help us if the device is tablet or phone. If device is tablet method will return true, otherwise it'll return false.
public boolean isTablet(Context context) {
boolean isTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
return isTablet;
}
If above method return true, which means the device is Tablet. Now we have to detect whether device is 10" tablet or not. If device is 10" following method will return true, otherwise it'll return false.
public boolean isXLTablet(Context context) {
boolean isXLTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
return isXLTablet;
}
public boolean isTablet(Context context) {
boolean isTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
return isTablet;
}
If above method return true, which means the device is Tablet. Now we have to detect whether device is 10" tablet or not. If device is 10" following method will return true, otherwise it'll return false.
public boolean isXLTablet(Context context) {
boolean isXLTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
return isXLTablet;
}
Comments
Post a Comment