0

When you start an android application, the operating system detects the screen resolution and uses the graphics included in the folder mdpi, hdpi, xhdpi or xxhdpi.

My question is: is there any way to know which folder to use android?

for example, would be perfect if I could get a variable that indicates the value "mdpi" or "xxhdpi" ...

I searched but I always find ways to get the resolution, and I want to be sure which is the folder "res" that will use Android.

Thank you very much in advance

Sergio76
  • 3,835
  • 16
  • 61
  • 88

2 Answers2

0

Try this method hope this helps you

private String getTheDeviceType(Context mContext) {
        try {
            switch (mContext.getResources().getDisplayMetrics().densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                return "ldpi";
            case DisplayMetrics.DENSITY_MEDIUM:
                return "mdpi";
            case DisplayMetrics.DENSITY_HIGH:
                return "hdpi";
            case DisplayMetrics.DENSITY_XHIGH:
                return "xhdpi";
            case DisplayMetrics.DENSITY_XXHIGH:
                return "xxhdpi";
            }

        } catch (Throwable e) {
        }
        return "";
    }
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
0

try this

switch (getResources().getDisplayMetrics().densityDpi) {
  case DisplayMetrics.DENSITY_LOW:
  // ...
  break;
   case DisplayMetrics.DENSITY_MEDIUM:
 // ...
break;
  case DisplayMetrics.DENSITY_HIGH:
// ...
break;
  case DisplayMetrics.DENSITY_XHIGH:
// ...
break;
 }

and also refer this. How to check an Android device is HDPI screen or MDPI screen?

Community
  • 1
  • 1
Invader
  • 679
  • 3
  • 10