Search code examples
androidmobiletabletlandscapelandscape-portrait

Android Tablet Landscape and Portrait Modes


I want to extend my mobile app to Android Tablet as well. My mobile app supports only Portrait mode in mobile but in Tablet I want to support both Landscape and Portrait modes.

But I don't want to change modes at runtime.

For Ex. If the user opens the app with his Tablet in Landscape mode, the app should run only in Landscape mode even if he rotates to Portrait while using the app.

This is possible in iPad but I don't know if it is possible in Android Tablet.

If it is possible how do I do it?


Solution

  • Is not a orthodox way, but you can achieve it like this, create 2 resource files one generic and one for sw600dp (tablet) and add a bool "istablet"

    enter image description here

    Then in your activity OnCreate method

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!getResources().getBoolean(R.bool.is_tablet)) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }