private void GetSystemInfo () { //The first way to get the pixel width of the screen is to use //displaymetrics metric = new in activity Displaymetrics (); Activity.getwindowmanager (). Getdefaultdisplay (). Getmetrics (metric); The second way to get the pixel width of the screen is high //Get the pixel height of the screen pix screenheight = getresources (). Getdisplaymetrics (). Heightpixels; Gets the pixel width of the screen pix screenwidth = getresources (). Getdisplaymetrics (). widthpixels; }
Private voidGetSystemInfo () {//requires contextDisplaymetrics metric =NewDisplaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Metric); //the first way to get pixel density intwidth = metric.widthpixels;//width (PX) intHeight = metric.heightpixels;//height (PX)LOG.E ("++mylog++widthpixels", "" "+width); LOG.E ("++mylog++heightpixels", "" "+height); floatdensity = metric.density;//density (0.75/1.0/1.5) intdensitydpi = metric.densitydpi;//density dpi (120/160/240)LOG.E ("++mylog++density", "" "+density); LOG.E ("++mylog++densitydpi", "" "+densitydpi); //the second way to get pixel density getresources () intheight1 = Getresources (). Getdisplaymetrics (). Heightpixels;//width (PX) intWidth1 = Getresources (). Getdisplaymetrics (). Widthpixels;//height (PX)LOG.E ("++mylog++width1", "" "+width1); LOG.E ("++mylog++height1", "" "+height1); floatDensity1 =getresources (). Getdisplaymetrics (). density; intDENSITYDPI1 =getresources (). Getdisplaymetrics (). densitydpi; LOG.E ("++mylog++density1", "" "+density1); LOG.E ("++mylog++densitydpi1", "" "+densityDpi1); floatScaledDensity1 =getresources (). Getdisplaymetrics (). scaleddensity; LOG.E ("++mylog++scaleddensity1", "" "+scaledDensity1); //pixel density x/ydpi//physical pixels per inch of the screen in the Y dimension floatXDPI1 =getresources (). Getdisplaymetrics (). xdpi; floatYDPI1 =getresources (). Getdisplaymetrics (). ydpi; LOG.E ("++mylog++xdpi1", "" "+xdpi1); LOG.E ("++mylog++ydpi1", "" "+ydpi1); }
How to get screen width/resolution related information on Android