Getting device orientation?

I have a camera preview function that is forced to stay in landscape mode.

Is it possible to indicate the current orientation of the phone (rather than the orientation of the screen).

Basically, I want to know if the user supports the phone in portrait mode or in landscape mode, so I can correctly rotate the received captured bitmap (right now it is always displayed in landscape mode).

thank

+3
source share
2 answers
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            p.set("orientation", "portrait");

            ....
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {   
            p.set("orientation", "landscape");
            ....
        } 
+2
source

Application.onConfigurationChanged() SensorEventListener. , .

0

Source: https://habr.com/ru/post/1726030/


All Articles