Created
September 6, 2018 16:48
-
-
Save jamezrin/432ebb50b976c400e4481569c371bbbb to your computer and use it in GitHub Desktop.
Take screenshot with python-adb and save it to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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