The event when the SIM card is changed

How to access the event when the SIM card is changed on the mobile device?

+13
source share
4 answers

Basically, the answer to this question " How to track the change in SIM status " is the correct answer to your question.

So you create a new class

package abc; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class SimChangedReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { Log.d("SimChangedReceiver", "--> SIM state changed <--"); // Most likely, checking if the SIM changed could be limited to // events where the intent extras contains a key "ss" with value "LOADED". // But it is more secure to just always check if there was a change. } } 

and adapt your AndroidManifest.xml to accommodate

 <!-- put this where your other permissions are: --> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- and --> <application android:name="abc..." ... > <!-- put this somewhere into your application section: --> <receiver android:name="abcSimChangedReceiver"> <intent-filter> <action android:name="android.intent.action.SIM_STATE_CHANGED"/> </intent-filter> </receiver> </application> 

As usual on Android, there are no guarantees that it works on any version or on any manufacturers.

+13
source

I don’t know about the event, but the phone will be turned off and on when the SIM card is replaced, so you can create a service that stores the serial number of the SIM card in the settings, and then compare the serial number stored with that in the current SIM card when the service starts.

Here is information on accessing SIM card data: Accessing a SIM card using the Android app?

+8
source

Save the saved SIM card identifier and every time the phone switches from AirplaneModeON to AirplaneModeOFF, check if the new SIM card identifier matches the one saved earlier.

Check this answer to find out how to determine your flight mode.

Hope this answers your question.

+7
source

You must register a BroadcastReceiver in order to receive the android.intent.action.SIM_STATE_CHANGED action.

This action is included in com.android.internal.telephony.TelephonyIntents.java and cannot be found in the Android documentation. When you received it (for example, connected a SIM card), add Sim State with the ss key.

+3
source

All Articles