How to access event when sim card is changed in mobile?
Basically, the answer to this question "How to monitor SIM state change" is the correct answer to your question as well.
So you create a new class
package a.b.c;
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's 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 contain
<!-- put this where your other permissions are: -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- and -->
<application
android:name="a.b.c...."
... >
<!-- put this somewhere into your application section: -->
<receiver android:name="a.b.c.SimChangedReceiver">
<intent-filter>
<action android:name="android.intent.action.SIM_STATE_CHANGED"/>
</intent-filter>
</receiver>
</application>
As usual on Android there no guarantees it works on any version nor on any manufacturer's devices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With