I\'m developing a mobile application based on Android with minSdkVersion=15
. I would like to support both orientations for tablets and only portrait for smartph
I also faced same problem for Android N devices. So to support both orientations for tablets and only portrait for phones I did the following trick:
Set portrait to each activity in Manifest. Looks bad, but in this case screen will not autorotate:
android:screenOrientation="portrait"
In your BaseActivity set:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isTablet(){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
}
protected boolean isTablet() {
return getResources().getBoolean(R.bool.tablet);
}