1

Possible Duplicate:
How to detect landscape left (normal) vs landscape right (reverse) with support for naturally landscape devices?

Is it possible to detect one landscape vs the other landscape when rotating the device?

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    }
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
    {
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

works but I'd like to see if I can determine which side of the phone it is on as I want to display a different layout.

Community
  • 1
  • 1
Ronnie
  • 11,138
  • 21
  • 78
  • 140

1 Answers1

3

You can, for devices running Android 2.2+. Check out this blog post for the details or you can skip to the punchline.

Haphazard
  • 10,900
  • 6
  • 43
  • 55
  • perfect, I am creating for 2.2+, what goes in front of `getRotation()` ? I tried `this.getRotation();` but says that method isn't available for my class – Ronnie May 16 '11 at 17:37
  • 2
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int orientation = display.getRotation(); – Haphazard May 16 '11 at 17:43