How to find dimension of a device in DPs via ADB

890 Views Asked by At

I got dimensions of a device using -

adb shell wm size

other ways to get it, -

adb shell dumpsys display | grep mBaseDisplayInfo

But I am not able to find device's resolution in DPs. (which should be 360x480)

In android code , we can do it using -

DisplayMetrics displayMetrics = resources.getDisplayMetrics(); 
float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density;

Now here I have width in Pixels from ADB, but can't get this density using ADB. There is a method to get density through ADB -

adb shell wm density

but that give results such as 480 420, so it is different density than the one we got by displayMetrics.density (which is a single digit number ie 2, 3 or 2.65).

Any idea how can I get device's dimensions in DPs or displayMetrics.density using ADB?

0

There are 0 best solutions below