11

As we can get the resolution in android, but how can we know the density of the device (screen) ?

thanks

matdev
  • 4,115
  • 6
  • 35
  • 56
Hitendra
  • 3,218
  • 7
  • 45
  • 74

1 Answers1

27

Execute the following code:

float scale = getApplicationContext().getResources().getDisplayMetrics().density;

and check the value of scale:

  • 0.75 means low density
  • 1.0 means standard (medium) density
  • 1.5 means high (large) density
  • 2.0 means extra high density
  • 3.0 means extra extra high density
  • 4.0 means extra extra extra high density

See the documentation for more info.

Yirkha
  • 12,737
  • 5
  • 38
  • 53
chikka.anddev
  • 9,569
  • 7
  • 38
  • 46
  • hi chirag if possible pls see the post http://stackoverflow.com/questions/4758278/redraw-image-on-canvas-on-touch-event – Hitendra Jan 22 '11 at 05:04
  • today there is also tvdpi and xhdpi . probably more to come in the future. more information here: http://developer.android.com/reference/android/util/DisplayMetrics.html – android developer May 19 '13 at 15:11