1

My app has 3 screens, and all of them must be portrait-only in smartphones and both orientation for tablets.

Unitl now I was using the following code in OnCreate:

if (!getResources().getBoolean(R.bool.isTablet)) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

However if I hold the smartphone in landscape mode and launch the application it will show in landscape for a few seconds then rotate to portrait.

Many answers here suggest locking orientation via manifest, but that would lock the orientation in tablets, which is not desired.

I would be very grateful for any information that leads me to a solution. Thanks.

Saito Mea
  • 455
  • 4
  • 11

1 Answers1

2

You could lock it in the Manifest and then unlock it in code if it's a tablet.

It may not matter for your case, but I've read that the Nexus 7 doesn't report itself as a tablet using the method you do. I'm not sure that's accurate though, never having tried it myself.

Khantahr
  • 8,156
  • 4
  • 37
  • 60
  • What exactly would I do to unlock in code? `setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)`? Because I think it would create the reverse effect in tablets, they would load as portrait then rotate to landscape. BTW, for detecting if the device is a tablet I am checking for screen size, large devices and above set a boolean resource `isTablet` to true. – Saito Mea Oct 26 '12 at 15:23
  • 1
    Oh I thought you were using some built-in boolean that I've heard rumors about. It may cause the reverse effect in tablets, I can't think of any other way to do it though. You could have a splash screen when your app starts, figure out the orientation requirements while that's displayed, and then move into the real app once it's figured out. – Khantahr Oct 26 '12 at 16:38
  • One of the screens is the splash screen already, where the issue happens. – Saito Mea Oct 26 '12 at 17:19