6

How do you take a screenshot via ADB for Android Things? I have tried:

adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell rm /sdcard/screen.png

and

adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
Onik
  • 19,396
  • 14
  • 68
  • 91
Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
  • have you tried from within Android Studio itself? – riggaroo Jan 08 '17 at 19:15
  • Thanks for the idea- unfortunately it throws an error: "Unexpected error while obtaining screenshot from device: EOF" – Quintin Balsdon Jan 08 '17 at 19:31
  • Is this related to your other question? i.e. is this with your non working screen plugged in or not? Did you have a hdmi screen connected? – Blundell Jan 08 '17 at 21:50
  • I have the same issue and it doesn't matter if I'm connected to external monitor or not. The retrieved .png file is 0kB in size and obviously doesn't contain the screen image. – Jan Slominski Jan 09 '17 at 13:18
  • Check this question: http://stackoverflow.com/questions/23207199/adb-screenshot-not-found - there is a possible solution using MonkeyRunner – Jan Slominski Jan 09 '17 at 13:24

3 Answers3

2

I couldn't make screepcap work in Android Things Developer Preview. The command results in a 0-size file.

That said, I recommend the following two options: either use the framebuffer or record a video (screenrecord seems to work) and convert it to an image later on by proper tool. I'll consider the first option, so the steps would be:

  • Pull the framebuffer to the host machine. Note that you need to start adbd as root in order to pass a permission check:

    adb root
    adb pull /dev/graphics/fb0 screenshot
    
  • Convert the raw binary to image by the tool you prefer. I'm using . The command below might not work for you due to different screen resolution or pixel format. If so, make proper changes.

    ffmpeg -f rawvideo -pix_fmt rgb565 -s 800x480 -i screenshot screenshot.png
    
Onik
  • 19,396
  • 14
  • 68
  • 91
  • Use `adb shell dumpsys window | grep mUnres` to find out the screen resolution. – Onik Jan 23 '17 at 18:50
  • @Andriy Omelchenko What was wrong at the first place? Wrong screen resolution? What value of `pix_fmt` worked for you? – Onik Jan 23 '17 at 19:45
  • 1
    Yes, - wrong screen resolution and `-pix_fmt rgb565` works for me too without changes. And You are cool ) Thanx! – Andrii Omelchenko Jan 24 '17 at 08:49
1

Seems, because of old limited OpenGL version in Android Things, described by Tatsuhiko Arai here there is no possibility to get screenshot via ADB, but You can record video (e.g. from Android Studio, or via ADB commands) and than grab frame from it, for example via ffmpeg:

ffmpeg -i device-2017-01-23-193539.mp4 -r 1 screen-%04d.png

where device-2017-01-23-193539.mp4 - name of recorded (via Android Studio) file .

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • I noticed they didn't put OpenGL into Android things - quite disappointing – Quintin Balsdon Jan 24 '17 at 09:43
  • @Quintin Balsdon _"I noticed they didn't put OpenGL into Android things"_ They did. Namely, it's `OpenGL ES-CM 1.0` which can be seen with `adb shell dumpsys | grep GLES`. – Onik Jan 26 '17 at 00:42
  • 1
    I also doubt it's because of _"old limited OpenGL version"_. I have `OpenGL ES-CM 1.1` on my `Android 4.2` phone and the `screencap` works as expected. – Onik Jan 26 '17 at 00:44
  • @Oink it's strange they didn't support the latest OpenGL the Raspberry Pi - thanks for showing me how to find it! – Quintin Balsdon Jan 26 '17 at 08:46
0

I've tried exactly this code with a little bit change like below (but no matter) and it works well. The image is in my platform-tools directory now.

adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png screen.png
adb shell rm /sdcard/screen.png
MRS4
  • 1
  • 1