获得当前activity的屏幕方向

WindowManager mgr = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE));

int lastOrientation = mgr.getDefaultDisplay().getRotation();

activity.setRequestedOrientation(lastOrientation);

原文地址:https://www.cnblogs.com/chenlong-50954265/p/3924548.html