Check if Sim Card is installed

Asked

Viewed 87 times

0

Hello,

I wonder if it is possible to check if the sim card on the device is installed on Android.

1 answer

2


A quick consultation in the documentation reveals the function TelephonyManager.getSimState(). Can be used like this:

final TelephonyManager telephony = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
if (telephony.getSimState() == TelephonyManager.SIM_STATE_READY) {
    // ...
}

The value returned is one of the following:

SIM_STATE_UNKNOWN // Em transição entre dois estados
SIM_STATE_ABSENT
SIM_STATE_PIN_REQUIRED
SIM_STATE_PUK_REQUIRED
SIM_STATE_NETWORK_LOCKED
SIM_STATE_READY

You can even set a callback to notify that the SIM situation changes:

telephony.listen(new PhoneStateListener() {
    @Override
    public void onServiceStateChanged(ServiceState serviceState) {
        // Verifique aqui a situação do SIM
    }
});
  • 2

    It is worth believing that some Telephonymanager states are also applied with the SIM Card inserted in the device (SIM_STATE_NETWORK_LOCKED and others), I think only the SIM_STATE_ABSENT and the SIM_STATE_UNKNOWN may mean that the SIM card is not present. And still worth remembering that there may be devices with 2 Slot’s, and this method only returns the state of the first Slot.

  • Worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.