Python Get Android Phone Screen Size Using ADB – ADB Tutorial

By | October 13, 2020

In this tutorial, we will introduce adb beginners how to get android phone screen size, which is very helpful to when you are control phone.

We will use python to call adb command to get android phone screen size.

Here is an example:

import subprocess
import os
import re

def get_screen_size():
    process = os.popen('adb shell wm size')
    output = process.read()
    m = re.search(r'(\d+)x(\d+)', output)
    if m:
        #(w,h)
        return int(m.group(1)), int(m.group(2))
    return None

size = get_screen_size()
print(size)

Run this code, you may get the size:

(1080, 1920)

1080 is the width and 1920 is the height.

They are physical size of android phone.

Physical size: 1080x1920
Category: ADB

Leave a Reply

Your email address will not be published. Required fields are marked *