Attempt and failure analysis of Android 4.3 screen-cutting function

Source: Internet
Author: User
Tags reflection

1. Background

The previous article on the source of the capture of the Android phone screen function (while pressing the power button and volume reduction, details http://blog.csdn.net/buptgshengod/article/details/19911909), After a week of research or not on the phone to implement the system screen-cutting function, summed up the method of trial and failure reasons.

2. Failure method Analysis (1) bufferframe read fb0

In the mobile phone's/dev/graphics directory fb0 file is responsible for screen rendering frame cache, there are some tutorials on the internet to use C to convert the phone fb0 to BMP format pictures. I android4.0 Lenovo mobile phone with a way to achieve the system screen-cutting function, but after android4.2 this method is not, Framebuffer has been unable to read.

(2) Reflection method

Because we want to call the screenshot API is a @hide hidden by Google class, so we thought of using the reflection method. The principle of the Java reflection mechanism is that Java is different from C or C++,java is running in a virtual machine. Therefore, the internal information and methods of the program can be directly invoked through reflection mechanism. The following is a screenshot of a Java virtual machine that I've written in reference to the stackoverflower above, reflecting code.

<span style= "FONT-SIZE:24PX;" >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;</span>

There is no error when compiling, through log information know that the Surfacecontrol function should be found, but the contents of the screenshot is null.

Possible cause analysis: The reflection mechanism is generally called a hidden method. But the surfacecontrol we're going to call is that the entire class is hidden, so it might be the reason the screenshot result is null.

(3) Compile and remove @hide SDK

It was the first and easiest way I thought. Because already has the code, therefore directly will surfacecontrol.java the front to remove, produces own SDK to be able. But... After a long night of waiting. The compiler has an error. The mistake is to appear in the Surfacecontrol. (A screenshot of the mistake was forgotten)

Possible reasons: It is not clear yet, plan to try again.

(4) Add the Core.jar and Framework.jar files that you have compiled and generated

will be in the source code generated files Core.jar and Framework.jar into the project, we found that the hidden API can indeed be invoked. However, the error occurred when install APK: conversion to Dalvik format failed with error 1.

Possible causes: A problem with apk signature, or a duplicate portion of the imported jar package and the original Android.jar.

(5) Google Code on the Open source project ASL.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

ASL is an open source library on Google code. The principle is to use the mobile phone to import a background running service, as long as the acceptance of intent sent specific information to screen. The result is to return to the black screen, through the message learned that a lot of people have this situation.

Possible causes: Due to the Android version update.

(6) Execute screenshots command in the ADB shell through the notes

When the phone is connected to the computer we execute the following commands to capture the screenshot.

<span style= "FONT-SIZE:18PX;" >ADB shell/system/bin/screencap-p/sdcard/screenshot.png</span>

So I imagined that the execution of this shell command on the phone would enable screenshots to function. Refer to the tutorials on the Web and write a program that can execute the shell command, details: http://blog.csdn.net/buptgshengod/article/details/19405819. But... The screenshot is OK, but the black screen is returned.
Possible reasons: no reason was found.

3. The last Hope (1) To import the jar package aspect of the signature problem, can be replaced by the corresponding file on the phone to resolve, see: http://blog.csdn.net/vincent_czz/article/details/ 7642538 (2) Call the C-Layer native screenshot function ScreenCaptureNative.cpp. See also: 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.