Ответ 1
В принципе, ответ на этот вопрос "Как отслеживать изменение состояния SIM" является правильным ответом на ваш вопрос.
Итак, вы создаете новый класс
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 extras contains a key "ss" with value "LOADED".
// But it is more secure to just always check if there was a change.
}
}
и адаптируйте свой AndroidManifest.xml для размещения
<!-- 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>
Как обычно на Android нет гарантий, что он работает ни на какой версии, ни на каких-либо производителях.