Issue
My app allows the user to take a screenshot which it then sends to the server.
On a real device, the screenshots are saved at /storage/emulated/0/Pictures/Screenshots/
so that is fine.
But on the emulator, when I click the Take screenshot button (which is located in the panel beside the emulator), the screenshot is saved to my computer, but I can't find it anywhere in the emulator's file system - the /storage/emulated/0/Pictures/
directory exists, but the /storage/emulated/0/Pictures/Screenshots/
sub-directory does not.
Is there any way I can access the screenshot image on the emulator, or is there another way of taking the screenshot?
Solution
Emulate Volume Down + Power event to trigger Android's screenshot, then screenshot pictures will be stored at emulator's /storage/emulated/0/Pictures/Screenshots
.
Here is the script. Run adb shell
, then copy the code below and run, you should see the emulator start taking a screenshot.
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
NOTE: My emulator's input device is "/dev/input/event1", this may be different for other devices. You can get the device info by running adb shell getevent
command, then press the emulator's key, the output will be something like this(My Volume Down key, these are hex numbers, so 0x0072 is 114d):
/dev/input/event1: 0001 0072 00000001
/dev/input/event1: 0000 0000 00000000
/dev/input/event1: 0001 0072 00000000
/dev/input/event1: 0000 0000 00000000
Answered By - wrkwrk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.