I am looking for a way to take a screenshot of device after test failed and before get closed.
I haven't used screenshots in my Android testing yet, but I know some solutions, which might be useful:
the best way to do it would be use Emma
or Spoon
framework.
Here you would find some useful information how to do it: http://elekslabs.com/2014/05/creating-test-reports-for-android-with-spoon-and-emma.html
Visit also Spoon
's official Github site: https://github.com/square/spoon and its Gradle's plugin: https://github.com/stanfy/spoon-gradle-plugin
and check related topic: How to get Spoon to take screenshots for Espresso tests?
You can also try this Facebook's library: https://facebook.github.io/screenshot-tests-for-android/
As I've already know, with Robotium
test framework is possible to create test with screenshots. Check: Correct way to take screenshot with Robotium and Cucumber
If you don't want to use any library, check source code of Robotium
framework class called ScreenshotTaker.java[click on link to see] and write your own ScreenshotTaker
class.
Hope it will help.