Dpi:dots-per-inch, the number of pixels per inch, that is, the greater the density, the more points are accommodated in each inch. This value is determined by the device itself and written to death.
Calculation method: Get to the screen resolution: Point.x and POINT.Y, then take out the screen dpi (number of pixels per inch), calculate the length and width of how many inches, that is: Point.x/dm.xdpi,point.y/ DM.YDPI, the length and width of the screen is calculated, and then using the Pythagorean theorem, calculate the angle of the bevel edge, that is, the screen size.
WindowManager manager = (WindowManager) context.getsystemservice (context.window_service);D isplaymetrics Displaysmetrics = new Displaymetrics (); Manager.getdefaultdisplay (). Getmetrics (Displaysmetrics); Point point = new Point (), Manager.getdefaultdisplay (). Getrealsize (point);D isplaymetrics dm = context.getresources (). Getdisplaymetrics ();d ouble x = Math.pow (point.x/dm.xdpi, 2);d ouble y = Math.pow (point.y/dm.ydpi, 2);d ouble ScreenInche s = math.sqrt (x + y);
Note: Here Displaymetrics do not use Context.getapplicationcontext (). Getresources (). Getdisplaymetrics () to get.
As mentioned above, DPI is written to the device from the factory, if the DPI value is not accurate, of course, does not calculate the exact screen size. That's why there's no screen size in the league stats, so the calculated screen size is only a reference.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Why Android doesn't calculate the exact screen size, and Android gets screen physical size, density, and resolution