Skip to content

Instantly share code, notes, and snippets.

@jamezrin
Created September 6, 2018 16:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamezrin/432ebb50b976c400e4481569c371bbbb to your computer and use it in GitHub Desktop.
Save jamezrin/432ebb50b976c400e4481569c371bbbb to your computer and use it in GitHub Desktop.
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