判断sim卡跟网络状态代码以及回收资源

判断sim卡和网络状态代码以及回收资源
ConnectivityManager mConManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (mConManager.getActiveNetworkInfo() != null) {  
            if (!mConManager.getActiveNetworkInfo().isAvailable()) {  
                 //添加代码
            }  
            ;  
        }else {  
            //添加代码 
        }  需要权限 android.permission.ACCESS_NETWORK_STATE
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
if(tm.getSimState()!=tm.SIM_STATE_READY)
{
Toast.makeText(this, "Sim卡未插入或者异常", Toast.LENGTH_SHORT).show();
//添加代码
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
关闭回收所有资源:
ActivityManager am = (ActivityManager)getSystemService  (Context.ACTIVITY_SERVICE);  

            am.restartPackage(getPackageName());
需要权限 android.permission.RESTART_PACKAGES