/** 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