0

I would need to be able to take screen dumps for testing, and with ICS there is now a screen shot function, that can be invoked by pressing (and holding) volume down and power button. Is there any way to script this function through adb? (As I understand it there's no public java API for it). I have tried to use KeyEvent from java to emulate power and volume button, and I have tried to use adb keyevent and adb sendevent without success. I suspect that the power button also generate some low level calls that are not generated with the above methods.

So do anyone know if it is possible to call the function from adb? If this is not possible, do someone know where in the source code this screen shot function exist? Maybe I can figure something out by reading it.

update

source code for capture the screen is in "frameworks/base/services/surfaceflinger/services/surfaceflinger/SurfaceFlinger.cpp" in a function called screenCapture. I do not know if it is possible to call it from jni, but I will try, because it would be great if I could take a screen shot through java.

Otherwise, @edthethird had a solution through android.amberfog.com/?p=168 that will make it possible to take a screenshot with the commandline.

Thank you for the help everyone!

AakashM
  • 62,551
  • 17
  • 151
  • 186
jjung
  • 230
  • 1
  • 4
  • 8

4 Answers4

10

In the form of adb commands, the following works on ICS devices:

adb shell /system/bin/screencap -p /sdcard/img.png
adb pull /sdcard/img.png img.png

See: http://a-more-common-hades.blogspot.com/2012/01/screenshot-command.html

Joe Bowbeer
  • 3,574
  • 3
  • 36
  • 47
1

Well this has nothing to do with ICS, but in eclipse, look at a Devices tab. There is a tiny little camera icon on the far right. (From right to left, it is "box", "line", "upside down triangle", and "camera". Click on this camera to take a screen shot of the currently selected device.

This works on any version of Android, not only ICS.

Device View in DDMS Eclipse

edthethird
  • 6,263
  • 2
  • 24
  • 34
  • If eclipse can do this, then there must be some way of achieving the same through adb. – danp Mar 01 '12 at 15:31
  • @danp If there's a way to do it automatically it would be great. I couldn't find out how to do it with ddms automatically. – jjung Mar 01 '12 at 16:00
  • @edthethird That could be a solution if I cannot find a way to use the screen shot function, thanks! I will look more into it. – jjung Mar 01 '12 at 16:02
1

See this question: Screenshot of the Nexus One from adb?

Basically you can pull the framebuffer using adb and convert it into a usable image yourself, or you can just use the command line utility provided by Google. Looking round I think you may need to tweak that utility a little to get it to work on newer versions of Android.

As the other answer points out though, its probably less hassle to just do this from Eclipse, unless you're trying to automate testing.

Community
  • 1
  • 1
TheLastBert
  • 466
  • 4
  • 16
  • Yes, unfortunately I am developing automatic tests for graphics, so I must be able to script it. We used the method you described before, but our new hardware does not support it and i must find a new way to do it. – jjung Mar 01 '12 at 16:04
  • I've been trying to do this from within an app, to no avail. help please? – Faizan Kazi Aug 08 '12 at 21:12
1

After looking into the source code, there is a library that does exactly what I want. frameworks\base\cmds\screencap\screencap.cpp The program can be executed on android by /system/bin/screencap . So it is possible to execute in Java on android by Runtime.getRuntime().exec();

A drawback is that you need a special certificate for taking screenshots.

jjung
  • 230
  • 1
  • 4
  • 8
  • Could you explain that a little bit? what special certificate? if I try: Process process = Runtime.getRuntime().exec("/system/bin/screencap"); nothing happens. – Faizan Kazi Aug 08 '12 at 21:09
  • Also if i try to do: Process process = Runtime.getRuntime().exec("/system/bin/screencap -h"); and set up a BufferedReader on the process's Input Stream, nothing comes back. – Faizan Kazi Aug 08 '12 at 21:11
  • if you check the logcat, you probably got an error message: " W/PackageManager(1862): Not granting permission android.permission.READ_FRAME_BUFFER to package com.xxx.xxx (protectionLevel=3 flags=0x8be46) – jjung Aug 09 '12 at 06:55
  • It is not enough to just add the READ_FRAME_BUFFER, to use the screencap you need to sign your app with a special certificate that allows you to use the frame buffer. I am not sure where we got our certificate from, if we got it from google or from our graphics programmers. But I am pretty sure that you cannot release an app with this certificate on google Play – jjung Aug 09 '12 at 07:10