Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Take screenshot with python-adb and save it to a file
import os
from adb import adb_commands
from adb import sign_m2crypto
# Devices running KitKat or later require auth
signer = sign_m2crypto.M2CryptoSigner(
os.path.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands()
device.ConnectDevice(
rsa_keys=[signer])
# Open file with binary writing flags and take screenshot
with open('file.png', 'wb') as file:
conn = device.protocol_handler.Open(
device._handle,
"shell:screencap -p".encode('utf8'),
)
for data in conn.ReadUntilClose():
file.write(data)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.