设置默认拨号sim1/sim2
1. 需求分析
自动化测试过程中需要拨打电话,仅仅只是电话就好。
但双卡情况下会有弹窗,让用户选择哪个sim卡拨号,所以需要接口去设置默认拨号为sim1或sim2,就么有弹窗了。
图示如下:
2. 原理解析
因为要有UI的变化,所以我们从系统framework源码中去找.
找到这个接口 :
setUserSelectedOutgoingPhoneAccount()
slotID就是卡槽ID, 卡槽1=0,卡槽2=1
subscription 为卡槽上注册的信息,就是sim卡信息
3. 实现代码
代码简写如下:
//导入包
import telecomMnager, telephonyManager, subScriptionManager
import subscriptionInfo
/**
* slot id, 0=sim1, 1=sim2
*/
public static boolean setDefaultSimCardForCall(int slotid){
if( !(slotid==0 || slotid==1) ) return false; //参数合法验证
//获取相关servie
SubscriptionManager sm = Context.getContext().getSystemService(SubscriptionManager.class);
TelephonyManager tym = Context.getContext().getSystemService(TelephonyManager .class);
TelecomManager tcm = Context.getContext().getSystemService(TelecomManager.class);
// service对象须判空
SubscriptionInfo si = sm.getActiveSubscriptionInfoForSimSlotIndex(slotid);
int subid = si.getSubscriptionId();
for(PhoneAccountHandle pah : tcm.getCallCapablePhoneAccounts()) {
if(subid == tym.getSubIdForPhoneAccount(tcm.getPhoneAccount(pah))) {
log("got it");
tcm.setUserSelectedOutgoingPhoneAccount(pah); //设置默认
return true;
}
}
return false;
}
–有任何疑问可留言讨论或发邮件给我timyhao@126.com, 谢谢