How to get the Android device screen size from the

2019-01-16 05:51发布

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 ?

标签: android adb
8条回答
仙女界的扛把子
2楼-- · 2019-01-16 06:32

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]

The following command will give you 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
查看更多
Viruses.
3楼-- · 2019-01-16 06:32
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

查看更多
等我变得足够好
4楼-- · 2019-01-16 06:35

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.

查看更多
我命由我不由天
5楼-- · 2019-01-16 06:35

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.

查看更多
Bombasti
6楼-- · 2019-01-16 06:38

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

查看更多
孤傲高冷的网名
7楼-- · 2019-01-16 06:38

Work is Good:

dumpsys window | grep Display

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

查看更多
登录 后发表回答