How to detect exact orientation of device in Froyo?

后端 未结 5 1786
执念已碎
执念已碎 2021-01-15 05:18

I\'m trying to temporarily lock the orientation of the Android device, where most of the time it changes with the sensor. So what I want to do is figure out what the current

5条回答
  •  终归单人心
    2021-01-15 06:22

    I am not sure if the constant is the issue that was no implemented on that API. Have you tried something like this?

     switch (((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getRotation()) {
        case Surface.ROTATION_90: 
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
            break;
        case Surface.ROTATION_180: 
            setRequestedOrientation(9); /* ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT */
            break;          
        case Surface.ROTATION_270: 
            setRequestedOrientation(8); /* ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE */
            break;
        default : 
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
        }
    

提交回复
热议问题