需要使用反射机制将ITelephony反射出来进行操作。

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) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (NoSuchMethodException e) {            // TODO Auto-generated catch block            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) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (SecurityException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (NoSuchMethodException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }        private void call(String number) {        Class<TelephonyManager> c = TelephonyManager.class;        Method getITelephonyMethod = null;        try {            getITelephonyMethod = c.getDeclaredMethod("getITelephony",                    (Class[]) null);            getITelephonyMethod.setAccessible(true);        } catch (SecurityException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (NoSuchMethodException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        try {            TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);            Object iTelephony;            iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);            Method dial = iTelephony.getClass().getDeclaredMethod("call", String.class);            dial.invoke(iTelephony, number);        } catch (IllegalArgumentException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (IllegalAccessException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (SecurityException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (NoSuchMethodException e) {            // TODO Auto-generated catch block            e.printStackTrace();        } catch (InvocationTargetException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }

更多相关文章

  1. Android(安卓)广播内部机制详解(三)
  2. Linux 解决文件名 中文乱码问题
  3. 关于Android Studio提交代码到Git上的操作(Mac)
  4. Android的Binder机制浅析
  5. Android使用SQLite数据库的简单实例
  6. Android UI Design Tips(Google官方出品:Android UI 设计指导)—

随机推荐

  1. AIDL入门
  2. 关于Android中使用MapActivity类的问题
  3. android Debug模式如何签名
  4. 开源 Android 开发平台 Rexsee 开发团队
  5. Static interface methods are only supp
  6. android小知识之意图(intent)
  7. Android 7.1 车机 Android 系统 在线升级
  8. android连续点击出现多个Activity界面
  9. Android Hierarchy Viewer
  10. 华软项目总结