The following code: (commented out will return 1 of the code, not annotated is able to connect to the WiFi code)
//Public wificonfiguration Createwifiinfo (String SSID, String Password,int Type) {//wificonfiguration config = new wificonfiguration ();//config.allowedAuthAlgorithms.clear ();//config.allowedGroupCiphers.clear ();//config.allowedKeyManagement.clear ();//config.allowedPairwiseCiphers.clear ();//config.allowedProtocols.clear ();////CONFIG. SSID = "\" "+ SSID +" \ ";//CONFIG. SSID = SSID;////wificonfiguration tempconfig = this. Isexsits (SSID);//if (tempconfig! = null) {//mwifimanager.removenetwork (tempconfig.networkid);// }////if (Type = = 1)//Wificipher_nopass// {//Config.wepkeys[0] = "";//Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE);//config.weptxkeyindex = 0;// }//if (Type = = 2)//WIFICIPHER_WEP// {//Config.hiddenssid = true;////config.wepkeys[0] = "\" "+ Password +" \ "";//config.wepkeys[0] = Password;//Config.allowedAuthAlgorithms.set (WifiConfiguration.AuthAlgorithm.SHARED);//Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP);//Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.TKIP);//Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.WEP40);//Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.WEP104);//Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE);//config.weptxkeyindex = 0;// }//if (Type = = 3)//WIFICIPHER_WPA// {////Config.presharedkey = "\" "+ Password +" \ "";//Config.presharedkey =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.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP);//Config.allowedPairwiseCiphers.set (WifiConfiguration.PairwiseCipher.CCMP);//config.status = WifiConfiguration.Status.ENABLED;// }//return config;// } Publicwificonfiguration createwifiinfo (String SSID, String Password,intType) {wificonfiguration config=Newwificonfiguration (); Config.allowedAuthAlgorithms.clear (); Config.allowedGroupCiphers.clear (); Config.allowedKeyManagement.clear (); Config.allowedPairwiseCiphers.clear (); Config.allowedProtocols.clear (); Config. SSID= "\" "+ SSID +" \ ""; Wificonfiguration Tempconfig= This. Isexsits (SSID); if(Tempconfig! =NULL) {mwifimanager.removenetwork (tempconfig.networkid); } if(Type = = 1)//Wificipher_nopass{config.wepkeys[0] = ""; Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE); Config.weptxkeyindex= 0; } if(Type = = 2)//WIFICIPHER_WEP{Config.hiddenssid=true; config.wepkeys[0] = "\" "+ Password +" \ ""; Config.allowedAuthAlgorithms.set (WifiConfiguration.AuthAlgorithm.SHARED); Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP); Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.TKIP); Config.allowedGroupCiphers.set (WIFICONFIGURATION.GROUPCIPHER.WEP40); Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.WEP104); Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE); Config.weptxkeyindex= 0; } if(Type = = 3)//WIFICIPHER_WPA{Config.presharedkey= "\" "+ 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.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP); Config.allowedPairwiseCiphers.set (WifiConfiguration.PairwiseCipher.CCMP); Config.status=WifiConfiguration.Status.ENABLED; } returnconfig; }
If you know why the SSID and PWD need double quotes, please add a comment below, thanks!
Android Development Connect WiFi addnetwork return-1