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