1

I want to write a function like this

public boolean isThisScreenWithHdpiDensity(){
    return true/false;
}

but I do not know how to calculate this at run time programmatic-ally

Lukap
  • 29,596
  • 60
  • 146
  • 239
  • possible duplicate of [getting the screen density programmatically in android?](http://stackoverflow.com/questions/3166501/getting-the-screen-density-programmatically-in-android) – aioobe Feb 08 '12 at 09:54

2 Answers2

8

Use this inside your function:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
switch(metrics.densityDpi){
     case DisplayMetrics.DENSITY_LOW:
                break;
     case DisplayMetrics.DENSITY_MEDIUM:
                 break;
     case DisplayMetrics.DENSITY_HIGH:
                 break;
}
Sandy
  • 6,040
  • 15
  • 64
  • 87
2
      public boolean isThisScreenWithHdpiDensity()
      {         
         DisplayMetrics metrics = new DisplayMetrics();
         getWindowManager().getDefaultDisplay().getMetrics(metrics);

         if(metrics.density == DisplayMetrics.DENSITY_HIGH)
         {
             return true;
         }

         return false;
      }
hp.android
  • 2,834
  • 1
  • 20
  • 19