Created
March 31, 2016 06:01
-
-
Save mustafasevgi/acc7a7b71b6bed3f6b56828b904bac1a to your computer and use it in GitHub Desktop.
is android device tablet?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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