锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

以编程方式在Android中为双SIM卡检索IMEI号码

时间:2022-09-16 15:00:00 y520高静压变送器

对于单个SIM,以下代码有效:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

String imei= tm.getDeviceId();

对于双SIM卡尝试了以下链接上的代码:

Android:检查手机是否为双SIM卡

但这对我没用。

让我知道是否还有其他解决方案。

看看stackoverflow.com/questions/13472951/

查看此链接stackoverflow.com/questions/14517338/

尝试使用API??添加到23级getDeviceId(int slotId)。

Returns the unique device ID of a subscription, for example, the IMEI

for GSM and the MEID for CDMA phones. Return null if device ID is not

available.

Requires Permission: READ_PHONE_STATE

我们可以为每一个SIM卡使用Android API和IMEI检查手机是单卡还是双卡

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

Log.i("OmSai","Single or Dula Sim" manager.getPhoneCount());

Log.i("OmSai","Defualt device ID" manager.getDeviceId());

Log.i("OmSai","Single 1" manager.getDeviceId(0));

Log.i("OmSai","Single 2" manager.getDeviceId(1));

如Android SDK developer.android.com/reference/android/telephony/中所述,用于Android 23 。

要找哪个版本?

我正在寻找API 15

getPhoneCount()方法不可用

TelephonyManager first = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG,"Device Id:" first.getDeviceId() ", device status:" first.getSimState() ", operator:" first.getNetworkOperator() "/" first.getNetworkOperatorName());

obParameter[0] = 1;

TelephonyManager second = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG,"Device Id:" second.getDeviceId() ", device status:" second.getSimState() ", operator:" second.getNetworkOperator() "/" second.getNetworkOperatorName());

虽然这个代码可以回答问题,但提供其他关于如何和/或为什么解决问题的上下文将提高答案的长期价值。

欢迎来到SO。请阅读此操作指南,以提供高质量的答案。

假设我必须在那里sim1和sim2.通过编程创建联系人,您可以告诉我们我们将使用它thanx的Sim URI吗? @Ravindra Barnwal

是的,我们可以同时得到两个IMEI使用以下代码

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

String imeiNumber1 = tm.getDeviceId(1); //(API level 23)

String imeiNumber2 = tm.getDeviceId(2);

我遵循你的回答,但结果恰恰相反(我会的" imeiNumber1"作为辅助IMEI,将" imeiNumber2"作为主要IMEI,然后进行了更多的研究,找到了解决方案。TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String imeiNumber1 = tm.getDeviceId(0); String imeiNumber2 = tm.getDeviceId(1);

假设我必须在那里sim1和sim2.通过编程创建联系人,您可以告诉我们我们将使用它thanx的Sim URI吗? @ user7036069

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

try {

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

Class< ? >[] parameter = new Class[1];

parameter[0] = int.class;

Method getFirstMethod = telephonyClass.getMethod("getDeviceId", parameter);

Log.d("SimData", getFirstMethod.toString());

Object[] obParameter = new Object[1];

obParameter[0] = 0;

TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

String first = (String) getFirstMethod.invoke(telephony, obParameter);

Log.d("SimData","first :" first);

obParameter[0] = 1;

String second = (String) getFirstMethod.invoke(telephony, obParameter);

Log.d("SimData","Second :" second);

} catch (Exception e) {

e.printStackTrace();

}

尝试使用它,这应该有助于在Android Lollipop获得两个设备ID

脚步:

1>您必须启用READ_PHONE_STATE权限

2>对于Android SDK v23 <=以下方式获取SIM 1和SIM 2 IMEI:

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

Log.e("IMEI---1:", tm.getDeviceId(0) );

Log.e("IMEI---2:", tm.getDeviceId(1) );

您可以在Android O或在更高的版本中使用IMEI。

Set deviceIdList = new HashSet<>();

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

int phoneCount = telephonyManager.getPhoneCount();

for (int i = 0; i < phoneCount; i ) {

deviceIdList.add(telephonyManager.getImei(i));

}

你可以同时使用这种方法同时获得imei。对不便道歉。我当时很着急。

public static void samsungTwoSims(Context context) {

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

try{

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

Class< ? >[] parameter = new Class[1];

parameter0] = int.class;

Method getFirstMethod = telephonyClass.getMethod("getDefault", parameter);

Log.d(TAG, getFirstMethod.toString());

Object[] obParameter = new Object[1];

obParameter[0] = 0;

TelephonyManager first = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG,"Device Id:" + first.getDeviceId() +", device status:" + first.getSimState() +", operator:" + first.getNetworkOperator() +"/" + first.getNetworkOperatorName());

obParameter[0] = 1;

TelephonyManager second = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG,"Device Id:" + second.getDeviceId() +", device status:" + second.getSimState()+", operator:" + second.getNetworkOperator() +"/" + second.getNetworkOperatorName());

} catch (Exception e) {

e.printStackTrace();

}

}

是,Android当前不支持Dual Sim。但是,您可以使用Java反射来检索所有可能的细节。

我研究了如何获取双SIM卡详细信息,并且可在以下设备上使用

三星Galaxy Neo

摩托E

微星A52

Micromax帆布

Linovo P780

HTC Dreem

摩托G

LG

华为Y520-U22

LG-P705

索尼ST26i

我成功从上述型号中获得了双SIM卡Detials

SubscriptionManager是一个类,您可以在其中获取android 5.1以上的所有单元格信息

您是否可以使用Reflections同时获得模拟人生运营商/运营商名称?

假设我必须在sim1和sim2中以编程方式创建联系人,那么您能告诉我我们将使用thanx的Sim URI吗? @ user3131373

AFAIK这是不可能的。您使用的Java反射可能适用于某些设备,但并非全部。但是,可能有一些特定于制造商的API允许这样做。

引用通用软件,

Android does not support multiple SIMs, at least from the SDK. Device

manufacturers who have created multi-SIM devices are doing so on their

own. You are welcome to contact your device manufacturer and see if

they have an SDK add-on or something that allows you to access the

second SIM.

这不再是正确的。您可以在最新版本的Android中同时使用imeis

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章