Sajal Ali
Sajal Ali

Reputation: 437

Detect when new sim is inserted in device

In my Android application I want to detect if a new sim is inserted (any sim other than the previous sim) in the device.

How can I do that?

Upvotes: 1

Views: 2599

Answers (1)

Tiago Dávila
Tiago Dávila

Reputation: 372

You can listen to: android.intent.action.SIM_STATE_CHANGED

This broadcast will trigger everytime user inserts a SIM card. You have to handle things as the way you wanted with given extras:

Intent: android.intent.action.SIM_STATE_CHANGED with extras: ss = LOCKED, reason = PIN Intent: android.intent.action.SIM_STATE_CHANGED with extras: ss = READY, reason = null Intent: android.intent.action.SIM_STATE_CHANGED with extras: ss = IMSI, reason = null Intent: android.intent.action.SIM_STATE_CHANGED with extras: ss = LOADED, reason = null

And then discover if sim card is new checking if TelephonyManager.getSubscriberId(). SubId means the entry that SIM card had by the time it was first inserted on a given device.

Hope it helps.

Upvotes: 2

Related Questions