Sto tentando di utilizzare la riflessione per accedere ad alcune funzionalità non pubblicate dell'API di telefonia. Attualmente sto riscontrando problemi nell'istanziare un oggetto serviceManager
necessario per ottenere il servizio "telefono" come raccoglitore che posso quindi utilizzare per istanziare un oggetto di telefonia necessario per effettuare una chiamata, una fine chiamata, ecc ...Riflesso per accedere alle funzioni di telefonia avanzate
attualmente quando faccio la chiamata
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() });
restituisce un NullPointerException. Credo che questo abbia a che fare con la creazione di un nuovo Binder invece di inviare il legante appropriata (che non sono sicuro di cui uno è appropriato)
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);
}
"Attualmente sto avendo difficoltà un'istanza di un oggetto ServiceManager" è l'unica informazione che si stanno dando sull'errore o un problema. Ci hai dato il codice. Ora dicci cosa sta facendo o non farlo è inaspettato e come sai che non funziona correttamente. –