TelephonyManager tm = (TelephonyManager) getApplicationContext() .getSystemService(Service.TELEPHONY_SERVICE);
try {
Class<TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
try {
iTelephony = (ITelephony) getITelephonyMethod.invoke(tm,
(Object[]) null);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
try {
Class<TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
} catch (Exception e) {
e.printStackTrace();
}
try {
iTelephony = (ITelephony) getITelephonyMethod.invoke(tm,
(Object[]) null);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
try {
iTelephony.endCall();
} catch (RemoteException e) {
e.printStackTrace();
}