I am using the following function to check network connectivity but application crashes when wifi status is swapped
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connec = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connec.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected() == true) {
return true;
}
return false;
}