Skip to content

Instantly share code, notes, and snippets.

@jimbray
Last active March 3, 2016 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimbray/b77ba283541e6829d39d to your computer and use it in GitHub Desktop.
Save jimbray/b77ba283541e6829d39d to your computer and use it in GitHub Desktop.
判断设备是否是 Tablet,适配Tablet设备的时候特别有用。
/**
* 判断是否是 Tablet
*
* @param activity Activity
* @return true, if is tablet device
*/
public static boolean isTablet(Activity activity) {
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
double screenSize = diagonalPixels / (160 * dm.density);
return screenSize >= 6.0D;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment