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,

And https://forum.unity.com/threads/screen-dpi-on-android.414014/

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。

目前官方的文档,

以及https://forum.unity.com/threads/screen-dpi-on-android.414014/

测试出来的结果都跟实际量出来的结果有差异。

测试的方法是测量横竖3cm的距离,从而获取横竖3cm距离的像素数,最后算ppi。

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

我相信我测量出来的才是正确的值,验证后发现用测量的值也能在不通的屏幕上显示相同视觉大小的图片。

我的问题是,有没有更加好的方式来得出这个ppi,而不是通过尺子测量?)

@JuliusM please help me.