Android 6.0 双卡拨号
相关 api
getCallCapablePhoneAccounts
Added in API level 23
Android 5.0 之前的版本
获取 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 双卡拨号的更多相关文章
- Android 5.0 双卡信息管理分析
首先,如前面的博文所讲的,Android5.0开始支持双卡了.另外,对于双卡的卡信息的管理,也有了实现,尽管还不是完全彻底完整,如卡的slot id, display name,iccid,color ...
- Android 6.0 运行时权限处理完全解析
一.概述 随着Android 6.0发布以及普及,我们开发者所要应对的主要就是新版本SDK带来的一些变化,首先关注的就是权限机制的变化.对于6.0的几个主要的变化,查看查看官网的这篇文章http:// ...
- Google Android 6.0 权限完全解析
注:本文只针对Google原生Android系统有效, 小米魅族等手机有自己的权限机制, 可能不适用 一.运行时权限的变化及特点 新的权限机制更好的保护了用户的隐私,Google将权限分为两类,一类是 ...
- Android 6.0 新功能及主要 API 变更
运行时权限 这个版本中引入了新的权限模型,现在用户可以在运行时直接管理应用程序的权限.这个模型基于用户对权限控制的更多可见性,同时为应用程序的开发者提供更流畅的应用安装和自动升级.用户可以为已安装的每 ...
- Android 4.0源码目录结构
转:http://blog.csdn.net/xiangjai/article/details/9012387 在学习Android的过程中,学习写应用还好,一开始不用管太多代码,直接调用函数就可以了 ...
- Android 6.0 Changes
原文链接:http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html 伴随着新特性和功能,Andr ...
- Android 4.0 ICS SystemUI浅析——StatusBar结构分析
Android 4.0 ICS SystemUI浅析——StatusBar结构分析 分类: Android2012-06-30 14:45 23687人阅读 评论(8) 收藏 举报 androidsi ...
- Android 7.0(牛轧糖)新特性
Android 7.0(牛轧糖)新特性 谷歌正式在I/O大会现场详细介绍了有关Android 7.0的大量信息.目前,我们已经知道,新一代Android操作系统将支持无缝升级,能够通过Vulkan A ...
- 还在期待安卓9.0吗?Android 10.0要来了
目前,美国 Google公司的 AndroidP (安卓9.0),已经正式全面推出有几个多月了.众多手机品牌厂商也都在积极的进行更新适配 Android 9.0 系统(修改UI界面也算是二次开发,嗯) ...
随机推荐
- 正则表达式替换img标签src值!!!
方法一: 相关链接:http://bbs.csdn.net/topics/320185735 实例:此实例自己做的时候讲字符串加了alt进行了有关修改 不清楚看上面链接 string test = ...
- ios开发之C语言第一天
最近在学习ios开发,先学习C语言,再学习OC和swift.正所谓"万丈高楼平地起",打好基础是很重要的,所以C语言也必须好好学习.学习中所使用的操作系统是OS X,开发工具是Xc ...
- 学习Swift -- 泛型
泛型 泛型代码可以让你写出根据自我需求定义.适用于任何类型的,灵活且可重用的函数和类型.它的可以让你避免重复的代码,用一种清晰和抽象的方式来表达代码的意图. 泛型所解决的问题 先来看一个交换两个int ...
- 从MVC到前后端分离
摘要:MVC模式早在上个世纪70年代就诞生了,直到今天它依然存在,可见生命力相当之强.MVC模式最早用于Smalltalk语言中,最后在其它许多开发语言中都得到了很好的应用,例如,Java中的Stru ...
- 调用相册怎么设置剪裁-b
//创建一个相册控制器 UIImagePickerController *pc = [[UIImagePickerController alloc] init]; //图片来源// UIImagePi ...
- BZOI 1507 [NOI2003] Editor
Background After trying to solve problem EDIT1(Editor) and being ****ed by Brainf**k, Blue Mary deci ...
- 要将PYTHON应用于工作啦
分析同事在线答疑的数据,考评模型还未最终给出: import time import sys import optparse #操作代码和同事名对应的文件 opfile = 'op_name.txt' ...
- C语言常用数学函数及其用法
转自:http://blog.sina.com.cn/s/blog_8b5a0d0001011779.html 三角函数:(所有参数必须为弧度) 1.acos 函数申明:acos (double ...
- struts2-core-2.1.6.jar!/struts-default.xml无法加载的问题
找到合适且匹配的jar包,更改完jar包后要去.metadata---.me_tcat---webapps---项目名----WEB-INF--lib下将多余的jar包去掉,否则还运行时还存在替换掉的 ...
- MYSQL常用命令集合
1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqld ...