How to get the Android device screen size from the adb command line?

前端 未结 9 1980
故里飘歌
故里飘歌 2020-12-07 10:37

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

相关标签:
9条回答
  • 2020-12-07 11:13

    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

    0 讨论(0)
  • 2020-12-07 11:13

    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.

    0 讨论(0)
  • 2020-12-07 11:16
    ANDROID:/ # dumpsys window | grep  mGlobalConfiguration                                                                                                                                                
    mGlobalConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw720dp w1920dp h532dp 160dpi
    

    So resolution is 1920x720

    0 讨论(0)
提交回复
热议问题