How to call the Android Stealth API

Source: Internet
Author: User

As a developer of Android apps, the Android SDK is the most familiar to developers on Android platforms. The SDK provides developers with great convenience, which makes the application development of Android platform much more efficient. Unfortunately, Android is far more than the SDK exposes, and there are a lot of hidden things that Google has not exposed to the user developer through the SDK. When you look at the Android source code, you'll see that these hidden APIs have one common feature: @hide before classes or methods.                            & nbsp   <ignore_js_op>  How to hide the API? 1)    under normal circumstances, i.e. without @hide, all public classes or methods are compiled and generated into the stub library's jar file. This stub library is actually an empty implementation, but it contains all the public methods. So with this stub library, application developers can develop in eclipse. 2)    Once the @hide is added, the class or method that is @hide marked is removed when compiling the stublibrary. Therefore, the application developer cannot "direct" invoke the hidden class or method through the stub library. If you force a hidden class or method to be called in Eclipse, Eclipse will make an error. A typical example is the Android.jar in the Android SDK, which contains an API that has been removed. , Activitymanager's Forcestoppackage () method cannot be found in the Android SDK. Can the hidden API be called? 1)    So app developers can use these hidden APIs??  the answer is yes. In a real-world environment, all APIs are present and implemented. Then it's easy to think of "reflection." If we already know the class name and method name of the target class, and the parameter list, we can still invoke it by reflection even if it is @hide. For the Java reflection, here we are not ready to expand, not very familiar with the students please study on their own. UnderThe face is an example of reflection. Iactivitmanageram = Activitymanagernative.getdefault ();Method forcestoppackage = Am.getclass (). Getdeclaredmethod ("Forcestoppackage", String.class); Forcestoppackage.setaccessible (true);Forcestoppackage.invoke (AM, yourpkgname); 2) Although the reflection is good, but it is really troublesome to write, originally a call code, a line can be done, but now with the launch of writing, it takes a lot of lines. Is there any other more convenient way to do it, in fact there is. The above we mentioned in the Android SDK Android.jar is a castrated version, if we can generate a full version, this problem is solved. The method is now the entire set of Android source code, and then do a full compilation. In the out/target/common/obj/java_libraries/directory, you can extract the stublibrary you want as needed. Take the framework as an example: the out/target/common/obj/java_libraries/framework_intermediates/ Classes.jar is copied to the Eclipse development environment and is mounted userlibrary so that it has a higher priority than Android.jar. Here are the steps to set up in eclipse: <ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op>
<ignore_js_op> Some problems needing attention 1) whether you are reflecting or using a self-compiled stublibrary, you can only resolve the problem of calling the hidden API, but not over the permission check. 2) Google hides some of the APIs, some of which may be because they are internal logic, do not want to be exposed, or the API interface is not finalized. So the hidden API on a low version of Android doesn't have to be available on a higher version of Android. This is something that must be noted. It is also said that the compatibility of the hidden API is relatively poor. So when using reflection calls to hide the API, be careful to reflect on the Android version in a different way.
Category: Android solve

How to call the Android Stealth API

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.