How do I determine a device's default orientation?

| | August 11, 2015

I am developing a game with accelerometer controls. This works well on all the mobile phones I’ve tested it on. However, when testing on a tablet, the y and x axes are reversed, presumably because the device’s default orientation is landscape.

How can I identify the default orientation of the device, to set my axes accordingly?

(I’m using Android SDK 1.5 – 1.7.)

One Response to “How do I determine a device's default orientation?”

  1. I figured out the best way to do this is to check the screen size on the device and base a boolean conditional to device on which axis to use. This is tested and working great.

    // Check the screen layout to determine if the device is a tablet.

    public boolean isTablet(Context context) {
        boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
        boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
        return (xlarge || large);

    // Changle Accelx or Accely input based on the above (Im using
    OpenGLES 1.1)

    if (isTablet(glGame)) {
        world.update(deltaTime, game.getInput().getAccelX());
    if (!isTablet(glGame)) {
        world.update(deltaTime, game.getInput().getAccelY());

Leave a Reply