Rob - 9 months ago 241

Bash Question

I need to find out device-width to keep track the set the different actions based on different width of every device, which is further used to write a script to automate the process. Through my research I get to find out using certain commands like-

`$ adb shell wm size`

Output-Physical size: 720x1280

adb shell wm density

Output-Physical density: 320

Curious to know, if there is any other better way of doing this?

Answer

You can write the following function to get the diagonal display size in inch using the information you have-

```
def find_display_size(d):
width=float(720);
height=float(1280);
dens=float(294);
wi=float(width)/(dens);
hi=float(height)/(dens);
x = math.pow(wi,2);
y = math.pow(hi,2);
screenInches = math.sqrt(x+y);
```

That is the best possible way I can think of and open to know the more correct way, if anybody has.

Also you can refer this-