The official android documentation suggests using getContext().getResources().getDisplayMetrics().density; to get the density of the device in order to scale images, etc, to a size appropriate to the device being used. This doesn’t seem to work, returning a value of 1.0f on every emulator (and my desire) across all versions. Alas, there’s another place to actually find it.

DisplayMetrics dm = new DisplayMetrics();
mActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);

int pixelHeight = (int) (dipHeight * dm.density);
Advertisements