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

对于单个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];

parameter[0] = 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值