0

my problem is that emulated in Android Studio Nexus 10 doesn't acts like a phone. I have tried 2 methods to detect is the device a tablet or phone:

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

and the variant from here Determine if the device is a smartphone or tablet? Both doesn't work with nexus 10 while working with nexus 7 and another tablet. May be it is the problem of emulator, I dont know. Help me with this please.

Community
  • 1
  • 1
Max Zavernutiy
  • 1,771
  • 1
  • 18
  • 27

1 Answers1

0

This is the old way of tablet determination. Just to point out what is going wrong, you arent checking if the device is XLARGE (which the n10 is). A more correct version of this outdated way is : (from https://stackoverflow.com/a/9590506/794088)

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

But instead of this, please follow this answer:

https://stackoverflow.com/a/14370196/794088

Community
  • 1
  • 1
petey
  • 16,914
  • 6
  • 65
  • 97