Use internal (COM. Android. Internal) and hidden (@ hide) APIs-Part 1

Source: Internet
Author: User

Xirihanlin 2011.06.02

Original path: http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/

Android has two types of APIs that cannot be accessed through the SDK.

The first is the API in the com. Android. Internal Package. I will call it the internal API. The second API type is a series of classes and Methods marked as @ hide attributes. Strictly speaking, this is not a single API, but a group of small hidden APIs. However, I still assume it as an API and call it a hidden API.

Hidden APIExample

You can check the android source code and find some variables, functions, and classes that are marked by the @ hide attribute.

The following example shows the variables hidden in wifimanager (API 10 Source Code.

Another example is to hide the setwifiapenabled function in wifimanager (API 10 Source Code.

Therefore, as long as you see the @ hide attribute, what you see is the hidden API.

InternalAndHidden APIDifference

The reason why the hidden API is hidden is to prevent developers from using the incomplete or unstable parts of the SDK (interface or architecture ). For example, the Bluetooth API is only available on API 5 (Android 2.0), and the @ hide attribute is hidden on API 3 and API 4. After these APIs are verified and cleared, Google developers will remove the @ hide attribute and make them official in API 5. API 4 and 5 have changed in many places. If yourProgramDepending on some hidden APIs, when deployed on the new platform, it may be in trouble.

For internal APIs, there is never a plan to open them up. It is the "Internal Kitchen" of Android, which should be regarded as a black box for developers. Everything will change. If you are dependent on some internal APIs, you may also be disappointed when these internal APIs change on the new Android release.

To sum up the differences:

Hidden API = ongoing work;

Internal API = black box;

InternalAndHidden APIDuring CompilationVs.Runtime

When you use the android SDK for development, you reference a very important JAR file-android. jar. It is located in the folder of the android SDK platform (sdk_dir/platforms/platform-x/Android. jar, where X indicates the API level ). This android. Jar removes all classes in the com. Android. Internal Package, and removes all classes, enumerations, fields, and Methods marked with @ hide.

But when you start an application on the device, it loads the framework. Jar (in simple words, it is equivalent to Android. Jar), but it does not remove the internal API and the hidden API. (But it is not user-friendly for developers, so I will show you how to use these Apis without reflection ).

There is one more thing to note about the internal API. The ADT plug-in of eclipse adds an additional rule that prohibits the use of anything in the com. Android. Internal Package. Therefore, even if we can get the original Android. Jar (Uncut version), there is no easy way to use these internal APIs through eclipse.

You can check it yourself. Create a new Android project (or use an existing project ). Check the referenced class library (right-click Project Properties> JAVA build path> libraries ).

Important conclusion: internal and hidden APIs are processed in the same way in the SDK (both from Android. jar removed), but the internal API is worse, it is also explicitly disabled by the eclipse ADT plug-in.

Use without reflectionInternalAndHidden API

TheseArticleThe ultimate goal is to enable developers to use internal and hidden APIs without reflection. If you have completed the steps described in the following sections, you can use these internal and hidden APIs, as public APIs. You no longer need to use reflection.

Note: If you are using these non-publicAPIYou must know that your program has great risks. Basically, the nextAndroid OSWhen updatingAPIWithout being damaged, different operators cannot be guaranteed to have consistent behavior. You can decide on your own.

There are three scenarios:

1. Internal and hidden APIs are available (Scenario)

2. Only the hidden API is available (scenario B)

3. Only internal API is available (Scenario C)

Scenario A is the sum of B and C. Scenario B is the simplest one (you do not need to modify the ADT of eclipse ).

Scenario A: Read Part1, 2, 3, 4, 5

Scenario B: Read Part1, 2, 3, 5

Scenario C: Read Part1, 2, 3, 4, 5

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.