84

I need a way to detect device screen size and density with adb. If there is no solution, where can I get the complete list of all existing android device with their screen size and density ?

1
  • If using Appium, you can use Dimension windowSize = driver.manage().window().getSize();. Jun 24, 2021 at 21:02

9 Answers 9

129

You can also access the WindowManager through ADB:

$ adb shell wm
usage: wm [subcommand] [options]
       wm size [reset|WxH]
       wm density [reset|DENSITY]
       wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM]

To get the screen resolution:

$ adb shell wm size
Physical size: 2880x1600

To get the screen the density:

$ adb shell wm density
Physical density: 320

You can also override the density by adding the new density:

$ adb shell wm density 160
41

LCD density is in the build.prop:

adb shell getprop ro.sf.lcd_density

And the resolution is availble in the dumpsys of the input activity:

# windows
adb shell dumpsys window | find "DisplayWidth"
# linux
adb shell dumpsys window | grep DisplayWidth

It works on all the devices I've tested with (2.2, 2.3.3, 2.3.4, 4.0.3; Acer Liquid E, HTC Wildfire S, HTC Incredible S, Motorola Atrix 4G, Samsung Galaxy Note, Samsung Galaxy Nexus), as well as the emulator, although the emulator's outputs are too clean to serve as a good example for parsing.

3
  • There is also the min/max range of valid input coordinates for the event handlers that you can get using getevent -p. This is relevant in the cases where some of the touch input device is under the bezel, so the usable-minimum actually starts at some value greater than 0.
    – Nisan.H
    Mar 16, 2012 at 16:49
  • 1
    ro.sf.lcd_density doesn’t work for two devices I tried (GT-P7510 and Dell Streak), and works for 5 others (GT-P1000, Galaxy Nexus, MotoA953, DROID2 GLOBAL, Xoom)
    – stansult
    Jun 18, 2013 at 20:31
  • 12
    If the above commands not working , try the command adb shell dumpsys window | find "mUnrestrictedScreen"
    – Vins
    Dec 11, 2013 at 11:15
27

Using dumpsys

dumpsys window displays

shows something like this:

Display: mDisplayId=0
  init=1080x1920 480dpi cur=1080x1920 app=1080x1920 rng=1080x1005-1920x1845
  layoutNeeded=false

another way:

dumpsys display

also shows some interesting stuff like:

mDefaultViewport=DisplayViewport{valid=true, displayId=0, orientation=0, logicalFrame=Rect(0, 0 - 1080, 1920), physicalFrame=Rect(0, 0 - 1080, 1920), deviceWidth=1080, deviceHeight=1920}

and last but not least:

dumpsys power

will display something like

Electron Beam State:
  mPrepared=false
  mMode=2
  mDisplayLayerStack=0
  mDisplayWidth=1080
  mDisplayHeight=1920
  mSurfaceVisible=false
  mSurfaceAlpha=0.0

that you could easily use to grep for mDisplayWidth and mDisplayHeight

14

To get required info from ADB, the following command executed from the command line will return a lot of useful properties about the connected devices

> adb shell getprop

To filter through these properties

on Unix use grep like

> adb shell getprop | grep density

on Windows use find like

> adb shell getprop | findstr "density"

Returned value looks like

[ro.sf.lcd_density]: [240]

for screen size put display instead of density

5
  • 1
    and screen size doesn't appear
    – user954469
    Sep 23, 2011 at 10:52
  • for screen size put display instead of density Sep 23, 2011 at 11:15
  • Motorola Xoom, for example, doesn't show display informations
    – user954469
    Sep 23, 2011 at 12:06
  • yeah I know, it's not for all devices. Sep 23, 2011 at 12:17
  • Is density the same as screen width? Apr 8, 2019 at 14:25
2
ANDROID:/ # dumpsys window | grep mGlobalConfiguration                                                                                                                                                
mGlobalConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw720dp w1920dp h532dp 160dpi

So resolution is 1920x720

1

Work is Good:

dumpsys window | grep Display

return: Display: init=320x480 cur=320x480 app=320x480 rng=320x295-480x455

0

You can get screen dimensions with this code:

public int getScreenHeight() {
    return getDisplay().getHeight();
}

private Display getDisplay() {
    return ((WindowManager) getContext().getSystemService(
            Context.WINDOW_SERVICE)).getDefaultDisplay();
}


public int getScreenWidth() {
    return getDisplay().getWidth();
}

Once you have the Display in the code above you can use DisplayMetrics to get the density. DisplayMetrics will also give you absolute display with and height.

1
  • I can't launch any application on devices.
    – user954469
    Sep 23, 2011 at 10:50
-1

Look at the output of adb shell dumpsys. The screen size shows up there several times, along with lots of other information.

... although now I'm in the office, while it works on my phone, it's absent from the Galaxy tablet. Darn.

-2

If you need to get the current status of range of Android device available in the market with it Screen Sizes and Densities Click here

This data is based on the number of Android devices that have accessed Android Market within a 7-day period ending on the data collection date

1
  • I need to get the screen size for particular device not all existing sizes.
    – user954469
    Sep 23, 2011 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.