2

I have created a function to calculate diagonal screen size based on the resolution and pixel density. viz-

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);
  diagScreenSizeRoundedoff = round(screenInches)
  logger.info("screenInches "+str(screenInches),also_console=True)
  logger.info("diagScreenSizeRoundedoff"+str(diagScreenSizeRoundedoff),also_console=True)

I want to fetch the information (resolution & pixel density) using adb shell. When I am trying this command-

$adb shell wm density

Result-
Physical density: 320

The result I am getting is the physical density of a device(=320), however the pixel density of the particular device is (~294). Curious to know what exactly is the difference between these two, also how I can find the pixel density using adb commands which is ~294 in this case.

PS- The device I am working on is- MOTO XT1068

Rajeev Dixit
  • 1,533
  • 2
  • 16
  • 25
  • I don't believe there is a way to get the actual physical density consistently. See the comments in: http://stackoverflow.com/questions/2193457/is-there-a-way-to-determine-android-physical-screen-height-in-cm-or-inches – Morrison Chang May 17 '16 at 05:51
  • There's actually a way. Check it here- http://kingscalculator.com/en/other-calculators/pixel-density-calculator. But in my case I need to calculate, diagonal screen size, which in turn requires pixel density. – Rajeev Dixit May 17 '16 at 06:15

1 Answers1

2

Android is fitting your device to one of group mdpi, hdpi, xhdpi etc. which have fixed density set. e.g. devices with 290-340 dpi will use 320 value, xxhdpi will be 480, mdpi only 160. This density is used for fetching data from resources (dimens, for calculating xml drawables, resizing drawable when is only in mhdpi folder, but device is xxdpi etc.) More densities and about topic in HERE

Screen density

The quantity of pixels within a physical area of the screen; usually referred to as dpi (dots per inch). For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen.

For simplicity, Android groups all actual screen densities into six generalized densities: low, medium, high, extra-high, extra-extra-high, and extra-extra-extra-high.

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • That's correct, also I am aware of these conventions, but still that doesn't answer my question (how exactly physical density is different from pixel density and how can I find the pixel density density of my device which is based on the resolution of the device) – Rajeev Dixit May 17 '16 at 05:32
  • pixels are physical unit, so I'm assuming pixel density = physical density. If you mean that mentioned in example 320 density is physical (adb tells you...) - its not. This value is set by system using matching to density group folders. 294 you have calculated is physical and pixel at the same time, 320 is grouped value for OS usage – snachmsm May 17 '16 at 05:34
  • Makes sense, but is there any way to find out the exact pixel density of the device using adb commands, as we are able to get all the properties of the device by saying 'get-prop' but there it doesn't say anything about pixel density. – Rajeev Dixit May 17 '16 at 05:38
  • 1
    They actually are the generalized densities, and the adb is putting it into xhdpi, (which is correct). But there should be a way to find out the pixel density based on the resolution of the device. – Rajeev Dixit May 17 '16 at 05:42
  • I don't know about any needed command for adb (real density or physical size in mm/cm/inch for calculating by own), I've even downloaded once some application (Windows, for device managing) from XDA in which I had to enter my device screen params, and author had some "respect" from xda community, so assuming it's not possible (otherwise it would be done and prog wouldn't yeld for manual config)... but wish you luck in searching, leave here proper answer if find :) – snachmsm May 17 '16 at 06:20