How Android Gets the screen size

Source: Internet
Author: User
Tags deprecated

/** Obtain the window manager and default display, which we'll use to * find out the size of the Devi Ce ' s display (in pixels)*/WindowManager WindowManager=(WindowManager) Getsystemservice (Context.window_service); Display Display=Windowmanager.getdefaultdisplay (); /*Obtain the API level of the device running the game*/        intAPI =Android.os.Build.VERSION.SDK_INT; /** we ' re dealing with deprecated methods, so We filter older devices * (less than API.) to use the O         Lder methods, while the new API levels * would use the non-deprecated methods on Ord to obtain the device ' s * Display size*/        if(API >= 13) { point point=NewPoint (); /*Pass The display size to the point object*/display.getsize (point); /** Pass the device ' s display size to our width/height variables to * capture*/Mdisplaywidth=Point.x; Mdisplayheight=Point.y; } Else {            /** If API level was less than, revert to using the deprecated * methods used for grabbing th E device ' s display size*/Mdisplaywidth=display.getwidth (); Mdisplayheight=display.getheight (); }

Android 13 previously used mdisplaywidth = Display.getwidth (); Mdisplayheight = Display.getheight ();

Android 13 is not recommended to take the screen size after the start, it is recommended to use Display.getsize (point);

How Android Gets the screen size

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.