Skip to content

Instantly share code, notes, and snippets.

@alexjlockwood
Created June 1, 2012 23:08
Show Gist options
  • Save alexjlockwood/2855673 to your computer and use it in GitHub Desktop.
Save alexjlockwood/2855673 to your computer and use it in GitHub Desktop.
Compatability Manager
public class CompatibilityUtil {
/**
* Get the current Android API level.
*/
public static int getSdkVersion() {
return Build.VERSION.SDK_INT;
}
/**
* Determine if the device is running API level 8 or higher.
*/
public static boolean isFroyo() {
return getSdkVersion() >= Build.VERSION_CODES.FROYO;
}
/**
* Determine if the device is running API level 11 or higher.
*/
public static boolean isHoneycomb() {
return getSdkVersion() >= Build.VERSION_CODES.HONEYCOMB;
}
/**
* Determine if the device is a tablet (i.e. it has a large screen).
*
* @param context The calling context.
*/
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
/**
* Determine if the device is a HoneyComb tablet.
*
* @param context The calling context.
*/
public static boolean isHoneycombTablet(Context context) {
return isHoneycomb() && isTablet(context);
}
/**
* This class can't be instantiated.
*/
private CompatibilityUtil() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment