user1461742
user1461742

Reputation:

Android can i get the device dpi by ppi

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).

Upvotes: 4

Views: 7018

Answers (2)

jayangaVliyanage
jayangaVliyanage

Reputation: 83

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

Upvotes: 2

Jug6ernaut
Jug6ernaut

Reputation: 8325

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.

Upvotes: 1

Related Questions