사례 1 : 아래 코드를 확인하십시오. Class 및 Method 객체를 가져올 수 있으며 제대로 작동합니다. 액세스하려고하는 메서드는 android.view.View :: dispatchPointerEvent입니다.Android Reflection - Android Jars
사례 2 : 클래스/메소드를 com.android.server.pm.PackageManagerService :: grantPermissionsLPw로 바꿀 때 NoMethodFoundException이 발생합니다. 클래스 액세스 할 수있었습니다.
사례 3 : 클래스/메소드를 android.hardware.input.InputManager :: injectInputEvent로 바꿀 때 NoMethodFoundException이 발생합니다. 클래스 액세스 할 수있었습니다.
질문은 : 왜 안드로이드 클래스/메소드 중 일부는 리플렉션을 통해 액세스 할 수 있으며 다른 방법은 아닌지?
Class _class = null;
try {
_class = Class.forName("android.view.View");
Log.i("Test", "Class found");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Method method = null;
try {
Log.i("Test", "Pre-Method found");
method = _class.getDeclaredMethod("dispatchPointerEvent",
MotionEvent.class);
Log.i("Test", "Method found");
} catch (Exception e) {
Log.i("Test","I failed."+e.getMessage()+e.toString());
//e.printStackTrace();
}
예, 적절한 매개 변수를 대체 않았다 시도하고 또한 사실 SetAccessible을 통해 개인 방법 중 처리했다 .. – Jailbroken
당신은 응용 프로그램 또는 에뮬레이터 내에서 실행하거나에서 호출 IDE 프로젝트? 당신이 에뮬레이터에 없다면 나는 당신이 스텁을 호출하고 있다고 생각합니다. –
기기에서 직접 실행 중입니다. – Jailbroken