0

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).

AndyAndroid
  • 4,039
  • 14
  • 44
  • 71

1 Answers1

0

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.

Community
  • 1
  • 1
Ranjit
  • 5,130
  • 3
  • 30
  • 66
  • thanks for the reply. Let me try to be a bit clearer. The main question was how to lock the screen. Do I have to do that in code (I think I know the code for this) or is there a way to do it in the manifest that I don't have to do it in code? (This I wouldn't know how to do, but is what I prefer even for the complete app not only single activities, but I can do it simply for all activites as well) – AndyAndroid Jan 31 '14 at 21:59
  • why not you create a class by extend the Application and do everything for total application what you want.i think for this you have to customize your manifest a little. – Ranjit Jan 31 '14 at 23:00