0

I am using different code for Mobile and Tablets. Using the following code to check for mobile or tablet:

final float scale = context.getResources().getDisplayMetrics().density;
        final float deviceWidth;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            deviceWidth = context.getResources().getDisplayMetrics().widthPixels / scale;
        } else {
            deviceWidth = (context.getResources().getDisplayMetrics().heightPixels / scale);
        }
        return deviceWidth >= 600;

I am using Huawei AGS Q09 - 10" tablet, which is 157 ppi density (MDPI device) It should be detected as tablet. But it gives 1.5 as device density (which is HDPI), Is there any possibilities for this changes?

P Fuster
  • 2,224
  • 1
  • 20
  • 30

1 Answers1

1

If you switch on the developer options in the settings, you can at least change the minimum width in the display section, which will make it call different code if you are using the minimum width as the target.

Read these Android Docs to target different minimum widths properly to support mobile and tablet versions of your screens.

P Fuster
  • 2,224
  • 1
  • 20
  • 30