1
    int currentOrientation = getResources().getConfiguration().orientation;
    if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
       getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
    }
    else {
       getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }

when i am rotating the mobile , my content is also rotating.In landscape and portrait i want same screen only.in the same way i want screen rotation in tablet.

m.v.n.kalyani
  • 760
  • 7
  • 20
  • 2
    Is [this](http://stackoverflow.com/questions/9279111/determine-if-the-device-is-a-smartphone-or-tablet) what you want? – Marius Jul 07 '14 at 12:59

1 Answers1

0

To detect whether app is running on phone or tablet, refer to this approach https://stackoverflow.com/a/9308284/923820 as Marius suggested.

Then, put this code in those Fragments which you want to prevent from orientation change:

@Override
public void onResume() {
    super.onResume();
    if (!tabletSize)
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

This would lock your screen in portrait mode when your app is running on phones. Change to ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE if you want to lock it in landscape mode instead.

Community
  • 1
  • 1
Alex Dmitriev
  • 3,664
  • 3
  • 29
  • 35