title: How to know if i am successfully connected to a WiFi Network?
body: <p>I want to enable the user to connect to WiFi networks through my app, the connecting goes properly when the user manages to enter the correct WiFi password, but when he enters a wrong WiFi password, <strong>Two</strong> unwelcomed issues appear:</p>
  
  <ol>
  <li>The app receives that it's now connected to that WiFi Network although the connection doesn't completed successfully due to wrong password.</li>
  <li>making it thinks that the connection happened, leading it to disconnect from the already successfully connected network, and then the user loses WiFi connection.</li>
  </ol>
  
  <p>I'm detecting the WiFi connections changing using a <code>BroadcastReceiver</code> with the following <code>manifest</code> description:</p>
  
  <pre><code>    &lt;receiver android:name="com.automation.standards.WifiReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>And dealing with the changes the following way :</p>
  
  <pre><code>WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
  
  if(wifiMgr.isWifiEnabled()){
          Toast.makeText(mContext, "wifi is enabled", Toast.LENGTH_LONG).show();
    }
  
  WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
  String connected_net = (wifiInfo.getSSID()).toString(); // Here I'm getting the failed-in-connection WiFi Net
  </code></pre>
  
  <p>and about how to connect to a WiFi network when the user presses connect and enters a password:</p>
  
  <pre><code>final WifiManager wifiManager = (WifiManager)(mContext).getSystemService(Context.WIFI_SERVICE);
  wifiManager.addNetwork(conf); // Adding the Network Configuration to the WifiManager
  wifiManager.disconnect();
  wifiManager.enableNetwork(conf.networkId, true);
  wifiManager.reconnect();
  wifiManager.saveConfiguration();
  </code></pre>