android-Screen Device screenshot

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.