我使用的是TelephonyManager,我可以获得SIM1的SubscriberID(IMSI),但SIM2无法获得相同的功能。但是我能够为两个SIM卡插槽获得IMEI否,但我仍然无法获得第二个SIM卡的IMSI。有没有办法获得这些信息?
答案 0 :(得分:4)
请记住这是获取订阅者身份的骇人听闻的ID,因此可能无法在所有设备上工作
将在Android 5.1.1及更高版本上运行并且需要 android.permission.READ_PHONE_STATE 权限
(记得向用户询问上面marshmallow中的android.permission.READ_PHONE_STATE权限 Android版本,因为它被标记为危险)
public String getSim1IMSI() {
String imsi = null;
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
try {
Method getSubId = TelephonyManager.class.getMethod("getSubscriberId", int.class);
SubscriptionManager sm = (SubscriptionManager) getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE);
imsi = (String) getSubId.invoke(tm, sm.getActiveSubscriptionInfoForSimSlotIndex(0).getSubscriptionId()); // Sim slot 1 IMSI
return imsi;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return imsi;
}
public String getSim2IMSI() {
String imsi = null;
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
try {
Method getSubId = TelephonyManager.class.getMethod("getSubscriberId", int.class);
SubscriptionManager sm = (SubscriptionManager) getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE);
imsi = (String) getSubId.invoke(tm, sm.getActiveSubscriptionInfoForSimSlotIndex(1).getSubscriptionId()); // Sim slot 2 IMSI
return imsi;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return imsi;
}
答案 1 :(得分:0)
您可以使用电话管理器中的getDeviceId方法
https://developer.android.com/reference/android/telephony/TelephonyManager.html#getDeviceId(int)