/**
* create a TelephonyInfo.java class
*/
import java.lang.reflect.Method;

import android.content.Context;
import android.telephony.TelephonyManager;

public final class TelephonyInfo {

private static TelephonyInfo telephonyInfo;
private String imeiSIM1;
private String imeiSIM2;
private boolean isSIM1Ready;
private boolean isSIM2Ready;

public String getImeiSIM1() {
return imeiSIM1;
}

/*public static void setImeiSIM1(String imeiSIM1) {
TelephonyInfo.imeiSIM1 = imeiSIM1;
}*/

public String getImeiSIM2() {
return imeiSIM2;
}

/*public static void setImeiSIM2(String imeiSIM2) {
TelephonyInfo.imeiSIM2 = imeiSIM2;
}*/

public boolean isSIM1Ready() {
return isSIM1Ready;
}

/*public static void setSIM1Ready(boolean isSIM1Ready) {
TelephonyInfo.isSIM1Ready = isSIM1Ready;
}*/

public boolean isSIM2Ready() {
return isSIM2Ready;
}

/*public static void setSIM2Ready(boolean isSIM2Ready) {
TelephonyInfo.isSIM2Ready = isSIM2Ready;
}*/

public boolean isDualSIM() {
return imeiSIM2 != null;
}

private TelephonyInfo() {
}

public static TelephonyInfo getInstance(Context context){

if(telephonyInfo == null) {

telephonyInfo = new TelephonyInfo();

TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));

telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();;
telephonyInfo.imeiSIM2 = null;

try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();

try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}

telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
telephonyInfo.isSIM2Ready = false;

try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
} catch (GeminiMethodNotFoundException e) {

e.printStackTrace();

try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
}

return telephonyInfo;
}

private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

String imei = null;

TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

try{

Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);

Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimID.invoke(telephony, obParameter);

if(ob_phone != null){
imei = ob_phone.toString();

}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}

return imei;
}

private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

boolean isReady = false;

TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

try{

Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);

Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);

if(ob_phone != null){
int simState = Integer.parseInt(ob_phone.toString());
if(simState == TelephonyManager.SIM_STATE_READY){
isReady = true;
}
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}

return isReady;
}

private static class GeminiMethodNotFoundException extends Exception {

private static final long serialVersionUID = -996812356902545308L;

public GeminiMethodNotFoundException(String info) {
super(info);
}
}
}

And then use this class like that:

private void isDualSimOrNot(){
TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this); String imeiSIM1 = telephonyInfo.getImeiSIM1();
String imeiSIM2 = telephonyInfo.getImeiSIM2(); boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
boolean isSIM2Ready = telephonyInfo.isSIM2Ready(); boolean isDualSIM = telephonyInfo.isDualSIM();
Log.i("Dual = "," IME1 : " + imeiSIM1 + "\n" +
" IME2 : " + imeiSIM2 + "\n" +
" IS DUAL SIM : " + isDualSIM + "\n" +
" IS SIM1 READY : " + isSIM1Ready + "\n" +
" IS SIM2 READY : " + isSIM2Ready + "\n");
}

Above code works perfectly for me.

转载自:http://stackoverflow.com/questions/11880881/how-can-i-get-both-imei-numbers-from-dual-sim-mobile

android双待手机获取每一张SIM卡的imei的更多相关文章

  1. 关于android各种双卡手机获取imei,imsi的处理(mtk,展讯,高通等)

    目前国内对于双卡智能手机的需求还是很大的,各种复杂的业务会涉及到双卡模块:而android标准的api又不提供对双卡的支持.导致国内双卡模块标准混乱,各个厂商各玩各的.目前我知道的双卡解决方案就有:m ...

  2. android获取通讯记录,sim卡和手机

    //获取手机和手机卡通讯录 public static String getContacts() { String szContacts = ""; szContacts=getP ...

  3. 如何判断手机收有几张SIM卡

    //判断卡槽1中是不是有卡 boolean hasIccCard1 = MSimTelephonyManager.getDefault().hasIccCard(0); //判断卡槽2中是不是有卡 b ...

  4. 获取sim 卡的IMEI 和 IMSI

    IReadOnlyList<string> networkAccIds = Windows.Networking.NetworkOperators.MobileBroadbandAccou ...

  5. Android本机号码及Sim卡状态的获取

    SIM卡存储的数据可分为四类:第一类是固定存放的数据.这类数据在移动电话机被出售之前由SIM卡中心写入,包括国际移动用户识别号(IMSI).鉴权密钥(KI).鉴权和加密算法等等.第二类是暂时存放的有关 ...

  6. 手机SIM卡知识大科普

    SIM卡 SIM卡是(Subscriber Identity Module 客户识别模块)的缩写,也称为智能卡.用户身份识别卡,GSM数字移动电话机必须装上此卡方能使用.它在一电脑芯片上存储了数字移动 ...

  7. 手机SIM卡无法识别解决方案

    SIM卡是工作中测试用的,经常插拔到不同的手机,前两天SIM卡放到手机中都能正常识别,今天插入到另一款手机中发现无法识别.心里糟了,是不是卡坏了,根据之 前的直觉,在公司找了一块橡皮,在SIM卡的芯片 ...

  8. 手机号是SIM卡的号呢,还是买手机时就带的

    可以用原来的号码!把原来的卡装在新手机里就可以了,你的号码没有改变! 手机的号是由sim卡来决定的! 但是卡上的号码显示的是卡的一些信息! 你不用去理会它! 全文:http://iask.sina.c ...

  9. 017 Android 获取手机SIM卡序列号和读取联系人

    1.获取手机SIM卡序列号 //5.存储sim卡系列号 //5.1获取sim卡系列号 TelephonyManager manager = (TelephonyManager) getSystemSe ...

随机推荐

  1. Java开源生鲜电商平台-系统简介

    Java开源生鲜电商平台-系统简介 1.生鲜电商平台的价值与定位. 生鲜电商平台是一家致力于打造全国餐饮行业智能化.便利化.平台化与透明化服务的创新型移动互联网平台,连接买家与卖家之间的一个平台 看以 ...

  2. DUIR Framework 相关技术介绍

    开发者在搭建界面自动化测试框架时,又或者在开发界面自动化控制的机器人时,往往需要对界面进行自动化的程序控制.而现在公司内部使用的杜尔自动化框架,就是一个封装了界面自动化控制逻辑的程序框架.基于该框架, ...

  3. remove the nth node from the end of the list

    problem description: remove the nth node from the end of the list for example: given: 1->2->3 ...

  4. thinkphp框架实现删除上传的文件

    public function article_delete(){ $article_id = I('get.article_id'); $model = M('zx_article'); $data ...

  5. 报错:严重: Servlet.service() for servlet [springmvc] in context with path [ ] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

    解决:service类或dao类需要@Autowired

  6. spring 整合 shiro框架

    shiro是用来干嘛的?从它的官网上(http://shiro.apache.org/)基本可以了解到,她主要提供以下功能: (1)Authentication(认证) (2)Authorizatio ...

  7. .NET之IOC控制反转运用

    当前场景: 如果有不同的用户.使用同一个系统.而不同的客户有某些不同的需求.在不改变系统主体的情况下,可以直接使用IOC控制反转依赖搭建项目 1.添加接口层 目前里面只有一个会员的类.里面有一个登录接 ...

  8. Java基础系列--桶排序

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/9045967.html 1.算法简介 桶排序可以算是最简单快速的排序算法了,只是限定条件要多 ...

  9. tkinter中表格的建立(十三)

    表格的建立 import tkinter from tkinter import ttk wuya = tkinter.Tk() wuya.title("wuya") wuya.g ...

  10. LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers

    344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...