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

前端 未结 9 2013
故里飘歌
故里飘歌 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题