4

I am developing an app for multiple screen support.

I just visited the wiki Android DeviceDensity Comparison page.

I want to convert ppi to dpi.

for example:

Samsung Galaxy Note has a ppi of 285 (according to the wiki page).

But in the wiki page the data for dpi is not there for every android device.

I want to know how to calculate dpi from ppi.

For example, the Samsung Galaxy Note has a ppi of 285. How do I calculate the density of the Samsung galaxy note device (in dpi).

Nikola K.
  • 7,093
  • 13
  • 31
  • 39

2 Answers2

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

 // Display device width and height in pixels
 screenHeightpx = dm.heightPixels;
 screenWidthpx  = dm.widthPixels;

 // Display device dpi value of X Y in pixels
 screenDPIx = dm.xdpi;
 screenDPIy = dm.ydpi;

I hope this will help you

eboix
  • 5,113
  • 1
  • 27
  • 38
1

IDK about converting ppi to dpi, as pixels-per-inch is a fix value, dpi dots-per-inch on the other hand depends on the screen density. You can how ever calculate dpi based on ppi and screen density. Here are two examples.

http://android-er.blogspot.com/2011/07/get-screen-size-in-dpi.html

getting the screen density programmatically in android?

mainly Jere.Jones answer.

Community
  • 1
  • 1
Jug6ernaut
  • 8,219
  • 2
  • 26
  • 26