How to get Android ppi?

I need to get the ppi for my android device so that I can display the same size picture on the different screen. For example, the same picture displayed on the ppi screen is 0.32mm.

The current official document,


The test results are different from the actual results.

The test method is to measure the distance of 3cm horizontally and vertically, so as to obtain the number of pixels of 3cm horizontally and vertically, and finally calculate ppi.

If the number of pixels 3cm across and 3cm up and down is 558, the ppi can be calculated by 558 squared +558 squared =A, and then the square root of the value A is to obtain the value B, and finally the corresponding ppi can be calculated.

I believe that what I measured is the correct value. After verification, I found that using the measured value can also display pictures with the same visual size on the different screen.

My question is, is there a better way to get this ppi than by measuring it with a ruler?

(我需要获取android设备的ppi,以便能在不通屏幕上显示图片的相同大小。 比如,同一个图片在不通的ppi屏幕上显示的大小都是0.32mm。





假如横竖3cm的像素数都是558,则计算ppi的方式是 558的平方+558的平方=A,然后对值A开平方得B值,最后算出对应的ppi。



@JuliusM please help me.