Use of hidden classes in Android Development

Source: Internet
Author: User

During development, we found that some classes were hidden with the upgrade of the Android version. Very worried. Someone proposed on the Internet to put the code into the source code environment for compilation, which is a bit difficult for me. First, there is no source code environment. Second, it is difficult for me to compile it. With the help of the powerful Internet, I found a method. Is to use the reflection mechanism in Java.

For more information about the reflection mechanism, let's learn about it. I will not delay everyone.

Let me talk about the problems I encountered:

Used in analog button processing:

Ibinder wmbinder = servicemanager. getservice ("window ");

Final iwindowmanager WM = iwindowmanager. stub. asinterface (wmbinder );

The classes to be introduced are:

Import Android. OS. servicemanager;

Import Android. View. iwindowmanager;

Unfortunately, these two classes are hidden after version 1.6.

After a day, I finally found a solution.

The method is as follows:

1. first, find the source code and find iwindowmanager. the aidl file creates the source code in the same path in your project. After the file is created, you will be prompted for other files to be added and add again until there is no error message. (PS: Of course, in some cases, I don't think my project will be used in the process, so some functions are blocked without authorization, and no problems have been found yet. Additional source code address:

Http://www.google.com/codesearch#ukcgseahr9A/trunk/lib/bin_1_5/android/view/WindowManager.aidl&type=cs)

2. Add code to replace the original Implementation Method

Try {

Object object = new object ();

Method getservice = Class. forname ("android. OS. servicemanager"). getmethod ("getservice", String. Class );

Object OBJ = getservice. Invoke (object, new object [] {New String ("window ")});

// System. Out. println (obj. tostring ());

Windowmger = iwindowmanager. stub. asinterface (ibinder) OBJ );

} Catch (classnotfoundexception ex ){

// Ignored

} Catch (nosuchmethodexception ex ){

// Ignored

} Catch (illegalaccessexception ex ){

// Ignored

} Catch (invocationtargetexception ex ){

// Ignored

}

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.