如何在Android手机中获取IMSI No of Second Sim

时间:2016-11-19 06:49:15

标签: android

我使用的是TelephonyManager,我可以获得SIM1的SubscriberID(IMSI),但SIM2无法获得相同的功能。但是我能够为两个SIM卡插槽获得IMEI否,但我仍然无法获得第二个SIM卡的IMSI。有没有办法获得这些信息?

2 个答案:

答案 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)