1

I want to lock my screen orientation for Android tabs and for handsets too. I want to lock my phone screen orientation as Portrait and tabs screen orientation as Landscape.

When i searched the solution for the same,then I got the solution as in manifest file,.But If i will use it,then it work for both the same,but my requirement is to use different orientation for different device..Suggest me something..

Kanika
  • 10,648
  • 18
  • 61
  • 81
  • Activity.setRequestedOrientation – slkorolev Oct 17 '11 at 05:52
  • I think this might help: http://stackoverflow.com/questions/3611457/android-temporarily-disable-orientation-changes-in-an-activity – goto10 Oct 17 '11 at 05:53
  • I think that doesnot work for me as that link was to stop the activity to restart again when the user rotate the phone – Kanika Oct 17 '11 at 05:58
  • http://stackoverflow.com/questions/7511330/how-to-detect-a-tablet-device-in-android/7511399#7511399 should help you. Good luck. – 500865 Oct 17 '11 at 06:06

1 Answers1

1

One each Activity you can take one check to know device type. In my app, I have used screen resolution as check; as tablets are having much more resolution than mobile devices:

        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int height_pixel = dm.heightPixels;
        int width_pixel = dm.widthPixels;

After this you can take resolution bounds to set orientation for mobile and tablets. like

 if((height_pixel*width_pixel)>***your_resolution_check***){
      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else{
      this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

This works fine for me.

Balaji Khadake
  • 3,449
  • 4
  • 24
  • 38