Skip to content

Instantly share code, notes, and snippets.

@letz
Created July 3, 2015 13:34
Show Gist options
  • Save letz/3756e5e97015f54aa84c to your computer and use it in GitHub Desktop.
Save letz/3756e5e97015f54aa84c to your computer and use it in GitHub Desktop.
Check if android device is tablet or smartphone
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
float yInches= metrics.heightPixels/metrics.ydpi;
float xInches= metrics.widthPixels/metrics.xdpi;
double diagonalInches = Math.sqrt(xInches*xInches + yInches*yInches);
if (diagonalInches>=6.5){
// 6.5inch device or bigger
}else{
// smaller device
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment