How to detect my screen orientation in portrait locked screen in android?

前端 未结 3 1901
刺人心
刺人心 2020-12-03 11:50

I want to find the camera screen orientation in locked portrait orientation mode, well I am using camera in my fragment class and I have already set my screen orientation as

3条回答
  •  情书的邮戳
    2020-12-03 12:37

    You gonna have to use:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
    
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            //do your stuff with the button
        }
    }
    

    If you want your activity not to be recreated during orientation then use

    android:configChanges="orientation|keyboardHidden|screenSize"

    If you want your activity to be forced to stay portrait then you gonna have to use

    in your manifest file in the activity you would like just try android:screenOrientation="portrait"

    Hope it helps!!!

提交回复
热议问题