利用反射拨号

private void dial(String number) {
  Class<TelephonyManager> c = TelephonyManager.class;
  Method getITelephonyMethod = null;
  try {
   getITelephonyMethod = c.getDeclaredMethod("getITelephony",
     (Class[]) null);
   getITelephonyMethod.setAccessible(true);
  } catch (SecurityException e) {
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
   e.printStackTrace();
  }

  try {
   TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
   Object iTelephony;
   iTelephony = (Object) getITelephonyMethod.invoke(tManager,
     (Object[]) null);
   Method dial = iTelephony.getClass().getDeclaredMethod("dial",
     String.class);
   dial.invoke(iTelephony, number);
  } catch (IllegalArgumentException e) {
   e.printStackTrace();
  } catch (IllegalAccessException e) {
   e.printStackTrace();
  } catch (SecurityException e) {
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   e.printStackTrace();
  }
 }

posted @ 2015-03-16 20:57  Dbzzcz  阅读(299)  评论(0编辑  收藏  举报