2

I have an android application that could be installed on a phone or a tablet. However the app is not fully compatible with tablet design-wise, so it's more convenient to use it with "zoom to fill screen" mode.

In a certain process I need to report about whether the device is a tablet or not. I've been using the method from this question. (saving a config value in the values-sw600dp and values-xlarge folders)

BUT, when using "zoom to fill screen" mode, it's not working. The value that's being fetched is the default one from values, and not the one stored at the "tablet-related" folders.

I also tried to retrieving the screen layout using getConfiguration().screenLayout, and in this case I'm getting SCREENLAYOUT_SIZE_NORMAL instead of SCREENLAYOUT_SIZE_XLARGE that is being retrieved when using the other mode -"stretch to fill screen".

Is there a way to know that the device running the application is a tablet even if in "zoom to fill screen" mode?

Community
  • 1
  • 1
Shlomi
  • 343
  • 5
  • 23

1 Answers1

0

This works fine for me in normal mode. Pl check it if it works in zoom to fill mode.

 private static boolean isTabletDevice(Context activityContext) {

            DisplayMetrics metrics = new DisplayMetrics();
            Activity activity = (Activity) activityContext;
            activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

            if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                    || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                    || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                    || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                    || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
                AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-True");
                return true;

        }
        AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-False");
        return false;
    }

You can also check with screen sizes of device and calcualte the size of the screen(may be diagonal) and if it's greater than 7 inch or something its a tablet:

int width = activityContext.getResources().getDisplayMetrics().widthPixels;
int height = activityContext.getResources().getDisplayMetrics().heightPixels;
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
  • As for the first method, I don't get it, what makes the if statement valid for separating tablet from other device if all densities are included in the statement? doesn't a mobile device also relevant for these densities? As for the second method - this will actually return different results when in regular mode and in "zoom to fill screen" mode. e.g. regular will return 800 pixel width, "zoom to fill.." will return 320 pixel width, so it's still impossible to understand it's tablet. – Shlomi Jan 21 '14 at 10:28