-1

I'm checking the size of the device and if it's not tablet I'll set orientation to portrait so I can't set orientation at Manifest. I'm checking the size and orientation at each Activity like this:

if(Services.isMobile()){
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

But it has two problems 1.I have to do like so an all activities (and there is a lot of them) 2.It doesn't work for Fragments.

Ali Aqa
  • 31
  • 1
  • 7

3 Answers3

0

You should add android:screenOrientation attribute to <activity> declaration in your manifest. For more details on what values the attribute accepts, see documentation

Alexander Zhak
  • 8,751
  • 4
  • 38
  • 65
0

You must declare it in the manifest file of every activity like android:screenOrientation="portrait"

Or you can create a base class and make it abstract StackOverflow portrait mode only

Community
  • 1
  • 1
marcel
  • 295
  • 3
  • 10
0

You can perform that programmatically :

You should test in all activities, or create a class and implement it in every activities.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Use it in FragmentActivity & it will work on fragments. Just be sure to have a correct layout

Sidd
  • 172
  • 9