code: public static boolean isOnline(Context context) {
      ConnectivityManager cm =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (cm == null) {
        return false;
      }
      NetworkInfo info = cm.getActiveNetworkInfo();
      return info != null && info.isConnectedOrConnecting();
    }
docs: Checks whether there's a network connection.
  
  @param context Context to use
  @return true if there's an active network connection, false otherwise