Wifimanager = (wifimanager) getsystemservice (context. wifi_service); Boolean bret1 = wifimanager. setwifienabled (true); // Add network if (wifimanager. startscan () // scan for available wireless networks {list <scanresult> scanresultlist = wifimanager. getscanresults (); For (INT I = 0; I <scanresultlist. size (); I ++) {scanresult scanret = scanresultlist. get (I); If (scanret. SSID. equalsignorecase ("test") // find test {wificonfiguration Config = new wificonfiguration (); config. SSID = "\" "+ scanret. SSID + "\" "; config. presharedkey = "\" password \ ""; // specify the password config. hiddenssid = true; config. allowedauthalgorithms. set (wificonfiguration. authalgorithm. open); config. allowedgroupciphers. set (wificonfiguration. groupcipher. TKIP); config. allowedkeymanagement. set (wificonfiguration. keymgmt. wpa_psk); config. allowedpairwiseciphers. set (wificonfiguration. pairwisecipher. TKIP); config. allowedprotocols. set (wificonfiguration. protocol. WPA); config. status = wificonfiguration. status. enabled; int netid = wifimanager. addnetwork (config); log. D ("wifipreference", "add network returned" + netid); Boolean Bret = wifimanager. enablenetwork (netid, true); log. D ("wifipreference", "enablenetwork returned" + BRET );}}}