How to Use hidden APIs in Android Application Development

Source: Internet
Author: User

In the beginning, it should be noted that Google has to hide some APIs (public classes, methods, or constants marked with @ hide) for a reason. A major reason is that the Android system is still evolving. Android 2.3.4 is coming soon from 1.0 and 1.1. These hidden APIs may be unstable. Therefore, using hidden APIs means that programs are less compatible.


If you want me to give suggestions, it is best not to use hidden APIs. However, some hidden APIs often play an unexpected role to realize some special functions or effects of Android applications. I will not give an example of what these Apis can do here. Well, if you don't know what the hidden APIs can do, give up using them as soon as possible ......


I don't want to go into the topic for a long time. There are two main ways to use the hidden API: first, the reflection method mentioned in "Learning Java reflection mechanism" gets the hidden API; second, use the fully compiled jar package classes generated during source code compilation. jar.


The reflection method is not described here. For details, see Java reflection mechanism learning. The advantage of using the reflection mechanism to hide APIS is that it is flexible and can capture exceptions in incompatible systems without crashing the program. The disadvantage is that the process is too complicated, in addition, it is difficult to implement inheritance of hidden classes. If you need to use a large number of hidden APIs, using reflection will undoubtedly bother programmers.


This article mainly introduces how to use hidden APIS by importing the fully compiled classes. jar package. This method is easy to implement and programmers are easy to program, just as those hidden APIs become visible in the SDK. Its disadvantage is its compatibility. We hope users will pay attention to it and take it into consideration.


After the Android framework source code is compiled, the out folder is generated in the source code path. In the out "target" common "obj" JAVA_LIBRARIES "framework_intermediates" path under this folder, the fully compiled jar library classes is generated. jar. All you need to do is import the jar library to your project.


During the process of importing classes. jar, there may be two problems (I am using the eclipse development environment, so I will only explain the problems encountered in this environment ).


The first problem is that the jar library is imported as another jar. It is found that the compilation is slow, and sometimes it cannot be compiled successfully. eclipse crashes or prompts "java. lang. OutOfMemoryError: Java Heap Space"Error. This problem may be caused by the fact that the jar is too large.I tried the parameters in eclipse. ini and it seems that it does not work. My approach is to create a custom library in eclipse and put classes. jar in the library. Add a library for the Android project, just like using the SDK. This can solve this problem well. I will not elaborate on how to create a custom library. It is very easy for a friend who does not know how to search or find a custom library.


Problem 2: The jar library has been correctly imported, but the hidden APIs still cannot be found. This is because the Build class path order is incorrect. Specifically, the import sequence of android. jar and classes. jar is incorrect. The order of classes. jar should be placed before android. jar. For details about how to adjust the Order of Build class path, choose properties> Java Build Path> order and Export ..


After successfully solving these two problems, I believe you can use Android to hide the API normally.

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.