This is the another option to handle all situation:
public void isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
} else {
Toast.makeText(ctx, "Internet Connection Is Required", Toast.LENGTH_LONG).show();
}
}