get the width and height of the deviceโs screen, if the resolution is less than that of the tablet, then you can adjust the orientation of the application to the portrait.
If you need display sizes in activity pixels, you can use getSize:
Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y;
If there is no Activity, you can get the default mapping through WINDOW_SERVICE:
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if(width<= (resolution width of tablet) && height<=(resolution height of tablet)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ); }
Do not specify a command in a manifest based
Android: screenOrientation
source share