3

When rotating an Android device into Landscape mode, it can be in 2 different positions, from the device's perspective, the bottom buttons could be either on the left or on the right. Is there a way to differentiate between these 2 modes? Either via onConfigurationChanged or via View.onSizeChanged I get the same result (obviously) as the device is on Landscape and the resolution is the same (800x480 in my case) for both "modes".

Thanks

IncrediApp
  • 10,303
  • 2
  • 33
  • 24

1 Answers1

8

This will get the screen orientation:

    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int orientation = display.getRotation();

Then you can check it like this:

   if(orientation == Surface.ROTATION_90) {
      // do something
   } else if (orientation == Surface.ROTATION_270) {
      // do something else
   }
Martyn
  • 16,432
  • 24
  • 71
  • 104
  • 1
    Important note that I've just discovered: display.getRotation() is only available on API versions 8 and up... For earlier version of the SDK use display.getOrientation() – IncrediApp Aug 23 '11 at 07:21