How to capture event of removal of SIM card in android? - 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).

Related

How long does a Subscription ID stick around in 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.

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 detect which sim card is in use

I am new to android and am making an app to send messages programmatic-ally . Since, I couldn't find a way to detect which SIM is used to send an SMS or that Dual SIM wasn't supported or applicable, my question is:
Is there a way to block a SIM Card in one's android phone? By "block" I mean, SIM_STATUS is returned to false by some means without actually removing the SIM from the SIM slot? Like, it stays there but is not ready to be used. Also, can i do the opposite?
And all this programmatic-ally without doing anything to the phone on manual basis.
By default android does not supported dual SIM. but
if u set default SIM for sms from android setting . your application will always send SMS from your default SIM

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.

sim card with disabled TS11 (Tele Service: Telephony) drains battery

I have a sim card with disabled TS11 (Tele Service: Telephony), im using this card only for data connection. My question is: it is possible to disalble TS11 service on android? Because when this sim card is in use, my phone thinks that there is no service and trying to find network wchich causes battery drain. Is there any solution for this problem?
This is a known problem with data-only SIM cards. To fix this, you'll need a rooted phone (or a phone with ability to pull/push files from /system partition). Also, you should save a backup of your framework.jar, because your phone might not work well with voice/data SIM cards after this modification. But, if you push original framework.jar back to your phone, everything will be restored.
The modification changes phone status to IN_SERVICE even when it's not connected to the network, so the phone stops searching for networks. Here are the details, however I don't recommend using batch file and prefer to to all modifications manually, it's safer that way.

Categories

Resources