场景是:现在是竖屏,设置屏幕方向为横屏。然后判断是否生效。
方法一(无效)
WindowManager mgr = ((WindowManager)this.getApplicationContext().getSystemService(Context.WINDOW_SERVICE));int lastOrientation = mgr.getDefaultDisplay().getRotation();
方法二(无效)
Configuration mConfiguration = this.getResources().getConfiguration();int lastOrientation = mConfiguration.orientation;
方法三(有效)
OrientationEventListener mScreenOrientationEventListener = new OrientationEventListener(mainActivity) {@Overridepublic void onOrientationChanged(int i) {if(45 <= i && i < 135|| 135 <= i && i < 225) {mOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;} else {mOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;}//mOrientation = ExifInterface.ORIENTATION_ROTATE_90;}};
如果觉得《获取Activity当前屏幕方向。》对你有帮助,请点赞、收藏,并留下你的观点哦!