Get through WindowManager
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
System.out.println ("Heigth:" + dm.heightpixels);
System.out.println ("width:" + dm.widthpixels);
Access through resources
Displaymetrics dm2 = Getresources (). Getdisplaymetrics ();
System.out.println ("heigth2:" + dm2.heightpixels);
System.out.println ("width2:" + dm2.widthpixels);
Get the default resolution of the screen
Display display = Getwindowmanager (). Getdefaultdisplay ();
System.out.println ("Width-display:" + display.getwidth ());
System.out.println ("Heigth-display:" + display.getheight ());
As you can see, the first and third methods use the Getwindowmanager () method, and the second method does not use Getwindowmanager (). Some netizens said that after writing Getwindowmanager () Eclipse will error, said there is no Getwindowmanager () This method, what is the reason? Because the Getwindowmanager () method is in class activity, if you write your own class that does not inherit from the class activity, you must write code in this class without using the Getwindowmanager () method. So when you write your own class that doesn't inherit from the class activity, you can only use the second method to get the size of your phone screen.
How Android Gets the device screen size