Android Development Connect WiFi addnetwork return-1

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.