wtorek, 29 marca 2011

Taking a screenshot in Android

There are plenty quite few decent methods for taking a screenshot in Android.

  • Monkey runner that comes with sdk 2.3 (works in 2.2 (checked) and earlier (assumed))
    http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html#SampleProgram
    This is pretty cool, python thing. I just wonder if that can be used within android with Android Scripting Engine. Definitely good choice for automated things like tests.
  • Reading framebuffer with an adb command
    adb pull /dev/graphics/fb0 screenshot.raw

    and processing this with some geeky commands. Might be impressive for your geekfriends but is not very simple to use.
    More about it you can read here here and there. The problem is that you have to count the buffer size, know the format of framebuffer and is not quite obvious.
  • Using android screenshot library maintained by polidea
  • Using ddms tool from sdk

    Pretty simple but you can't use it in an environment in automated, operatorless (no human involved) way.
  • Using a hierarchy viewer tool. With that you can take screenshots not only of the whole screen but also individual controls (views in android jargon).
  • Writing something around ddmlib. In fact all the tools above except ASL use ddmlib.
  • Last, but definetely not least is something by google itself. No surprise done on top of ddmlib.
    This tool is called screenshot and is in java. You can find that in sdk
    sdk/screenshot/src/com/android/screenshot/Screenshot.java.
    I am pretty sure you can compile it standalone with ddmlib as only dependency, but I had already built my sdk and it was compiled in

    android-source/out/host/linux-x86/bin/screenshot2
    and that simply works!
    ./screenshot2
    Usage: screenshot2 [-d | -e | -s SERIAL] [-l] OUT_FILE
    -d Uses the first device found.
    -e Uses the first emulator found.
    -s Targets the device by serial number.
    -l Rotate images for landscape mode.


Enjoy!

Brak komentarzy:

Prześlij komentarz