相关 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;
}

Android 6.0 双卡拨号的更多相关文章

  1. Android 5.0 双卡信息管理分析

    首先,如前面的博文所讲的,Android5.0开始支持双卡了.另外,对于双卡的卡信息的管理,也有了实现,尽管还不是完全彻底完整,如卡的slot id, display name,iccid,color ...

  2. Android 6.0 运行时权限处理完全解析

    一.概述 随着Android 6.0发布以及普及,我们开发者所要应对的主要就是新版本SDK带来的一些变化,首先关注的就是权限机制的变化.对于6.0的几个主要的变化,查看查看官网的这篇文章http:// ...

  3. Google Android 6.0 权限完全解析

    注:本文只针对Google原生Android系统有效, 小米魅族等手机有自己的权限机制, 可能不适用 一.运行时权限的变化及特点 新的权限机制更好的保护了用户的隐私,Google将权限分为两类,一类是 ...

  4. Android 6.0 新功能及主要 API 变更

    运行时权限 这个版本中引入了新的权限模型,现在用户可以在运行时直接管理应用程序的权限.这个模型基于用户对权限控制的更多可见性,同时为应用程序的开发者提供更流畅的应用安装和自动升级.用户可以为已安装的每 ...

  5. Android 4.0源码目录结构

    转:http://blog.csdn.net/xiangjai/article/details/9012387 在学习Android的过程中,学习写应用还好,一开始不用管太多代码,直接调用函数就可以了 ...

  6. Android 6.0 Changes

    原文链接:http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html 伴随着新特性和功能,Andr ...

  7. Android 4.0 ICS SystemUI浅析——StatusBar结构分析

    Android 4.0 ICS SystemUI浅析——StatusBar结构分析 分类: Android2012-06-30 14:45 23687人阅读 评论(8) 收藏 举报 androidsi ...

  8. Android 7.0(牛轧糖)新特性

    Android 7.0(牛轧糖)新特性 谷歌正式在I/O大会现场详细介绍了有关Android 7.0的大量信息.目前,我们已经知道,新一代Android操作系统将支持无缝升级,能够通过Vulkan A ...

  9. 还在期待安卓9.0吗?Android 10.0要来了

    目前,美国 Google公司的 AndroidP (安卓9.0),已经正式全面推出有几个多月了.众多手机品牌厂商也都在积极的进行更新适配 Android 9.0 系统(修改UI界面也算是二次开发,嗯) ...

随机推荐

  1. C语言学习总结(三) 复杂类型

    第五章.复杂数据类型 (数组.字符串.指针.结构体.枚举.共同体) 1.什么是数组? 概念:把具有相同类型的若干变量按有序的形式组织起来,这些按序排列的同类数据元素的集合称为数组: 按数组元素的类型不 ...

  2. Warning File `.depend' has modification time 1.6 s in the future

    一.前提知识 主机时间与虚拟机时间不同步所致.我们在某一操作系统所属磁盘空间下创建一个文件,那么这个文件的创建时间是以磁盘所属的操作系统的时钟为基准的. 我们假设主机windows的系统时间是10:0 ...

  3. c# 中List<T> union 深入理解

    http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800202.html 借用 这个兄弟的代码 我就不献丑了 .我这里指记录下 public ...

  4. js一些方法的扩展

    //JS扩展方法与C#的扩展方法非常相似,也是可以链式调用的,也是通过对某个类的扩展写法来实现.这个东西非常好用,如果将预先写好的方法放到一个js里面引用的话,那么后面写js将非常有趣. //下面给出 ...

  5. golang开发android环境搭建_window

    golang开发android环境搭建介绍 一 安装依赖软件: git:版本管理 go:  go开发环境(版本>=1.5),可直接下载window版的go安装包. android studio: ...

  6. Maven镜像配置

    镜像是为了提供更快的服务 如图:X就认为是Y的一个镜像. 编辑settings.xml配置中央仓库镜像: <settings> ... <mirrors> <mirror ...

  7. matlab提速技巧(自matlab帮助文件)

    matlab提速技巧(自matlab帮助文件) 1.首先要学会用profiler.1.1. 打开profiler.To open the Profiler, select View -> Pro ...

  8. Java cookie的使用

    1.cookie是什么? cookie是web应用当中非常常用的一种技术,用于储存某些特定的用户信息. 2.cookie的作用? 在用户登陆时将用户的信息存放在cookie中,用户在一定的时间中再次登 ...

  9. C/C++ 开源库及示例代码

    C/C++ 开源库及示例代码 Table of Contents 说明 1 综合性的库 2 数据结构 & 算法 2.1 容器 2.1.1 标准容器 2.1.2 Lockfree 的容器 2.1 ...

  10. leetcode面试准备: Jump Game

    1 题目 Given an array of non-negative integers, you are initially positioned at the first index of the ...