Android - How to access emulator screenshot via emulator?
Asked Answered
O

7

8

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?

Ohara answered 12/6, 2017 at 9:6 Comment(4)
I think most of the answers aren't getting your question. You are looking for a way to save the screenshot inside the /storage/emulated/0/Pictures/Screenshots of the emulator itself right? Can't you use the power + volume down combination on the emulator? does it work?Dukas
Thanks, Daniele - but how how I click both buttons at the same time?Ohara
using hotkeys maybe? I acutally don't know for sureDukas
Have just tried hotkeys, but no joy. I clicked the three dots (Extended controls) on the emulator panel, then selected Help and it shows all the keyboards shortcuts, but ctrl+S to take a screenshot works just like the aforementioned Take screenshot button. When I do ctrl+P (Power button) with ctrl+- (Volume down), it just powers off... :-/Ohara
C
9

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
Celiotomy answered 12/6, 2017 at 10:29 Comment(4)
Thanks for this. I'm not familiar with adb, but I've not added it to my path and can run adb shell - which shows generic_x86:/. From this point, I'm not sure how to paste your code in. Ctrl+C doesn't work and if I try typing your code in line by line, nothing seems to happen.Ohara
@ban-geoengineering If you are using Windows, click the top left icon ->edit->paste; If you are using linux, right click to show context menu -> paste.Celiotomy
You're a star! :-) Thanks very much - works a treat!Ohara
Under Android 9 I had to run the last command as root, but it worked! Thanks so much!Pyx
E
8

It will save in your PC . You can also specify the location of screenshots from the emulator settings.

Please see the following image for reference.

enter image description here

Elconin answered 12/6, 2017 at 9:10 Comment(0)
B
7

Pretty old question, but you can use power menu: Press and hold Power button enter image description here

Buckley answered 20/4, 2020 at 11:20 Comment(2)
This should be the accepted answer. Much simpler and effective way of getting a screenshot on the device itself.Jdavie
It's a great and easy way to simulate the screenshot on newer emulators. However for older emulators like API 21, had to use this answer: https://mcmap.net/q/1243417/-android-how-to-access-emulator-screenshot-via-emulatorCorkhill
S
4

It will save in your device (PC), you can see the location from the emulator setting, click on more icon from right side of your emulator, and then click on setting

screen shot location

Scruff answered 12/6, 2017 at 9:14 Comment(1)
Thanks, but the Screenshot save location is the file path for my computer, not for the emulator(?)Ohara
S
0

Use adb screencap command to your emulated device this should store the screen capture on the device itself allowing you to test your application.

Sheriff answered 12/6, 2017 at 13:29 Comment(0)
S
0
  1. Go to

Emulator settings > Settings > General > Screenshot save location > 'your file path'

  1. then select your desire location to save your screenshot. to find your taken screenshot you have to go your your file path which found by step 1.

hope its work.

Shoreless answered 8/5, 2021 at 9:5 Comment(0)
V
0

This is how you can prevent the user from taking a screenshot and capturing the screen(Kotlin):

import android.view.WindowManager.LayoutParams

override fun onCreate(savedInstanceState: Bundle?) {
    // ...
    window.setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)
    // ...
}
Victoriavictorian answered 27/11, 2022 at 17:48 Comment(2)
Not answer of asked questionBoswell
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBipack

© 2022 - 2024 — McMap. All rights reserved.