0

I want my app to be always displayed landscape on tablets, but it should rotate ok on mobiles. Is there a way to do this (besides of having 2 different apks)?

Frank
  • 2,777
  • 5
  • 18
  • 30

1 Answers1

1

Use a method to check whether the device is a tablet, then force orientation if it's true.

// From https://stackoverflow.com/questions/5832368/tablet-or-phone-android
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);
}

// ...

// Do this from any Activity you do not wish to rotate on tablets:
if (isTablet(this))
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141
  • AFAIK there are devices in which these instructions don't work as expected, they keep on waiting for the views to be setup, etc – Frank Feb 13 '13 at 07:09
  • "Waiting for the views to be set up"? I'm not really sure what you mean. As long as you do this before `setContentView()`, it has no views to wait for. – Cat Feb 13 '13 at 14:36