public double screenInches() {
WindowManager wm = (WindowManager)
getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
// 屏幕宽度
float screenWidth = display.getWidth();
// 屏幕高度
float screenHeight = display.getHeight();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
// 屏幕尺寸
double screenInches = Math.sqrt(x + y);
return screenInches ;
}