}
}
/*连接到热点*/
public void connectToHotpot(){
if(passableHotsPot==null || passableHotsPot.size()==0)
return;
WifiConfiguration wifiConfig=this.setWifiParams(passableHotsPot.get(0));
int wcgID = wifiManager.addNetwork(wifiConfig);
boolean flag=wifiManager.enableNetwork(wcgID, true);
isConnected=flag;
System.out.println("connect success? "+flag);
}
/*设置要连接的热点的参数*/
public WifiConfiguration setWifiParams(String ssid){
WifiConfiguration apConfig=new WifiConfiguration();
apConfig.SSID="""+ssid+""";
apConfig.preSharedKey=""12122112"";
apConfig.hiddenSSID = true;
apConfig.status = WifiConfiguration.Status.ENABLED;
apConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
apConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
apConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
apConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
apConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
apConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
return apConfig;
}
@Override
protected void onDestroy() {
super.onDestroy();
/*销毁时注销广播*/
unregisterReceiver(wifiReceiver);
}
}