//Landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//Portrait
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

//Both
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);