I was wanting to take screenshots the other day from an emulator, and like a phone its definitely not easy to press the volume down button and the power button both together (it is a different thing, that i crazily tried to do πŸ˜”, but had no luck, πŸ˜‚

So here, i am just posting something i found on StackOverflow, just so that it is handy in times of need. (I am sure most of you might agree that it does take a while to search for something you found useful, just to realise that the link is lost in an ocean of tabs or you just can’t simply track it. That’s a hard feeling, by the way)

Steps:

  1. Type adb shell in the terminal or adb -s {emulator-name-here-minus-curly-braces} shell
  2. Enter in the following as is, and you would be good to go (observe the emulator for the screenshot icon πŸ˜‰ )
cat > /data/local/tmp/screenshot.sh <<EOF
#!/bin/sh
echo 'volume key: down'
sendevent /dev/input/event1 1 114 1
echo 'power key: down'
sendevent /dev/input/event1 1 116 1
sendevent /dev/input/event1 0 0 0
sleep 1
echo 'volume key: up'
sendevent /dev/input/event1 1 114 0
echo 'power key: up'
sendevent /dev/input/event1 1 116 0
sendevent /dev/input/event1 0 0 0
EOF
sh /data/local/tmp/screenshot.sh

Of course, there are other ways suggested, like:

  1. Taking a screenshot via the camera icon from the emulator side bar.
  2. Capturing screen via Android Studio Logcat

But these options, do not literally capture the screenshot on the device, but just take a screen capture of the current state of the emulator and save it on the desktop.

The choice is yours, as to what kind of “screenshot” you actually want.

Happy coding πŸ˜€

Courtesy: StackOverflow user wrkwrk
StackOverflow Answer here

Advertisements