0

I have been developing an audits app and want one of my screens not to rotate using the sensors. I don't want to change the manifest but want to do this by using java any help would be appreciated.

2 Answers2

2

To Make your application run only in portrait mode:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

To Make your application run only in landscape mode:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Note: Use it before setContentView method.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
0

Use one of the following to restrict to specific orientation:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // for portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);  // for landscape
Qasim
  • 5,181
  • 4
  • 30
  • 51