title: How do I see if Wi-Fi is connected on Android?
body: <p>I don't want my user to even try downloading something unless they have Wi-Fi connected. However, I can only seem to be able to tell if Wi-Fi is enabled, but they could still have a 3G connection.</p>
  
  <pre><code>android.net.wifi.WifiManager m = (WifiManager) getSystemService(WIFI_SERVICE);
  android.net.wifi.SupplicantState s = m.getConnectionInfo().getSupplicantState();
  NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(s);
  if (state != NetworkInfo.DetailedState.CONNECTED) {
      return false;
  }
  </code></pre>
  
  <p>However, the state is not what I would expect. Even though Wi-Fi is connected, I am getting <code>OBTAINING_IPADDR</code> as the state.</p>