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
}