ree1991
ree1991

Reputation: 197

Which SIM slot is checked when telephonyMananger.getSimSerialNumber() is called in a dual sim phone?

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).

Upvotes: 1

Views: 2147

Answers (2)

Prithvi Bhola
Prithvi Bhola

Reputation: 3151

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.

Upvotes: 3

grabarz121
grabarz121

Reputation: 656

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)
    }

Upvotes: 1

Related Questions