1
votes

I need the SIM Serial Number to identify the SIM Card for application. The code is very simple for single SIM phones,

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
sim_ID = telephonyManager.getSimSerialNumber();

However, when I test this on a dual SIM phone it gets weird because I can't be sure if the serial number returned is from Slot 1 or Slot 2. Is there any way to get both sim serial numbers? Or can I, in any way, identify which Sim slot is returning the serial number when the above code is called?

P.S. I don't need IMEI numbers or IMSI numbers. I specifically need the SIM serial number (SSN).

2
I am sure that sim1 is used in case of dual sim. I can't prove it, but I'm sure. You can check it by inserting 1 sim into sim2 slot and having sim1 slot empty, and calling this code after that. I think it should return nothing/crash/return empty string. - Vladyslav Matviienko
@VladyslavMatviienko "I am sure that sim1 is used in case of dual sim." - no that is a very wrong assumption. I thought that too at first. But that is not the case. I have tested and found that if only SIot 2 is enabled, that is returned. Then I inserted another sim in Slot 1, the code kept returning SSN of Slot 2. Now if I remove the sim of Slot 2, then it returned the SSN of Slot 1. - ree1991

2 Answers

3
votes

For API level >= 22

It can be obtained using the SubscriptionManager class (added in API level 22, https://developer.android.com/reference/android/telephony/SubscriptionManager)

SubscriptionManager sManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)
SubscriptionInfo infoSim1 = sManager.getActiveSubscriptionInfoForSimSlotIndex(0);
SubscriptionInfo infoSim2 = sManager.getActiveSubscriptionInfoForSimSlotIndex(1);

For API level <= 21

For single SIM: TelephonyManager.getSimSerialNumber()

For dual sim: It depends on the manufacturer of the phone. There is no defined way for getting Sim Serial Number for dual sim below API level 21.

1
votes

Check this.

TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    SubscriptionManager manager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    List<SubscriptionInfo> infoList = manager.getActiveSubscriptionInfoList();

    for (int i = 0; i < infoList.size(); i++) {

        SubscriptionInfo info = infoList.get(i);
        //info.getSimSlotIndex() <- sim card slot number
        //info.getNumber() <- sim card phone number (if exist, you can set this in sim card management)
    }