I have an app in which I have to check whether sim card is inserted in device or not and make some condition if sim is not inserted then show dialog else do something ,how can I do that
Asked
Active
Viewed 865 times
2 Answers
3
Below function returns true if sim is present.
public static boolean isSimSupport(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); //gets the current TelephonyManager
return !(tm.getSimState() == TelephonyManager.SIM_STATE_ABSENT);
}

Rudresh
- 731
- 1
- 10
- 26
0
You can use TelephonyManager API. this API provides access to information about the telephony services on the device.
for reference : https://developer.android.com/reference/android/telephony/TelephonyManager.html
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int simState = manager.getSimState();
switch (simState) {
case TelephonyManager.SIM_STATE_ABSENT:
// do something
break;
case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
// do something
break;
case TelephonyManager.SIM_STATE_PIN_REQUIRED:
// do something
break;
case TelephonyManager.SIM_STATE_PUK_REQUIRED:
// do something
break;
case TelephonyManager.SIM_STATE_READY:
// do something
break;
case TelephonyManager.SIM_STATE_UNKNOWN:
// do something
break;
}

ErShani
- 392
- 2
- 9