title: Weird behavior when trying to detect when Wifi network connected android
body: <p>I am currently trying to do a relatively simple task in Android. </p>
  
  <p>I want to detect when a wireless network is fully connected. At this moment I do not care whether there is internet connection, I just want to know the exact moment when my device is considered connected to network. </p>
  
  <p>I will try to describe what I did, and how miserably had I failed. </p>
  
  <p>Bare in mind that I have tried official recommendations as well as some answers here but to no avail. </p>
  
  <p>Activity registers receiver:</p>
  
  <pre><code>IntentFilter intentFilter = new IntentFilter();
  intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
  registerReceiver(ReceiverClass,intentFilter);
  </code></pre>
  
  <p>In my receiver I  have tried stuff from <a href="https://stackoverflow.com/a/22626736/2093954">this</a> answer</p>
  
  <pre><code> NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    if(info != null) {
       if(info.isConnected()) {
          // Do your work
          Log.d("tag", "connected");
       }
    }
  </code></pre>
  
  <p>But my app is not working as expected. When I kill Wifi (swipe from top and turn it off) I receive a broadcast (obviously) but both of my If's go trough and I get this logged! 
  After I turn on wifi I get 2 more logs that everything is connected. I have tried a thing or two like this</p>
  
  <pre><code>WifiInfo wi =  intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
  
  if(wi != null) {
      SupplicantState ss = wi.getSupplicantState();
      Log.d("I am desperate", ss.equals(SupplicantState.COMPLETED));
      }
  }
  </code></pre>
  
  <p>but the same stuff happens. I get true 3 times. </p>
  
  <p>I am not an expert in android, I believe I am missing something quite obvious. Any help for me?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am more an more considering the possibility that this is an issue in Android system. At the moment I stopped trying to get informations from Intent. </p>
  
  <p>I have tried to use <a href="http://developer.android.com/reference/android/net/wifi/WifiManager.html#EXTRA_WIFI_STATE" rel="nofollow noreferrer">EXTRA_WIFI_STATE</a> but the command:</p>
  
  <pre><code>Log.d("WifiState" getIntExtra(WifiManager.EXTRA_WIFI_STATE, -9000));
  </code></pre>
  
  <p>Logs me always the default (-9000) for every single broadcast I receive. </p>
  
  <p>If I try to <a href="http://developer.android.com/reference/android/net/wifi/WifiManager.html#SUPPLICANT_CONNECTION_CHANGE_ACTION" rel="nofollow noreferrer">SUPPLICANT_CONNECTION_CHANGE_ACTION</a> broadcast - that is never even caught. I am really puzzled here...</p>