在 Android 操作系统中,我使用反射来获取IWindowManager
:
Class tempClass = Class.forName("android.os.ServiceManager");
Method method = tempClass.getMethod("getService", String.class);
IBinder binder = (IBinder) method.invoke(null,new Object[] { "window" });
IWindowManager mIWM = IWindowManager.Stub.asInterface(binder);
并使用反射得到ViewServer
:
Class mViewServer = Class.forName("com.android.server.ViewServer");
但是使用下面的代码会抛出java.lang.IllegalArgumentException
:
Constructor ct = mViewServer.getDeclaredConstructor(Class.forName("com.android.server.WindowManagerService"));
ct.setAccessible(true);
Object mVSObject = ct.newInstance(mIWM);
构造ViewServer
函数是:
ViewServer(WindowManagerService windowManager) {
...
}
谁能帮帮我,非常感谢!