对于单个 SIM 以下代码有效:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String imei= tm.getDeviceId();
对于双 SIM 卡,我尝试了以下链接上的代码:
但这对我不起作用。
让我知道是否有其他可能的解决方案。
对于单个 SIM 以下代码有效:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String imei= tm.getDeviceId();
对于双 SIM 卡,我尝试了以下链接上的代码:
但这对我不起作用。
让我知道是否有其他可能的解决方案。
尝试使用getDeviceId(int slotId)
API 级别 23 中的添加。
返回订阅的唯一设备 ID,例如 GSM 的 IMEI 和 CDMA 手机的 MEID。如果设备 ID 不可用,则返回 null。
需要权限:
READ_PHONE_STATE
我们可以通过使用Android API和IMEI为每个sim卡检查手机是单卡还是双卡
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));
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());
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
是的,我们可以使用以下代码获取两个 IMEI 号码
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imeiNumber1 = tm.getDeviceId(1); //(API level 23)
String imeiNumber2 = tm.getDeviceId(2);
AFAIK 这是不可能的。您使用的 java 反射可能适用于某些设备,但不是全部。但是,可能有一些制造商特定的 API 允许这样做。
引用Commonsware,
Android 不支持多个 SIM 卡,至少来自 SDK。已创建多 SIM 卡设备的设备制造商正在自行开发。欢迎您联系您的设备制造商,看看他们是否有 SDK 插件或允许您访问第二张 SIM 卡的东西。
是的,Android 目前不支持 Dual Sim。但是您可以使用 Java 反射检索所有可能的细节。
我研究获取双 SIM 卡详细信息,它适用于以下设备
Samsung Galaxy Neo
Moto E
Micromax A52
Micromax Canvas
Linovo P780
HTC Dreem
Moto G
LG
HUAWEI Y520-U22
LG-P705
Sony ST26i
我成功从上述型号获得双 SIM 卡详细信息
步骤: 1 > 您必须启用 READ_PHONE_STATE 权限
<uses-permission android:name="android.permission.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) );
您可以使用此方法获取两个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 O 或更高版本中使用 IMEI。
Set<String> 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));
}
尝试使用以下代码获取 Android 设备的 IMEI 号码:
telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
btn_imei.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CODE);
return;
}
StringBuilder stringBuilder = new StringBuilder();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (int i = 0; i < telephonyManager.getPhoneCount(); i++) {
stringBuilder.append(telephonyManager.getImei(i));
stringBuilder.append("\n");
}
}
txt_imei.setText(stringBuilder.toString());
}
});
TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);
String imeiSIM1 = telephonyInfo.getImsiSIM1();
String imeiSIM2 = telephonyInfo.getImsiSIM2();
boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
boolean isSIM2Ready = telephonyInfo.isSIM2Ready();
boolean isDualSIM = telephonyInfo.isDualSIM();
TextView tv = (TextView) findViewById(R.id.txt_imei);
tv.setText(" IME1 : " + imeiSIM1 + "\n" +
" IME2 : " + imeiSIM2 + "\n" +
" IS DUAL SIM : " + isDualSIM + "\n" +
" IS SIM1 READY : " + isSIM1Ready + "\n" +
" IS SIM2 READY : " + isSIM2Ready + "\n");
}