随笔-348  评论-598  文章-0  trackbacks-0
需要使用反射机制将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();
        }
    }


---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2011-01-25 14:38 TiGERTiAN 阅读(9951) 评论(6)  编辑  收藏 所属分类: Android

评论:
# re: Android弹出拨号界面和拨打电话实现 2012-04-04 11:12 | hello1719
您好啊,我想问一下,为什么我用这段代码的时候,有两句报错呢?如下所示

iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);
dial.invoke(iTelephony, number);


报错内容是:Unhandled exception type InvocationTargetException

您顺便能把ITelephony.aidl 文件内容发一下吗?是不是我少添加了什么内容呢?  回复  更多评论
  
# re: Android弹出拨号界面和拨打电话实现 2012-04-04 18:23 | TiGERTiAN
@hello1719
跟AIDL没啥关系吧,就是直接反射内部类的内部方法  回复  更多评论
  
# re: Android弹出拨号界面和拨打电话实现 2012-04-06 10:19 | hello1719
@TiGERTiAN
嗯已经解决了。。
  回复  更多评论
  
# re: Android弹出拨号界面和拨打电话实现 2013-01-08 09:25 | xiaotang_hb
请问楼主,这里能改变,拨号界面和拨打界面吗?显示我的自定义界面UI?请教下,给我点思路。谢谢  回复  更多评论
  
# re: Android弹出拨号界面和拨打电话实现 2016-03-08 16:45 | jaime
请我dial和call方法有什么区别么?   回复  更多评论
  
# re: Android弹出拨号界面和拨打电话实现 2016-03-09 10:44 | firetomato
这找不到call是怎么回事?现在有别的方法实现这个功能吗?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: