Search code examples
androidrotationlandscape

Can I detect both landscapes in android?


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.


Solution

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