How to know the orientation of the screen?

1

What code that perceives and returns the screen orientation?

If the cell phone is standing or lying down?

    
asked by anonymous 28.06.2016 / 09:36

2 answers

5
Configuration configuration = getResources().getConfiguration();

    if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE){
        //...
    }else{ 
        //...
    }

In this example, it checks if the position of the screen is landscape if not, it can only be in portrait (standing)!

Pretty simple.

    
28.06.2016 / 09:36
1

To check for guidance, just use this code:

getResources().getConfiguration().orientation

There is a return for each type of guidance, which you can check below:

  • ORIENTATION_UNDEFINED = 0
  • ORIENTATION_PORTRAIT = 1
  • ORIENTATION_LANDSCAPE = 2
  • ORIENTATION_SQUARE = 3

Details

16.09.2016 / 22:38