600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 【android开发】【通信】设置默认拨号sim1/sim2

【android开发】【通信】设置默认拨号sim1/sim2

时间:2020-04-01 19:36:06

相关推荐

【android开发】【通信】设置默认拨号sim1/sim2

设置默认拨号sim1/sim2

文章目录

设置默认拨号sim1/sim21. 需求分析2. 原理解析3. 实现代码

1. 需求分析

自动化测试过程中需要拨打电话,仅仅只是电话就好。

但双卡情况下会有弹窗,让用户选择哪个sim卡拨号,所以需要接口去设置默认拨号为sim1或sim2,就么有弹窗了。

图示如下:

2. 原理解析

因为要有UI的变化,所以我们从系统framework源码中去找.

找到这个接口 :

setUserSelectedOutgoingPhoneAccount()

slotID就是卡槽ID, 卡槽1=0,卡槽2=1

subscription 为卡槽上注册的信息,就是sim卡信息

3. 实现代码

代码简写如下:

//导入包import telecomMnager, telephonyManager, subScriptionManagerimport subscriptionInfo/*** slot id, 0=sim1, 1=sim2*/public static boolean setDefaultSimCardForCall(int slotid){if( !(slotid==0 || slotid==1) ) return false; //参数合法验证//获取相关servieSubscriptionManager 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@, 谢谢

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。