I am trying to use reflection in Java to access hidden classes in Android source code so I can end a call programmatically. The problem I am having is the method forName() generates a java.lang.ClassNotFoundException whatever I do. I tried many things including writing the name of the class as a String with the package name as a prefix and put that as argument of forName("TelePhonyManager.tm"), same error message. I understand this has to do with the classpath but no fix so far.Even when I tested with the current class I'm working with, and its package name I had the same error.
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
Object telephonyService = m.invoke(tm); // Get the internal ITelephony object
c = Class.forName(telephonyService.getClass().getName()); // Get its class
m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method
m.setAccessible(true); // Make it accessible
m.invoke(telephonyService); // invoke endCall()
Aucun commentaire:
Enregistrer un commentaire