title: WI-FI is on but not connected to network
body: <p>I am developing an android app which requires to check internet connection.When the WI-FI of the device is off it works perfectly fine but when I turn on the Wi-Fi but do not connect to the available network,it is force closing.What could be the problem?Please Help
  boolean isNetworkConnectionAvailable() {  </p>
  
  <pre><code>  boolean connected = false;
  
      ConnectivityManager cm =(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  
      if (cm != null) {
          NetworkInfo ni = cm.getActiveNetworkInfo();
  
          if(ni != null){
  
                  if(ni.isConnected())
                  connected = true;
                  else
                      connected=false;
  
             }
  
      }
  
  
  
      return connected;
  </code></pre>
  
  <p>} </p>