public void call(String number)
{
Class<TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Object iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);
Method call = iTelephony.getClass().getDeclaredMethod("call", String.class);
call.invoke(iTelephony, number);
}catch (Exception e){
e.printStackTrace();
}
}
public void endCall()
{
Class<TelephonyManager> c = TelephonyManager.class;
Method getITelephonyMethod = null;
try {
getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null);
getITelephonyMethod.setAccessible(true);
TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Object iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);
Method endCall = iTelephony.getClass().getDeclaredMethod("endCall");
endCall.invoke(iTelephony);
}catch (Exception e){
e.printStackTrace();
}
}
<uses-permission android:name="android.permission.CALL_PHONE"/><!-- 拨打电话的权限 -->