title: unable to connect SSID from scan result - Android
body: <p>I have used WifiManager to scan the available wifi using, </p>
  
  <pre><code>mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
          mainWifi.startScan();
  </code></pre>
  
  <p>I can get list of networks. </p>
  
  <p>but when I try to connect to Speecific wifi SSID  <code>String hotspot="some_wifi_name";</code> in this case, It add the hotspot to WifiConfig but after that it goes in Infinite loop while connecting and again scans the result, an loop goes on. </p>
  
  <p>Following is <code>Broadcast Receiver</code> I used for connecting thi my SSID,</p>
  
  <pre><code>class WifiReceiver extends BroadcastReceiver {
  
      ArrayList&lt;String&gt; connections = new ArrayList&lt;String&gt;();
      WifiConfiguration conf;
  
      public void onReceive(Context c, Intent intent) {
  
          WifiManager wifiManager = (WifiManager) c
                  .getSystemService(Context.WIFI_SERVICE);
  
          List&lt;ScanResult&gt; wifiList;
          wifiList = mainWifi.getScanResults();
          for (int i = 0; i &lt; wifiList.size(); i++) {
  
              String ssid = wifiList.get(i).SSID;
              int rssi = wifiList.get(i).level;
              Log.d("SSID: ", "" + wifiList.get(i).SSID.toString()
                      + " signal: " + rssi);
  
              if (ssid != null &amp;&amp; ssid.equals(hotspot)) {
                  Log.d("SSID Hotspot: ",
                          "" + wifiList.get(i).SSID.toString());
                  conf = new WifiConfiguration();
                  conf.SSID = "\"" + hotspot + "\"";
                  conf.allowedKeyManagement
                          .set(WifiConfiguration.KeyMgmt.NONE);
                  wifiManager.addNetwork(conf);
              }
          }
  
          List&lt;WifiConfiguration&gt; list = wifiManager.getConfiguredNetworks();
  
          loops:
          for (WifiConfiguration j : list) {
  
  
              if (j.SSID != null &amp;&amp; j.SSID.equals("\"" + hotspot + "\"")) {
                  Log.d("Config", "" + j.SSID);
                  wifiManager.disconnect();
                  wifiManager.enableNetwork(j.networkId, true);
  
                  wifiManager.reconnect();
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Why It is scanning the wifi again after getting desired SSID and goes in the Infinite Loop, where is the wrong thing . </p>