How to use the hidden API in Android app development

Source: Internet
Author: User

The first point to note is thatGoogle has a reason to hide some APIs ( the public class, method, or constant that adds @hide markup). The big reason for this is that the Android system itself is in constant evolutionary development. From 1.0,1.1 to the now-coming Android 2.3.4. These hidden APIs themselves may be unstable, so using a hidden API means that theprogram is worse for compatibility.


If you want me to give advice, it's best not to use the hidden API. Sometimes , however, the hidden API can play an unexpected role in order to achieve some special features or effects for Android applications . I'm not here to give an example of what these APIs can do specifically. Well, if you don't know what the hidden API can do, then quit using them as soon as possible ...


Don't want to be lengthy, go straight to the chase. There are two main ways to use the hidden API : First, the reflection method I referred to in the study of the Java reflection mechanism gets the hidden API, and thesecond is the fully compiled jar package generated when compiling with the source code. Classes.jar.


The use of reflection, in this is not described in detail, see the "Java reflection mechanism of learning ." The advantage of using the reflection mechanism to hide The API is the flexibility to catch exceptions in incompatible systems without crashing the program, the drawback being that the process is too complicated and that it is difficult to implement the inheritance of hidden classes. If you need to use a lot of hidden APIs, it can be annoying for programmers to use reflection.


The main thing this article introduces is to implement the use of the hidden API by importing the fully compiled Classes.jar package . This approach is simple and programmer programming is simple, just as the hidden APIs become visible in the SDK . Its disadvantage is the compatibility problem, I hope users pay attention to, in the use of a clear consideration.


After compiling the Android Framework Source code, under the source path will generate an out folder, under this folder out "target" common "obj" java_libraries "Framework_ Intermediates " path, the compiled Jar library Classes.jar will be built . All you need to do is import this jar library into your project.


During the import Classes.jar process, there are two issues that may occur (I use the Eclipse development environment, so I will only explain the issues that this environment encounters).


     Problem one is to import this jar Library by importing a different jar , and find that the compilation is slow, and sometimes not even compiled successfully, eclipse crash or prompt for "java.lang.outofmemoryerror: java heap space" error. The problem, probably because the jar is too large for the reason, the online said to change the parameters in the Eclipse.ini, the individual tried, it seems to have little effect. My practice is to create a new custom library in Eclipse and then place Classes.jar in the library . Android Project adds a library , just like using SDK . This can be a good solution to this problem. How to create a new custom library I do not detail, do not know the friends of their own search under or groping under, very simple.
/span>


The second problem is that the jar library has been properly imported , but the hidden API is not found. The reason for this is that the Build class path order is incorrect, specifically The import order of Android.jar and Classes.jar is incorrect. Classes.jar should be placed in the order before Android.jar, specifically adjust the Build class path order where the properties- > Java Build Path, Order and Export. .


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

How to use the Hide API (go) in Android app development

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.