리플렉션을 사용하여 전화 통신 API의 일부 게시되지 않은 기능에 액세스하려고합니다. 현재 serviceManager
개체를 인스턴스화하는 데 문제가 있습니다.이 개체는 "전화"서비스를 바인더로 사용하여 전화, 끝내기 등의 작업을 수행하는 데 필요한 전화 통신 개체를 인스턴스화하는 데 사용할 수 있습니다.고급 전화 기능에 액세스하기위한 반사
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() });
을 할 때
현재는 NullPointerException이 반환합니다. 나는 이것이 당신이 얻을 것이다
Binder tmpBinder = new Binder();
tmpBinder.attachInterface(null, "fake");
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { tmpBinder });
를 다음을 수행하여 (하나는 적절한있는 내가 확실하지 오전) 적절한 바인더
public void placeReflectedCall() throws ClassNotFoundException,
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException,
InstantiationException {
String serviceManagerName = "android.os.IServiceManager";
String serviceManagerNativeName = "android.os.ServiceManagerNative";
String telephonyName = "com.android.internal.telephony.ITelephony";
Class telephonyClass;
Class telephonyStubClass;
Class serviceManagerClass;
Class serviceManagerStubClass;
Class serviceManagerNativeClass;
Class serviceManagerNativeStubClass;
Method telephonyCall;
Method telephonyEndCall;
Method telephonyAnswerCall;
Method getDefault;
Method[] temps;
Constructor[] serviceManagerConstructor;
// Method getService;
Object telephonyObject;
Object serviceManagerObject;
String number = "1111111111";
telephonyClass = Class.forName(telephonyName);
telephonyStubClass = telephonyClass.getClasses()[0];
serviceManagerClass = Class.forName(serviceManagerName);
serviceManagerNativeClass = Class.forName(serviceManagerNativeName);
Method getService = // getDefaults[29];
serviceManagerClass.getMethod("getService", String.class);
Method tempInterfaceMethod = serviceManagerNativeClass.getMethod(
"asInterface", IBinder.class);
// this does not work
serviceManagerObject = tempInterfaceMethod.invoke(null,
new Object[] { new Binder() });
IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject,
"phone");
Method serviceMethod = telephonyStubClass.getMethod("asInterface",
IBinder.class);
telephonyObject = serviceMethod
.invoke(null, new Object[] { retbinder });
telephonyCall = telephonyClass.getMethod("call", String.class);
telephonyEndCall = telephonyClass.getMethod("endCall");
telephonyAnswerCall = telephonyClass.getMethod("answerRingingCall");
telephonyCall.invoke(telephonyObject, number);
}
오류 또는 문제에 대해주는 유일한 정보는 "현재 나는 데 문제가 ServiceManager에 객체를 인스턴스화하는 데 문제". 우리에게 코드를 주셨습니다. 이제는 그것이하고있는 일과하지 않는 일을 예기치 않게 알려주고 올바르게 작동하지 않는다는 것을 어떻게 알 수 있습니까? –