Connect WiFi Tool Class

Source: Internet
Author: User

1  Public classWificonnect {2 3 Wifimanager Wifimanager;4 5     //constructor Function6      PublicWificonnect (Wifimanager wifimanager) {7          This. Wifimanager =Wifimanager;8     }9 Ten     //provides an external interface for incoming wireless networks to be connected One      Public BooleanConnect (String SSID, String Password,intType) { A  -Wificonfiguration Wificonfig = This -                 . Createwifiinfo (SSID, Password, Type); the  -Wificonfiguration Tempconfig = This. Isexsits (SSID); -         if(Tempconfig! =NULL) { - wifimanager.removenetwork (tempconfig.networkid); +         } -  +         intNetID =wifimanager.addnetwork (wificonfig); A         BooleanFlag = Wifimanager.enablenetwork (NetID,true); at         returnFlag; -     } -  -     //See if you have previously configured this network -     Privatewificonfiguration isexsits (String SSID) { -List<wificonfiguration> Existingconfigs =Wifimanager in . Getconfigurednetworks (); -          for(wificonfiguration existingconfig:existingconfigs) { to             if(ExistingConfig.SSID.equals ("\" + SSID + "\" ")) { +                 returnExistingconfig; -             } the         } *         return NULL; $     }Panax Notoginseng  -     //Configure Wificonfiguration the      Publicwificonfiguration createwifiinfo (String SSID, String Password, +             intType) { Awificonfiguration config =Newwificonfiguration (); the config.allowedAuthAlgorithms.clear (); + config.allowedGroupCiphers.clear (); - config.allowedKeyManagement.clear (); $ config.allowedPairwiseCiphers.clear (); $ config.allowedProtocols.clear (); -Config. SSID = "\" "+ SSID +" \ ""; -  theWificonfiguration Tempconfig = This. Isexsits (SSID); -         if(Tempconfig! =NULL) {Wuyi wifimanager.removenetwork (tempconfig.networkid); the         } -  Wu         if(Type = = 1)//Wificipher_nopass -         { AboutConfig.wepkeys[0] = ""; $ Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE); -Config.weptxkeyindex = 0; -         } -         if(Type = = 2)//WIFICIPHER_WEP A         { +Config.hiddenssid =true; theConfig.wepkeys[0] = "\" "+ Password +" \ ""; - config.allowedauthalgorithms $ . Set (WifiConfiguration.AuthAlgorithm.SHARED); the Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP); the Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.TKIP); the Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.WEP40); the config.allowedgroupciphers - . Set (WifiConfiguration.GroupCipher.WEP104); in Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.NONE); theConfig.weptxkeyindex = 0; the         } About         if(Type = = 3)//WIFICIPHER_WPA the         { theConfig.presharedkey = "\" "+ Password +" \ ""; theConfig.hiddenssid =true; + config.allowedauthalgorithms - . Set (WifiConfiguration.AuthAlgorithm.OPEN); the Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.TKIP);Bayi Config.allowedKeyManagement.set (WifiConfiguration.KeyMgmt.WPA_PSK); the config.allowedpairwiseciphers the . Set (WifiConfiguration.PairwiseCipher.TKIP); -             //Config.allowedProtocols.set (WifiConfiguration.Protocol.WPA); - Config.allowedGroupCiphers.set (WifiConfiguration.GroupCipher.CCMP); the config.allowedpairwiseciphers the . Set (WifiConfiguration.PairwiseCipher.CCMP); theConfig.status =WifiConfiguration.Status.ENABLED; the         } -         returnconfig; the     } the  the}

Connect WiFi Tool Class

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.