Problem:
How do I use adb to get a screenshot from an Android device or emulator?
I'd like to target a specific device when more than one are connected to adb.
I already know how to open adb shell and put a device in debugging mode.
Solution:
One method is the following:
-
Get list of devices:
adb devices -l
You should get a list that looks like:
-
Once you have a device identifier, such as "emulator-5554", you can use similar commands as below. (Replace "emulator-5554" with your device identifier).
adb -s emulator-5554 shell screencap -p /sdcard/screencap.png adb -s emulator-5554 pull /sdcard/screencap.png
-
(Optional) remove the last screencap from your device (in this example, named "emulator-5554"):
adb -s emulator-5554 shell rm /sdcard/screencap.png
Other notes:
If you've only got one device accessible to adb, you can simply do the following:
adb shell screencap -p /sdcard/screencap.png
adb pull /sdcard/screencap.png
adb shell rm /sdcard/screencap.png
If you'd like to see a one-liner to do the above, check out the neat example here: http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
References:
- https://developer.android.com/studio/command-line/adb.html
- For an elegant one-liner of the above, check out: http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
No comments:
Post a Comment