Starting on API Level 22, there is native support in Android for Dual-SIM devices. At the center of the APIs, there is SubscriptionInfo.getSubscriptionId()
.
Using these IDs, you can retrieve SmsManager
s for each respective SIM card to send SMS and MMS. You can also identify through which SIM card an SMS was received on the SMS_RECEIVED_ACTION
, and so on.
However, what is the lifetime of a Subscription ID? Can I store a Subscription ID in a local database and count on it to still be valid and pointing to the same SIM card later? By later, I mean after rebooting the device, removing its SIM card and popping it back in, or even after factory resetting the device.
I tested the resilience of
SubscriptionId
myself, using two SIM cards, though on a Single-SIM device, since that is what I had available at the time.First, I noted the
SubscriptionId
the system was giving me when SIM Card A was inserted. TheSubscriptionId
I was getting had a value of2
.Next, I restarted the device. The
SubscriptionId
after restart was still2
.Then, I turned off the device, removed SIM Card A and put in SIM Card B. After turning the device back on, the
SubscriptionId
changed to4
.Lastly, I turned the device back off, removed SIM Card B and put SIM Card A back in. After turning the device back on, the
SubscriptionId
changed back to2
.In conclusion, it looks like Android assigns a
SubscriptionId
unique to each SIM Card. TheSubscriptionId
seems to survive system reboots, and SIM Card removal and reinsertion. I did not test factory resets, but my gut feeling is that it probably will not survive those, since the system would not have any history of interaction with a SIM Card after a factory reset.