0
votes

I know that I can set the screen layout to portrait or landscape in my activity's xml tag in the manifest to prevent the screen from rotation.

I have an app which shall run on a phone and on a tablet. On the tablet I want to have landscape and on the phone I want to have portrait mode. How can I do this configuration? (And of course when the device rotates the screen shall not).

1

1 Answers

0
votes

For check whether its a tab or not, you can use this simple method:

public boolean isTablet(Context context){
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}

OR

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

Both are helpful for you.

For more information, check this conversation.