Monday 22 December 2014

Check SIM card availability in Android.


 
Sometimes, It is necessary to check the availability of Network service in Android. Here is the code.

TelephonyManager telephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

int simState = telephonyManager.getSimState();
switch (simState) {

    case TelephonyManager.SIM_STATE_ABSENT:
       Toast.makeText(context, "SIM Card Not Available., Toast.LENGTH_SHORT).show();
       break;
     case TelephonyManager.SIM_STATE_READY:
       Toast.makeText(context, "SIM Card Available.", Toast.LENGTH_SHORT).show();

}

No comments:

Post a Comment