Reprint Please specify: http://www.cnblogs.com/frank-zouxu/p/4158159.html
Today, a company project in progress, encountered the problem of the screen to take the word, the problem is step, the first to solve how to intercept the device screen, because the Android device is based on the Linux kernel, so try to find the android command screencap, Found in the source code of Android4.0:
Screencap is written in C + + and screenshot is based on C. Use screencap here. First enter the phone's shell mode and go to the command line: adb shell screencap-h for printing information
Usage:screencap [-HP] [-D Display-id] [FILENAME] -h:this message -p:save the file as a PNG. -d:specify the display ID to capture, default 0.If FILENAME ends with. png It'll be saved as a PNG. If FILENAME is not given, the results would be printed to stdout.
Then we use Java code to complete the screen capture:
null,null); OutputStream = sh.getoutputstream (); Os.write ("/system/bin/screencap-p" + "/sdcard/img.png"). GetBytes ("ASCII"));
Use shell command to complete screenshot operation at runtime Os.flush (); Os.close (); Sh.waitfor ();
The screenshot file (img.png) is saved to the root of the SD card. The time is hasty, the whole process is not detailed, only for the record of today's income.
android-Screen Device screenshot