I tried the one liner solution to capture screenshot via adb and the file is created successfully on PC but it is unreadable:
C:\Program Files\Android\android-sdk\platform-tools>adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > c:\users\utilisateur\desktop\android_screenshot1.png
The file seem to be correct but I think the Magic is not correct:
EDIT: The same issue happened with Git Bash for Windows.
Press the Power and Volume down buttons at the same time. If that doesn't work, press and hold the Power button for a few seconds. Then tap Screenshot. If neither of these work, go to your phone manufacturer's support site for help.
In this example, we will use subprocess.Popen () to run adb command and get the data of android phone screenshot. Then we will save image data to png file. You should notice: binary_screenshot cotains the screenshot data, the type of it is byte.
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.
adb shell screenrecord /sdcard/example.mp4. This command will start recording your device’s screen using the default settings and save the resulting video to a file at /sdcard/example.mp4 file on your device. When you’re done recording, press Ctrl+C in the Command Prompt window to stop the screen recording.
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.
adb exec-out screencap -p > screen.png
will save it on your machine directly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With