How long does a Subscription ID stick around in Android? - android

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 SmsManagers 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. The SubscriptionId I was getting had a value of 2.
Next, I restarted the device. The SubscriptionId after restart was still 2.
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 to 4.
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 to 2.
In conclusion, it looks like Android assigns a SubscriptionId unique to each SIM Card. The SubscriptionId 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.

Related

Change data subscription (SIM card) in multi-sim Android phone

I have a dual-sim Android phone and during the morning I use one of the SIM cards for the data connection, and during the evening I use the other one. It's a pita to manually switch from one card to the other twice every day, so I thought I could create a simple app that does the switching at a given time.
I've been reading and looks like starting at version 5.1 of Android's API, theres a SubscriptionManager class which offers info about current subscriptions (data, voice, sms, etc), but as far as I've seen there're a lot of get methods but no setters anywhere.
Does the Android API offer a way of setting the SIM card used in the data connection? I guess it does, because otherwise it wouldn't be possible to change it from the settings panel.

Detect "Ask Every Time" setting on outgoing calls for Dual Sim Phones

I am working on an app that successfully intercepts NEW_OUTGOING_CALL broadcast on outgoing calls and handles calls accordingly. Everything works perfectly fine on single SIM devices.
On Dual SIM devices, I am able to detect which SIM is the default calling SIM by reading the ICCID (it changes depending on which SIM is the default calling SIM) and I am also able to handle calls accordingly (either handle it by my app or pass it back to the native dialer).
The problem I am facing is when users choose the "Ask every time" option. When they choose that option, the ICCID is still read as whichever SIM was set as the default SIM last.
I would like to detect that users have chosen this option so I can pop up a dialog thats asks them, which SIM they want to conduct their call over.
I searched through stackoverflow and scoured everything I could find on Dual SIM but I couldn't find an answer to this question. All the logic I added into handling calls on Dual SIM phones has been rendered useless by this part.
Is there something I can read (whether its a broadcast or an intent extra or an android setting) that would tell me that users want to be asked which SIM to use every time they attempt a call?
Thanks for the help.

How to capture event of removal of SIM card in android?

In android, how do I capture the event of SIM card removal? Usually on phones like htc 1x, we can remove the SIM card without removing the battery and there is no notification as such of power off or restart of the phone. I want to capture the event of SIM card removal, so that I can pop-up some messages.
Check answer number one, You can check whether the sim card is available or not in device by using TelephonyManager class.
How can I check whether the Sim Card is available in an android device?
According to this answer, the system sends out an android.intent.action.SIM_STATE_CHANGED intent when the SIM card when the SIM card changes, for example when entering or leaving airplane mode, and presumably also when removing or inserting a SIM card.
It should be noted that as this is an undocumented API that may change without notice, and it may also not be available on some devices.
As for shutting down or restarting, according to this answer, the system sends out an android.intent.action.ACTION_SHUTDOWN intent (on Android 1.6 or later).

Moving incoming messages to SIM card in Android

I need to move the incoming messages in my android phone directly to the sim card. I know I can click the message and move manually to SIM, but I need to do it automatically. I couldnt find that option anywhere in the settings. I am also fine with an app doing this.
You can try to use AT commands (in your program). E.g. AT+CPMS="SM","SM","SM" - this makes your phone to use its SIM card as the SMS storage.

Check SIM PIN with SDK Android

My app needs to check the pin inserted by a user with the SIM card pin and that Android has to answer me if the pin inserted is correct. I only need to check, never change the code pin.
It is possible?
Not sure if it can be done, but:
I would not rely on a SIM card being present - think of tablets with WiFi only.
Also as a user I would not trust any application that would ask for the pin of my SIM card.

Categories

Resources