//挂断卡x
LogUtil.d("开始挂断卡x");
try {
Method method = Class.forName("android.os.ServiceManager")
.getMethod("getService", String.class);
IBinder binder = (IBinder) method.invoke(null, new Object[]{Context.TELEPHONY_SERVICE});
ITelephony telephony = ITelephony.Stub.asInterface(binder);
for (int i = 0; i < 20; i++) {
boolean callSuccess = telephony.endCallForSubscriber(i);
if (callSuccess) {
LogUtil.d("挂断卡:" + i + "成功");
} else {
LogUtil.d("挂断卡:" + i + "失败");
}
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.d("挂断卡x出错" + e.getMessage());
}
在双卡手机,并且拨打电话的卡是电信卡的情况下,无法使用endCall挂断另外一张卡。
通过查看源码,看到了另外一个方法endCallForSubscriber
endCallForSubscriber要传入一个subId,这是sim卡的id,在有的手机是0,有的是1,有的是6 ,所以挨着end一次
vivo 三星 锤子 小米 测试都可用
附aidl下载连接:
https://download.csdn.net/download/icewst/11588854
直接把这个放到代码根目录。 就能找到endCall和endCallForSubscriber了。