3

For API 22+ I am trying to use SubscriptionManager to read dual SIM IMSI.

The IMSI is a 14 to 15 characters in the following format: "MCC-MNC-MSIN" MCC = Mobile Country Code (e.g. 310 for USA); MNC = Mobile Network Code (e.g. 410 for AT&T), MSIN = sequential serial number.

There is no method in the class to get the IMSI. There are methods to get both MCC & MNC but not MSIN.

So my question is, how to get the full IMSI using SubscriptionManager?

Update: SubscriptionManager returns wrong/same MCC & MNC for different SIMs. Testing on Motorola Moto E running Android 5.1

Update: SubscriptionManager is working fine on Moto G running Android 6.0. But there is no way to read the SIM status.

Beshoy Fayez
  • 300
  • 5
  • 10
  • Wouldn't MISN be subscriptionInfo.getNumber()? – Gabe Sechan Apr 28 '16 at 00:08
  • The documentation doesn't clearly state that and it is always empty. Besids I don't need the MSISDN here. @GabeSechan – Beshoy Fayez Apr 28 '16 at 00:36
  • Is it compulsory for you to use the SubscriptionManager?If you use SystemProperties class to get the number what will be the problem? – Lips_coder Apr 28 '16 at 07:30
  • @CrazyAndroid I don't care about the phone number. I want the full IMSI. SubscriptionManager provides the first to parts (MCC & MNC) but not the last part (MSIN) which is a unique 9 digit not equal to the phone number. – Beshoy Fayez Apr 28 '16 at 20:56

1 Answers1

4

There is a public but hidden method getting the subscriber ID(the IMSI for a GSM phone) for a given subscription ID. I don't know why it is hidden but you can call it without problem using java reflection.

Even getSubscriberId internally calls getSubscriberId(int subId), so i think it is safe to use.

Here's an example.

TelephonyManager telephonyManager = (TelephonyManager) mContext
            .getSystemService(Context.TELEPHONY_SERVICE);
int slotIndex = 1;
int subscriptionId = SubscriptionManager.from(mContext).getActiveSubscriptionInfoForSimSlotIndex(slotIndex).getSubscriptionId();
try {
    Class c = Class.forName("android.telephony.TelephonyManager");
    Method m = c.getMethod("getSubscriberId", new Class[] {int.class});
    Object o = m.invoke(telephonyManager, new Object[]{subscriptionId});

    String subscriberId = (String) o;
} catch (Exception e) {
    e.printStackTrace();
}