[Android] How to disable the screen orientation?

Below utility are got from the web:

    private static int _oldScreenOrientation;
    public static void disableScreenOrientation() {
        _oldScreenOrientation = activity.getRequestedOrientation();
        
        if(isLandscape())
            activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        else
            activity.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    
    public static void restoreScreenOrientation() {
        activity.setRequestedOrientation(_oldScreenOrientation);
    }
原文地址:https://www.cnblogs.com/jalenwang/p/2803246.html