双卡双待手机[海信]挂断来电和指定卡去电实现

本文探讨了双卡双待手机中如何通过指定SIM卡拨打电话,并介绍了挂断来电的技术细节。利用反射方法实现了对主副卡来电状态的判断及挂断功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

海双卡双待手机[海信]挂断来电和指定卡去电实现的技术调研信双卡手机拨打电话时,在启动拨打电话时,传递一个参数给系统,这样系统的可以根据该参数判断使用指定的卡:
 Intent i = new Intent();
 i.setAction(Intent.ACTION_CALL);
 i.setData(Uri.parse("tel:" + address));
 i.putExtra("subscription", type);// subscription 是名称,不可改变. type :1为gsm卡|0为电信卡
 i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 context.startActivity(i);


海信手机在挂断电话时,使用反射方法,获取endcall(int) 参数来挂断电话,
 try {
                TelephonyManager mTelephyMgr = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
                Method getITelephonyMethod = mTelephyMgr.getClass().getDeclaredMethod("getITelephonyMSim");
                getITelephonyMethod.setAccessible(true);
                Object objITelephonyMSim = getITelephonyMethod.invoke(mTelephyMgr);
                Method intEndCall = objITelephonyMSim.getClass().getMethod("endCall", int.class);
                intEndCall.invoke(objITelephonyMSim, 1);//可挂断主/副卡来电(挂断当前来电)    
//              intEndCall.invoke(objITelephonyMSim, 0);//只能挂断副卡来电
                AVLog.d("block", "block the incoming call");
            } catch (Exception e) {
                e.printStackTrace();
            }


上面代码中之所以没有将注视的代码去掉是因为,经测试当endcall方法参数为1时,可以挂断主卡和副卡来电,参数为0时,只能挂断副卡来电.那么

intEndCall.invoke(objITelephonyMSim, 1);


以上一句话就是可以挂断两个卡的来电了. 移植项目中测试发现.打进电话测试: 广播接收到"android.intent.action.PHONE_STATE"这个action ,监听到此广播,再判断来电状态
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
int callState = tm.getCallState();//获取来电时状态


主卡来电时,上面代码通过,但是在副卡来电获取callState状态时,callState状态是0(PHONE_IDLE =0 电话挂断状态,PHONE_RINGRING = 1是响铃状态).那么继续猜测,副卡来电时,android系统的api方法getCallState()是不能获取副卡的来电状态的,这需要使用反射方法获取主卡和副卡的状态,只要有来电,一定有一个卡的callstate是PHONE_RINGRING状态,代码如下
        Method getITelephonyMethod = mTelephyMgr.getClass().getDeclaredMethod("getITelephonyMSim");
        getITelephonyMethod.setAccessible(true);
        Object objITelephonyMSim = getITelephonyMethod.invoke(mTelephyMgr);
        Method intEndCall = objITelephonyMSim.getClass().getMethod("getCallState", int.class);
        int state1 = (Integer) intEndCall.invoke(objITelephonyMSim, 0);//主卡状态
        int state2 = (Integer)intEndCall.invoke(objITelephonyMSim, 1);//副卡状态
        if (state1 == 1 || state2 ==1) {
        //来电话了,执行拒接逻辑
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值