4

I have a use case where I need to check whether a SIM is active in the device. In older devices, I can use TelephonyManager to get the SIM state and check whether it is SIM_STATE_READY. The issue is with API 22 and above.

Using SubscriptionManager, when I call getActiveSubscriptionInfoList, it sends me details about the SIMs present, even if I have turned them off. I went through the documentation of SubscriptionManager but couldn't find a similar method to check SIM's state. Using TelephonyManager in API above 22 gives information only about the default SIM, I would like to know this about both slots in dual SIM phones. Also, I found an overloaded variant of getSimState in TelephonyManager which does accept the slot as a parameter, but that got introduced in API 26. I would like a solution that will work in APIs 22-25 as well.

Is there a way I could identify that even though the SIM is present in the device, it isn't active?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • https://stackoverflow.com/questions/3981007/how-can-i-check-whether-the-sim-card-is-available-in-an-android-device Did you check this link – Rahul Arora Feb 22 '19 at 10:42
  • Did you check the official [doc](https://developer.android.com/reference/android/telephony/TelephonyManager.html#getSimState(int)) – Tanveer Munir Feb 22 '19 at 10:43
  • @RahulArora That link mentions getting deviceId for different slots which will just confirm the presence of a slot, it doesn't tell me if the SIM is active. – Himanshu Prasad Feb 22 '19 at 10:51
  • @TanveerMunir I did mention that method in my question, the issue is that it was introduced in API 26. I need something similar which will work for APIs 22-25. – Himanshu Prasad Feb 22 '19 at 10:51
  • @HimanshuPrasad I think you are asking about that `getActiveSubscriptionInfoList` which is available in API 22 please have to look at this [doc](https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoList%28%29) – Tanveer Munir Feb 22 '19 at 11:17
  • @TanveerMunir As mentioned in my question, that method returns the SIM details even if I turn off the SIM from phone settings. – Himanshu Prasad Feb 22 '19 at 11:22
  • @HimanshuPrasad I post my answer hope that's work for you. – Tanveer Munir Feb 22 '19 at 11:40

2 Answers2

0

You can check by like this if Device is dual sim

    SubscriptionManager sManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        SubscriptionInfo infoSim1 = sManager.getActiveSubscriptionInfoForSimSlotIndex(0);
        SubscriptionInfo infoSim2 = sManager.getActiveSubscriptionInfoForSimSlotIndex(1);
        int count = 0;
        if (infoSim1 != null ) {
            count++;
        }
        if (infoSim2 != null){
            count++;
        }

count decides that how many sims are active.

OR

You can get the count then check one by one

sManager.getActiveSubscriptionInfoCount()

Hope it's work.

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
  • 1
    As I mentioned, I have already tried this. The returned object isn't null even if you turn off the SIM from the phone settings. – Himanshu Prasad Feb 22 '19 at 11:43
  • You mentioned that you are using `getActiveSubscriptionInfoList` this method not this `getActiveSubscriptionInfoForSimSlotIndex(0)` according doc it's return null if sim is not in an active state. – Tanveer Munir Feb 22 '19 at 11:48
  • getActiveSubscriptionInfoList returns an array and getActiveSubscriptionInfoForSimSlotIndex returns individually according to the slot. Both of them return the info of the SIM which is present but turned off. – Himanshu Prasad Feb 22 '19 at 11:53
  • @HimanshuPrasad yes I know that but according to document its returns null if the sim is not active. – Tanveer Munir Feb 22 '19 at 11:58
  • @TanveerMunir then share the doc link if possible – Mohd Qasim Apr 22 '22 at 13:44
  • after disable the sim getting __SubscriptionInfo __ object not __null__ value – Mohd Qasim Apr 22 '22 at 13:55
0
 TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneCount() == 2) {
  // Dual sim
}

Examples here

Axes Grinds
  • 756
  • 12
  • 24