Android 隐藏类的使用
在模拟按键处理时用到了:
java代码:
IBinder wmbinder = ServiceManager.getService( "window" );
final IWindowManager wm = IWindowManager.Stub.asInterface( wmbinder );
需要引入的类是:
java代码:
import android.os.ServiceManager;
import android.view.IWindowManager;
方法如下: 1. 首先查找源码,找到了IWindowManager.aidl文件,将源码按照相同的路径在自己的工程中创建;
2. 添加代码替换原来的实现方法
java代码:
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
}
反射机制的应用1:
java代码:
import android.os.ServiceManager;
ITelephony.Stub.asInterface(ServiceManager.getService("phone")).answerRingingCall();