12

how can it so that when a tablet is running the application, it is forced to run it in landscape and when a phone is running the application, it is forced to run it in portrait? I've managed to force it to run in lets say portrait, but then it run portrait for tablets too... Portrait mode in tablets is ugly :( Thanks

Alexandre Hitchcox
  • 2,704
  • 5
  • 22
  • 33

2 Answers2

10

Here is my suggestion: First try to determine the type of device using screen dimensions. You could refer to this post. On the second step you can change the screen orientation using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);. There is another post here.

Community
  • 1
  • 1
Jermin Bazazian
  • 1,932
  • 2
  • 17
  • 20
2

Just set nosensor parameter for activity in manifest:

    <activity
        android:name=".activity.MyActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" 
        android:screenOrientation="nosensor">

By the way, some tablets may be detected as phones, for example Nexus 7.

Alex Kucherenko
  • 20,168
  • 2
  • 26
  • 33