SoFunction
Updated on 2025-04-10

Android development tutorial: How to determine whether it is a mobile phone or a tablet


/**
* Determine whether it is a tablet
 *
 * @return
 */
private boolean isPad() {
 WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
 Display display = ();
// Screen width
 float screenWidth = ();
// Screen height
 float screenHeight = ();
 DisplayMetrics dm = new DisplayMetrics();
 (dm);
 double x = ( / , 2);
 double y = ( / , 2);
// Screen size
 double screenInches = (x + y);
// If the size is greater than 6, it is a Pad
 if (screenInches >= 6.0) {
  return true;
 }
 return false;
}