Search code examples
androidscreen-orientationandroid-orientation

Setting different orientations for Phone and Tablet on Android


I would like to do the following in my app:

  • Portrait mode only for the phone
  • Portrait mode and landscape mode for tablets.

I know i can easily change the orientation in the manifest file but that will affect the entire application.

I have also thought of creating separate activities, to handle the different versions but i don't know how to detect the type of device using the application.

Does anyone know how to tackle this?


Solution

  • You can use the following piece of code to differentiate between normal/large screen and block the orientation change accordingly.

    public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }