code: public static boolean isAvailable(Context context) {
          boolean connected = false;
          ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          if (cm != null) {
              NetworkInfo ni = cm.getActiveNetworkInfo();
              if (ni != null) {
                  connected = ni.isConnected();
              }
          }
          return connected;
      }
docs: Check if a network is available