Android basics 42: Use the internal (COM. Android. Internal) and hidden (@ hide) APIs to customize the Android platform

Source: Internet
Author: User

In the previous article, I showed you how to create a custom original-android.jar that contains both internal APIs and all classes in the hidden APIs.

The next step is to modify the existing Android platform (sdk_dir/platforms/platform-x/Android. Jar ). You can simply replace Android. jar with the original-android.jar created in part 1, but with unlimited use of internal APIs and hidden APIs for all your projects. This is not suitable because you may not allow this in most projects. In addition, you basically want to disable these APIs (this is the default behavior of ADT/Android. Jar), but you only need to use internal and hidden APIs in a few projects.

To achieve this flexibility, you need to create a new custom Android platform. When you do not need to use internal and hidden APIs, you use the original Android platform. You can use a customized Android platform to access internal and hidden APIs.

Android SDK directory tree

Let's take a look at how the android SDK is organized:

We need the "platforms" directory to go in:


Here is a list of supported Android platforms.

Now let's see how this is associated with eclipse settings. Right-click an android project and choose Properties> android. You can see a list of supported platforms (it reflects... /Platforms/folder ). Below is:

Create a new platform

To create a customized platform, copy the Android-9 folder, name it Android-9-internals, and make some modifications:

  1. Delete Android. jar from the Android-9-internals folder.
  2. Copy the original-android.jar and rename it to Android. jar.
  3. Modify the build. Prop file:

...

Ro. Build. version. SDK = 9-> Ro. Build. version. SDK =-9

...

Ro. Build. version. Release = 2.3-> Ro. Build. version. Release = 2.3.extended

Restart eclipse and check that the new platform is displayed. below is what I see:

Why do I select API level-9? This is because it must be a number and cannot be 9 (or another existing API level). Otherwise, your customized platform will not be used (it will be displayed in the list, but it does not work, and the platforms with the same original numbers will be used during compilation ).

Below is the libraries view (when the custom platform is selected ):

Summary

In the previous article, I explained how to create an uncut version original-android.jar for Android. jar. In this article, I demonstrated how to create a custom Android platform using this original-android.jar. This is sufficient for using hidden APIs, but it is necessary to use internal APIs further. This is because the ADT still prohibits the use of classes in the com. Android. internals package (see the above ). In the next article, I will show you how to customize the ADT and allow the use of internal APIs.

References:

Using Internal (COM. Android. Internal) and hidden (@ hide) APIs [Part 1: customizing the Android platform]

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.