Android Screen Capture Using ADB

Objective: Take a screenshot of an Android device display using adb shell.

To take a screenshot of an Android device display, we will need to use the screencap utility. This does not require root access. Screenshots are saved in PNG format.

Connect your Android device to the computer with a USB cable. Make sure that USB debugging is enabled on the device and run adb using the following syntax.

The screenshot will be saved to /sdcard/screen.png. Note that if there’s already an existing file, it will be overwritten. If you would like to save the output file with another extension other than .png, then you will need to pass the -p option to screencap.

To pull the file from your Android device to your computer, use the adb pull command.

Once the file has been transferred to your computer, you can delete the file from your Android device.

If you would like the screenshot file to be written directly to your computer, then we can tell screencap to write the output to stdout instead. But there’s a small problem. Apparently, when writing the screenshot data to stdout, adb shell converts 0x0a (linefeed) to 0x0d0a (carriage return, linefeed) – this will corrupt the output screenshot file.

The solution is to use sed to undo the conversion.

Another option is to use uuencode and uudecode.

Alternatively, you can also use base64 instead of uuencode/uudecode.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }