code: public static boolean isNetworkAvailable(Context context) {
          ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
          return activeNetworkInfo != null && activeNetworkInfo.isConnected();
      }
docs: Checks to see if the device is connected to a network (cell, wifi, etc).
  
  @param context The current Context or Activity that this method is called from
  @return true if a network connection is available, otherwise false.