code: public static boolean isNetworkAvailable(Context context) {
          ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo info = manager.getActiveNetworkInfo();
          return info != null && info.isAvailable();
      }
docs: Checks if the network is available or not.
  This is not guarantee that the network is connected and can communicate through the network.
  @param context the context.
  @return true if the network is available.