Skip to content

Instantly share code, notes, and snippets.

@mustafasevgi
Created March 31, 2016 06:01
Show Gist options
  • Save mustafasevgi/acc7a7b71b6bed3f6b56828b904bac1a to your computer and use it in GitHub Desktop.
Save mustafasevgi/acc7a7b71b6bed3f6b56828b904bac1a to your computer and use it in GitHub Desktop.
is android device tablet?
public boolean isTablet() {
try {
// Compute screen size
DisplayMetrics dm = context.getResources().getDisplayMetrics();
float screenWidth = dm.widthPixels / dm.xdpi;
float screenHeight = dm.heightPixels / dm.ydpi;
double size = Math.sqrt(Math.pow(screenWidth, 2) +
Math.pow(screenHeight, 2));
// Tablet devices should have a screen size greater than 6 inches
return size >= 6;
} catch(Throwable t) {
Log.error(TAG_LOG, "Failed to compute screen size", t);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment