Test and failure analysis of the screenshot function of android4.3

Source: Internet
Author: User

(Reprinted please indicate the source: http://blog.csdn.net/buptgshengod) 1. Background

The previous talk in the source code captured the android mobile phone screenshot function (at the same time press the power key and volume reduction, details http://blog.csdn.net/buptgshengod/article/details/19911909), after a week of research or not on the phone to achieve the system screenshot function, summarize the methods and causes of failure.

2. Analysis of Failure methods (1) bufferframe reading fb0

The fb0 file in the/dev/graphics directory of the mobile phone is the frame cache for screen rendering. There are some tutorials on how to use c to convert fb0 from the mobile phone to bmp format. I used a method on the android Lenovo mobile phone to implement the system screenshot function, but this method won't work after Android, and framebuffer can no longer be read.

(2) Reflection Method

Because the screenshot api we want to call is a @ hide class hidden by google, we came up with the reflection method. The principle of the java reflection mechanism is that, unlike c or c ++, java runs on virtual machines. Therefore, internal information and methods of the program can be directly called through the reflection mechanism. The following is a piece of screenshot function reflection code written by referring to stackoverflower.

sc = Class.forName("android.view.SurfaceControl");method=sc.getMethod("screenshot", new Class[] {int.class, int.class});Object o = method.invoke(sc, new Object[]{(int) dims[0],(int) dims[1]});mScreenBitmap =(Bitmap)o;
No error is reported during compilation. The surfacecontrol function should be found through log information, but the screenshot content is null.

Possible Cause Analysis: the reflection mechanism generally calls a hidden method. However, the SurfaceControl to be called is hidden from the entire class, so it may be because the screenshot result is null.

(3) Compile and remove the @ hide sdk

This is the simplest and most crude method that I thought of first. Because the Code already exists, you can directly remove the code before SurfaceControl. java and generate your own sdk. But... After a long wait night. The compiler reports an error. The error occurs in surfacecontrol. (I forgot to make the mistake at the time)

Possible cause: It is not clear yet. I plan to try again.

(4) Add the core. jar file and framework. jar file compiled by yourself

Import the core. jar and framework. jar files in the source code to the project. We can find that the hidden api can be called. However, when installing apk, the following error occurs: Conversion to Dalvik format failed with error 1.

Possible cause: the apk signature is incorrect, or the imported jar package is duplicated with the original android. jar package.

(5) Open-Source Project asl on google code.

Asl is an open source library on google code. The principle is to use a mobile phone to import a service running in the background, as long as the specific information sent by intent is received, screenshots are taken. The result of the experiment is a black screen. I learned from the message that many people are experiencing this situation.

Possible cause: the android version is updated.

(6) execute the screenshot command in the adb shell on the note.

Execute the following command when the mobile phone is connected to the computer.

adb shell /system/bin/screencap -p /sdcard/screenshot.png
So I imagined whether this shell command could be implemented on the mobile phone. Refer to the online tutorial to write a program that can execute shell commands. For details, visit http://blog.csdn.net/buptgshengod/article/details/19405819. But... Screenshots are acceptable, but black screens are returned.
Possible cause: no cause is found.

3. The final hope (1) Import jar package signature problem, can be solved by replacing the corresponding file in the phone, see: http://blog.csdn.net/vincent_czz/article/details/7642538 (2) Call the native function ScreenCaptureNative. cpp in c layer. See http://blog.csdn.net/zx19899891/article/details/7072291

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.