android双待手机获取每一张SIM卡的imei

/**
* 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

时间: 2024-07-30 14:39:38

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

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

关于android各种双卡手机获取imei,imsi的处理(mtk,展讯,高通等) 目前国内对于双卡智能手机的需求还是很大的,各种复杂的业务会涉及到双卡模块:而android标准的api又不提供对双卡的支持.导致国内双卡模块标准混乱,各个厂商各玩各的.目前我知道的双卡解决方案就有:mtk,展讯,高通,broadcom等. 由于公司业务需要,必须要对双卡手机获取各自的imei,imsi,所以也做了一些研究: 首先是最为应用广泛的mtk平台,国内山寨手机以及一些低端品牌双卡都是做的mtk的双卡解决方

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

SIM卡存储的数据可分为四类:第一类是固定存放的数据.这类数据在移动电话机被出售之前由SIM卡中心写入,包括国际移动用户识别号(IMSI).鉴权密钥(KI).鉴权和加密算法等等.第二类是暂时存放的有关网络的数据.如位置区域识别码(LAI).移动用户暂时识别码(TMSI).禁止接入的公共电话网代码等.第三类是相关的业务代码,如个人识别码(PIN).解锁码(PUK).计费费率等.第四类是电话号码簿,是手机用户随时输入的电话号码.用户全部资料几乎都存储在SIM卡内,因此SIM卡又称为用户资料识别卡. 

Android 6.0 SIM卡初始化流程

本文主要讲述Android 6.0 SIM卡初始化流程,这个过程也涉及到UICC框架的初始化,UICC(Universal Integrated Circuit Card)的架构图如下: /** * This class is responsible for keeping all knowledge about * Universal Integrated Circuit Card (UICC), also know as SIM's, * in the system. It is also

编写代码模拟手机与SIM卡的组合关系。.........

编写代码模拟手机与SIM卡的组合关系. 要求: SIM卡类负责创建SIM卡: Phone类负责创建手机: 手机可以组合一个SIM卡: 手机可以更换其中的SIM卡. package test; public class phone { SIM sim;//声明对象 void setSIM(SIM card) { sim = card; } long lookNumber() { return sim.getNumber(); } } package test; public class SIM {

Android 通过反射及AIDL获取双卡手机SIM卡相关信息,及注册监听

在Android 5.0之前,虽然也有手机是双卡手机,但是双卡方案都是ODM厂商自己做的,或者是有芯片厂商提供的源码完成.因此,如果要在4.4甚至更早之前的手机上获取双卡信息,基本上不是一向巨大的工程.虽然之前尝试过使用反射方法去获取 高通的"android.telephony.MSimTelephonyManager"类 MTK的"com.mediatek.common.telephony.ITelephonyEx.aidl"类, 打印出函数的方法和参数以及类属性

【小功能2】android获取手机信息(号码,内存,CPU,分辨率,MAC,IP,SD卡,IMEI,经纬度,信号强度等等)

为了实现一个功能,需要搜集手机信息,自己先在网上找了相关信息进行了汇总,主要是汇集手机的信息,一般想要的信息在手机设置->关于手机->状态消息里面包含了手机的各种信息,下面的代码中也主要显示了那些信息,但是源码的方法我还没有看,先把总结的贴出来.先上图(太多就截取几个).  上代码啦,太多了,就写主要代码了. // 获取Android手机中SD卡存储信息 获取剩余空间 public void getSDCardInfo() { // 在manifest.xml文件中要添加 /* * <u

Android Demo手机获取验证码

注册很多app或者网络账户的时候,经常需要手机获取验证码,来完成注册,那时年少,只是觉得手机获取验证码这件事儿很好玩,并没有关心太多,她是如何实现的,以及她背后的故事到底是什么样子的,现在小编接手的这个项目里面,就需要通过手机号进行注册,并且手机号发送相应的验证码,来完成注册,那么在一些应用app里面到底是如何实现点击按钮获取验证码,来完成注册这整个流程的呢?今天小编就以注册为例,和小伙伴们分享一下,如何通过手机号获取验证码来完成注册的一整套流程以及如何采用正则表达式来验证手机号码是否符合电信.

TelephonyManager类:Android手机及Sim卡状态的获取

TelephonyManager这个类很有用,可以得到很多关于手机和Sim卡的信息. 直接上注释后的代码,请享用 package net.sunniwell.app;import android.app.Activity;import android.os.Bundle;import android.telephony.CellLocation;import android.telephony.PhoneStateListener;import android.telephony.Telepho

Android开发之获取手机SIM卡信息

TelephonyManager是一个管理手机通话状态.电话网络信息的服务类.该类提供了大量的getXxx(),方法获取电话网络的相关信息. TelephonyManager类概述: 可用于訪问有关设备上的电话服务信息. 应用程序能够使用这个类的方法来确定电话服务和状态,以及訪问某些类型的用户信息.应用程序还能够注冊一个侦听器以接收的电话状态变化通知. 你不能直接实例化这个类;相反,你能够通过Context.getSystemService(Context.TELEPHONY_SERVICE)方