相关 api

getCallCapablePhoneAccounts
Added in API level 23

Android 5.0 之前的版本

Call from second sim

获取 sim 卡数量

public static boolean isMultiSim(Context context){
boolean result = false;
TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
if(telecomManager != null){
List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
result = phoneAccountHandleList.size() >= 2;
}
return result;
}

用指定 sim 卡拨号

public static void call(Context context, int id, String telNum){
TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); if(telecomManager != null){
List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts(); Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + telNum));
intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandleList.get(id));
context.startActivity(intent);
}
}

获取卡的颜色

public static int getSimColor(Context context, int id){
int highlightColor = 0;
TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
if(telecomManager != null) {
List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts(); PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandleList.get(id));
if (phoneAccount != null) {
highlightColor = phoneAccount.getHighlightColor();
}
}
return highlightColor;
}

获取最近一次通话使用的 sim 卡

public static String getLastestSim(Context context, String telNum){
String result = "SIM1";
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER, CallLog.Calls.PHONE_ACCOUNT_ID},
CallLog.Calls.NUMBER + " = ?", new String[]{telNum}, CallLog.Calls.DEFAULT_SORT_ORDER);
if (cursor != null && cursor.moveToFirst()) {
int subId = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));
Logger.d(TAG, "getLastestSim subId:" + subId);
int slotId = getSlotIdUsingSubId(subId, context);
Logger.d(TAG, "getLastestSim slotId:" + slotId);
if(1 == slotId){
result = "SIM2";
}
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(cursor != null){
cursor.close();
}
} Logger.d(TAG, "getLastestSim result:" + result); return result;
}

用 SubscriptionId 获取 slot_id

public static int getSlotIdUsingSubId(int subId,Context context) throws InvocationTargetException {
int result = 0;
try {
Class<?> clz = Class.forName(SUBSCRIPTION_MANAGER);
Object subSm;
Constructor<?> constructor = clz.getDeclaredConstructor(Context.class);
subSm = constructor.newInstance(context);
Method mth = clz.getMethod("getSlotId", int.class);
result = (int)mth.invoke(subSm, subId); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| IllegalArgumentException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return result;
}

最新文章

  1. 好玩的Handler
  2. PHP运行及语句及逻辑
  3. JQuery实现图片轮播效果源码
  4. prototype.js简介
  5. com组件远程桌面rdp模块的调用
  6. uva 120 stacks of flapjacks ——yhx
  7. Controller之间传递数据:属性传值
  8. iOS开发 Date转字符串
  9. ASP.NET伪静态-无法读取配置文件,因为它超过了最大文件大小的解决办法
  10. ACM1019_最大公倍数
  11. ViewPager和SwipeRefreshLayout之间嵌套使用时发生&quot;事件&quot;冲突
  12. [iOS]使用symbolicatecrash分析crash文件
  13. MFC窗口的父子关系和层级关系
  14. TinyFox 部署在CentOS7 中测试使用
  15. 封装sqlhelper类
  16. 水dp第二天(背包有关)
  17. 解决PhpStorm卡顿的问题
  18. IP地址及网络常识
  19. 单点登录系统和CAS的简介
  20. 机器学习笔记之二-win10+cuda9.1+CUDNN7+Anaconda3+VS2017+tensorflow1.5+opencv3.4

热门文章

  1. hadoop 学习笔记 (十) mapreduce2.0
  2. 随时可以给doT模板传任何你想要的值
  3. Android 使用HttpClient方式提交GET请求
  4. QT变异版本下载(SJLJ长跳转,DWARF不传递错误(32位专用),SEH(64位专用)),以及QT的实验室项目
  5. c++复习基础要点02 虚函数与模板 与static inline是否共存
  6. 【POJ】2886 Who Gets the Most Candies?
  7. C++ Prime:decltype类型指示符
  8. dpkg error
  9. Defining as a &quot;long&quot; or &quot;int&quot; type throws an error on startup
  10. POJ 1503 Integer Inquiry 简单大数相加